PDA

View Full Version : Read DS18S20



PICante
- 18th September 2008, 16:44
Hi all.

Short time ago I found this code posted by CocaColaKid “ReadDS18S20” in this thread: http://www.picbasic.co.uk/forum/showthread.php?t=8974&highlight=DS18S20
Very neat I thought until I discovered that the STR function is not supported for 16FXXX, too bad. I have searched and found other pieces of code but they all seems to have a different approach to the task and I felt I could understand this code better. The PBP manual is not very helpful on OW and my question is what do I need to be change (and why) in this code to make it compile for the 16F688?

Thanks!

skimask
- 18th September 2008, 17:09
Very neat I thought until I discovered that the STR function is not supported for 16FXXX, too bad
Double check your manual...and compare what it says to the datasheet for the 16F688.
'cause it looks to me like everybody in that other thread is using a 16Fxxxx series PIC and nobody is using an 18F.

PICante
- 18th September 2008, 17:38
Hi skimask!

Sorry, I’m somewhat confused here I don’t know what to believe in (of curse I believe in you!) since I also got a compilation error saying: “ERROR: Macro OWINSTR?W not found in macro file.”

Huuh?


Edit: Hey… it’s the other way around, it says 12-bits not supported! (found my glasses) :-) . Then (as usual) I must be doing something else wrong!

skimask
- 18th September 2008, 17:48
since I also got a compilation error saying: “ERROR: Macro OWINSTR?W not found in macro file.”
The latest PBP update should fix that problem.
If not, there's a thread somewhere around here relating a problem similar to that..somewhere...


Edit: Hey… it’s the other way around, it says 14-bits not supported! (found my glasses) :-) . Then (as usual) I must be doing something else wrong!
I don't know which manual you're reading.
My manual says 12-bits aren't supported using the REP and STR modifiers. I'd tend to believe that due to the stack/ram constraints of 12 bit devices.

PICante
- 18th September 2008, 17:55
Yes, my manual also says 12-bit. edited almost instantaneously! :-)

I have got the P250a patch installed, can’t seem to find any newer?

skimask
- 18th September 2008, 17:57
Yes, my manual also says 12-bit. edited almost instantaneously! :-)

I have got the P250a patch installed, can’t seem to find any newer?

There's a b patch out now.

Show the code...

PICante
- 18th September 2008, 18:03
I will try to find and run the patch to find out if that’s the culprit.

Thanks ski

PICante
- 18th September 2008, 19:20
Patch in place..... No, that did not cancel the compile error!
Here’s the code:



READTEMP:

OWOUT PORTA.5,1,[$CC, $44] ' SEND Start Temperature Conversion command


OWOUT PORTA.5,1,[$CC, $BE] ' SEND Read Temperature command


OWIN PORTA.5,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



Thanks!

Acetronics2
- 18th September 2008, 19:44
Hi,

Is not that much simpler than yout modifyer and the two following lines :




OWIN PORTA.5,0,[STR dq\9] ' Retrieve all 9 bytes of data

RawTemp.Byte0 = dq[0]

RawTemp.byte1 = dq[1]





( taken from a Malc C example )




OWIN Porta.5, 2, [R_Temp.Lowbyte, R_Temp.Highbyte] ' Read two bytes / end comms



Alain

PICante
- 18th September 2008, 21:38
Hi Alain,

Your suggestion tested, does not compile due to multiple errors in the line.

Made a search in the forum but could not find anything regarding the STR macro problem.

Thanks.

skimask
- 18th September 2008, 22:51
I know that's not ALL of the code...

Acetronics2
- 19th September 2008, 09:12
does not compile due to multiple errors in the line.

Made a search in the forum but could not find anything regarding the STR macro problem.


I can't believe it ...

I can't ...

Alain

PICante
- 19th September 2008, 10:43
I know that's not ALL of the code...

You are correct; it’s not all the code. The rest of the code is working fine this is only going to be the part (subroutine) to measure temperature. And it’s also the part that does not compile.

Thanks!

Bruce
- 19th September 2008, 10:58
Looks like you have dq defined as a WORD VS BYTE.

skimask
- 19th September 2008, 12:37
You are correct; it’s not all the code. The rest of the code is working fine this is only going to be the part (subroutine) to measure temperature. And it’s also the part that does not compile.

Thanks!

The rest of the code may very well be working fine, but the rest of the code also has any setup/initialization/interrupts that you are using, therefore, is just as important as the code that's messing up.
I must be making this up as I go or something...

CocaColaKid
- 19th September 2008, 14:34
We need to see how the variables are declared as well as other settings. Its obviously not this part of the code that is the culprit because it compiles fine for others which means there is a problem somewhere else in the code. Like Bruce said, it could be something simple like a word variable being declared as a byte.

PICante
- 15th October 2008, 19:31
Hi Guys!

Been busy doing other stuff but now I’m back to finish this project! As some of you suspected it was a “simple” mistake, a word variable was declared as a byte! Now it runs like clockwork!
It seems the problem is always simple, finding the problem is the hard part!

Thank you all!