Skip to content
Snippets Groups Projects
Commit f934e3dd authored by Xoaquin Castrelo's avatar Xoaquin Castrelo
Browse files

Added time tracking.

parent a8feb213
No related branches found
No related tags found
No related merge requests found
#include "time.hpp"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
static uint32_t millis;
void initTime()
{
cli();
TCCR0A = (1 << WGM01); // CTC mode, TOP = OCRA
TCCR0B = (1 << CS01) | (1 << CS00); // 64th prescaler
OCR0A = 249; // set TOP for 1 kHz interrupts
TIMSK0 = (1 << OCIE0A); // enable compare A interrupt
sei();
}
uint32_t getCurrentMillis()
{
return millis;
}
ISR(TIMER0_COMPA_vect)
{
millis++;
}
#ifndef TIME_H
#define TIME_H
#include <stdint.h>
/**
* Initialises time.
*/
void initTime();
/**
* Gets the number of milliseconds since program start.
*/
uint32_t getCurrentMillis();
#endif /* TIME_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment