From d63e2a190fcc83978ffcead60e2d6db597ed8ecc Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Fri, 20 Jul 2012 00:10:39 +0200 Subject: [PATCH] examples: Fix frequency of ac_input signal The comment in ac_input.h specifies 50 Hz, but it was actually 500 Hz. This off-by-one-zero error probably went unnoticed because of inaccurate sleep handling (which was fixed in the previous commit). --- examples/parts/ac_input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/parts/ac_input.c b/examples/parts/ac_input.c index 75d0718..2262c3e 100644 --- a/examples/parts/ac_input.c +++ b/examples/parts/ac_input.c @@ -25,6 +25,9 @@ #include "sim_time.h" #include "ac_input.h" +#define USECS_PER_SECOND (1000 * 1000) +#define HZ (50) + static avr_cycle_count_t switch_auto( struct avr_t * avr, @@ -34,7 +37,7 @@ switch_auto( ac_input_t * b = (ac_input_t *) param; b->value = !b->value; avr_raise_irq(b->irq + IRQ_AC_OUT, b->value); - return when + avr_usec_to_cycles(avr, 100000 / 50); + return when + avr_usec_to_cycles(avr, USECS_PER_SECOND / HZ); } static const char * name = ">ac_input"; @@ -44,7 +47,8 @@ void ac_input_init(avr_t *avr, ac_input_t *b) b->irq = avr_alloc_irq(&avr->irq_pool, 0, IRQ_AC_COUNT, &name); b->avr = avr; b->value = 0; - avr_cycle_timer_register_usec(avr, 100000 / 50, switch_auto, b); + avr_cycle_timer_register_usec(avr, USECS_PER_SECOND / HZ, switch_auto, b); printf("ac_input_init period %duS or %d cycles\n", - 100000 / 50, (int)avr_usec_to_cycles(avr, 100000 / 50)); + USECS_PER_SECOND / HZ, + (int)avr_usec_to_cycles(avr, USECS_PER_SECOND / HZ)); } -- 2.39.5