~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to JonnyC/STAR/STAR_off_time/STAR_off_time.c

  • Committer: Selene Scriven
  • Date: 2015-01-24 06:12:28 UTC
  • mto: This revision was merged to the branch mainline in revision 101.
  • Revision ID: ubuntu@toykeeper.net-20150124061228-2bbcb4gnpk5lcfnc
JCapSolutions   2014-11-15
git commit: b68e06325a55862d29de8bf616556a9d08ecdcae
Added compile option to gradually ramp down for the turbo instead of the standard step down

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * 1.0 Initial version
6
6
 * 1.1 Bug fix
7
7
 * 1.2 Added support for dual PWM outputs and selection of PWM mode per output level
 
8
 * 1.3 Added ability to have turbo ramp down gradually instead of step down
8
9
 *
9
10
 */
10
11
 
63
64
 * Settings to modify per driver
64
65
 */
65
66
 
66
 
#define VOLTAGE_MON                     // Comment out to disable
 
67
//#define VOLTAGE_MON                   // Comment out to disable
67
68
 
68
69
#define MEMORY                          // Comment out to disable
69
70
 
 
71
#define TICKS_250MS                     // If enabled, ticks are every 250 ms. If disabled, ticks are every 500 ms
 
72
                                                        // Affects turbo timeout/rampdown timing
 
73
 
70
74
// Levels should start around 10 with Fast PWM
71
75
 
72
76
#define MODE_MOON                       3       // Can comment out to remove mode, but should be set through soldering stars
73
77
#define MODE_LOW                        14  // Can comment out to remove mode
74
78
#define MODE_MED                        39      // Can comment out to remove mode
75
 
#define MODE_HIGH_W_TURBO       110     // MODE_HIGH value when turbo is enabled
76
 
#define MODE_HIGH                       255     // Can comment out to remove mode
 
79
//#define MODE_HIGH                     255     // Can comment out to remove mode
77
80
#define MODE_TURBO                      255     // Can comment out to remove mode
78
 
#define TURBO_TIMEOUT           240 // How many WTD ticks before before dropping down (.5 sec each)
 
81
#define MODE_TURBO_LOW          140     // Level turbo ramps down to if turbo enabled
 
82
#define TURBO_TIMEOUT           240 // How many WTD ticks before before dropping down
 
83
#define TURBO_RAMP_DOWN                 // By default we will start to gradually ramp down, once TURBO_TIMEOUT ticks are reached, 1 PWM_LVL each tick until reaching MODE_TURBO_LOW PWM_LVL
 
84
                                                                // If commented out, we will step down to MODE_TURBO_LOW once TURBO_TIMEOUT ticks are reached
79
85
 
80
86
#define FAST_PWM_START      8 // Above what output level should we switch from phase correct to fast-PWM?
81
87
#define DUAL_PWM_START          8 // Above what output level should we switch from the alternate PWM output to both PWM outputs?  Comment out to disable alternate PWM output
91
97
 * =========================================================================
92
98
 */
93
99
 
94
 
#ifdef MODE_TURBO
95
 
#undef  MODE_HIGH
96
 
#define MODE_HIGH       MODE_HIGH_W_TURBO
97
 
#endif
98
 
 
99
100
//#include <avr/pgmspace.h>
100
101
#include <avr/io.h>
101
102
#include <util/delay.h>
200
201
}
201
202
 
202
203
inline void WDT_on() {
203
 
        // Setup watchdog timer to only interrupt, not reset, every 500ms.
 
204
        // Setup watchdog timer to only interrupt, not reset
204
205
        cli();                                                  // Disable interrupts
205
206
        wdt_reset();                                    // Reset the WDT
206
207
        WDTCR |= (1<<WDCE) | (1<<WDE);  // Start timed sequence
 
208
        #ifdef TICKS_250MS
 
209
        WDTCR = (1<<WDTIE) | (1<<WDP2); // Enable interrupt every 250ms
 
210
        #else
207
211
        WDTCR = (1<<WDTIE) | (1<<WDP2) | (1<<WDP0); // Enable interrupt every 500ms
 
212
        #endif
208
213
        sei();                                                  // Enable interrupts
209
214
}
210
215
 
271
276
        
272
277
#ifdef MODE_TURBO       
273
278
        //if (ticks == TURBO_TIMEOUT && modes[mode_idx] == MODE_TURBO) { // Doesn't make any sense why this doesn't work
274
 
        if (ticks == TURBO_TIMEOUT && mode_idx == (mode_cnt - 1)) {
 
279
        if (ticks >= TURBO_TIMEOUT && mode_idx == (mode_cnt - 1) && PWM_LVL > MODE_TURBO_LOW) {
 
280
                #ifdef TURBO_RAMP_DOWN
 
281
                set_output(PWM_LVL - 1);
 
282
                #else
275
283
                // Turbo mode is always at end
276
 
                set_output(modes[--mode_idx]);
277
 
                store_mode_idx(mode_idx);
 
284
                set_output(MODE_TURBO_LOW);
 
285
                if (MODE_TURBO_LOW <= modes[mode_idx-1]) {
 
286
                        // Dropped at or below the previous mode, so set it to the stored mode
 
287
                        // Kept this as it was the same functionality as before.  For the TURBO_RAMP_DOWN feature
 
288
                        // it doesn't do this logic because I don't know what makes the most sense
 
289
                        store_mode_idx(--mode_idx);
 
290
                }
 
291
                #endif
278
292
        }
279
293
#endif
280
294