Skip to content

ADC_INTERNAL_TEMP calculation in Example4 appears to be incorrect #158

Closed
@davexre

Description

@davexre

Subject of the issue

The calculation method for ADC_INTERNAL_TEMP described in the code for Example4 appears to be off by a wide margin - at least for the RedBoard Artemis.

Your workbench

  • What platform are you using?
    2018 MacBook Pro, Arduino IDE 1.8.12, SparkFun RedBoard Artemis

  • What version of the device are you using? Is there a firmware version?
    Apollo3 IC revision code: B0
    Arduino library v 1.0.30

  • How is the device wired to your platform?
    USB-C cable

  • How is everything being powered?
    via the USB cable

  • Are there any additional details that may help us help you?

Steps to reproduce

Connect a RedBoard Artemis and run Example4_analogRead

Expected behaviour

I would expect to see a valid temperature in degrees C - for normal room temperature, somewhere in the neighborhood of 20-22 (+/- 3 per the notes in Example4's code).

Actual behaviour

The code outputs a temperature in the 440 degree C range, instead. Example rows look like:

A3: 16383 VCC/3: 9134 VCC: 3.34V internalTemp: 441.09 vss: 0
A3: 16383 VCC/3: 9130 VCC: 3.34V internalTemp: 440.31 vss: 0
A3: 16383 VCC/3: 9131 VCC: 3.34V internalTemp: 440.84 vss: 0
A3: 16383 VCC/3: 9133 VCC: 3.34V internalTemp: 441.64 vss: 0

I added a bit of code to output the intermediate math steps - the data corresponding to the last row above is:
Internal temp raw: 8221 internal temp voltage: 1.68

So, 8221 is the raw read off the ADC, and that calculates to a voltage of 1.68 in the code (using 3.34v as the reference voltage).

@stephenf7072 and I had a discussion on the SparkFun forum ( https://forum.sparkfun.com/viewtopic.php?f=169&t=52770 ). He conjectured that Example4 should really be using 2.0v for vref (which corresponds to the ADC reference voltage), and then it looks like there's an offset on top of that. Subtracting 247 (for Stephen) or 242 (for me) gets us to a result like looks like our room temperatures. So, a raw reading of 8221 becomes 22C for me, which perfectly lines up with my current room temp. Basically, this code:

float temperature = (analogRead(ADC_INTERNAL_TEMP) * 2.0 / 16384) / 0.0038 - 242)

I've dug into the library code here a bit, but I've not yet pinned down the issue - this might not be something I can find without more intimate knowledge of the hardware spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions