altos: Sample the accelerometer reference voltage on v1.1 boards
authorKeith Packard <keithp@keithp.com>
Sat, 15 Jan 2011 20:18:32 +0000 (12:18 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 17 Jan 2011 04:24:36 +0000 (20:24 -0800)
This places the 5v reference samples in an array parallel to the basic
ADC values. It doesn't do anything with the values, just stores them.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_adc.c
src/ao_pins.h

index abac22a31e619322b644e49264022c52c3d63c40..cef20e61731e869a5a3a517d7a2186cf9fa5c694 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -163,6 +163,11 @@ struct ao_adc {
 #endif
 
 #if HAS_ADC
+
+#ifndef HAS_ACCEL_REF
+#error Please define HAS_ACCEL_REF
+#endif
+
 /*
  * ao_adc.c
  */
@@ -178,6 +183,9 @@ struct ao_adc {
  */
 extern volatile __xdata struct ao_adc  ao_adc_ring[AO_ADC_RING];
 extern volatile __data uint8_t         ao_adc_head;
+#if HAS_ACCEL_REF
+extern volatile __xdata uint16_t       ao_accel_ref[AO_ADC_RING];
+#endif
 
 /* Trigger a conversion sequence (called from the timer interrupt) */
 void
index f577b4582afe02ca838500b2d3d9e5e344612835..3adf9b2e70277526e252770c7071dec7a400d0b1 100644 (file)
 #include "ao_pins.h"
 
 volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
+#if HAS_ACCEL_REF
+volatile __xdata uint16_t      ao_accel_ref[AO_ADC_RING];
+#endif
 volatile __data uint8_t                ao_adc_head;
 
 void
 ao_adc_poll(void)
 {
+#if HAS_ACCEL_REF
+       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 2;
+#else
        ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0;
+#endif
 }
 
 void
@@ -41,20 +48,29 @@ ao_adc_isr(void) __interrupt 1
        uint8_t __xdata *a;
 
        sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT;
-       if (sequence == ADCCON3_ECH_TEMP)
-               sequence = 2;
-       a = (uint8_t __xdata *) (&ao_adc_ring[ao_adc_head].accel + sequence);
+#if HAS_ACCEL_REF
+       if (sequence == 2) {
+               a = (uint8_t __xdata *) (&ao_accel_ref[ao_adc_head]);
+               sequence = 0;
+       } else
+#endif
+       {
+               if (sequence == ADCCON3_ECH_TEMP)
+                       sequence = 2;
+               a = (uint8_t __xdata *) (&ao_adc_ring[ao_adc_head].accel + sequence);
+               sequence++;
+       }
        a[0] = ADCL;
        a[1] = ADCH;
-       if (sequence < 5) {
+       if (sequence < 6) {
 #if HAS_EXTERNAL_TEMP == 0
                /* start next channel conversion */
                /* v0.2 replaces external temp sensor with internal one */
-               if (sequence == 1)
+               if (sequence == 2)
                        ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP;
                else
 #endif
-                       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1);
+                       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | sequence;
        } else {
                /* record this conversion series */
                ao_adc_ring[ao_adc_head].tick = ao_time();
index 9446964e1f02b7f8427386414157e25ed421638c..2c5b9db5ca749a34f7f7d9f3884c53b848906dae 100644 (file)
@@ -31,6 +31,7 @@
        #define AO_LED_RED              1
        #define LEDS_AVAILABLE          (AO_LED_RED)
        #define HAS_EXTERNAL_TEMP       0
+       #define HAS_ACCEL_REF           0
 #endif
 
 #if defined(TELEMETRUM_V_1_1)
@@ -46,6 +47,7 @@
        #define AO_LED_RED              1
        #define LEDS_AVAILABLE          (AO_LED_RED)
        #define HAS_EXTERNAL_TEMP       0
+       #define HAS_ACCEL_REF           1
        #define SPI_CS_ON_P1            1
        #define SPI_CS_ON_P0            0
        #define M25_CS_MASK             0x02    /* CS0 is P1_1 */
@@ -81,6 +83,7 @@
        #define AO_LED_GREEN            1
        #define LEDS_AVAILABLE          (AO_LED_RED|AO_LED_GREEN)
        #define HAS_EXTERNAL_TEMP       1
+       #define HAS_ACCEL_REF           0
        #define SPI_CS_ON_P1            1
        #define SPI_CS_ON_P0            0
 #endif