Help With Temperature

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:

Help With Temperature

Post by Bobw »

I am trying to display temperature in degrees Fahrenheit.
I am using the following sensor :
http://ww1.microchip.com/downloads/en/D ... 21942e.pdf
I am also using a 16F1827
I am able to read the sensor no problem.
I am using an example that John Crow (thanks John) had posted http://www.matrixmultimedia.com/mmforum ... 445#p49124

This work fine but I am lost as to how to convert it to one decimal place and display in degrees Fahrenheit.

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

Re: Help With Temperature

Post by Bobw »

Guess I can not compile it to hex
get the following errors

FCD_ADC1_ADC_RAW_Average_Channel_Byte in: C:\Users\Bob-Notebook\Documents\FlowCode\newhum5.c
FCD_ADC1_ADC_RAW_Average_Channel_Int in: C:\Users\Bob-Notebook\Documents\FlowCode\newhum5.c
FCD_ADC1_ADC_RAW_Disable_Channel in: C:\Users\Bob-Notebook\Documents\FlowCode\newhum5.c
License restricted by the following files:
C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/libc.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/rand.pic16.lib C:\Program Files (x86)\Flowcode\v5\Tools\BoostC\lib/float.pic16.lib newhum5.objRecompile the code with a less restrictive compiler license!
License exceeded by RAM: 0 bytes
License exceeded by ROM: 690 words
You have reached the limit of the Standard License
PIC12,PIC16 max code size:4096 words, max RAM banks:Unlimited, Non commercial use only
You can upgrade your license. Please visit: http://www.sourceboost.com
failure
Return code = -2
Flowcode was unable to assemble the ASM file due to the following errors:

Guess I need a new license

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Help With Temperature

Post by Benj »

Hello,

What license type are you currently working with? Is it the home/student version?

I think you can either pay the difference to upgrade to pro or upgrade to a v6 license.

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

Re: Help With Temperature

Post by Bobw »

I am using the home student version.
I read in other post where floats take up a lot of ROM, did not realize it was that memory hungry.
May just leave it at whole numbers.
Have attached what I have so far using whole numbers.
It works great for Humidity. My temperature calculations are off.
I have it in a loop to just get the temperature working before I move on to the rest.
Humidity appears to be right on with my calibrated humidity device I have. The sensor I use is very sensitive, just breath on it and it will read a change.

Bob
Attachments
newhum44.fcf
(15.2 KiB) Downloaded 304 times

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

Re: Help With Temperature

Post by Bobw »

After reading more on floats, I think I will use the LEFT and RIGHT function to get the results I need.
I am not sure how to set the ADC to read the 10 bit resolution (0-1023) or 0.004883 MV per step.
Do I have to use the VREF pin of the PIC by connecting +5 volts to it, or is that done internally?
I know that 10MV from the temp sensor=1 degree C.
Using Voltage in/0.01 should give me a digital reading *0.4883 = tempC
I am lost as the the variables I need to set, and should they be float values or integers?

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

Re: Help With Temperature

Post by Bobw »

Thanks to this post:
http://www.matrixmultimedia.com/mmforum ... 523#p56523
I have it figured out and working.
For those also building projects, do read other post, down load the included charts. It took me looking at 3 other examples before I understood how the LEFT and RIGHT commands worked, how to properly read the ADC value and figure how it relates to temperature change (Have DATA sheet handy)
I am glad someone did not just make it work for me, but that I understand how it works.

Yes I copied the code that Bill and Martin used, but I understand the inner workings of it which is even better.
It is a real winner work around as opposed to using memory intensive FLOATS.
I am worried it wont display a negative temperature, but will see when I stick the probe in my freezer (should be -1 to -5 F).
Thanks to all on this board for all the help over the years.

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: Help With Temperature

Post by medelec35 »

Hi Bob,
Glad you have got your flowchart working and one of my flowcharts contributed to helping you..
Bobw wrote:For those also building projects, do read other post, down load the included charts.
I totally agree with that.
Bobw wrote:I am glad someone did not just make it work for me, but that I understand how it works.
I also agree with that as I believe you learn far more by studying other flowcharts than saying can you create a chart for me.

Thanks for letting us know :)

Matin
Martin

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

Re: Help With Temperature

Post by Bobw »

I think my calculations may be still off.
My temp sensor can go from -40C to +125C or 10.0mv per degree C. (yes I am using Fahrenheit but can convert it all later)
That would = 165 steps.
If I read the ADC as an int. I can get 1024 steps (0-1023)
If I divide the ADC value(1024) by the sensor steps (165) this should give me 6.206 or an increase in ADC value of 6.206 per each degree of temperature increase.

