Aquarium Controller Temp. reading question?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Hi guys,

I have A question related to my previous posthttp://www.matrixmultimedia.com/mmforum ... f=7&t=8176

My temperature probe KTY-26 PTC. Is working correctly for sometime now. but only shows whole degrees like 25,26,27 but what I want is this 25.1, 25.2, 25.3 ect.
But I'm not sure how to get this to work ore how to start this to work. I looked in my datasheet and my Microcontroller (PIC16F877a) has an 10-Bit resolution so thats not a problem.

I tried to change 22 into 22.1 ect in the supplementary code section but that doesn't work @ all.
Can you help me to make this work.

I want to display a temperature range from 10 degrees C to 40 degrees C. whit a resolution of 0.1C.

Hope you can help.

Regards Jordy

ps. all the files cane bee found by clicking the link @ the top.
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Spanish_dude »

I did'nt look a t your code but I suspect you are using bytes (char) or integers.

Bytes and integers can't have point numbers.

Ex : 5/2 = 2 (for integers and bytes)

But there are 2 ways to solve this problem.
The first one is to use the "float" variable type, but you'll need to add C-code.
The second way to solve the problem is to as follows.

Ex: (5 * 10) / 2 = 25

Once you have this value you'll need to get the unit and write it after a '.' on the LCD.

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Hi spanish_dude,

Thanks for your reply.

About that,

Using floating point is not an option, because it uses to much memory.
but the seconde option sounds better but I don't fully understaint.
Maybe you explain in more detail.

Thanks,

Regards Jordy
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Spanish_dude »

Hi,

"In real life" dividing 5 by 2 would give 2.5, but integers can't contain point numbers.
(Doing integer = 5/2 will give you 2 instead of 2.5)

Thus multiplying 5 by 10 and then dividing it by 2 will give you 25 as result.

You then need to write on the LCD "2.5".
You'll need to find a method to add a "." between the "2" and the "5".

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Spanish_dude,

I don't understand you're calculation
When I read in 25*C because my lookup table says so (25 corresponds to a particulaire value)

When I multiply this by 10 >> 25*10 = 250 what I need to do next is divide this by 2 >>>> 250/2 = 125
I don't think thats correct. Ore do I use the formula in the wrong way, I dont now.

Please Help me.

Thanks,

Regards Jordy
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Spanish_dude »

Why would you divide by 2 ?
I was just giving an example on how to have a 0.1 precision using integers (without it using point numbers).
I could have written 5/3 or 5/4 instead of 5/2.

What you'll need to do is read the ADC value, multiply that by 10 and then execute some formula to get the ADC converted into °C.

(So you won't be needing any lookup table)

If you want to use a lookup table instead of a formula, the only way to get 0.1 precision is to add more measurements to your lookup table (with 0.1 precision of course).

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

So if you are intrested using 10bit ADC resolution then if would be possible to use a 10bit LUT (well your be using two 8bits to be precise)
See:
http://www.matrixmultimedia.com/mmforum ... igh#p20779
The only thing making it more complex if you have a range that the difference exceeds 255, then you will require another two sets of LUT
E.g you want to read a temperature of 10.0 to 40.0 you will require 400-100 = 300 LUT values
so your 300 LUT's will range from 100 to 400. then after retrieving you will need to conbert result to a string, display the fist two digits ON LCD using the LEFT$,2 function, then a decimal point, then the RIGHT$,1 function
If this is what you would like to try, then if you give it a go and if you get stuck, I will help you create your four 10bit look-up-table.
Just let be know the 10bit ADC range you will be reading
i.e the ADC value and the equivalent temperature.

I can understand why Spanish_dude said about using a formula. If the result is linear, it does makes things so much easier.
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Hi, Medelec

Soo much thanks for your reply,
I'm working on a 10bit lookup table right now and I'm hoping to finish this tomorrow.
I really appreciate your support.

Hope we can make this work :)

Regards Jordy Kleian
:P
the will to learn, should not be stopped by any price

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

I think this will do it.
I'm not sure maybe you can look it over for some errors.

Thanks Medelec


Regards Jordy
Attachments
10bit lookup-table.xls
(112.5 KiB) Downloaded 300 times
the will to learn, should not be stopped by any price

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

Hi Jordy,
Important: (only worked out whilst altering your excel sheet ...sorry. :oops: ) You only need two 8 bit LUTS because of the values you are retrieving!
See below.

