Raw Register Decode and Thermocouple Volts

Ada re-derives this chapter’s own numbers step by step, at full precision

foundations
math-foundations
calculation-audit
sensors
Ada ADA · CALCULATION AUDIT

Raw Register Decode and Thermocouple Volts

The chapter walks through raw DS18B20 register pairs to decode into Celsius, including a case that combines to 0xFF90 — either -7.0°C once two’s complement is applied, or a nonsensical 4089°C if the sign bit is ignored — alongside a K-type thermocouple example with hot junction 250°C, cold junction 25°C, and a 200x amplifier gain. This audit asks the question that discrepancy invites: is the naive unsigned read of 0xFF90 just a rounding slip, or does skipping the sign convention turn a valid cold reading into complete nonsense?

Companion to the chapter Lab: Temperature Sensors — every number here comes from that chapter.

Ada: This chapter runs two conversions worth checking to the digit: the DS18B20 register-to-Celsius decode – including the signed case, where a naive parse is dangerous – and the K-type thermocouple voltage. The DS18B20 rule is T = raw / 16, because the low four bits hold the fraction, so one LSB is 1 / 16 = 0.0625 C.

The three register cases:

  • 0xD0 0x01 little-endian combines MSB:LSB to 0x01D0 = 464, so T = 464 / 16 = 29.0 C.
  • 0x90 0xFF combines to 0xFF90. Read as unsigned that is 65424, but bit 15 is set, so two’s complement gives 65424 - 65536 = -112, and T = -112 / 16 = -7.0 C. Skip the signed step and you would report 65424 / 16 = 4089 C – the difference between a valid cold reading and nonsense.
  • 0x0550 = 1360, so T = 1360 / 16 = 85.0 C, the power-on default.
  • At 9-bit resolution the low three bits are undefined, so the step widens to 2^3 / 16 = 0.5 C.

The K-type thermocouple (Seebeck coefficient ~41 uV/C, hot 250 C, cold 25 C, 200x amplifier, 12-bit 3.3 V ADC):

  • V = 41 x (250 - 25) = 41 x 225 = 9225 uV = 9.225 mV.
  • After gain: 9.225 mV x 200 = 1845 mV = 1.845 V, safely under the 3.3 V rail.
  • One ADC step is 3.3 V / 4096 = 0.8057 mV, which maps back to 0.8057 / (41 x 200 / 1000) = 0.0983 C per step.

The audit’s lesson is that the signed decode is not optional bookkeeping: the same 16 bits read as +4089 C or -7.0 C depending on whether two’s complement is honored, so the register width and sign convention belong in the acceptance test right next to the temperature.

Every number above is taken from the chapter’s own material and re-derived step by step.