diff options
author | Brett Weiland <brett_weiland@bpcspace.com> | 2022-09-09 18:33:15 -0500 |
---|---|---|
committer | Brett Weiland <brett_weiland@bpcspace.com> | 2022-09-09 18:33:15 -0500 |
commit | 7b006d6f2032ac46074d693ae59a971bee327ace (patch) | |
tree | 60963598d99001e0850e34d6271db8bd65e04fa4 /src/debug.c |
init
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); +} |