-
-
Notifications
You must be signed in to change notification settings - Fork 17
PDB STM
Context
Here is a representation of the thermistor setup
Problem
The ADC for the temperature sensor takes in voltage drop from a thermistor. We need to convert this to the temperature. However, datasheets for different thermistors differ in how they report how a change in temperature affects the thermistor. For example, during 2022-23's development cycle, the thermistor's temperature coefficient was given in terms of millivolts/degree Celsius. Meanwhile, the 2023-24 thermistor had its temperature coefficient given in ohms/degree Celsius.
Solution
Example: 2022-2023 thermistor: MCP9701A
Since we know the relationship between volts and Celcius, we can just get the temperature directly from the ADC.
The general equation for converting ADC value (
So, we need to get the parameters of the ADC. The STM boards should have a 12 bit ADC. The thermistor is also powered by a 3.3V source. This means the math to convert the ADC value to voltage will be:
Once we have this, we can just calculate the difference between the ADC voltage and the voltage at a base temperature (
For the 2022-2023 development cycle, the base temperature was 0 degrees celcius, the voltage at that temperature was 0.4V, and the temperature coefficient was 0.0195V/degree Celcius. So, the equation becomes:
Example: 2023-2024 themistor: TMP6431DECR
The calculations for this one are a bit more complicated than the Volts/Celcius section. But don't worry, it's fun! 😄
The basic premise is the same. We have to convert the ADC value to Celcius. The ADC value is linked to the voltage of the thermistor. We then need to use that to find the resistance of the thermistor, and then find the temperature.
Finding the voltage from the ADC value is the same as the first section, or:
And after we plug in the same values, we get:
To get the resistance from the voltage, it might be easier to get the voltage from the resistance first, and then rearrange the equation. Since the output to the ADC is in parallel to the thermistor, the voltage drop over the themistor is the same as the voltage read by the ADC. From the diagram at the top of the page, we can see that the circuit forms a voltage divider. This means the voltage drop over the thermistor will be the voltage source times the thermistor resistance divided by the total resistance, or:
After some rearranging to solve for the resistance of the thermistor, we have:
Which can also be written as
The source voltage is the same 3.3V, so we have:
Now, since we have to resistance of the thermistor, we can relate that to the temperature. The 2023-2024 thermistor had a temperature coefficient(
We also know the resistance at a base temperature(
And after plugging in the values we have:
Now, we can plug the resistance of the thermistor into the equation and get the temperature in terms of the ADC value (as stated above, the voltage read by the ADC is the same as the voltage drop over the thermistor, so we can substitute
In the code, this equation is broken down into the ADC Voltage, Thermistor Resistance, and Final Temperature for readability.
Context We have a PDB on the rover.
Problem
Solution