disabled reading analog inputs with burst mode (for now at least)
diff --git a/gyro_board/src/usb/analog.c b/gyro_board/src/usb/analog.c
index b2ab48f..8dcaf26 100644
--- a/gyro_board/src/usb/analog.c
+++ b/gyro_board/src/usb/analog.c
@@ -2,19 +2,32 @@
#include "LPC17xx.h"
+#define USE_BURST 0
+
void analog_init(void) {
SC->PCONP |= PCONP_PCAD;
- // Enable AD0.0, AD0.1, AD0.2, AD0.3
+ // Enable AD0.0, AD0.1, AD0.2, and AD0.3.
PINCON->PINSEL1 &= ~(3 << 14 | 3 << 16 | 3 << 18 | 3 << 20);
PINCON->PINSEL1 |= 1 << 14 | 1 << 16 | 1 << 18 | 1 << 20;
+
+#if USE_BURST
ADC->ADCR = (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3) /* enable all 4 */ |
7 << 8 /* 100MHz / 8 = 12.5MHz */ |
1 << 16 /* enable burst mode */ |
1 << 21 /* turn on ADC */;
+#else
+ ADC->ADCR = 7 << 8 /* 100MHz / 8 = 12.5MHz */ |
+ 1 << 21 /* turn on ADC */;
+#endif
}
uint16_t analog(int channel) {
+#if !USE_BURST
+ // Set the channel number to the one we want.
+ ADC->ADCR = (ADC->ADCR & ~0xFF) | (1 << channel);
+ ADC->ADCR |= 1 << 24; // start conversion
+#endif
uint32_t value;
do {
switch (channel) {
diff --git a/gyro_board/src/usb/encoder.c b/gyro_board/src/usb/encoder.c
index f01dd47..c04a8b8 100644
--- a/gyro_board/src/usb/encoder.c
+++ b/gyro_board/src/usb/encoder.c
@@ -509,9 +509,6 @@
packet->main.left_drive = encoder5_val;
packet->main.right_drive = encoder4_val;
packet->main.indexer = encoder3_val;
- packet->main.battery_voltage = analog(3);
- packet->main.left_drive_hall = analog(1);
- packet->main.right_drive_hall = analog(2);
NVIC_DisableIRQ(EINT3_IRQn);
@@ -535,6 +532,7 @@
packet->main.capture_bottom_fall_delay = capture_bottom_fall_delay;
packet->main.bottom_fall_delay_count = bottom_fall_delay_count;
packet->main.bottom_fall_count = bottom_fall_count;
+ packet->main.bottom_rise_count = bottom_rise_count;
packet->main.bottom_disc = !digital(1);
NVIC_EnableIRQ(EINT3_IRQn);
@@ -553,6 +551,10 @@
NVIC_EnableIRQ(EINT3_IRQn);
- packet->main.bottom_rise_count = bottom_rise_count;
+ // Do all of the analogs last because they have the potential to be slow and
+ // jittery.
+ packet->main.battery_voltage = analog(3);
+ packet->main.left_drive_hall = analog(1);
+ packet->main.right_drive_hall = analog(2);
}
}