aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-ramping.c
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster/fsm-ramping.c')
-rw-r--r--spaghetti-monster/fsm-ramping.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index abbfbde..1667c00 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -70,7 +70,7 @@ void set_level(uint8_t level) {
set_level_override(level);
#else
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_ON) || defined(PWM1_PHASE_SYNC)
static uint8_t prev_level = 0;
uint8_t api_level = level;
#endif
@@ -93,6 +93,20 @@ void set_level(uint8_t level) {
TINT1_LVL = 0;
TINT2_LVL = 0;
#endif
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_OFF)
+ PWM1_CNT = 0;
+ #endif
+ #if defined(PWM2_CNT) && defined(PWM2_PHASE_RESET_OFF)
+ PWM2_CNT = 0;
+ #endif
+ #if defined(PWM3_CNT) && defined(PWM3_PHASE_RESET_OFF)
+ PWM3_CNT = 0;
+ #endif
+ #ifdef LED_OFF_DELAY
+ // for drivers with a slow regulator chip (eg, boost converter),
+ // delay before turning off to prevent flashes
+ delay_4ms(LED_OFF_DELAY/4);
+ #endif
// disable the power channel, if relevant
#ifdef LED_ENABLE_PIN
LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
@@ -104,6 +118,10 @@ void set_level(uint8_t level) {
// enable the power channel, if relevant
#ifndef USE_TINT_RAMPING // update_tint handles this better
#ifdef LED_ENABLE_PIN
+ #ifdef LED_ON_DELAY
+ uint8_t led_enable_port_save = LED_ENABLE_PORT;
+ #endif
+
#ifndef LED_ENABLE_PIN_LEVEL_MIN
LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN);
#else
@@ -114,9 +132,29 @@ void set_level(uint8_t level) {
else // disable during other parts of the ramp
LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
#endif
+
+ // for drivers with a slow regulator chip (eg, boost converter),
+ // delay before lighting up to prevent flashes
+ #ifdef LED_ON_DELAY
+ // only delay if the pin status changed
+ if (LED_ENABLE_PORT != led_enable_port_save)
+ delay_4ms(LED_ON_DELAY/4);
+ #endif
#endif
#ifdef LED2_ENABLE_PIN
- LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN);
+ #ifdef LED2_ON_DELAY
+ uint8_t led2_enable_port_save = LED2_ENABLE_PORT;
+ #endif
+
+ LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN);
+
+ // for drivers with a slow regulator chip (eg, boost converter),
+ // delay before lighting up to prevent flashes
+ #ifdef LED2_ON_DELAY
+ // only delay if the pin status changed
+ if (LED2_ENABLE_PORT != led2_enable_port_save)
+ delay_4ms(LED2_ON_DELAY/4);
+ #endif
#endif
#endif // ifndef USE_TINT_RAMPING
@@ -138,7 +176,7 @@ void set_level(uint8_t level) {
#ifdef USE_DYN_PWM
uint16_t top = PWM_GET(pwm_tops, level);
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_SYNC)
// wait to ensure compare match won't be missed
// (causes visible flickering when missed, because the counter
// goes all the way to 65535 before returning)
@@ -154,27 +192,27 @@ void set_level(uint8_t level) {
// repeat for other channels if necessary
#ifdef PMW2_TOP
- #ifdef PWM2_CNT
+ #if defined(PWM2_CNT) && defined(PWM2_PHASE_SYNC)
while(prev_level && (PWM2_CNT > (top - 32))) {}
#endif
PWM2_TOP = top;
#endif
#ifdef PMW3_TOP
- #ifdef PWM3_CNT
+ #if defined(PWM3_CNT) && defined(PWM3_PHASE_SYNC)
while(prev_level && (PWM3_CNT > (top - 32))) {}
#endif
PWM3_TOP = top;
#endif
#endif // ifdef USE_DYN_PWM
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_ON)
// force reset phase when turning on from zero
// (because otherwise the initial response is inconsistent)
if (! prev_level) {
PWM1_CNT = 0;
- #ifdef PWM2_CNT
+ #if defined(PWM2_CNT) && defined(PWM2_PHASE_RESET_ON)
PWM2_CNT = 0;
#endif
- #ifdef PWM3_CNT
+ #if defined(PWM3_CNT) && defined(PWM3_PHASE_RESET_ON)
PWM3_CNT = 0;
#endif
}
@@ -184,7 +222,7 @@ void set_level(uint8_t level) {
update_tint();
#endif
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_ON) || defined(PWM1_PHASE_SYNC)
prev_level = api_level;
#endif
#endif // ifdef OVERRIDE_SET_LEVEL