-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.c
62 lines (52 loc) · 1.34 KB
/
logic.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
#include "declarations.h"
int timePassed(int start){
if(currMom() >= 86400){return currMom() + 86400 - start;}
else{return currMom() - start;}
}
void readADC(char channel){
// Select A2D channel to read
ADCON0 = ((channel <<2));
ADCON0bits.ADON = 1;
ADCON0bits.GO = 1;
while(ADCON0bits.GO_NOT_DONE){__delay_ms(5);}
}
void startTMR3(void){
T3CON = 0b10110000;
TMR3H = 0b10011001;
TMR3L = 0b01011011;
TMR3ON = 1;
}
void startTMR1(void){
T1CON = 0b10110000;
TMR1H = 0b11011001;
TMR1L = 0b01011011;
TMR1ON = 1;
}
void calibrateWheels(void){
TMR1ON = 0;
int i = 1;
int prev;
do{
if (i < 20){updateS1(1);}
else if(i<(20+40)){updateS1(2);}
else if(i<(20+40+80)){updateS1(1);}
else if(i<(20+40+80+100)){updateS1(2);}
else{i=1;}
i++;
if (i==1){prev = 0;}
else{prev = ADRES;}
readADC(IR1);
}while(ADRES>prev || ADRES<wheelThresh);
do{
if (i < 20){updateS3(1);}
else if(i<(20+40)){updateS3(2);}
else if(i<(20+40+80)){updateS3(1);}
else if(i<(20+40+80+100)){updateS3(2);}
else{i=1;}
i++;
if (i==1){prev = 0;}
else{prev = ADRES;}
readADC(IR4);
}while(ADRES>prev || ADRES<wheelThresh);
startTMR1();
}