Hi,
I recently got notified of your post from another member. I’m the “OP” you referred to. Yes I did have the same problem with Example4 as you had. There are two things wrong with that example. The first one, already identified by “stephenf” in his reply, is the need to use 2.0V as the reference voltage multiplier for the ADC, not the VCC voltage of 3.35V. With a 14 bit resolution the analog divisor is 2^14 = 16384 (rather than the 16383 you show in your post). For your analog reading of 8248 the voltage is then 8248*2/16384 = 1.0068V, which is similar to my readings near 68 degF. The next problem with the example is how they use the 3.8 mV/degC specification for the internal temperature sensor (see Apollo3 datasheet for specifications). This specification only provides the slope of an assumed linear temperature response. Unfortunately, the specification does not give the associated reference temperature and voltage at which this slope applies. These additional values are needed to find an unknown temperature. It would be reasonable to assume the reference temperature to be 68 degF (20 degC) since this is the reference typically given for RTD’s. But you still need the associated reference voltage, which will vary from chip to chip, as will the slope. But all is not lost, because all you need are two voltage readings at two known temperatures (obtained with an independent accurate temperature measuring device) to create a chip specific calibration! For the most accuracy the temperatures should be fairly diverse, ideally the extremes of the intended temperature measuring range but at least say 40 degF apart.
For a linear temperature response (which is a reasonable assumption for a limited range of temperatures, on the order of -20 degF to 240 degF, the slope is equal to (V2 - V1)/(T2 - T1). To find a new temperature T3, given a voltage reading V3, you can use either V1, T1 or V2, T2 as your reference in the following equation:
(V3 - Vref)/(T3 - Tref) = slope (now known from previous measurements). After rearranging you get:
T3 = Tref + (V3 - Vref)/slope.
The above will give you the most accurate calibration for a given chip. However, some Apollo3 boards, such as the Redboard Artemis, have factory calibration data, stored in flash memory, that can be read. These values are referred to as “Trims”. See the Ambiq SDK example adv_vbatt.c, in the SDK\boards\apollo3_evb\examples folder, to see how these values can be retrieved. The trim values are based on a hypothetical linear response from 0 degK to any other temperature. No temperature sensor is going to be linear over such an extreme range but the resulting equation will work over a reasonable range centered around 68 degF. The slope, using trim values, is:
slope = (Vtrim - Voffset)/(Ttrim - 0)
In the above equation Voffset is the theoretical voltage at 0 degK that correlates to the actual measured slope. The temperature equation, based on trims, is the same as that derived above with the exception that the temperature values must be in degK. Using Voffset and 0 degK as the reference values, this gives:
T3 degK = 0 degK + (V3 - Voffset)/slope = Ttrim degK*(V3 - Voffset)/(Vtrim - Voffset)
For boards that don’t have calibration data, the following generic values are provided in the SDK:
Ttrim = 299.5 degK, Vtrim = 1.02809V, Voffset = -0.00428V
These generic values result in a slope of 3.447 mV/degC, which is similar to calibrated values for my two Redboard Artemis boards, which are:
Board1: Ttrim = 298.601 degK, Vtrim = 1.01355V, Voffset = 0.003235V, which gives a slope of 3.3835 mV/degC
Board2: Ttrim = 299.45 degK, Vtrim = 1.00525V, Voffset = -0.00055V, which gives a slope of 3.3588 mV/degC
The calibrated values for Board2 produce results very close to independent temperature measurements, but those for Board1 differ by up to 10 degF! Therefore, the best calibration values to use are those you obtain yourself from two independent temperature readings and associated voltage measurements.