I have altered your excel sheet slightly to show the LUT values that you can copy and paste.
I have not completed it, but hopefully there's enough completed to allow you to finish the sheet off.
The idea I have taken from Ben's excel sheet (he is a wizzard at exel :P ) that can be found here
http://www.matrixmultimedia.com/mmforum ... =28&t=8256
After you copied data form excel and pasted in Flowchart (suplemterey code window) , you must delete any double comma's.
E.g. if you see 118,,120, remove comma so it's 118,120, etc.
The idea is this:
If the value of 10 bit ADC is 176 bytes it's converted into the LUT retrieval value by taking 170 away.
176-170=6.

LUTa = 100,101,102,103,104,106,107,108,109,110,112 Etc


the sixth value of LUTa = 107
So after converting to a string = "107"
Lefts,2 "107" = "10"
Right$,1"107" = "7"
After DP placed in between two strings
= "10" "." "7"
10.7 displayed

To save rom space Look up table a should only be 100 to 255, so If ADC bytes is <309 then LUT a is Retrieved
If ADC bytes is >=309 then LUT b is Retrieved
This time instead of - 170, it is - 309
E.g if 10 bit ADC= 326, then LUT position retrieved is 326 - 309 = 17.
the 17th value of LUTb = 19
The good news is you will only need the two LUT in total.
This is because the high byte from 256 to 398 is always = 1
so LUT b need only contain the low bytes.
After retrieving low bytes, INT value = low bytes +256

So If the value of 10bit ADC is 326 bytes
since > 309, LUT b is used.
INT = 19 + 256 = 275 = 27.5 deg C

Hopefully I have explained all of this OK, and there this enough for you to finish.
If you get stuck, post what you have done so far and I will help you complete your flowchart.

Martin
Attachments
10bit lookup-table.xls
Modified Excel Sheet
(124 KiB) Downloaded 295 times
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

I really don't now what to do next.
What are LUT value 10Bit H and L. I dont now what you are maining, because you said
you only need two 8 bit LUTS because of the values you are retrieving!


I really don't now what to finish because I have now Idea what to do.
Why do I have to make 2 lookup tables. Why is it not possible to make one table with 100-400 import this to my flow code program.
And use the string manipulation to extract 275 into (27) & (5) and place a . in between.

Don't get me wrong here I really want to understand your way of working I really do, but it confuses my And I get a little bit stressed out because I dont have a clue.
Hope you will help me to understand the process of making a table the way you have explained to my.

I understand Its not always easy, but I'm willing to learn :wink:

Regards Jordy Kleian
the will to learn, should not be stopped by any price

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

Hi Jordy
Jordy101091 wrote: What are LUT value 10Bit H and L.
All Values of 10H when 10bit ADC>309 = 1
10Bit L = temperature x 10 - (10 bit H x256)
e.g if temperature = 39.8 deg C
then 10 bit low = 398 - (1 * 256) = 142
Jordy101091 wrote: Why do I have to make 2 lookup tables. Why is it not possible to make one table with 100-400 import this to my flow code program.
Regards Jordy Kleian
Unless I have misunderstood what you are saying, value of LUT can only be 0 to 255 as they are 8bit only.
so you can't use any value above 255
Jordy101091 wrote: Don't get me wrong here I really want to understand your way of working I really do, but it confuses my And I get a little bit stressed out because I dont have a clue.
I can appreciate what you are saying. It can be very difficult sometimes to think along similar lines of other people. That happens to us all ( My boss and wife will say that about me! :P :lol: ).
Besides It could be the way I worded it all, That's confusing.

Please remember, what I posted was
1) Just theory I thought of.
2) May not be the best method or even work.

If you can, I would recommend you post your flowchart (Or send in a PM if you don't want it to be available to the public) before the point of getting stressed.
We want this to be an enjoyable task, not a stressful task!
Then you will be able to look at the flowchart I modified, and follow how it works.
Don't worry about completing Excel Sheet I will do that as well.

Martin
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Thanks For understanding,

Maybe I will understand you're method of making the LUT a bit better when its completed.
Looking forward to see the result.

Thanks Again for helping me out here, really appreciate it.

Regards Jordy
the will to learn, should not be stopped by any price

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

Hi Jordy,
No problem.

I have modified excel sheet to allow you read 10bit ADC and convert it into Temperature from 10.0 C to 40.0C
I have changed the way excel retrieves the data, so you don't have to look for commas and delete them.
Attached is also a flowchart that has excel data imported, so you should be able to follow how it works easier.
To convert to your flowchart, its just a case of changing some variable names.
If you want to give it a try for your self, then if you get stuck I will complete your flowchart for you and send it in a PM.
Main thing is, don't let it get to the point you get stressed.
Let me know in a PM if you are struggling.
Have fun trying and good luck :)

Martin
Attachments
Flowcode temperature test_Modified 10bit.fcf
(12 KiB) Downloaded 334 times
10bit lookup-table2.xls
(150 KiB) Downloaded 221 times
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

