diff options
Diffstat (limited to 'src/debug.c')
-rw-r--r-- | src/debug.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..858195e --- /dev/null +++ b/src/debug.c @@ -0,0 +1,31 @@ +#include <avr/io.h> +#include <stdio.h> +#include <util/delay.h> +#include "debug.h" + + + + + +/* + * TCNTn: timer/counter + * TCCRnA/B/C: timer/counter control registers + */ +void timer_init() { + TCCR1A = 0; //no waveform generation or something like that + TCCR1B = _BV(CS00); //no prescaling; use internal clock + TCCR1C = 0; +} + +//makes it easier to print time; is an unsigned int and NOT to be used for more then printing +unsigned int ticks_to_seconds(uint16_t start, uint16_t end) { + return ((unsigned int)(end - start) / F_CPU); +} + +void test_timer() { + uint16_t start, end; + start = TCNT1; + _delay_ms(1000); + end = TCNT1; + printf("1 second is %u ticks\n", end - start); +} |