-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer1.c
More file actions
30 lines (23 loc) · 671 Bytes
/
Copy pathtimer1.c
File metadata and controls
30 lines (23 loc) · 671 Bytes
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
#include <avr/io.h>
#include <avr/interrupt.h>
#include "timer1.h"
void timer1_init(void) {
// Clear ouput compare registers
OCR1A = 0;
OCR1B = 0;
OCR1C = 0;
TCCR1A =
_BV(WGM10) | // Phase correct, 10-bit PWM
_BV(WGM11) |
0;
TCCR1B = 0;
timer1_source(TIMER1_INT);
TCCR1C = 0;
}
void timer1_source(enum timer1_clock_source cs) { TCCR1B = (TCCR1B & 0xF8) | cs; };
void OC1A_enable() { TCCR1A |= _BV(COM1A1); }
void OC1A_disable() { TCCR1A &= ~(_BV(COM1A1)); }
void OC1B_enable() { TCCR1A |= _BV(COM1B1); }
void OC1B_disable() { TCCR1A &= ~(_BV(COM1B1)); }
void OC1C_enable() { TCCR1A |= _BV(COM1C1); }
void OC1C_disable() { TCCR1A &= ~(_BV(COM1C1)); }