From bdc953feff23f71a7641c0e5e09036c808a833fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 19 Oct 2013 22:17:59 +0200 Subject: [PATCH] channel PWM reimplemeted --- firmware/main.c | 58 ++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) 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