From: notaz Date: Tue, 9 Jul 2013 00:05:02 +0000 (+0300) Subject: 32x: a hack for dealing with pwm inaccuracy X-Git-Tag: v1.85~59 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc3aea8e705ec38bdeca7f31fa069c37dd7217d3;p=picodrive.git 32x: a hack for dealing with pwm inaccuracy --- diff --git a/pico/32x/pwm.c b/pico/32x/pwm.c index 3adbf211..e3385aad 100644 --- a/pico/32x/pwm.c +++ b/pico/32x/pwm.c @@ -52,10 +52,15 @@ void p32x_timers_do(unsigned int cycles) cycles *= 3; - pwm_cycle_counter += cycles; - while (pwm_cycle_counter > pwm_cycles) { - pwm_cycle_counter -= pwm_cycles; - pwm_smp_expect++; + // since we run things in async fashion, allow pwm to lag behind + // but don't allow our "queue" to be infinite + cnt = pwm_smp_expect - pwm_smp_cnt; + if (cnt <= 0 || cnt * pwm_cycles < OSC_NTSC/7*3 / 60 / 2) { + pwm_cycle_counter += cycles; + while (pwm_cycle_counter > pwm_cycles) { + pwm_cycle_counter -= pwm_cycles; + pwm_smp_expect++; + } } // WDT timers