-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.c
30 lines (25 loc) · 900 Bytes
/
timer.c
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
/*
Title: timer.c
Authors: Mikael Ferland, Joël Brisson
Date: 4/10/2015
Purpose: Initialysation, writing and reading for TWI between master and slaves, using i2c protocol.
Software: AVR-GCC to compile
Hardware: ATMega32 on STK500 board
Note: 0xFE and 0xFF is reserved by the system for restart and stop condition.
*/
#include "timer.h"
void timer_Init()
{
/*
The PWM frequency for the output can be calculated by the following equation:
focnPWM=Fcpu/(N*256)
N is the prescaler factor
*/
//Fast PWM mode 10bits with /8 prescale
outp((1<<COM1A1)|(0<<COM1A0)|(1<<COM1B1)|(0<<COM1B0)|(0<<FOC1A)|(0<<FOC1B)|(1<<WGM11)|(0<<WGM10),TCCR1A);
outp((0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10),TCCR1B);
//Set TOP Value to get 5ms with /8 prescale
ICR1 = 0x270F;
//Enable Timer1 Overflow Interrup
outp((1<<TOIE1),TIMSK);
}