temperature calculations

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

temperature calculations

Post by Bobw »

I am using a thermistor into an ADC port for temperature.
In most of the post I have read, most reference a LOOK UP table to compare the ADC value to displayed temperature.
I have two variables Labeled "temp" = Byte (0-255), the second labeled "adjtemp" =integer (-32768 to 32767)
Not having the actual sensor I as of yet, I do not know what the actual voltage drop it will cause in real life. In simulation I use the following calculation:
adjtemp = temp- 50
This will now give me a variable that can provide a negative number. When I adjust the slider (in the sim) I can display a negative value for temperature.
Until I actually build the circuit I have no idea how much to subtract, But I think I can get it close enough for the 1 degree F resolution I am looking for.
Any thoughts?

Bob

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: temperature calculations

Post by medelec35 »

Hi Bob,

Yes the

Code: Select all

adjtemp = temp- 50 
would be the way to go.
That would probably be better than using 16bit LUT method.

My thoughts would be to have an initial offset first.
This is because the 1st data is retrieved when ADC = 0
While reading a temperature, no matter what the temperature ADC should never be 0
So if for the very lowest temperature ADC is 85 then to save wasted ROM space you could have:
Room Temp LUT1.png
(77.09 KiB) Downloaded 3237 times
The 147 was to limit the highest temperature, so LUT max has not been exceeded.
You will need to change that for your application.

We can help you further when your thermistor arrives.
Do you have a datasheet or part number for your thermistor?
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: temperature calculations

Post by Bobw »

I am using a Microchip MCP9701T-E/TT
Data SHEET:http://www.mouser.com/ds/2/268/21942e-53364.pdf
From the data sheet:
temperature coefficients are scaled to provide a 1°C/bit resolution for an 8-bit ADC with a reference voltage of 2.5V and 5V, respectively
• Wide Temperature Measurement Range:
- -40°C to +125°C (Extended Temperature)
- -40°C to +150°C (High Temperature)(MCP9700/9700A)

• Accuracy:
- ±2°C (max.), 0°C to +70°C (MCP9700A/9701A)
- ±4°C (max.), 0°C to +70°C (MCP9700/9701)
• Optimized for Analog-to-Digital Converters (ADCs):
- 10.0 mV/°C (typical) MCP9700/9700A
- 19.5 mV/°C (typical) MCP9701/9701A
• Wide Operating Voltage Range:
- VDD = 2.3V to 5.5V MCP9700/9700A
- VDD = 3.1V to 5.5V MCP9701/9701A
• Low Operating Current: 6 µA (typical)
DC ELECTRICAL CHARACTERISTICS
Electrical Specifications: Unless otherwise indicated:
MCP9700/9700A: VDD = 2.3V to 5.5V, GND = Ground, TA = -40°C to +125°C and No load.
MCP9701/9701A: VDD = 3.1V to 5.5V, GND = Ground, TA = -10°C to +125°C and No load.

I think it will serve my purpose.

Bob

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: temperature calculations

Post by medelec35 »

Bobw wrote:I am using a Microchip MCP9701T-E/TT
A LUT is only required for the non linear standard negative or positive temperature thermistors.
You will not require a LUT for the part you posted about.

Just a basic calculation box will sort that out nicely.

For example if you ReadAsInt with adc component and an Int variable called Temperature.
Then you can use the following formula:
Temperature =Temperature /4 - 20

That should allow a direct temperature reading from -20C to the maximum temperature range of MCP9701T

You wont be able to go lower than -20 unless you choose MCP9700 series.
Then a different formula is required.

Edit:
In theory you can ReadAsByte as the byte would increase or decrease by 1 per degC as 1 byte = 0.0196V
So a different formula can be used.
I just thought it may be more accurate reading as Int, but not got that sensor so unable to test theory out.

Martin

Martin
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: temperature calculations

Post by Bobw »

Martin,
Thanks for the input.
I know there are a few ways to go about it. Was just trying to avoid using a LUT. Yeah I am lazy that way.
I am going to start a new thread and post my project as it goes along. I know watching the development of other peoples projects has helped me in the past.
Have enough to do writing all the decision trees to compare temperature to humidity. I have one so far and things simulate about the way I wanted.

Bob

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: temperature calculations

Post by medelec35 »

No worries.
The Way I described it on post dated Sun Jan 26, 2014 2:30 pm, was avoiding LUT's :)

To check if you have got formula correct is to look at the datasheet for MCP9701 you will see that at 0C (32F ) the voltage out is 400mV
With ReadAsByte the LCD should show a reading of 32F when ADC = 255/5*0.4 = 20
Or
Slider is showing (100/255) * 255/5*0.4 = 8%
So when the Blue value shown below the slider is on 8 you know that the sensor is reading approx 0C or 32F
When the Blue value shown below the slider is on 25 you know that the sensor is reading approx 43C or 109F

It would be wise to use the graph of FIGURE 2-16 on the data sheet to check all is correct by converting the voltage into byte or INT, then use the byte or int as a value after the ADC read i/p
Easiest way is to add the Temp variable to the variable watch window.
Set a break point for the icon that's next one down to the read ADC component. then select run. when stopped at the break point enter the byte or int value on the variables watch window.
Check the reading on LCD is same or similar to expected temperature shown at FIGURE 2-16 on the data sheet.

I have attached a flowchart with the new calculation within for you to have a look at.
Note, the temperature will looks like it jumps a lot within simulation. that is because the slider value is in % and not int.
1% approx change of 11 int.
So when going from 8% to 9% the ADC is going from 81 to 92

I have also added a small bit of hysteresis so motor is not going on/off/on/off etc. around the set point.

In theory temperature displayed in deg F should be correct for MCP9701T.
I have used the following to convert deg C to deg F:
F = (C * 18 +320)/100
Perhaps you could try it when your sensor arrives?

Martin
Attachments
TempHumV2.fcf
(20.37 KiB) Downloaded 315 times
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: temperature calculations

Post by Bobw »

Martin,
I know my temperature/Humidity calculations will need to be cleaned up.
The temperature probe will be mounted aprox 25' external to the board so wire resistance and such will play into the final numbers. I am still writing out my Yes/No trees on paper before I flowcode them. 13 of them so far, and that is just for the temperature. I am including some hysteresis into my trees.

Bob

Post Reply