RF TX/RX link w Ds18B20 trouble

pengoomeister

New Member
Hi,
I think I'am out of ideas and need some help with my code.
I have built TX and RX units which works when I run a simple test loop with LEDs connected. I've run the code in proteus and in the virtual terminal everything works, it also works on my veloboard connecting the PICs with a straight wire.
But in real life I have trouble getting a stable transmission, and my temperature from the TX unit is 0.0.

TX code
Code:
'Symbol definitions
symbol TempRead = w0    '(b1:b0)
symbol TempC_100 = w1    '(b3:b2)
symbol Whole = b4
symbol Remainder = b5
symbol msb = b7

symbol STATIONID = $02

main:
    pause 5000
    high 2 'turn on DS18B20 temp sensor
    ReadTemp12 2,TempRead    'Read tube air temp
    low 2 'deactivate temp sensor
    Goto DoCal    'Calculate Temp
end

DoCal:
    msb = TempRead / 256 / 128    'Find most significant bit, 0 means a positive number.
    if msb = 1 then    '1 is a negative number
        TempRead = TempRead ^ $ffff + 1    'Twos comp for neg calc
    endif
    'Start 12 bit conversion
    TempC_100 =  TempRead * 6
    TempRead = TempRead * 25 / 100
    TempC_100 = TempC_100 + TempRead
    'End 12 bit conversion
    Whole = TempC_100 / 100    ' "/" returns whole number
    Remainder = TempC_100 // 100    ' "//" or "%" = modulus divide
    Remainder = Remainder / 10    'Reduces the amount of decimal places by one, but rounds down.

if msb = 0 then

positive:
high 1 'activate transmitter
pause 500
serout 4,T300,($55, $55, $55, B4, B5, B7, STATIONID)
low 1 'deactivate transmitter
pulsout 0,20000 ' red LED winks as data sent
goto main
endif

if msb = 1 then

negative:
high 1 'activate transmitter
pause 500
serout 4,T300,($55, $55, $55), B4, B5, B7, STATIONID
low 1 'deactivate transmitter
pulsout 0,20000 ' red LED winks as data sent
goto main
endif
RX code
Code:
'Reciver code
'Symbol definitions
symbol Whole = b4
symbol Remainder = b5
symbol msb = b7
symbol STATIONID = b6

high 1 'activate reciver
pulsout 0,2000 ' red LED winks as data sent


rxloop:
serin 4,T300,Whole, Remainder, msb, STATIONID
pulsout 0,2000 ' red LED winks as data sent


if msb = 0 then

positive:
serout 2,T300,(#Stationid,";",#Whole,".",#Remainder,13, 10) 'DataLink
pulsout 0,20000 ' red LED winks as data sent
goto rxloop
endif

if msb = 1 then

negative:
serout 2,T300,(#Stationid,";","-",#Whole,".",#Remainder,13, 10) 'DataLink
pulsout 0,20000 ' red LED winks as data sent
goto rxloop
endif
 

eclectic

Moderator
I have made a start with the programs.

I used an AXE091 board.
08M (tx) HARDwired to 18X (rx)

T600 serout/serin

Code:
'Symbol definitions
#picaxe 08M
symbol TempRead = w0    '(b1:b0)
symbol TempC_100 = w1    '(b3:b2)
symbol Whole = b4
symbol Remainder = b5
symbol msb = b7

symbol STATIONID = $02

main:
    pause 5000
    ;;;;;;;;
    ReadTemp12 2,TempRead    'Read tube air temp
    ;;;;;;;;
    Goto DoCal    'Calculate Temp
end

DoCal:
    msb = TempRead / 256 / 128    'Find most significant bit, 0 means a positive number.
    if msb = 1 then    '1 is a negative number
        TempRead = TempRead ^ $ffff + 1    'Twos comp for neg calc
    endif
    'Start 12 bit conversion
    TempC_100 =  TempRead * 6
    TempRead = TempRead * 25 / 100
    TempC_100 = TempC_100 + TempRead
    'End 12 bit conversion
    Whole = TempC_100 / 100    ' "/" returns whole number
    Remainder = TempC_100 // 100    ' "//" or "%" = modulus divide
    Remainder = Remainder / 10    'Reduces the amount of decimal places by one, but rounds down.

if msb = 0 then

positive:

serout 4,T600,($55, $55, $55, B4, B5, B7, STATIONID) 

sertxd(#B4, #B5,#B7,#STATIONID) ; for testing ****



pulsout 0,20000 ' red LED winks as data sent
goto main
endif

;;;;;;;;;;;;;;;
negative:

pause 500
serout 4,T600,($55, $55, $55, B4, B5, B7, STATIONID)

pulsout 0,20000 ' red LED winks as data sent
goto main
Code:
'Reciver code
'Symbol definitions
#picaxe 18X
symbol Whole = b4
symbol REemainder = b5
symbol msb = b7
symbol STATIONID = b6

high 1 'activate reciver
pulsout 0,2000 ' red LED winks as data sent


rxloop:
serin 1,T600,($55,$55,$55),Whole, REemainder, msb, STATIONID ; No input 4 on 18x****

sertxd(#Stationid,";",#Whole,".",#REemainder,13, 10)
pulsout 0,2000 ' red LED winks as data sent


if msb = 0 then

positive:
serout 2,T600,(#Stationid,";",#Whole,".",#REemainder,13, 10) 'DataLink
pulsout 0,20000 ' red LED winks as data sent
goto rxloop
endif



negative:
serout 2,T600,(#Stationid,";","-",#Whole,".",#REemainder,13, 10) 'DataLink
pulsout 0,20000 ' red LED winks as data sent
goto rxloop
I hope it helps.
I have not had time to put in all the comments.


Welcome to the Picaxe Forum.

e
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
This is most likely IMO to be down to the pre-amble, qualifiers and timing etc...

serout 4,T300,($55, $55, $55, B4, B5, B7, STATIONID)
serin 4,T300,Whole, Remainder, msb, STATIONID

Should become something like ...

serout 4, T300, ( "UUUUUUUUUUUUUUU" )
pause 10
serout 4, T300, ("XYZ", B4, B5, B7, STATIONID )

serin 4, T300, ("XYZ"), Whole, Remainder, msb, STATIONID
 

westaust55

Moderator
Last edited:

BeanieBots

Moderator
I'd go for transmitting the raw data and doing the conversion at the reciever end. That way there is less data to transmit.
 

MFB

Senior Member
Plotting

If you would like to plot and store data on a PC, download a free copy of StampPlot from www.selmaware.com. Includes simple examples (for Basic Stamp) of how to format the data and add a checksum.
 
Top