Your bit-banged read & write routines use a @ NOP for a 1uS delay, but you're running
at 20MHz so these are only 200nS. You would need 5 x @ NOP for a 1uS delay.
Your bit-banged read & write routines use a @ NOP for a 1uS delay, but you're running
at 20MHz so these are only 200nS. You would need 5 x @ NOP for a 1uS delay.
Thanks For The Math Help
As For As Speed Goes I Have Treid 4 And 20 Does Not Make A Difference
Will Work On The Math Issue
Do You Have The Thermostat Program In Pbp Not Hex
Thanks
Hi, Jcleaver
The thermostat program was for you to verify what you had to find ... and show you a different Bargraph view.
NOT to copy / paste it ...
You can find any parts of it on this forum, The DS18x20 subject has been widely explored during the past months.
but that need some little efforts ... is it the problem ?
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
This code works great and gives the correct temperature throughout the sensors range in both Fahrenheit and Celsius. The format is like this: TempC = 2250 = 22.50ºC, TempF = 7250 = 72.50ºF.
Code:ReadDS18S20: owout sensor,1,[$CC, $44] ' Send Start Temperature Conversion command owout sensor,1,[$CC, $BE] ' Send Read Temperature command owin sensor,0,[STR dq\9] ' Retrieve all 9 bytes of data RawTemp.Byte0 = dq[0] RawTemp.byte1 = dq[1] if RawTemp.8 = 1 then ' Check if temperature is a negative reading SignC = Negative RawTemp.lowbyte = RawTemp.lowbyte ^ 255 ' Invert data else SignC = Positive endif dummy = RawTemp.0 ' Store the half degree indicator bit TempC = ((RawTemp.lowbyte) >> 1) * 100 ' Divide raw data by 2 to give real temperature TempC = TempC + (dummy * 50) ' Add the half degree is present if SignC = Negative then ' Only proceed if temperature is negative if TempC => 1770 then SignF = Negative TempF = (TempC + 5000) * 900 TempF = div32 500 TempF = TempF - 12200 return else SignF = Positive TempF = (TempC + 5000) * 900 TempF = div32 500 TempF = 12200 - TempF return endif endif SignF = Positive TempF = TempC * 18 / 10 + 3200 return
Jack
The reason your PBP version did not work was because:
You attempted to convert C to F using the RAW temp from the DS18S20.
TEMP = ((TEMP*9/5)+32 )
Then tried to calculate the temp from the results.
Lcdout $fe, 1, dec (temp >> 1),".",dec(temp.0 * 5)," degrees C"
For the fun of it lets plug some numbers in assume 27.5 C is the temp today.
From the datasheet : The temperature sensor output has 9-bit resolution, which corresponds to 0.5°C steps.
so 27.5*2 = 55
Temp = (55*9/5) + 32 = 131
So Temp now is equal to 131.
Next we shift right 131>>1 same as temp/2 = 65.5
Hmmm 65.535 does that number ring a bell?
Wonder what would happen if you were to shift first then convert C to F like all of the other code posted does?
temp = (temp>>1*9/5) +32 = (27.5*9/5)+32 = 81.5 F
Hopefully this explains to you why it works in MikroBasic and not in PBP. The math is not broken, just the order of operation.
That is why I said check math, simple change would fix it.
Acetronic: I ask because you posted for jcleaver, would not take without asking first.![]()
Last edited by manwolf; - 24th July 2008 at 20:21.
I am trying to follow your code in an effort to better understand it, but I don't understand
SignC = Positive
It would help if you shared the declarations of the variables used.Code:ReadDS18S20: owout sensor,1,[$CC, $44] ' Send Start Temperature Conversion command owout sensor,1,[$CC, $BE] ' Send Read Temperature command owin sensor,0,[STR dq\9] ' Retrieve all 9 bytes of data RawTemp.Byte0 = dq[0] RawTemp.byte1 = dq[1] if RawTemp.8 = 1 then ' Check if temperature is a negative reading SignC = Negative RawTemp.lowbyte = RawTemp.lowbyte ^ 255 ' Invert data else SignC = Positive endif dummy = RawTemp.0 ' Store the half degree indicator bit TempC = ((RawTemp.lowbyte) >> 1) * 100 ' Divide raw data by 2 to give real temperature TempC = TempC + (dummy * 50) ' Add the half degree is present if SignC = Negative then ' Only proceed if temperature is negative if TempC => 1770 then SignF = Negative TempF = (TempC + 5000) * 900 TempF = div32 500 TempF = TempF - 12200 return else SignF = Positive TempF = (TempC + 5000) * 900 TempF = div32 500 TempF = 12200 - TempF return endif endif SignF = Positive TempF = TempC * 18 / 10 + 3200 return
sensor equates to the hardware pin connected to the sensor?
RawTemp is a word?
dq is an array of 9?
dummy is a byte?
TempC is a byte?
TempF is a byte?
I don't get SignC or SignF and how you can equate to 'Positive' or 'Negative', I couldn't find a reference in the PBP manual.
Explanation would be appreciated.
Regards,
Steve
Last edited by ecoli-557; - 9th May 2014 at 16:52. Reason: put in the code
"If we knew what we were doing, it wouldn't be called research"
- Albert Einstein
For positive temperatures the output increases from 0000h as the temperature increases from 0 deg C.I don't get SignC or SignF and how you can equate to 'Positive' or 'Negative', I couldn't find a reference in the PBP manual.
Explanation would be appreciated
For negative temperatures the output decreases from FFFFh as the temperature falls below -0.5 deg C.
To check for negative any output bit can be checked for 1, when that bit is outside the temperature range of the sensor. The data sheet says
The sign bit (S) indicates if the value is positive or negative: for positive numbers S = 0 and for negative numbers S = 1.
In the program RawTemp.8 is chosen as the sign bit.
Steve Earl www.datageo.co.uk
Bookmarks