-
Notifications
You must be signed in to change notification settings - Fork 3
/
timer.cpp
48 lines (34 loc) · 965 Bytes
/
timer.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "timer.h"
#include "artnet.h"
#include "dmx.h"
#include <avr/io.h>
#include <avr/interrupt.h>
//Different counters
volatile uint16_t timer01hzCounter = 0;
volatile uint8_t timer022HZCounter = 0;
volatile uint32_t millisCounter = 0;
void setupTimer0(void) {
//################# Timer0 - 1Khz
TCC0.CTRLA = TC_CLKSEL_DIV1024_gc; // Presacler 1024
TCC0.CTRLB = 0x00; // select Modus: Normal
TCC0.PER = 32; // Zähler Top-Wert 1000 Hz
TCC0.CNT = 0x00; // Zähler zurücksetzen
TCC0.INTCTRLA = 0b00000011; // Interrupt Highlevel
}
uint32_t millis(void) {
return millisCounter;
}
ISR(TCC0_OVF_vect)
{
timer01hzCounter++;
millisCounter++;
if(timer01hzCounter >= 1000) {
timer01hzCounter = 0;
artnet.doTimerStuff1Hz(); //Art-Net
}
timer022HZCounter++;
if(timer022HZCounter >= 23) {
timer022HZCounter = 0;
startDMX_TX(); //Reicht? TODO: Timer, 44mal/sec
}
}