altos: Add 5V reference computation for v1.1 boards.
authorKeith Packard <keithp@keithp.com>
Sat, 15 Jan 2011 08:50:39 +0000 (00:50 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 15 Jan 2011 08:50:39 +0000 (00:50 -0800)
This should compensate for changes in the 3.3V voltage.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosPad.java
doc/telemetrum-outline.svg
src/ao.h
src/ao_adc.c
src/ao_config.c
src/ao_flight.c
src/ao_ignite.c
src/ao_log.c
src/ao_pins.h

index 669543472a71ff3074ad823f0e24c562dcc4220e..e345e5dafcdd8480ef0a36f1833fc60401bf002b 100644 (file)
@@ -152,7 +152,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
        class GPSLocked extends LaunchStatus {
                void show (AltosState state, int crc_errors) {
                        value.setText(String.format("%4d sats", state.gps.nsat));
-                       lights.set(state.gps.locked);
+                       lights.set(state.gps.locked && state.gps.nsat >= 4);
                }
                public GPSLocked (GridBagLayout layout, int y) {
                        super (layout, y, "GPS Locked");
index 542df64cd3330e097998c96eca2e0e26f8960083..d5e1700eed3f88527ffabda0e405ee93e58cc821 100644 (file)
@@ -14,7 +14,7 @@
    id="svg2"
    version="1.1"
    inkscape:version="0.47 r22583"
-   sodipodi:docname="telemetrum.svg">
+   sodipodi:docname="telemetrum-outline.pdf">
   <defs
      id="defs4">
     <marker
index 37a39a790b643b7061a1614fa3e6f128d90b4a5d..d661714d9f037a1dfbc4ad2d1d2cb20da2357e47 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
@@ -649,7 +657,7 @@ enum ao_flight_state {
        ao_flight_invalid = 9
 };
 
-extern __xdata struct ao_adc           ao_flight_data;
+extern __data uint8_t                  ao_flight_adc;
 extern __pdata enum ao_flight_state    ao_flight_state;
 extern __pdata uint16_t                        ao_flight_tick;
 extern __pdata int16_t                 ao_flight_accel;
index 49d2519e209d5c4f2faf594c5afb08da9da42af6..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;
-}
-
-void
-ao_adc_sleep(void)
-{
-       ao_sleep(&ao_adc_ring);
+#endif
 }
 
 void
 ao_adc_get(__xdata struct ao_adc *packet)
 {
-       uint8_t i = ao_adc_ring_prev(ao_adc_head);
+       uint8_t i = ao_adc_ring_prev(ao_flight_adc);
        memcpy(packet, &ao_adc_ring[i], sizeof (struct ao_adc));
 }
 
@@ -47,25 +48,34 @@ 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();
                ao_adc_head = ao_adc_ring_next(ao_adc_head);
-               ao_wakeup(ao_adc_ring);
+               ao_wakeup(DATA_TO_XDATA(&ao_adc_head));
        }
 }
 
index e97b7eb121192a41d1876fa530e9188d828e75e5..bbee3b443e6a0a7e17bfb9805af311dfba6e3982 100644 (file)
@@ -209,10 +209,10 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant
        puts("Calibrating..."); flush();
        i = ACCEL_CALIBRATE_SAMPLES;
        accel_total = 0;
-       cal_adc_ring = ao_adc_head;
+       cal_adc_ring = ao_flight_adc;
        while (i) {
-               ao_sleep(&ao_adc_ring);
-               while (i && cal_adc_ring != ao_adc_head) {
+               ao_sleep(DATA_TO_XDATA(&ao_flight_adc));
+               while (i && cal_adc_ring != ao_flight_adc) {
                        accel_total += (int32_t) ao_adc_ring[cal_adc_ring].accel;
                        cal_adc_ring = ao_adc_ring_next(cal_adc_ring);
                        i--;
index 7fe85cb1522ac786579b824cd714c97dc088d9f3..8f8562350be3baa9e517a73b01ba7ba9e524b49c 100644 (file)
@@ -146,16 +146,24 @@ ao_flight(void)
        ao_raw_pres = 0;
        ao_flight_tick = 0;
        for (;;) {
-               ao_sleep(&ao_adc_ring);
+               ao_wakeup(DATA_TO_XDATA(&ao_flight_adc));
+               ao_sleep(DATA_TO_XDATA(&ao_adc_head));
                while (ao_flight_adc != ao_adc_head) {
                        __pdata uint8_t ticks;
                        __pdata int16_t ao_vel_change;
+                       __xdata int16_t *ao_adc;
                        ao_flight_prev_tick = ao_flight_tick;
 
                        /* Capture a sample */
-                       ao_raw_accel = ao_adc_ring[ao_flight_adc].accel;
-                       ao_raw_pres = ao_adc_ring[ao_flight_adc].pres;
-                       ao_flight_tick = ao_adc_ring[ao_flight_adc].tick;
+                       ao_adc = &ao_adc_ring[ao_flight_adc].tick;
+                       ao_flight_tick = *ao_adc++;
+#if HAS_ACCEL_REF
+                       ao_raw_accel = (uint16_t) ((((uint32_t) *ao_adc << 16) / (ao_accel_ref[ao_flight_adc] << 1))) >> 1;
+                       *ao_adc++ = ao_raw_accel;
+#else
+                       ao_raw_accel = *ao_adc++;
+#endif
+                       ao_raw_pres = *ao_adc++;
 
                        ao_flight_accel -= ao_flight_accel >> 4;
                        ao_flight_accel += ao_raw_accel >> 4;
index f2b15dd23e741da0d29df0682d7c02d830717890..603fcd25f3e37105487ad1005894cfdbabcc9815 100644 (file)
@@ -52,7 +52,6 @@ ao_igniter_status(enum ao_igniter igniter)
        __xdata uint8_t request, firing, fired;
 
        __critical {
-               ao_adc_sleep();
                ao_adc_get(&adc);
                request = ao_ignition[igniter].request;
                fired = ao_ignition[igniter].fired;
index 8666482b51ab6da82b086cdf9b5c1423cc26b957..ea36da5e8b43b2e554b2ea271c91289c4ae95473 100644 (file)
@@ -99,10 +99,10 @@ ao_log(void)
        /* Write the whole contents of the ring to the log
         * when starting up.
         */
-       ao_log_adc_pos = ao_adc_ring_next(ao_adc_head);
+       ao_log_adc_pos = ao_adc_ring_next(ao_flight_adc);
        for (;;) {
                /* Write samples to EEPROM */
-               while (ao_log_adc_pos != ao_adc_head) {
+               while (ao_log_adc_pos != ao_flight_adc) {
                        log.type = AO_LOG_SENSOR;
                        log.tick = ao_adc_ring[ao_log_adc_pos].tick;
                        log.u.sensor.accel = ao_adc_ring[ao_log_adc_pos].accel;
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