summaryrefslogtreecommitdiff
path: root/src/debug.c
blob: 858195ef74fba8d30307822d86048e38435edf33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}