summaryrefslogtreecommitdiff
path: root/src/ao_convert.c
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 /src/ao_convert.c
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>
Diffstat (limited to 'src/ao_convert.c')
-rw-r--r--src/ao_convert.c10
1 files changed, 9 insertions, 1 deletions
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;
}