-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimer.c
52 lines (45 loc) · 888 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "timer.h"
#if defined(__dsPIC33F__)
#include <p33Fxxxx.h>
#elif defined(__PIC24H__)
#include <p24hxxxx.h>
#endif
void InitTimer6()
{
T6CONbits.TON = 0; // Stop timer
T6CONbits.TCKPS = 1; // Prescaler is 1:1 3 1:256 2 1:64 1 1:8 0 1:1
T6CONbits.TCS = 0; // Timer mode
PR6 = 2500; // 40MHz osc, 1ms interrupt (pr6/20000000)*TKP
TMR6 = 0;
IPC11 |= 0x7000; // Highest interrupt priority
IFS2bits.T6IF = 0;
IEC2bits.T6IE = 1;
}
void StartTimer6()
{
TMR6 = 0;
T6CONbits.TON = 1;
}
void StopTimer6()
{
T6CONbits.TON = 0;
}
void InitTimer2()
{
T2CONbits.TON = 0; // Stop timer
TMR2 = 0;
PR2 = 0xfffe;
T2CONbits.TCKPS = 1; // Prescaler is 1:8
T2CONbits.TCS = 0; // Using internal clock
T2CONbits.TGATE = 0;
}
void StartTimer2()
{
TMR2 = 0;
T2CONbits.TCKPS = 1; // Prescaler is 1:8
T2CONbits.TON = 1;
}
void StopTimer2()
{
T2CONbits.TON = 0;
}