altos: Add support for MegaAccel daughter card.
authorKeith Packard <keithp@keithp.com>
Sat, 2 Jun 2012 06:07:38 +0000 (23:07 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 2 Jun 2012 06:07:38 +0000 (23:07 -0700)
Switches all acceleration computation to using the MegaAccel
accelerometer to ensure support for high-g flights.

MPU6000 values continue to be logged as normal

Signed-off-by: Keith Packard <keithp@keithp.com>
src/cc1111/ao_adc.c
src/cc1111/ao_arch.h
src/core/ao_data.h
src/megametrum-v0.1/ao_pins.h
src/stm/ao_adc_stm.c

index 956439566abacdaa3340cc98dae5c668dcf64645..ce827e2596ac7b576fc84056507e0e68cecf1dd1 100644 (file)
@@ -56,7 +56,7 @@ ao_adc_isr(void) __interrupt 1
        /* TeleMetrum readings */
 #if HAS_ACCEL_REF
        if (sequence == 2) {
-               a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].accel_ref);
+               a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.accel_ref);
                sequence = 0;
        } else
 #endif
index 704ae4f911c2db6356bce656e893c79f02d7d0f6..44116b812d9a07820a41c99d24089e1790ebc5b5 100644 (file)
@@ -205,6 +205,7 @@ struct ao_adc {
        int16_t         v_batt;         /* battery voltage */
        int16_t         sense_d;        /* drogue continuity sense */
        int16_t         sense_m;        /* main continuity sense */
+       int16_t         accel_ref;      /* acceleration reference */
 };
 
 #define AO_DATA_RING   32
index bb26c4c0dcb61895e90d5985a331a0e17c8cb814..83f8df597e44cbd1ae9295a85d5e1b1e22276324 100644 (file)
@@ -31,9 +31,6 @@ struct ao_data {
 #if HAS_ADC
        struct ao_adc                   adc;
 #endif
-#if HAS_ACCEL_REF
-       uint16_t                        accel_ref;
-#endif
 #if HAS_MS5607
        struct ao_ms5607_sample         ms5607;
 #endif
@@ -82,7 +79,7 @@ typedef int16_t alt_t;
  * ao_data_accel_invert        - flip rocket ends for positive acceleration
  */
 
-#if HAS_MPU6000
+#if HAS_MPU6000 && !HAS_HIGHG_ACCEL
 
 typedef int16_t accel_t;
 
@@ -181,7 +178,7 @@ typedef int16_t accel_t;
  */
 #if HAS_ACCEL_REF
 #define ao_data_accel_sample(packet) \
-       ((uint16_t) ((((uint32_t) (packet)->adc.accel << 16) / ((packet)->accel_ref << 1))) >> 1)
+       ((uint16_t) ((((uint32_t) (packet)->adc.accel << 16) / ((packet)->adc.accel_ref << 1))) >> 1)
 #else
 #define ao_data_accel_sample(packet) ((packet)->adc.accel)
 #endif /* HAS_ACCEL_REF */
index ff0edaa9b9f23ae02263725b526514b2233c54a0..75b2204530beafa04fabbda886cbf26376330e14 100644 (file)
@@ -98,6 +98,7 @@
 #define HAS_FLIGHT             1
 #define HAS_ADC                        1
 #define HAS_ACCEL              1
+#define HAS_ACCEL_REF          1
 #define HAS_LOG                        1
 
 #define AO_DATA_RING           32
@@ -107,6 +108,8 @@ struct ao_adc {
        int16_t                 sense[AO_ADC_NUM_SENSE];
        int16_t                 v_batt;
        int16_t                 v_pbatt;
+       int16_t                 accel_ref;
+       int16_t                 accel;
        int16_t                 temp;
 };
 
@@ -142,13 +145,22 @@ struct ao_adc {
 #define AO_ADC_V_PBATT_PORT    stm_gpiob
 #define AO_ADC_V_PBATT_PIN     1
 
+#define AO_ADC_ACCEL_REF       10
+#define AO_ADC_ACCEL_REF_PORT  stm_gpioc
+#define AO_ADC_ACCEL_REF_PIN   0
+
+#define AO_ADC_ACCEL           11
+#define AO_ADC_ACCEL_PORT      stm_gpioc
+#define AO_ADC_ACCEL_PIN       1
+
 #define AO_ADC_TEMP            16
 
 #define AO_ADC_RCC_AHBENR      ((1 << STM_RCC_AHBENR_GPIOAEN) | \
                                 (1 << STM_RCC_AHBENR_GPIOEEN) | \
-                                (1 << STM_RCC_AHBENR_GPIOBEN))
+                                (1 << STM_RCC_AHBENR_GPIOBEN) | \
+                                (1 << STM_RCC_AHBENR_GPIOCEN))
 
