You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
625 B
34 lines
625 B
2 years ago
|
/**
|
||
|
* Time base
|
||
|
*/
|
||
|
|
||
|
#include "time_base.h"
|
||
|
|
||
|
#include <stdint.h>
|
||
|
#include <avr/interrupt.h>
|
||
|
|
||
|
/// timestamp counted in units of 100ms
|
||
|
volatile uint16_t timestamp_100ms = 0;
|
||
|
/// sub-second counter, counts 0-9 then overflows
|
||
|
static volatile uint16_t subsec_counter = 0;
|
||
|
|
||
|
// 100ms counter
|
||
|
ISR(TIMER1_COMPA_vect)
|
||
|
{
|
||
|
timestamp_100ms++;
|
||
|
|
||
|
subsec_counter++;
|
||
|
if (subsec_counter == 10) {
|
||
|
subsec_counter = 0;
|
||
|
second_callback_irq();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void init_timebase()
|
||
|
{
|
||
|
// CTC & presc=256
|
||
|
TCCR1B = (1 << WGM12) | (1 << CS12);
|
||
|
TIMSK1 = (1 << OCIE1A); // Enable CTC interrupt
|
||
|
OCR1A = 6250; // 100ms
|
||
|
}
|