forked from UWARG/RC-Car-Bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.c
32 lines (25 loc) · 740 Bytes
/
clock.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
#include "clock.h"
#include <p33FJ256GP710A.h>
static long int time = 0;
void __attribute__((__interrupt__, no_auto_psv)) _T2Interrupt(void){
//Timer Interrupt used for the control loops and data link
time += 20;
IFS0bits.T2IF = 0;
}
long int getTime() {
return time;
}
void InitClock()
{
PLLFBD = 38; // M = 40
CLKDIVbits.PLLPOST = 0; // N1 = 2
CLKDIVbits.PLLPRE = 0; // N2 = 2
OSCTUN = 0;
RCONbits.SWDTEN = 0;
// Clock switch to incorporate PLL
__builtin_write_OSCCONH(0x01); // Initiate Clock Switch to
// FRC with PLL (NOSC=0b001)
__builtin_write_OSCCONL(0x01); // Start clock switching
while (OSCCONbits.COSC != 0b001); // Wait for Clock switch to occur
while(OSCCONbits.LOCK != 1) {};
}