Two questions:
1) is my basic math correct?
2) How should I adjust so that I could show a negative temperature?

I am using this equation to start:
Fahrenheit = ReadADC * 49 / 10


I have it figured out how to display a decimal number without the floats. And I can easily convert C to F later.

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: Help With Temperature

Post by medelec35 »

Hi Bob.
I have worked out a formula that hopefully should convert an integer directly into Fahrenheit * 10
So you can try:
Fahrenheit = ADC*88/10-576
Hopefully this should read temperature from -40F to +257F with greatest error in some places of +/- 4.4F
It's just a starting place until a better formula is found.

Note Minimum ADC = 20 = -40F
Max = 358 = 257F

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: Help With Temperature

Post by Bobw »

Martin,
Thank you will give it a go.

I do have a question about ADC VOLTAGE. If you try to read ADC voltage in the Simulator, it only displays whole numbers. 0 volts to 5 volts.
I am hoping that in real life it will read 1024 steps (10 bit) of 0.0048828125 volts per step up to 5 volts.

Should have bought a Fahrenheit sensor, would have save some head aches.

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: Help With Temperature

Post by medelec35 »

Hi Bob,
With int and bytes there are only whole numbers.
So what the formula does is take the value of ADC = 0 to 1023 and converts it to Fahrenheit * 10 as stated on my previous post.
What you need to get the flowchart to do is precede the last number with a decimal point i.e:
Reading F V1.png
(43.93 KiB) Downloaded 4928 times
I modified the flowchart posted here:
http://www.matrixmultimedia.com/mmforum ... 523#p53142
With the revised formula.

Note ADC 40 = 195 mV

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: Help With Temperature

Post by Bobw »

Martin,
Your formula works great!!!! Appears to be about +- .3 degrees compared with a calibrated thermometer I have here.
If I could ask you to break down your formula so I can make sure I understand the actual numbers.
What does the 88/10-576 all stand for?
I think a basic mistake I was making was thinking that at the lowest reading of my sensor -40C the ADC would be at Zero (not True), and at the highest +150C it would be 1023 (not true).
I also failed to take into consideration that while the PIC does not deal with decimals well, it will deal with them if you increase their value to a higher number (Val*100).
I see many temperature related post on here, I have been taking notes and think I will try to write a tutorial for others when I am done. Most like myself get lost in the formulas verses the actual use of FLOWCODE.
I can see where floats may provide a bit more accuracy if needed, but using the LEFT,RIGHT string manipulation works just as well with much less memory loss.

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: Help With Temperature

Post by medelec35 »

Hi Bob,
Bobw wrote:Your formula works great!!!! Appears to be about +- .3 degrees compared with a calibrated thermometer I have here.
Wow!
Thanks for that as I was not expecting it to work that well to be honest.
Bobw wrote:If I could ask you to break down your formula so I can make sure I understand the actual numbers.
No problem, I can post step by step so you can see how I derived at

Code: Select all

88/10-576
This all relates to MCP9700/9700A and displaying results in deg Fahrenheit:

First I looked at the data sheet and it stated that voltage changes by 10mV per deg C and the offset is 500mV.
So at 0 deg C the Voltage out will be 0*0.010+0.5
Next I created a spread sheet and placed a 0 in column A, then you can see what I did in all the other columns:
Step1.png
(3.74 KiB) Downloaded 4910 times
Then I got column A to increment by 1 going below the 0 and decrement by 1 going above the 0, then dragged all the cell formulas to fill all the blank cells up to -40C and down to 125 since
Next I opened my Formula Generator which Can be found here:
http://www.matrixmultimedia.com/mmforum ... 99&#p13504
Entered the following data from the top row:
Step2.png
(4.7 KiB) Downloaded 4910 times
And the data from the last row:
Step3.png
(11.42 KiB) Downloaded 4910 times
Into my Formula generator:
Results.png
(10.41 KiB) Downloaded 4910 times
Now a bit of PIC integer knowledge is handy.
For example since the maximum integer number is 32767 you can't exceed this within a calculation
Since the highest value for ADC is 358 then you can't use 358 * 879 since 314682 is greater than 32767.
The way around this is use 358*88
Now you know where ADC * 88 comes from.
the 10 is used because it was originally /100 but we have multiplied by 88 instead of 879.
Final part on the formula generator is -28787/50
I just broke that down a bit more by:
28787/50 = 575.75
I just rounded it up to 576.
Putting it all together:
88/10-576

Martin
Martin

Post Reply