He Martin,

I don't now how you have done this, but it works man wonderful.
But I really like to know How the program works, If its not to much trouble, can you explain my step-by-step whats going on.
Also I'm beginning to understand how the lookup table works but when I want to look where you get the data from the look up table B I cant find it, Its like the rows are invisible.

Hope you can help me out.

Regards Jordy
the will to learn, should not be stopped by any price

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

Sure I can help you out.

First I have hidden the wrong columns, that's why you can't see how LUTb was created. I was meant to hide column U, Not S or T sorry about that.
You can just drag the columns to un-hide them.
But I have Attached an unhidden Sheet anyway.
The main formula used was to convert 10bit integer to two 8bits.
I.e ByteHigh = (IntValue/ 256)
ByteLow = IntValue - ByteHigh* 256

The value of LUT required is in column Q
So column R = 8bit value of column Q but only when column Q is below 256.
column S = high byte value of column Q necessay when number is higher than 255. when int value is >255 but < 512 then High byte = 1
column T = low byte value of column Q. Since high byte is 1, This is found by value of column Q - (1x256)
E.g if value in column Q= 283 then low byte = 283-(1x256) = 27

column P is place in the LUT a number is retrieved. 0 = 1st number, 1=2nd number etc.

Your Excel sheet is a bit different to how I have normally seen them done.
Namely its normally the ADC Bytes that goes up sequentially by 1 and LUT value is derived from ADC Bytes. But still it works the way you have done it so well done for that. :)

Martin
Attachments
10bit lookup-table2.xls
(150 KiB) Downloaded 209 times
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Hi, Martin

I have made some changes to your flow code so I can Use it with my own program. And it works :)
Thanks again.

Image


But I have A little question for you, How can I use an interupt to update the temperature every minute. Now I have made a simple counter that counts to 30000 and then reads the ADC and returns again and start counting from 0 to 30000 (it only gives me an delay of 10ms). I think this can be done more effective. Can you explain me How this can be done.

Thanks Again.

Regards Jordy
the will to learn, should not be stopped by any price

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

Jordy101091 wrote:Hi, Martin

I have made some changes to your flow code so I can Use it with my own program. And it works :)
Thanks again.
That's great! Glad you got it working OK. Your program looks very good!
I used that flowchart because that's the one you originally posted, so at least I know the config settings work for you.
Jordy101091 wrote:How can I use an interupt to update the temperature every minute. Now I have made a simple counter that counts to 30000 and then reads the ADC and returns again and start counting from 0 to 30000 (it only gives me an delay of 10ms). I think this can be done more effective. Can you explain me How this can be done
I have used timer2. Only reason used that timer is because timer1 is used with PWM, and you may need to set watchdog timer with an extended time out duration. That can be achieved by altering a prescaller that is normally shared with timer0.
I have updated file you sent via PM,and set it back with the Temperature to update every minute routine. Note: using Timer2 means it will not update with Flowcode simulator, but will work on your hardware.
How it works:
Timer2 has the interrupt frequency set for 75Hz. This means access Timer_Tick macro will be accessed 75 times a second, no matter what part of program is being accessed.
With interrupt, when ready to trigger after a set period of time, the program will halt, call the interrupt macro, then when that's finished, program will continue from where it left off.
Each time the interrupt macro is accessed, count is incremented by 1.
As soon as interrupt macro has been accessed 75 times, then 1 second has passed so count is reset to 0 and Seconds is incremented by 1.
As soon as 60 seconds has passed a flag called Update is set to 1.
In the main routine. If update is = 0 then Temperature Macro is not accessed.
When update is = 1 then Temperature Macro is accessed, and update is reset to 0, so it waits for the next minute to elapse.

Hope this helps.

Martin
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

So much thanks to you Martin you're comments are really useful really appreciate it.
I hope that you want to continue helping me with problems I maybe have in the future.

Thanks again.

Regards Jordy Kleian :P
the will to learn, should not be stopped by any price

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: Aquarium Controller Temp. reading question?

Post by medelec35 »

Your welcome Jordy,
Is your project working the way you wanted it to, including Temperature that updates every minute?

Martin
Martin

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: Aquarium Controller Temp. reading question?

Post by Jordy101091 »

Almost,

The temperature reading is working correctly.
The update time of one min. Is working fine. The only
Thing thing that's not completely working, is the notification of
The temp. To high to low. But that only needs math.

The next step is to make room for an ph sensor, current sensing circuit.
And a USB interface.

So there lots of work to do.

Greetings Jordy
the will to learn, should not be stopped by any price

Post Reply