From f8bf5cf4bb61ef4b8c01c68dfc3fe826d9e91360 Mon Sep 17 00:00:00 2001 From: Johannes Kroll Date: Mon, 5 Mar 2012 22:37:20 +0100 Subject: pwm loop update --- pwm.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pwm.c b/pwm.c index e981e2d..cf7b854 100644 --- a/pwm.c +++ b/pwm.c @@ -35,21 +35,13 @@ void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b) void pwm_worker_loop(void) { for (;;) { - if (value_red) - PORTA |= (1 << PA0); - if (value_green) - PORTA |= (1 << PA1); - if (value_blue) - PORTA |= (1 << PA2); - - for (uint16_t i = 0; i < 4096; i++) { - if (value_red < i) - PORTA &= ~(1 << PA0); - if (value_green < i) - PORTA &= ~(1 << PA1); - if (value_blue < i) - PORTA &= ~(1 << PA2); - } + for (uint16_t i = 0; i < 4096; i++) { + // this should take about the same time for each iteration, regardless of pulse width + PORTA= (PORTA & ~((1< i? (1< i? (1< i? (1<