picaxe readtemp function equivalent in picbasic
Hi,
This may be a completely retarded question but i have very little experience with picbasic and picaxe for that matter.
I'm working on a project and i've got a code i've written in picaxe. I've used the readtemp command but i'm unsure how i would use this in the picbasic logic.
Is there an equivalent term to use, my programming is pretty much just comparing two temperature sources (both DS18S20's) and checking for a varience between the two, then turning on an output when the difference is great enough.
Thanks in advance
Re: picaxe readtemp function equivalent in picbasic
Re: picaxe readtemp function equivalent in picbasic
Sorry I'm still not really grasping the concept;
my current code looks simular to this
in picaxe
readtemp 0, b0 'storage cell 1 temp
readtemp 1, b1 'storage cell 2 temp
start:
let b0=b0+30 'simulate 30 degree celcius offset
if b0>b1 then 'check if storage cell 1 is more than cell 2
high 3 'open solenoid to transfer
endif
let b0=b0-30 'return b0 to true reading
in picbasic ive written it roughly like this but unsure how to do the readtemp part or i'm possibly completely wrong all together?
trisb.0=1
trisb.1=1
cell1temp var portb.0
cell2temp var portb.1
solenoid var portb.3
start:
let cell1temp = cell1temp +30
if cell1temp > cell2temp then
high solenoid
endif
let cell1temp = cell1temp - 30
Re: picaxe readtemp function equivalent in picbasic
Pretty much forget the picaxe stuff. It does not look like picaxe is comparable with PBP.
Follow the example I linked to for one-wire devices. Bruce gives the best explanation I know of.
Re: picaxe readtemp function equivalent in picbasic
MiskaA...
Here is another example on how to read the DS18B20 temp sensor... or several of them. This example is based on the same code that Mackrackit linked to.
http://www.picbasic.co.uk/forum/content.php?r=374-How-to-read-a-one-wire-DS18B20-temperature-sensor-or-nine-of-them
Re: picaxe readtemp function equivalent in picbasic
Thanks for the links, it's has given me some more insight into what i'm trying to acheive.
I'm actually using a pic16f684 and have connected the "DQ" pins of the temp sensors to their own pins on the pic chip (pins 6 & 7) so i don't think i need to identify them via a 1 cable network?
Could i just use something like;
trisc.4 = 1
trisc.3=1
cell1 VAR PortC.4 ' One-wire data pin "cell1" on PortC.4
cell2 VAR PortC.3 ' One-wire data pin "cell2" on PortC.3
solenoid VAR PORTC.1 'solenoid contactor coil power
Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Real_Cold CON 1 ' Define Real_Cold = 1
R_Temp VAR WORD ' RAW Temperature readings
TempCell1c VAR WORD ' Temp in deg C
TempCell2c VAR WORD ' Temp in deg C
start:
GOSUB Temp_1
GOSUB Temp_2
let tempcell1c = tempcell1c + 21
if tempcell1c > tempcell2c then
high solenoid
else
low solenoid
end if
let tempcell1c = tempcell1c - 21
pause 45000
goto start
Temp_1:
OWOUT cell1, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44]
OWIN cell1, 4, [Stat]' Check for still busy converting
IF Stat = 0 THEN W1' Still busy?, then loop
OWOUT cell1, 1,[$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$BE]
OWIN cell1, 2, [Temp.LOWBYTE,Temp.HIGHBYTE]' Read two bytes, then end communications
GOSUB Convert_Temp1
Convert_Temp1: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
Tempcell1c = DIV32 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
ENDIF
RETURN
Temp_2:
OWOUT cell2, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44]
OWIN cell2, 4, [Stat]' Check for still busy converting
IF Stat = 0 THEN W1' Still busy?, then loop
OWOUT cell2, 1,[$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$BE]
OWIN cell2, 2, [Temp.LOWBYTE,Temp.HIGHBYTE]' Read two bytes, then end communications
GOSUB Convert_Temp2
Convert_Temp2: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
Tempcell2c = DIV32 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
ENDIF
RETURN
Yikes: ' Display full range -C to -F conversion
Sign = "-" ' Display - symbol for negative temp
Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
Tempcell1c = DIV32 10 ' Use Div32 value to calculate precise deg C
Tempcell2c = DIV32 10 ' Use Div32 value to calculate precise deg C
ENDIF
RETURN