examples: Fix frequency of ac_input signal
authorJakob Gruber <jakob.gruber@gmail.com>
Thu, 19 Jul 2012 22:10:39 +0000 (00:10 +0200)
committerJakob Gruber <jakob.gruber@gmail.com>
Thu, 19 Jul 2012 22:10:39 +0000 (00:10 +0200)
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

index 75d0718..2262c3e 100644 (file)
@@ -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));
 }