summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0c2533b)
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>
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);
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++;
if (!strcmp(data->state, "pad")) {
if (data->gps.gps_locked && data->gps.nsat >= 4) {
state->npad++;
return (ground_accel - accel) / count_per_mss;
}
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)
{
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;
uint8_t __xdata *a;
sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT;
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 */
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();
} else {
/* record this conversion series */
ao_adc_ring[ao_adc_head].tick = ao_time();
int16_t ret;
ao_mutex_get(&ao_temp_mutex);
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;
}
ao_mutex_put(&ao_temp_mutex);
return ret;
}