-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
87 lines (60 loc) · 1.62 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
PROJECT MAESTRO, ROSE FLOAT ANIM. COMPUTER
MAIN PROGRAM LOOP
Sean Conant 3 September 2011
Fix ADC ACQ and preparing for multiples valves
Repeats continuously. No interrupts used.
*/
#include <p18f46k22.h>
#include "rosefloat.h"
#pragma config FOSC = INTIO67 //internal oscillator
#pragma config BOREN = OFF //no brownout functions
#pragma config WDTEN = OFF //no watchdog timer
#pragma config PBADEN = ON //on reset, PORTB = analog
#pragma config MCLRE = EXTMCLR //MCLR pin works
void main (){
//Define ADC I/O
int i=0;
extern int desired_position;
Initialize_ADC();
//Define SPI I/O
configSPI();
//************* May need to initialize ADC ports....
//TRISAbits.RA0 = 1;
// TRISAbits.RA1 = 1;
while(1){
//SPI in
for(i=0;i<16;i++)
{
commandOut(PID(desired_position(i),Current_Position(i),i);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//This will need to be done by SPI in
///////////////////////
int desired_position(int a)
{
int j;
switch(a)
{
case 1: j=Get_ADC(1); break;
case 2: j=Get_ADC(3); break;
// case 3: j=Get_ADC(); break;
// case 4: j=Get_ADC(); break;
// case 5: j=Get_ADC(); break;
// case 6: j=Get_ADC(); break;
// case 7: j=Get_ADC(); break;
// case 8: j=Get_ADC(); break;
// case 9: j=Get_ADC(); break;
// case 10: j=Get_ADC(); break;
// case 11: j=Get_ADC(); break;
// case 12: j=Get_ADC(); break;
// case 13: j=Get_ADC(); break;
// case 14: j=Get_ADC(); break;
// case 15: j=Get_ADC(); break;
// case 16: j=Get_ADC(); break;
default: break;
}
return j;
}