-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_100us.c
66 lines (54 loc) · 1018 Bytes
/
timer_100us.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "timer_100us.h"
#include "core.h"
extern uint8_t DEMODULATOR_TimerPeriodOver;
extern uint8_t MAIN_TimerPeriodOver;
void TIMER_Init(void)
{
// Turn off the timer and disable interrupts
T1CONbits.TON = 0;
_T1IE = 0;
// Set the configuration
_T1IF = 0;
_T1IP = 7;
TMR1 = 0;
PR1 = 9999;
T1CONbits.TECS = 0b01;
T1CONbits.TCS = 1;
T1CONbits.TCKPS = 0b00;
T1CONbits.TSYNC = 0;
// Re-enable interrupts
_T1IE = 1;
}
void TIMER_On(void)
{
TMR1 = 0;
_T1IF = 0;
T1CONbits.TON = 1;
}
void TIMER_Off(void)
{
T1CONbits.TON = 0;
TMR1 = 0;
_T1IF = 0;
}
void TIMER_SetHalfPeriod(void)
{
PR1 = 4900;
}
void TIMER_SetPeriodPerc(float percentage)
{
PR1 = (int)(9999 * percentage);
}
void TIMER_SetFullPeriod(void)
{
PR1 = 9999;
}
/**
* Timer1 interrupt callback
*/
void __attribute__((__interrupt__, auto_psv)) _T1Interrupt(void)
{
MAIN_TimerPeriodOver = 1;
DEMODULATOR_TimerPeriodOver = 1;
_T1IF = 0;
}