Switch to using internal cc1111 temperature sensor
authorKeith Packard <keithp@keithp.com>
Mon, 11 Jan 2010 00:31:50 +0000 (16:31 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 11 Jan 2010 00:35:58 +0000 (16:35 -0800)
v0.2 has no temperature sensor, and several of the v0.1 boards didn't
get a temperature sensor loaded. Use the internal temperature sensor
on the cc1111 in all cases instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-view/aoview_state.c
ao-tools/lib/cc-convert.c
src/ao_adc.c
src/ao_convert.c

index 838899a..505bcdd 100644 (file)
@@ -127,10 +127,10 @@ aoview_state_derive(struct cc_telem *data, struct aostate *state)
        accel_counts_per_mss = ((data->accel_minus_g - data->accel_plus_g) / 2.0) / 9.80665;
        state->acceleration = (data->ground_accel - data->flight_accel) / accel_counts_per_mss;
        state->speed = data->flight_vel / (accel_counts_per_mss * 100.0);
-       state->temperature = ((data->temp / 32767.0 * 3.3) - 0.5) / 0.01;
-       state->drogue_sense = data->drogue / 32767.0 * 15.0;
-       state->main_sense = data->main / 32767.0 * 15.0;
-       state->battery = data->batt / 32767.0 * 5.0;
+       state->temperature = cc_thermometer_to_temperature(data->temp);
+       state->drogue_sense = cc_ignitor_to_voltage(data->drogue);
+       state->main_sense = cc_ignitor_to_voltage(data->main);
+       state->battery = cc_battery_to_voltage(data->batt);
        if (!strcmp(data->state, "pad")) {
                if (data->gps.gps_locked && data->gps.nsat >= 4) {
                        state->npad++;
index ac6962b..8d6876a 100644 (file)
@@ -213,10 +213,19 @@ cc_accelerometer_to_acceleration(double accel, double ground_accel)
        return (ground_accel - accel) / count_per_mss;
 }
 
+/* Value for the CC1111 built-in temperature sensor
+ * Output voltage at 0°C = 0.755V
+ * Coefficient = 0.00247V/°C
+ * Reference voltage = 1.25V
+ *
+ * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
+ *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
+ */
+
 double
 cc_thermometer_to_temperature(double thermo)
 {
-       return ((thermo / 32767 * 3.3) - 0.5) / 0.01;
+       return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
 }
 
 double
index b0bfceb..2b972e6 100644 (file)
@@ -46,16 +46,18 @@ 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);
        a[0] = ADCL;
        a[1] = ADCH;
        if (sequence < 5) {
                /* start next channel conversion */
-               sequence++;
-               /* skip channel 2, we don't have a temp sensor on v0.2 */
-               if (sequence == 2)
-                       sequence++;
-               ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | sequence;
+               /* v0.2 replaces external temp sensor with internal one */
+               if (sequence == 1)
+                       ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP;
+               else
+                       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1);
        } else {
                /* record this conversion series */
                ao_adc_ring[ao_adc_head].tick = ao_time();
index 57ed737..f29ce9e 100644 (file)
@@ -49,7 +49,15 @@ ao_temp_to_dC(int16_t temp) __reentrant
        int16_t ret;
 
        ao_mutex_get(&ao_temp_mutex);
-       ret = (int16_t) ((temp >> 4) * 3300L / 2047L) - 500;
+       /* Output voltage at 0°C = 0.755V
+        * Coefficient = 0.00247V/°C
+        * Reference voltage = 1.25V
+        *
+        * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
+        *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
+        *      ≃ (value - 19791) * 1012 / 65536
+        */
+       ret = ((temp - 19791) * 1012L) >> 16;
        ao_mutex_put(&ao_temp_mutex);
        return ret;
 }