blob: 1e89f98f560f3f653396e081e142f594e4c7e77b [file] [log] [blame]
Austin Schuhb402fd42019-04-13 00:02:53 -07001#include "motors/pistol_grip/controller_adc.h"
2
3#include "motors/peripheral/adc.h"
4
Stephan Pleinesf63bde82024-01-13 15:59:33 -08005namespace frc971::motors {
Austin Schuhb402fd42019-04-13 00:02:53 -07006
7void AdcInitSmall() {
8 AdcInitCommon();
9
10 // M0_CH0F ADC1_SE17
11 PORTA_PCR17 = PORT_PCR_MUX(0);
12
13 // M0_CH1F ADC1_SE14
14 PORTB_PCR10 = PORT_PCR_MUX(0);
15
16 // M0_CH2F ADC1_SE15
17 PORTB_PCR11 = PORT_PCR_MUX(0);
18
19 // M0_ABS ADC0_SE5b
20 PORTD_PCR1 = PORT_PCR_MUX(0);
21
22 // M1_CH0F ADC0_SE13
23 PORTB_PCR3 = PORT_PCR_MUX(0);
24
25 // M1_CH1F ADC0_SE12
26 PORTB_PCR2 = PORT_PCR_MUX(0);
27
28 // M1_CH2F ADC0_SE14
29 PORTC_PCR0 = PORT_PCR_MUX(0);
30
31 // M1_ABS ADC0_SE17
32 PORTE_PCR24 = PORT_PCR_MUX(0);
33
34 // WHEEL_ABS ADC0_SE18
35 PORTE_PCR25 = PORT_PCR_MUX(0);
36
37 // VIN ADC1_SE5B
38 PORTC_PCR9 = PORT_PCR_MUX(0);
39}
40
41SmallAdcReadings AdcReadSmall0(const DisableInterrupts &) {
42 SmallAdcReadings r;
43
44 ADC1_SC1A = 17;
45 while (!(ADC1_SC1A & ADC_SC1_COCO)) {
46 }
47 ADC1_SC1A = 14;
48 r.currents[0] = ADC1_RA;
49 while (!(ADC1_SC1A & ADC_SC1_COCO)) {
50 }
51 ADC1_SC1A = 15;
52 r.currents[1] = ADC1_RA;
53 while (!(ADC1_SC1A & ADC_SC1_COCO)) {
54 }
55 r.currents[2] = ADC1_RA;
56
57 return r;
58}
59
60SmallAdcReadings AdcReadSmall1(const DisableInterrupts &) {
61 SmallAdcReadings r;
62
63 ADC0_SC1A = 13;
64 while (!(ADC0_SC1A & ADC_SC1_COCO)) {
65 }
66 ADC0_SC1A = 12;
67 r.currents[0] = ADC0_RA;
68 while (!(ADC0_SC1A & ADC_SC1_COCO)) {
69 }
70 ADC0_SC1A = 14;
71 r.currents[1] = ADC0_RA;
72 while (!(ADC0_SC1A & ADC_SC1_COCO)) {
73 }
74 r.currents[2] = ADC0_RA;
75
76 return r;
77}
78
79SmallInitReadings AdcReadSmallInit(const DisableInterrupts &) {
80 SmallInitReadings r;
81
82 ADC0_SC1A = 5;
83 while (!(ADC0_SC1A & ADC_SC1_COCO)) {
84 }
85 ADC0_SC1A = 17;
86 r.motor0_abs = ADC0_RA;
87 while (!(ADC0_SC1A & ADC_SC1_COCO)) {
88 }
89 ADC0_SC1A = 18;
90 r.motor1_abs = ADC0_RA;
91 while (!(ADC0_SC1A & ADC_SC1_COCO)) {
92 }
93 r.wheel_abs = ADC0_RA;
94
95 return r;
96}
97
Stephan Pleinesf63bde82024-01-13 15:59:33 -080098} // namespace frc971::motors