Skip to content

Commit f7d39ce

Browse files
committed
comment on the revised algorithm
1 parent a943167 commit f7d39ce

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ports/atmel-samd/common-hal/microcontroller/Processor.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@
8383

8484
// Extract the production calibration data information from NVM (adapted from ASF sample),
8585
// then calculate the temperature
86+
//
87+
// This code performs almost all operations with scaled integers. For
88+
// instance, tempR is in units of 1/10°C, INT1VR is in units of 1mV, etc,
89+
// This is important to reduce the code size of the function. The effect on
90+
// precision is a ~.9°C difference vs the floating point algorithm on an
91+
// approximate 0..60°C range with a difference of ~.5°C at 25°C. When the fine
92+
// calculation step is skipped, the additional error approximately doubles.
93+
//
94+
// To save code size, rounding is neglected. However, trying to add back rounding
95+
// (by computing (a + b/2) / b instead of just a / b) actually didn't help
96+
// accuracy anyway.
8697
#ifdef SAMD21
8798
STATIC float calculate_temperature(uint16_t raw_value) {
8899
uint32_t val1; /* Temperature Log Row Content first 32 bits */

0 commit comments

Comments
 (0)