summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-01-10 16:31:50 -0800
committerKeith Packard <keithp@keithp.com>2010-01-10 16:35:58 -0800
commit9856b7c4397afcecc8f541af9a83824e817b3612 (patch)
tree71d2d68717c29cd96addd22d1734bbb5040a4b56
parent0c2533be15858774ef9381aa8c8344356fd5b971 (diff)
Switch to using internal cc1111 temperature sensor
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>
-rw-r--r--ao-tools/ao-view/aoview_state.c8
-rw-r--r--ao-tools/lib/cc-convert.c11
-rw-r--r--src/ao_adc.c12
-rw-r--r--src/ao_convert.c10
4 files changed, 30 insertions, 11 deletions
diff --git a/ao-tools/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c
index 838899a7..505bcddc 100644
--- a/ao-tools/ao-view/aoview_state.c
+++ b/ao-tools/ao-view/aoview_state.c
@@ -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++;
diff --git a/ao-tools/lib/cc-convert.c b/ao-tools/lib/cc-convert.c
index ac6962ba..8d6876a0 100644
--- a/ao-tools/lib/cc-convert.c
+++ b/ao-tools/lib/cc-convert.c
@@ -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
diff --git a/src/ao_adc.c b/src/ao_adc.c
index b0bfceb1..2b972e6c 100644
--- a/src/ao_adc.c
+++ b/src/ao_adc.c
@@ -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();
diff --git a/src/ao_convert.c b/src/ao_convert.c
index 57ed7370..f29ce9e9 100644
--- a/src/ao_convert.c
+++ b/src/ao_convert.c
@@ -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;
}