Page 2 of 2

Re: DS18B20 Temperature Component Macro

Posted: Sun Sep 20, 2015 3:03 pm
by medelec35
Hi Ted,
TedO wrote:By the way, your MPC9701 thermometer works very well
Thanks.
If you prefer that sensor I can incorporate within your application.


Reason why you Flowchart is not working when you add in your case:

Code: Select all

Temp = Temp * 49 / 10
Is because the string part has been removed.
Reason it makes a difference is because when GetInt is used along with Temp = Temp * 49 / 10 then the temperature result will be temperature * 10
for example if room is 20deg C, since LM35 has 10mV per C output then Vout = 0.01 * 20 = 0.2V
ADC for 0.2V is 1024/5*0.2 = 41
Therefore after the formula Temp = Temp * 49 / 10
When Temp = 41
Temp = 41 * 49 / 10 = 200 = 20.0 degC

I have modded your flowchart to give the extra decimal point, but done it without the complexity of the strings so I actually prefer it this way.

That can easily be removed if necessary.

Martin

Re: DS18B20 Temperature Component Macro

Posted: Mon Sep 21, 2015 10:51 am
by TedO
Hi Martin

Thanks once again for bailing me out due to my inexperience! Your valued sharing of your experience to newcomers is greatly appreciated, my friend Martin will be delighted to hear about the help.
I fully understand the formula now having seen that the ADC has a 10 bit output which is 2 to the power 10 =1024, what I don't understand is the 49....how does it fit into the equation?
The reworked oil controller is more than I expected as I did not know how to read the value after the decimal point, please explain what the "MOD" command does.
Please excuse my inquiring mind, it is the only way to learn!! I am sure the name "medelec" stands for electronic medic :D which you have been to me so unselfishly.

Rgds
Ted

Re: DS18B20 Temperature Component Macro

Posted: Mon Sep 21, 2015 4:42 pm
by Benj
Hi Ted,

I can't explain the 49 but I can help with the MOD function.

Mod or modulus is basically giving you the remainder after a divide operation.

so...

21 mod 10 is 1
33 mod 10 is 3
54 mod 10 is 4
60 mod 10 is 0

It will eat up lets say more than a few processor cycles so best not to use unless you need to or if your not bothered about the run speed. Saying this it is significantly faster than using a floating point calculation.

Re: DS18B20 Temperature Component Macro

Posted: Mon Sep 21, 2015 6:24 pm
by medelec35
Hi Ted,
TedO wrote: Thanks once again for bailing me out due to my inexperience! Your valued sharing of your experience to newcomers is greatly appreciated, my friend Martin will be delighted to hear about the help.
No problem,
Glad I can help you and your friend with the cool name :lol:
TedO wrote: what I don't understand is the 49....how does it fit into the equation?
Where I got the 49 from is:
1 deg = 10mv = calculated ADC of 1024/5*0.01 = 2.048
So if you have ADC of 2.048 then to get temperature you need to times by 1/2.048 = 0.488 or rounding up to 0.49
Which should be more accurate then 0.5
Without floats you cant times by any number apart form whole numbers.
E.g with PIC maths using integers 200 * 0.9 = 0
as I want to times by 0.49 whats required is first multiply up to a whole number = 49 then you can times by ADC value, then divide back down.
TedO wrote:Please excuse my inquiring mind, it is the only way to learn!! I am sure the name "medelec" stands for electronic medic :D which you have been to me so unselfishly.
Best way to learn in my opinion.
You are so near!
medelec is because I use to service medical equipment so short for medical electronics

Martin

Re: DS18B20 Temperature Component Macro

Posted: Tue Sep 22, 2015 2:19 pm
by TedO
Hi Martin

The oil temp controller is working like a charm now, need to transfer the design onto a PCB. My friend with the cool name has asked me to thank you for your help. Thanks also to Benj for explaining the Modulus function.

Thanks also for explaining the calculation formula and how you came to use the number 49, I understand it perfectly well now, it won't trip me again!

You would make an excellent electronics tutor, seriously.

Rgds
Ted