diff --git a/firmware/main.c b/firmware/main.c index d7c11b0..3cc9ab8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -90,13 +90,14 @@ uint16_t burst[PULSE_MAX]; /* pulse times forming a burst (from timer) */ /* channel variables */ #define LEVELS 10 /* the number of PWM levels */ -volatile uint8_t ch_tick = 0; /* the tick counter for the channel PWM */ +volatile uint8_t ch_tick = 0; /* to tick for the channel PWM */ +uint8_t on[CHANNELS_1+CHANNELS_2]; /* at which tick turn the channel on */ +uint8_t off[CHANNELS_1+CHANNELS_2]; /* at which tick turn the channel off */ /* flags, set in the interrupts and handled in the main program */ volatile bool uart_flag = false; /* an incoming activity on the UART */ volatile bool power_flag = false; /* a change in the power or fan */ volatile bool ir_flag = false; /* to process a burst */ -volatile bool pwm_flag = false; /* to trigger a PWM tick */ volatile bool channel_flag = false; /* indicate a change in the channel PWM values */ volatile bool learn_flag = false; /* learn an IR command for an action */ enum IR_ACTIONS to_learn = IR_ACTION_END; /* IR action to learn */ @@ -163,8 +164,23 @@ ISR(TIMER1_COMPA_vect) { /* timer 1 OCR1A match interrupt vector */ /* timer 0 interrupt used generate a PWM for the channels */ ISR(TIMER0_COMPA_vect) { /* timer 0 OCR0A match interrupt vector */ - ch_tick = (ch_tick+1)%LEVELS; - pwm_flag = true; + ch_tick++; + if (pwr_ok) { + for (int i=0; i