Here's the fourth patch in the Build-a-Driver series for MCP9808.
(If this post seems out of context, please refer to "Build-a-Driver Introduction" post.)
This patch updates the temp calculation.
In hindsight, I should have implemented the changeable resolution times before the temp calcs. Although the temp calcs could be done purely w pencil/paper at any time, it wasn't until I started testing resolution times that I more fully understood the resolution model.
Still returning that 12 bit raw temp value, but changing the scale.
Ambient Temp = raw * integration_time
Ambient Temp = raw * (1/2^shift * integration_time)
Ambient Temp = raw * .06250
Integration time * Shift = Scale
.5 * .125 = .0625
.25 * .25 = .0625
.125 * .5 = .0625
.0615 * 1 = .0625
Scale is now returned as 62500 and IIO_VAL_INT_PLUS_MICRO
After the next patch with the resolution switching support, I'll post the test data & proof this works.
This version mcp9808-calc-v2.c
To view complete revision history go here.
Labels: Build-a-Driver, MCP9808