-#define AO_NUM_ADC_PIN         (AO_ADC_NUM_SENSE + 2)
+#define AO_NUM_ADC_PIN         (AO_ADC_NUM_SENSE + 4)
 
 #define AO_ADC_PIN0_PORT       AO_ADC_SENSE_A_PORT
 #define AO_ADC_PIN0_PIN                AO_ADC_SENSE_A_PIN
@@ -166,8 +178,12 @@ struct ao_adc {
 #define AO_ADC_PIN6_PIN                AO_ADC_V_BATT_PIN
 #define AO_ADC_PIN7_PORT       AO_ADC_V_PBATT_PORT
 #define AO_ADC_PIN7_PIN                AO_ADC_V_PBATT_PIN
+#define AO_ADC_PIN8_PORT       AO_ADC_ACCEL_REF_PORT
+#define AO_ADC_PIN8_PIN                AO_ADC_ACCEL_REF_PIN
+#define AO_ADC_PIN9_PORT       AO_ADC_ACCEL_PORT
+#define AO_ADC_PIN9_PIN                AO_ADC_ACCEL_PIN
 
-#define AO_NUM_ADC             (AO_ADC_NUM_SENSE + 3)
+#define AO_NUM_ADC             (AO_ADC_NUM_SENSE + 5)
 
 #define AO_ADC_SQ1             AO_ADC_SENSE_A
 #define AO_ADC_SQ2             AO_ADC_SENSE_B
@@ -177,7 +193,9 @@ struct ao_adc {
 #define AO_ADC_SQ6             AO_ADC_SENSE_F
 #define AO_ADC_SQ7             AO_ADC_V_BATT
 #define AO_ADC_SQ8             AO_ADC_V_PBATT
-#define AO_ADC_SQ9             AO_ADC_TEMP
+#define AO_ADC_SQ9             AO_ADC_ACCEL_REF
+#define AO_ADC_SQ10            AO_ADC_ACCEL
+#define AO_ADC_SQ11            AO_ADC_TEMP
 
 /*
  * Pressure sensor settings
@@ -230,4 +248,6 @@ struct ao_adc {
 #define AO_MPU6000_INT_PIN     13
 #define AO_MPU6000_I2C_INDEX   STM_I2C_INDEX(1)
 
+#define HAS_HIGHG_ACCEL                1
+
 #endif /* _AO_PINS_H_ */
index ea9e25e48a9f94d0438c7d4ca03e908be1c89c99..24a1fdd012a0bc0d68c650c00b429e42942bf91c 100644 (file)
@@ -82,7 +82,7 @@ ao_adc_poll(void)
        stm_adc.sr = 0;
        ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1),
                            &stm_adc.dr,
-                           (void *) (&ao_data_ring[ao_data_head].tick + 1),
+                           (void *) (&ao_data_ring[ao_data_head].adc),
                            AO_NUM_ADC,
                            (0 << STM_DMA_CCR_MEM2MEM) |
                            (STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) |
@@ -180,6 +180,15 @@ ao_adc_init(void)
 #ifdef AO_ADC_PIN9_PORT
        stm_moder_set(&AO_ADC_PIN9_PORT, AO_ADC_PIN9_PIN, STM_MODER_ANALOG);
 #endif
+#ifdef AO_ADC_PIN10_PORT
+       stm_moder_set(&AO_ADC_PIN10_PORT, AO_ADC_PIN10_PIN, STM_MODER_ANALOG);
+#endif
+#ifdef AO_ADC_PIN11_PORT
+       stm_moder_set(&AO_ADC_PIN11_PORT, AO_ADC_PIN11_PIN, STM_MODER_ANALOG);
+#endif
+#ifdef AO_ADC_PIN12_PORT
+       stm_moder_set(&AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG);
+#endif
 
        stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_ADC1EN);
 
@@ -240,7 +249,19 @@ ao_adc_init(void)
 #if AO_NUM_ADC > 8
        stm_adc.sqr4 |= (AO_ADC_SQ9 << 10);
 #endif
-
+#if AO_NUM_ADC > 9
+       stm_adc.sqr4 |= (AO_ADC_SQ10 << 15);
+#endif
+#if AO_NUM_ADC > 10
+       stm_adc.sqr4 |= (AO_ADC_SQ11 << 20);
+#endif
+#if AO_NUM_ADC > 11
+       stm_adc.sqr4 |= (AO_ADC_SQ12 << 25);
+#endif
+#if AO_NUM_ADC > 12
+#error "need to finish stm_adc.sqr settings"
+#endif
+       
        /* Turn ADC on */
        stm_adc.cr2 = AO_ADC_CR2_VAL;