PDA

View Full Version : Please help with code for DS18B20



fratello
- 30th December 2008, 10:11
I made the great project of "Digital thermostat (080090-11)" from Elektor july_august 2008 ; unfortunate I do not have DS1820 but DS18B20. The temperature show on display is like "xxx.xx 'C" !.
I read this : "In order to convert the HEX code to a temperature value, first you need to identify if you are using a DS18S20, or DS18B20 series sensor. The code to read the temperature needs to be slightly different for the DS18B20 (and DS1822), because it returns a 12-bit temperature value (0.0625 deg precision), while the DS18S20 and DS1820 return 9-bit values (0.5 deg precision)".
I try millions different routines, but the result is verry bad...because of this section, I think :
"DisplayTemp:
If V >= 10000 then ' Above 0 C.
Temperature=V-10000
Else
Temperature=10000-V ' Below 0 C.
EndIf
LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature, " ",223,"C "
Return"
All the codes I try change the Temperature set and Hysteresis, and the display show the temperature (ex. 24.56'C) , but useless function of thermostat...(Set temperature = 2000.00 and Hysteresis = 200.00).
And the temperature is different (+24.67 'C) by other device (DS18B20 + PIC 12F675 + LCD Nokia = 23.1'C ; LM35DZ + mV = 23.1 'C)
It is possible to increase the accuracy of this thermometer/thermostat ?
Can somebody help me to modify the source for using DS18B20 ?
Thanks in advance !

Acetronics2
- 30th December 2008, 14:26
Hi, Fratello

I played a bit with your program ... Elektor won't be anymore what it was ... -cries-

Note you'll have to comment the Easypic5/16F877A section and uncomment the Elektor section.

This way you will be able to use the 18B20 in any resolution you like ...

And OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!

Alain

fratello
- 30th December 2008, 15:24
THANK YOU VERRY MUCH !!!! You make me happy ! I will try the code and I will keep You informed. Thanks again !
****** A HAPPY NEW YEAR !!!! ******
******* TO ALL !!!! *******
LE : Now is great, even still remain the 1°C difference...but "OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!".
Thanks again !
B.t.w : what can I use instead of DS18B20 for more accurate measurement ?

Acetronics2
- 31st December 2008, 09:55
B.t.w : what can I use instead of DS18B20 for more accurate measurement ?

Hi, Fratello

I had a look to all the sensors you can find on the market ...

The best "out of the box" accuracy ( all including ) will be roughly +/- 0.5 °C ... don't be sad !!!

going further needs multipoint CALIBRATION ... with some really expensive devices.

Note linearity is "not so bad" in our measuring range ... so, with a two points calibration ( 0 and 100°C ) , you can reach +/- 0.1 °C without too much pain.

And remember ... DS18x20 in continuous measurement mode like here, without being fixed on a heatsink, has a 1°C self heating value ... ( a look at the Datasheet will confirm !!! )

Just have a look to the values displayed from the power up ...

Alain

Melanie
- 31st December 2008, 10:58
You missed some Alain.

We have Industrial Sensors that directly return 16-bit Temperature to two Decimal Places (in the range 0.00C-100.00C).

It is however a complete waste of time... just breathing in the vicinity, or even just walking nearby create air-currents which wildly change the readings - we just end up ignoring the last digit. If you're trying to distill some moonshine for the New Year festivities, you're not really bothered in monitoring the temperature to hundredths of a degree.

Acetronics2
- 31st December 2008, 14:17
Hi, Mel

Happy to read from you !!!

Of course, those sensors exist ... ( you have forgotten to give us the price ... lol ), but are totally out of our Hobbiysts galaxy ...

Have a Happy new Year

Regards
Alain

Melanie
- 1st January 2009, 15:24
Happy New Year to you and everyone too...

Aa a rough guide about 25 Euro's in singles, falling to below about 18 Euro's at 100 pcs, and about 10 Euro's at 1000 pcs.

Yes of course, you can't beat the few cents a DS1820 costs, but then it's not a bare chip, but a fully enclosed product with attached leads and connectors, post sensor processor, integral noise immunity, etc etc with integral seals all ready to bolt straight into your pipework or manifold.

If you want cheap, then just use an NTC Thermistor and plot it's curve into a PIC. You can easilly get better than 0.1C accuracy through simple interpolation across 90% of the curve. It's the way it's done in 99.9% of the cheaper Industrial and domestic Controls. I really don't see the point of DS1820's, LM35's etc, they're a waste of money for something that can be done so much simpler if only folks stopped and thought about the problem. OK, if you've only got a single I/O and a dozen items on the interconnecting bus, then fine, but otherwise why?

Acetronics2
- 1st January 2009, 16:37
Ok, Mel

You're talking resolution while I'm talking accuracy ...

DS already give .0625°C resolution ... but that do not mean anything because you only know you are inside the +/- 0.5 °C error gap.
LM 335 have your ADC resolution ... but always an "out of the box" +/- 0.5 °C precision

That is why I say ( and repeat ... ) you can't get a better reading WITHOUT a calibration ... or comparison with a known reference.

Even the MS5534 ( 16 bits! ) which comes with its calibration coeffs ... is given for a GUARANTEED +/- .8°C accuracy ...

For NTC's the problem is the +/- 5 to 20% value tolerance ... that need an individual curve adjustment to each sensor ( only 1 point ... yes... but one point calibration ! )


The only **predictable** High accuracy sensors are Platinium RTD's ... But , ... How much to pay for a class A probe ??? ...

Temp and Thermal measurements are always funny ... and make you humble !!!

Alain

fratello
- 2nd January 2009, 08:56
Thank you for replays !!!
I wish to all a happy NEW YEAR 2009 !

I think I go crazzy with this little thermostat probleme ; I write ( based on Yours great codes) four routines ; everyone display a different temperature. Which of them is -in yours opinion - the best ?

1.OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [Temperature.Lowbyte, Temperature.Highbyte]
Convert_Temp:
Dummy = 625 * Temperature
TempC = DIV32 10
TempC = (Temperature & $7FF) >> 4
Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
Temperature = TempC*100 + Float

2.OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [RAWTEMP.Lowbyte, RAWTEMP.Highbyte]
Convert_Temp:
dummy = RAWTEMP * 625
TempC = DIV32 100
Temperature = TempC

3.OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [Temperature.Lowbyte, Temperature.Highbyte]
Convert_Temp:
TempC = (Temperature & $7FF) >> 4
Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
Temperature = TempC*100 + Float

4.OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 0, [Temperature.LowByte, Temperature.HighByte, Skip 4, Count_Remain, Count_Per_C]
Convert_Temp :
Temperature = (((Temperature >> 1) * 100) - 25) + (((Count_Per_C - Count_Remain) * 100) / Count_Per_C)
if Temperature > 32767 then '32767 check if BIT12=1
Temperature= ~Temperature
temperature=temperature>>3 ; divide by 8

Thanks in advance for your support ; I hope I don't became boring !!!!

Acetronics2
- 2nd January 2009, 10:53
Hi, Fratello

Too wide a question ... It's on your own now.

Here it's yours to take :

1) your Datasheets, and do not mix different sensors ( ! ), see how values are coded for each.

2) your PbP Manual, and look at how PbP can calculate and see where roundings can lead to ( small ...) outputted value differences.

...

Alain

fratello
- 2nd January 2009, 11:39
I use the same sensor, the same circuit, just I re-write the code...the results are never the same...:confused:

Gabestarting
- 3rd January 2009, 21:57
I intend to start tomorrow with the same project, using the same sensor DS18S20. May i use it without changing the code?

Gabestarting
- 4th January 2009, 19:16
Sorry, reading the text again i observed that i have the right sensor, i was lucky...So, the thermostat works fine, i am happy for the bas-file, however it is easier to understand than assembler. I made the circuit on a stripboard. Have a nice evening!

fratello
- 9th January 2009, 13:20
I want now to try to read the temperature with two sensors DS18B20 ; one for IN and other for OUT. It is possible ? How can I display both temperatures ?
Help, please !

Acetronics2
- 9th January 2009, 16:27
Hi, Fratello

some homework to do for you ...

take the DS18B20 Datasheet out, and look at :

1) How to get the device ID
2) How to address the device with it's ID

Buuuuuut, I do think ALL the answers you look for already are posted on this Maaarrrrrvellous Forum !!!

It's called SEARCH Function ...

Alain

PS: HELP Function momentarily out of use : New Year update ... lol

fratello
- 9th January 2009, 20:44
I try to read the serial number of my DS18B20 sensor with this code :

TRISA= %11110000 ' RA0..3=Outputs RA4=Input
TRISB= %00000111 ' RB0..RB2=Inputs, RB3..RB7=Outputs
CMCON=7 ' Disable comparators

DEFINE LCD_DREG PORTB ' LCD on port B
DEFINE LCD_DBIT 4 ' Data bits B4..B7
DEFINE LCD_RSREG PORTA ' RS on PORTA
DEFINE LCD_RSBIT 1 ' RS on A1
DEFINE LCD_EREG PORTA ' E on PORTA
DEFINE LCD_EBIT 0 ' E on A0
DEFINE LCD_BITS 4 ' LCD 4 bit mode
DEFINE LCD_LINES 2 ' 2 line LCD display

DQ Var PORTA.4 ' One-wire data pin
i Var Byte
Temp Var Byte
ReadRom Con $33

Pause 500
LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off
Pause 250

Main

OWOut DQ, 1, [ReadRom]
for i = 0 to 7
OWIn DQ, 0, [Temp]
LcdOut $FE, $80, Hex Temp
Next
LcdOut $FE, $14
LcdOut $FE, $14
Pause 1000
GoTo Main


but on display appears only "A7". What I do wrong ? Thanks !

Darrel Taylor
- 9th January 2009, 21:22
LcdOut $FE, $80, Hex Temp

The $80 moves the cursor to Line1 Column1, and it overwrites the previous values on each loop. All you see is the last loop.
<br>

fratello
- 10th January 2009, 09:36
Per aspera ad astra !!!!
I write another code :

DQ Var PORTA.4 ' One-wire data pin
i Var Byte
Temp Var Byte
ReadRom Con $33
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code


Begin:
PAUSE 500 ' Wait .5 second
LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off

Start_Convert
OWOUT DQ, 1, [$33] ' Issue Read ROM command

ID_Loop:
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
for i = 0 to 7
LcdOut HEX ID[i]
next i
END



Now I have on display : 28CAC648100A7
I think now it is correct. Can You confirm ? Thanks !

Acetronics2
- 10th January 2009, 09:56
Hi, Fratello

Looks fine

my DS shows 7A00000190DF64

read you soon

Alain

Darrel Taylor
- 10th January 2009, 10:20
Almost, but there's not enough digits.

64-bits (8-bytes), will have 16 hex digits.

Try it this way ...

LcdOut HEX2 ID[i]

fratello
- 10th January 2009, 11:23
Thank you all for reply !
In this book : "PIC Microcontrollers: Know It All" from Lucio Di Jasio, Tim Wilmshurst, Dogan Ibrahim, John Morton, Martin Bates, Jack Smith, D.W. Smith, and Chuck Hellebuyck - witch is my inspiration , I read this :
"Dallas Semiconductor’s 1-wire specifications define device serial numbers as 8 bytes (64 bits) long.The family code for 18B20 digital thermometer chips is $28. The CRC (cyclic redundancy code) is an error-checking feature, so that, should we desire, we may verify that the 56 bits of the family code and serial number have been correctly received and were not corrupted. We’ll not further consider how CRCs are calculated, as it’s a topic well beyond the level of this introductory book.
When we run the program, we see the following output:
28 4C D4 3E 0 0 0 D6
...
The digits 4C D4 3E 0 0 0 D6 are, of course, dependent upon the particular DS18B20 chip.
I plugged in a second DS18B20 chip and found its serial number:
28 FE DA 3E 0 0 0 C1
In the output, $28 is the family number and $D6 (or $C1 in the second example) is the CRC. The center six bytes represent the serial number of the chip. But, here’s a difference between the result and the serial number specification isn’t there? The definition has the CRC sent first and the family code sent last. Yet, Program 22.1 displays the family code first, and the CRC last.The explanation is that 1-wire devices store the least significant byte at the lower address and
the most significant byte at the higher address. Bytes are transmitted and received from lowest address to highest address. Hence, the net effect is the send/receive byte order is reversed from the data sheet description. This is more confusing to describe than to use; when we wish to address a particular device, we just repeat the byte order we read with Program 22.1"

So, I think it is enough for me these results.
Next step is : Reading multiple sensors on the same bus.
... :( Wish me luck !
I will keep you informed and - hope- I will receive yours advices again.
All the best !

Acetronics2
- 10th January 2009, 13:10
Hi, Fratello

From the Datasheet Organigrams ... you'll see the Bytes Order is inverted ...

as you worked Well ...




'************************************************* ****************************
SensID:' Sensor Identification
'************************************************* ****************************

OWOUT DQ, 1, [ $33 ] ' Read Chip code
OWIN DQ, 2, [ FAM,ID[6],ID[5],ID[4],ID[3],ID[2],ID[1],CRC]

IF FAM = $05 THEN

LCDOUT $FE,$80, "DS 2405 "

PAUSE 1000

LCDOUT $FE,$80, " CRC: ",HEX2 CRC," FAM: ", HEX2 FAM

ENDIF

IF FAM = $10 THEN

LCDOUT $FE,$80, "DS 18S20/1820"

PAUSE 1000

LCDOUT $FE,$80, " CRC: ",HEX2 CRC," FAM: ", HEX2 FAM

ENDIF

IF FAM = $28 THEN

LCDOUT $FE,$80, "DS 18B20 "

OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_11bit] 'Skip ROM search and write N_bits
' resolution to scratch pad
PAUSE 1000

LCDOUT $FE,$80, " CRC: ",HEX2 CRC," FAM: ", HEX2 FAM

ENDIF

LCDOUT $FE,$C0," ID:",HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6]



Here Data are shown with their signification ... Hope it will help

Alain

fratello
- 10th January 2009, 21:37
Thanks for support !!!!
First code (post #18) return this result : 28 CA C6 48 1 0 0 A7
Second code (post # 22) return : CA C6 48 01 00 00


In the code that I write now I use something like this :
"Init1
OWOut DQ, 1, [$55, $28, $FE, $DA, $3E, $0, $0, $C1, $4E, $FF, $FF, $7F]
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $48]
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $B8]
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE]
Pause 1000
OWOut DQ, 0, [Temperature.Byte0, Temperature.Byte1, 0, 0, DS18B20_12bit]


Init2
OWOut DQ, 1, [$55, $28, $FE, $DA, $3E, $0, $0, $C1, $4E, $FF, $FF, $7F] 'SENSOR 2 !!!!!!!!! not reading yet !!!!
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $48] 'SENSOR 2 !!!!!!!!! not reading yet !!!!
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $B8] 'SENSOR 2 !!!!!!!!!
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE] 'SENSOR 2 !!!!!!!!!
Pause 1000
OWOut DQ, 0, [Temperature.Byte0, Temperature.Byte1, 0, 0, DS18B20_12bit]


Main
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $44] ' Start temperature conversion Sensor 1

WaitLoop:
While not DQ
Wend

OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE]
OWIn DQ, 0, [Temperature.Byte0, Temperature.Byte1]
GoSub Convert_Temp
GoSub DisplayTemp

Part2
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $44] ' Start temperature conversion Sensor 2

WaitLoop2:
While not DQ
Wend"



I hope it's good...will see !

fratello
- 12th January 2009, 10:10
Hello !
Me again ...:(...I write the code attached, but the temperature on display don't modify (IN = 91.25 'C ; OUT = 25.18 'C)... Know somebody where is the mistake ? Thanks in advance...

fratello
- 12th January 2009, 13:28
I found the mistakes ! I re-re-re...-write te code. Now works fine !
I did it !! I am verry happy ! I take a little pause -just a few hours- and I will try to adapt this code to the old code of thermostat, for having both function : dual termometre and thermostat. I will keep you informed ! All the best !

I know the accuracy is +/- 0.5 'C , but it is normal this ? One sensor show 25.21 'C and the other 26.18 'C... I put the sensors together, and I fix them with one earring, this is the temperatures after 15 min... Maybe i's something wrong in my code ?!

fratello
- 13th January 2009, 07:02
Hope I am not boring with this subject !
1. I replace one sensor and now both temperatures are similar.
2.I write the code for dual thermometer and thermostat ; works verry good ! :)
If somebody have idea to improve this code, please post here !
I wish you all the best !

Acetronics2
- 13th January 2009, 12:32
Hi, Fratello

What about a nice Bargraph to show what's going on ... ???

like this one :



'************************************************* ****************************
'************************************************* ****************************
' AFFICHAGE
'************************************************* ****************************
'************************************************* ****************************

'Motifs CGRAM

LCDOUT $FE,$40,$00,$00,$00,$00,$00,$04,$04,$04 ' Cust Char $0 'Small bar
LCDOUT $FE,$48,$00,$00,$00,$04,$04,$04,$04,$04 ' Cust Char $1 'Mid bar
LCDOUT $FE,$50,$04,$04,$04,$04,$04,$04,$04,$04 ' Cust Char $2 'Big bar
LCDOUT $FE,$58,$04,$04,$0E,$0E,$0E,$1F,$1B,$11 ' Cust Char $3 'Arrow
LCDOUT $FE,$60,$11,$1B,$1F,$0E,$0E,$0E,$04,$04 ' Cust Char $4 'Inv Arrow
LCDOUT $FE,$68,$04,$04,$0E,$1F,$1F,$0E,$04,$04 ' Cust Char $5 'Diamond

'************************************************* ****************************
Aff:'Affichage temp
'************************************************* ****************************

'préparation chiffre : sign = 1 = valeur négative

Decal = ( TempC // 5 ) << 1

IF NOT sign THEN

Loscale = ( TempC /5 ) * 5
Hiscale = (( TempC /5 ) + 1) * 5

IF Float > 25 AND Float <= 75 then Decal = Decal + 1
IF Float > 75 Then Decal = Decal + 2

ELSE

Loscale = (( TempC /5 + 1 ) * 5) * -1
Hiscale = ((TempC /5) * 5 )* -1
Decal = 10 - Decal

IF Float > 25 AND Float <= 75 then Decal = Decal - 1
IF Float > 75 Then Decal = Decal - 2

TempC = TempC * -1

ENDIF


'Impression valeurs 1ère ligne

IF Sign THEN

LCDOUT $FE, $80 ,SDEC2 Loscale,178,Unit," "
IF TempC = 0 THEN LCDOUT "-"
LCDOUT SDEC TempC,".",dec2 Float
IF ABS TempC < 10 then LCDOUT " "
LCDOUT $FE,$80 + 11,SDEC2 Hiscale,178,Unit

ELSE

LCDOUT $FE, $81 ,SDEC2 Loscale,178,Unit," ",SDEC TempC,".",dec2 Float
IF TempC < 10 then LCDOUT " "
LCDOUT $FE,$80 + 12,SDEC2 Hiscale,178,Unit

ENDIF


'Impression échelle 2ème ligne

LCDOUT $FE,$C0,$01,$00,$02,$00,$01,$00,$01,$00,$01,$00,$0 1,$00,$02,$00,$01,$00

'Impression index

IF Tempeff < ( Setpoint - 5 ) THEN

LCDOUT $FE, $C2 + Decal,$03 'Index Chauffage

ELSE

IF Tempeff > ( Setpoint + 5 ) THEN

LCDOUT $FE, $C2 + Decal,$04 ' Index Refroidissement

ELSE

LCDOUT $FE, $C2 + Decal,$05 ' Index Zone neutre

ENDIF

ENDIF



Better shown on attachment

fratello
- 13th January 2009, 15:10
Thanks for reply !
Sorry, but my LCD is 2 x 16 ; at first line I display "In" and at second "Out" values of temperatures. Otherwise, nice code are You writing :cool:.

fratello
- 13th January 2009, 19:46
New problem :
-the thermometer PIC 12F675 + DS18B20 + Nokia LCD = 24.5 'C
-the thermometer LM 35DZ + Fluke 830DM = 24.5 'C
-the thermometer PIC 16F628A + DS18B20 = 25.5 ' C !!!!!!!!!!!

I try to write in PIC the same code of themperature conversion like Mr.Novakovic Ivica.
Check for similarity !!!! Why this diference ? I thing I go crazy, soon :( ....

Acetronics2
- 13th January 2009, 19:53
Hi,




count_remain, count_per_c



DO NOT use that with DS 18B20 ....

That's a first step.

Alain

fratello
- 14th January 2009, 08:21
Anything code I write in thermo that I made, the temperatures are NOT similar with those measured with other devices (mentioned). I try to change the sensor (I use three !) but nothing change. I don't know what to believe : which of temperature is - more- accurate ?

fratello
- 14th January 2009, 09:16
I found this on forum :
"OSCCON = %01100000 'Internal clock set to 4-MHz (MUST DO THIS!!!)"
I added in my code, but PBP say "Error : Undefined Symbol 'OSCCON'.
Maybe this is the error that shows different temperatures ?

Melanie
- 14th January 2009, 09:55
Have you checked your PICs DATASHEET to see if it has an OSCCON register?

fratello
- 14th January 2009, 15:30
My mistake...mea culpa...

fratello
- 16th January 2009, 07:07
Based on the book mentioned at post #21, I re-write the code for this project. I implement a new procedure for initializing the sensors. The results are verry good. Want somebody to improve this ? I wish You all the best !
Thanks again for Your support !

mvs_sarma
- 24th March 2009, 15:56
Hi, Fratello

I played a bit with your program ... Elektor won't be anymore what it was ... -cries-

Note you'll have to comment the Easypic5/16F877A section and uncomment the Elektor section.

This way you will be able to use the 18B20 in any resolution you like ...

And OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!

Alain

But DS18B20 is capable of giving a better resolution??

Ioannis
- 24th March 2009, 19:37
Its resolution (its step in other words) is 0.0625 but its accuracy is +/-0.5C

Ioannis

mvs_sarma
- 3rd April 2009, 15:23
Based on the book mentioned at post #21, I re-write the code for this project. I implement a new procedure for initializing the sensors. The results are verry good. Want somebody to improve this ? I wish You all the best !
Thanks again for Your support !
@Fratello,
is your latest software working in the range 0 to 100 deg Celsius at least?
When I tried for that and with one sensor, it shows -0.06 Celsius. and the sensor would not respond for variation
We have presently temperatures around 33.5 Celsius, as we entered summer season in India.

fratello
- 4th April 2009, 05:35
The code is ok ! Check the DS18B20 serials numbers ! I don't know if the thermostat work with just one sensor ! Good luck !

mvs_sarma
- 4th April 2009, 06:28
The code is ok ! Check the DS18B20 serials numbers ! I don't know if the thermostat work with just one sensor ! Good luck !
as long as a working project of elektor is modded by adding another sensor, it should work for a single sensor also. I have just disabled all lines pertaining to sensor2.
I am asking for practical test result, not the program being OK as per our assumption, please. whether you are able to read temperature like normal room and and a piece of ice ? with one of the sensors, with other sensor reading just room temp?

fratello
- 5th April 2009, 07:53
In my test I measure :
- MINUS 15.20 ' C in the refrigerator
- PLUS 24.15 ' C in the room.
With one sensor and with two sensor too.

Acetronics2
- 5th April 2009, 09:02
When I tried for that and with one sensor, it shows -0.06 Celsius. and the sensor would not respond for variation


Some ( wrong ! ) values have a typical meaning :

0.06 as a "measure " shows a connecting ( or sensor ) problem ... Check your DQ line ...
85 shows conversion not completed ...

Alain

mvs_sarma
- 6th April 2009, 10:41
In my test I measure :
- MINUS 15.20 ' C in the refrigerator
- PLUS 24.15 ' C in the room.
With one sensor and with two sensor too.
Can you upload the .bas file that you have used please !!

fratello
- 7th April 2009, 09:16
See post #35. Renamethe file .txt as .bas.

mvs_sarma
- 8th April 2009, 08:15
In my test I measure :
- MINUS 15.20 ' C in the refrigerator
- PLUS 24.15 ' C in the room.
With one sensor and with two sensor too.
Thanks Fratello !!

lew247
- 8th December 2009, 19:46
Hi, Fratello

I played a bit with your program ... Elektor won't be anymore what it was ... -cries-

Note you'll have to comment the Easypic5/16F877A section and uncomment the Elektor section.

This way you will be able to use the 18B20 in any resolution you like ...

And OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!

Alain

I've been playing with this all day today and it's a great piece of code.
I used this as I have an easypic 6*

I have one problem/question that perhaps someone could answer please

When I program the pic, the sisplay shows * at the end of the 1st line even when no buttons are or have been pressed, I thought the * was only to show a button had been pressed?

Also if I cycle through the button presses, ie set temp and set hysteresis they both work fine
however when I press the button again to show the actual temp that also works. but it never seems to update UNLESS I hold the button in, then it updates continually

I've been trying to get it to update at a regular interval or any interval but it just wont, am I doing something wrong or does it never update the temp?

Acetronics2
- 8th December 2009, 20:23
Hi,

That looks no pullups - or a Pulldown ! - on PORTA.0 input ... the " * " only appears when Porta.0 is tied to ground.

Everything fine here ...

Alain

lew247
- 8th December 2009, 21:11
Hi,

That looks no pullups - or a Pulldown ! - on PORTA.0 input ... the " * " only appears when Porta.0 is tied to ground.

Everything fine here ...

Alain

I thought that might be the problem, but where would I put
high portA.0

If I put it before the mainloop it displays the temperature all the time,
if I put it at the end of mainloop then it still displays the * and stays on set temperature.

I can't figure out where to put it, must be easy but I just cant see it.

Acetronics2
- 9th December 2009, 16:55
I thought that might be the problem, but where would I put
high portA.0

If I put it before the mainloop it displays the temperature all the time,
if I put it at the end of mainloop then it still displays the * and stays on set temperature.

I can't figure out where to put it, must be easy but I just cant see it.


May be you could place The pullup resistorS ( 3 x 47-100k ) between Porta.0,1 and 2 and VCC ...

No need to place it inside the Pic ... that won't work !

Alain

lew247
- 9th December 2009, 18:53
Sorry Alain, I wasn't too clear on what I meant.

The easypic board HAS pullup resistors on those ports.

When i run the program, the lcd sits there with just the * displaying even when no button has been pressed (portA.0 in this circuit/program)

it does nothing else.

When I press portA.0 the display cycles through set temp (which I can set properly with portA.1 and portA.2)
Next press brings it to the Hysteresis which again will set ptoperly

the 3rd press brings up the temperature display mode (mode 0 )

It displays the temperature at the moment the button is pressed but it never updates or checks again.

I have checked it works by holding down the button on portA.0 and if held down (LOW) then the display works properly, measuring the temperature continious, and if the temp changes it makes port C.0 or C.2 high depending on the set temp and hysteresis.

My problem is I cannot get it to continually measure temperatre without holding down portA.0

Also when I turn the power on first all I get is the LCD blank other than * being displayed.

Having read the code, * should only display after each button press, but it always displays.

Also I'd like it when power is turned on to measure and show the temperature continoiusly until the button (portA.0) is pressed.


Hope that made more sense, as I knew I couldn't put resistors inside the pic :)

malc-c
- 9th December 2009, 23:02
Very informative thread and funny enough something that I was hoping to work on myself as I'm looking at replacing the simple on/off thermostats that control the heating in my reptiles vivariums.

Can someone (Alain?) post up a schematic for the project. (or settings for the EasyPIC5) - I'm looking at trying to develop this a bit further so the output is pulsed, with the mark / space ratio reducing as the set point is neared. I've used commercial on/off stats, and the temperatures are hard to control. The idea is to keep the hot spot fairly constant and below 35C max, as constant exposure to a surface above this temperature can cause a burn risk to snakes.


With the thermometer probe placed on the shelf near the logger (it wasn't actually touching the same spot), and with the thermostats sensor in the cool part of the shelf, the thermostat was set so the digital thermometer read a max of 34C. Here's are the results - the bit you are interested in is between 18:00 hrs onwards

http://www.micro-heli.co.uk/VIV1%20HOT.jpg

Obviously the heat was conducting through the wood, which cooled slower than if the sensor was measuring air or the surface of the heater. But you can see that there is a large temperature swing between the min and max readings, and that the surface reached over 40C

To reduce this difference I placed the two probes next to the logger directly above the heater. Here is the results, which still show the same cycling, but with a lower differential (average 5 degree C), but is more stable

http://www.micro-heli.co.uk/Viv1%20hot%202.jpg

The pulse proportional stat reduces the cycling as it's not switching the heater on/off/on, it maintains a steady temperature by pulsing power to it thus the heater never cools.

I could purchase a couple of commercial PP stats for around £100 (possibly less via mail order) but then where's the fun in that :) Now I know there are a lot of you experience programmers that have dabbled with PWM, so wonder if you would like to add your comments here.

malc-c
- 9th December 2009, 23:03
In the set up below I used a commercial data logger to record the surface temp of the shelf over a 24 hr period.

http://www.micro-heli.co.uk/sensor.jpg

Although I had originally posted this in my post above, the forum software said I had more than 4 images ????

Darrel Taylor
- 10th December 2009, 04:43
Malcolm,

Sounds like the perfect job for a PID loop.
<br>

Acetronics2
- 10th December 2009, 08:29
Sorry Alain, I wasn't too clear on what I meant.

The easypic board HAS pullup resistors on those ports.

...

Hope that made more sense, as I knew I couldn't put resistors inside the pic :)

Hi, Lew

You have a HARDWARE misconfig somwhere on your board ...

the program AT THE MOMENT, is running aboard my EasyPic5 ...

Check pullup jumpers on Porta.0,1,and 2 : UP
check buttons jumper : GND

Nothing more nothing less ...

Alain

Acetronics2
- 10th December 2009, 08:40
Hi, Malc

Do you understand the "why" of the Parallax document, now ... ???

You'll have to place your Button Key INSIDE the vivarium ( hé,hé ... WITH the snakes !!! ) if you want a true image of your temp.

The graphs you've shown can't be used to finely trim a regulator ... but are a good example.

Temp measurement and moreover probes placing is a real art ... to get a nice temp regulation.

But let's begin by the beginning :

ALL you have to do already is in ZE Book ... with relevant code.

We'll see details later ...

Till then, I'll implement the PID Regulator on my existing " 84 " Thermostat ( not the one shown here, but a nicer one which is pin for pin compatible !! )

Alain

lew247
- 10th December 2009, 09:24
Alain

You were right as always. I hadn't the board configured properly.

I totally forgot about the row of jumpers to set the pins pull-up or pull-down, I had it set wrong.

Thank you

malc-c
- 10th December 2009, 18:47
Hi, Malc

You'll have to place your Button Key INSIDE the vivarium ( hé,hé ... WITH the snakes !!! ) if you want a true image of your temp.

Alain

Agreed,

I've just taken a further reading with the probes 2" from the heater, so its sampling the air temperature. Here's the result (the button logger still on the shelf as shown)

http://micro-heli.co.uk/Viv1%20hot3.jpg

If you ignore the fluctuations in between 10pm and 3am when the snake was out and obviously laying on the sensor, and look at the period 4am to 4pm you'll see it a lot more stable and only has a 0.2C deviation.

DT, could you elaborate on a PID loop.

Alain, could you provide a link to that file... I'm frantically searching for a DS1820 so I can start developing this project, but as my PBP programming is so rusty (and basic) may need you guys to offer some assistance if I get stuck (or should that be when I get stuck :) :( )

malc-c
- 10th December 2009, 18:52
DT, could you elaborate on a PID loop.




OK - google was my friend :)

http://en.wikipedia.org/wiki/PID_controller

malc-c
- 10th December 2009, 18:58
http://upload.wikimedia.org/math/a/9/b/a9beb5ee392aa86e76d734e9e761b148.png

Err.... yeah... :confused:


previous_error = 0
integral = 0
start:
error = setpoint - actual_position
integral = integral + (error*dt)
derivative = (error - previous_error)/dt
output = (Kp*error) + (Ki*integral) + (Kd*derivative)
previous_error = error
wait(dt)
goto start


LOL - £34 for a commercial thermostat looks more promising !

Darrel Taylor
- 10th December 2009, 19:00
OK - google was my friend

http://en.wikipedia.org/wiki/PID_controller
You've got better friends than that.
HenrikOlsson for instance ...

PID-filter routine (2nd try).
http://www.picbasic.co.uk/forum/showthread.php?t=5874

I've used it. It works great.
It's a little tricky to find the correct constants. But trial and error usually works.
Although there is a purposeful method to tune the loop.
<br>

malc-c
- 10th December 2009, 19:12
You've got better friends than that.
HenrikOlsson for instance ...

PID-filter routine (2nd try).
http://www.picbasic.co.uk/forum/showthread.php?t=5874

I've used it. It works great.
It's a little tricky to find the correct constants. But trial and error usually works.
Although there is a purposeful method to tune the loop.
<br>

Sorry Darrel.... it's been a long day......!

mvs_sarma
- 14th December 2009, 12:02
See post #35. Renamethe file .txt as .bas.

when the same is compiled and loaded, it just behaves as i reported earlier a frozen value of 0.06
no variation
But luckily it is working for you perhaps. May i expect a hex file for 16F628A please?

mvs_sarma
- 16th December 2009, 11:28
Some ( wrong ! ) values have a typical meaning :

0.06 as a "measure " shows a connecting ( or sensor ) problem ... Check your DQ line ...
85 shows conversion not completed ...

Alain
Fratello's code has definite mistakes, and need attention. With the mistakes How it was working for him is a wonder.The suspected line numbers, i shall be indicating for consideration / possible correction.

I suspect that the code posted by him at #35 is not what he might be using.

Acetronics2
- 16th December 2009, 14:44
Hi, Sarma

What are you talking about ???

Fratello's code can of course bear some little improvements but WORKS FINE !!!

( I just translated it to a 16F877A aboard an Easy Pic 5 ... and it's nice.)

Alain

PS: do not tell me you are waiting for custom code or you do not have something personnal working since the 8th of April ... please ...

Archangel
- 16th December 2009, 16:51
http://upload.wikimedia.org/math/a/9/b/a9beb5ee392aa86e76d734e9e761b148.png

Err.... yeah... :confused:



LOL - £34 for a commercial thermostat looks more promising !

What ? That's as clear as mud! I thought they taught you that in primary school. :D
34 pounds for a thermostat? Must be the VAT ! Damn Globalists, want to federalize the world !
http://www.prothermostats.com/product.php?p=honeywell_th5110d1006&product=100934
$40 US 24.42 GBP

astanapane
- 21st September 2011, 08:24
hi all,

i would like to make the circuit for the thermostat. could you please upload the circuit schematic? thanks a lot for your help.

astanapane
- 23rd September 2011, 23:04
Dear all,

sorry for asking you for the schematic, i did it from the code but i need your advice according to the second sensor please.

could you please help me out to finish the schematic?

thanks.

astanapane
- 25th September 2011, 13:33
i have been trying to simulate the circuit on the proteus and also trying to make it work on the test board.

On the simulation i have some result but on the test board i dont get anything on the lcd.

Unfortunately with the code from Elektor i get some results on the lcd on the test board. But very wrong result like 234 oC.

Could someone upload the hex file from Mr. Fratello's #35? Could anyone made it work?

Heckler
- 25th September 2011, 14:45
but i need your advice according to the second sensor please.
could you please help me out to finish the schematic?


The second sensor (and the third, forth, fifth, etc, etc.) simply goes in parallel with the first... see example below.

6011

The PIC's job is to address each individual sensor to read its value. That is how the One-Wire bus works. Each sensor has an address and will only respond to it's address.

fratello
- 25th September 2011, 16:39
Each sensor has an address and will only respond to it's address.
Yes. right !!! In my code I put the individual code of each sensor . For working with ANOTHER sensors, first you need to read the address of each sensor and then modify the code. You can find some examples on this forum...

astanapane
- 25th September 2011, 16:57
hello,

thanks for the answer. i use the DS18B20, so i dont need to do any modification.

The problem is that i cannot see anything on the display. It looks like something is really wrong inside the code.

I think that i make the mistake on the code or the circuit above.

1) does this schematic corresponds to the code? (i need to put one more sensor)
2) do i need to do anything inside the code

for example in the following lines do i need to chose one of these?

;DS18B20_9bit CON %00011111 ; 93.75ms, 0.5°C
;DS18B20_10bit CON %00111111 ; 187.5ms, 0.25°C
;DS18B20_11bit CON %01011111 ; 375ms, 0.125°C
;DS18B20_12bit CON %01111111 ; 750ms, 0.0625°C (default)
DS18B20_1_12bit CON %01111111 ; 750ms, 0.0625°C
;DS18B20_2_12bit CON %01111111 ; 750ms, 0.0625°C


But still i dont see anything on my lcd.

astanapane
- 25th September 2011, 17:17
To be more specific,

as i understand i need to find the unique ID from each sensor and then modify it on the code.

First i need to solve an other problem, what about i dont see anything on the display?

Shouldnt i see some 'no sensor' or like that at least?

fratello
- 25th September 2011, 18:34
Yes, it's right what you say in post #71 !
Put this in top of code :

@ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON
define osc 4
REMOVE Xtal and caps (no need quartz precision) ; or keep it - but then replace "Intosc_osc_noclkout" with "XT_Osc".
Now you MUST have something on display !

astanapane
- 25th September 2011, 21:10
i've tried it but nothing on the lcd again,

i think it has to do with the osc commands and there is the problem.

i put a 4mhz ceramic with two legs, i idid also tried the ceramic 4mhz with 3 legs. Nothing on the screen.

i'm sad that cannot complete it.

thanks a lot for your help! am i doing something wrong with the schematic? Do i need anything else?

The code from the elektor works, but i dont have the ds1820. And it is on the screen xxx.xx

But i dont understand why it does not work with your code.

cncmachineguy
- 25th September 2011, 21:49
First you need to prove the pic is running. There are no caps shown in above schematic at the xtal, do you have caps on it? Have you made a led blink? Did you try internal osc?

From the quick skim I did on this thread, it seems I have read several posts claiming the code works. Time to look at your hardware.

astanapane
- 26th September 2011, 05:29
ok i will try later this afternoon to blink an led.

Do i need capacitors for the ceramic 4 mhz resonator? I have also used a ceramic with 2 legs resonator at 4 mhz.

In any case i will try to blink an led.

As i mentioned on my previous posts, i have tried also the code from elektor, and works. (i just dont have the right sensor DS1820 which is very old and i dont get the right results. but i have something in the screen at least.

With the code from Mr. Fratello, i dont have anything on the screen. That mean that there is something wrong, either with the hardware or software.

Thank a lot again for your help.

fratello
- 26th September 2011, 06:07
The software it's ok !!! Remove the X-tal (leave pins 15 & 16 free), re-compile the code with added from post #73, check the RV1, check the connection to LCD., check the voltage (5 volts).
6012

astanapane
- 26th September 2011, 07:39
ok thanks a lot fratello,

please give me some time to do it in the afternoon.

I have done something else with a completed different thermostat.

please check for my video (http://www.youtube.com/watch?v=AW9CR_mvzXE) from an other thermostat with an old ds1621, a friend of mine gave it me i can upload the code if you like. (really sorry for my Greeks at the video, i upload it for the AVCLUB.gr there is a sub forum for flashlights)

The reason i put the video is to see the menu for the thermostat configuration. It is nice to see the configured temp and the real time temp at the same time.

Please check the video at 2:12 for the configuration menu.

astanapane
- 26th September 2011, 16:08
there is something on the display now.

thanks a lot. The problem now is that i dont have the right value for the temp.

It appears a minus value for both INT and EXT sensor.

also the values for the SET POINTs are only in minus values. I think the minus symbol appears on both 75 and -25. I will upload pictures later on.

The values now i have are

INT: -0.06
EXT: -0.06

fratello
- 26th September 2011, 17:41
See post #42 !

astanapane
- 26th September 2011, 19:53
ok,

there is no problem with the DQ link.

there is no bad component DS18B20. I have put two new DS18b20 that are working on a different circuit.

How do i know the DS serial number? Do i need to get the serial number from my DS18b20 and place it to the code?

astanapane
- 26th September 2011, 20:14
Sorry for asking so many things, i just be so close to make it work.

So do i need to read the serial number for each sensor and place it inside the code?

do i need to follow that http://www.picbasic.co.uk/forum/content.php?r=374-How-to-read-a-one-wire-DS18B20-temperature-sensor-or-nine-of-them?

and then get the serial number from the DS?

fratello
- 27th September 2011, 05:55
Read first page of THIS topic !!!

Ioannis
- 27th September 2011, 09:13
Every device on 1-Wire network has in its internal EEPROM a unique serial number that has to be known to the host.

Otherwise the host can not find the device and communicate.

On Maxim site there is an application note about a way to automatically find the devices on the local 1-wire network. SO every time your controller powers up, it makes an device scan and stores the found ID's or serial numbers.


The second method is to find the serial numbers by your self and store them in the internl EEPROM of the controller.


AN187, is the Note that describes the method

Ioannis

astanapane
- 27th September 2011, 09:42
Fratello and Ioannis,

thanks for your help.

Now i understand. It is very similar to RFID serial number. You can retrieve the serial from the device.

I will make a small program to retrieve the serial from the device and place it to the code.

i will come back with my results.

Best Regards,

fratello
- 27th September 2011, 15:31
I will make a small program to retrieve the serial from the device and place it to the code.

It's in post #22. Enjoy !

astanapane
- 27th September 2011, 18:24
Hi Fratello,

here we are step by step.

i did retrieve the serial number from the DS18B20. I placed it to the code and worked.

I put two sensors and now i have INT and EXT temp. I can say that they are really close the temp from two sensors.

Now i would like to ask you if the code is for the temp only or the thermostat.

I have place two LED on the porta.2 and porta.3, but i dont see any light.

Do i need to configure anything else?

fratello
- 28th September 2011, 06:18
Good job ! Keep it so !
You need to add these lines :

If V < TargetTemp - Hyst then ' Below Target temperature - Hysteresis
PORTA.2=1 ' Activate Warm Output
PORTA.3=0 ' Deactivate Cold Output
EndIf

If V > TargetTemp + Hyst then ' Above Target temperature + Hysteresis
PORTA.2=0 ' Deactivate Warm output
PORTA.3=1 ' Activate Cold Output
EndIf
just in front of

GoSub SelectSign ' +/blank/- Sign
GoSub DisplayTemp ' Temperature to LCD


Goto MainLoop ' Do it forever

astanapane
- 28th September 2011, 08:30
Hi Fratello,

your help is much appreciated.

I will follow your instructions this afternoon. The code is working really well and the temperatures are very close to other circuits i have.

Thanks a lot!!!

astanapane
- 28th September 2011, 16:55
hi again,

i place the code at your suggestion, and it is ok,

the problem is that the low and high indications are flashing they are not stable on when they are activated.

is that normal?

astanapane
- 28th September 2011, 21:38
ok i found the problem,

if i place small current LEDs they are flashing when the port is activated.

If i place an LED more than 25mA then it stays light and stable.

But!!! i have seen an other problem. The INT sensors seems to stack some times, and gets unstack if there is a rapid change on the EXT sensor.

Have anyone noticed that? Do you think that this is Sensor problem?

thanks.

astanapane
- 2nd October 2011, 08:33
Ok after all i found out that it was the sensor problem.

According to the outputs on the ports for high and low indication, the problem exists.

Once i place a low current 10mA it does not light but flashing very low.

If i place an led more that 20mA then it fully light up.

I dont know if anyone has the same problem.

fratello
- 2nd October 2011, 09:02
The function on thermostat it's made with R (4k7 - from PIC port), transistor (BC547), relay (from collector to plus).

astanapane
- 2nd October 2011, 19:27
Thanks Fratello,

i havent test with any transistor, because normally it works with an indication of LED. The ports can handle 100mA. I thought that would work like that.

This week i will be in Vienna and then i will be in America for some Seminars. So i wont be able to test in my lab the code or a circuit.

I will get 3 uLED 3,2 touch from Sparkfun and i will try to make and complete the circuit for RFID that i have started in addition to codelock circuit.

Ioannis
- 3rd October 2011, 11:39
Which display did you ordered? the 4D 3.2" touch screen?

Ioannis

astanapane
- 3rd October 2011, 18:17
yes this one Ioanni.

http://www.sparkfun.com/products/10089

astanapane
- 8th December 2011, 09:38
i'm facing the same problem with the LED output pulses.

Is there anyone has the same problem? I cannot fix it.

Once the temp goes closer to the SET temp, the output seems to have pulses before it light the LED at its level.

It looks like the PIC sends pulses at the very close set temp and once it comes to the action, lights the LED.

To be more specific.

Lets say we SET the TEMP at 22 C. and .10 C. the plus and minus from 22 C.

If the display goes to 21.6 or 21.8 the indicator LED flashes very low with pulses.

If the TEMP goes to 22.20 then the LED lights.

Please let me know if anyone of you having the same problem. To program i use the PIC KIT 2.

thanks a lot.

I would like to say that i have test the circuit with Transistor also and Resistor 4,7K.

But at the point close to the set TEMP the led keeps flashing, and once is reaching the (emaple 22.20 C) it goes stable active.

Ioannis
- 8th December 2011, 10:28
The comparisson is done with the program code in post #88 (http://www.picbasic.co.uk/forum/showthread.php?t=10345&p=108243#post108243)?

Ioannis

astanapane
- 9th December 2011, 09:04
Hi Ioannis,

Yes, i have added the lines Fratello told me in order to activate the outputs.

Ioannis
- 9th December 2011, 09:24
It should not do this. The code has some kind of hysteresis which prevents the play at he output.

What if you increase this hysteresis?

Ioannis

fratello
- 9th December 2011, 17:00
I made tens of this thermostat, for all my friends, relatives....without troubles. Maybe it's time to show us Your schematic !

Acetronics2
- 9th December 2011, 20:22
May we ALSO see your FULL code ???

...

Alain

astanapane
- 10th December 2011, 16:09
Yes sure, i will upload the code soon, and i will also make a small video if you want.

On the output, i have done the following configurations.

1) only an LED
2) light the LED through resistor.
3) light the LED through a transistor.

In case number 1. the 3MM LED does not go ON but it flashes very low with some pulses, it is not noticeable. (the 5 mm goes on)
In case number 2. the LED works just fine
In case number 3. the LED works just fine

My question is, if anyone understands why it does not light up straight from the PIC (pin) output with no transistor or resistor.

thanks a lot and sorry for the trouble

Ioannis
- 10th December 2011, 17:07
I can only assume an overload with some kind of interference with something else around...

I would never load directly PIC output pins.

Ioannis

fratello
- 10th December 2011, 19:13
My opinion : MUST connect the LED trough resistor (R=U/I ; where U=5V and I depend on LED colour) ...

astanapane
- 10th December 2011, 19:51
it is strange because most of the times PICs can directly drive loads until 100mA. The leds get something like 10mA or less. The thing is that it looks like some pulses coming up from the pin. Can i test the PIN without any load on it with an oscilloscope? IF i have pulses then can we identify what the problem should be?

Archangel
- 11th December 2011, 02:22
it is strange because most of the times PICs can directly drive loads until 100mA. . . . Ok I took this comment out of context . . . 100 ma if all port pins have a load on them distributed across the entire port . . . 25ma max on a single output pin. . . unless I misread the data sheets.

astanapane
- 26th December 2011, 22:40
Fratello,

i have changed your code a little bit, only a very simple thing in order to have two outputs.

instead of this


If V < TargetTemp - Hyst then ' Below Target temperature - Hysteresis
PORTA.2=1 ' Activate Warm Output
PORTA.3=0 ' Deactivate Cold Output
EndIf

If V > TargetTemp + Hyst then ' Above Target temperature + Hysteresis
PORTA.2=0 ' Deactivate Warm output
PORTA.3=1 ' Activate Cold Output
EndIf

i used this


If V < TargetTemp - Hyst then ' Below Target temperature - Hysteresis
PORTA.2=1 ' Activate Warm Output

EndIf

If V > TargetTemp + Hyst then ' Above Target temperature + Hysteresis
PORTA.2=0 ' Deactivate Warm output
EndIf

If V2 < TargetTemp - Hyst then ' Below Target temperature - Hysteresis
PORTA.3=0 ' Deactivate Cold Output
EndIf

If V2 > TargetTemp + Hyst then ' Above Target temperature + Hysteresis
PORTA.3=1 ' Activate Cold Output
EndIf

and now i have two outputs. Very simple change but useful.

Regards,

Ioannis
- 27th December 2011, 08:27
I used to manipulate the ports directly, but once I had a problem and suspicion have fallen on the technique among other things.

So, I now only use HIGH and LOW commands even if these eat a little program memory just to be sure.

If your code is small enough to fit in one page then you probably can use direct port control.

Ioannis

electron
- 28th April 2013, 21:12
Thanks for support !!!!
First code (post #18) return this result : 28 CA C6 48 1 0 0 A7
Second code (post # 22) return : CA C6 48 01 00 00


In the code that I write now I use something like this :
"Init1
OWOut DQ, 1, [$55, $28, $FE, $DA, $3E, $0, $0, $C1, $4E, $FF, $FF, $7F]
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $48]
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $B8]
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE]
Pause 1000
OWOut DQ, 0, [Temperature.Byte0, Temperature.Byte1, 0, 0, DS18B20_12bit]


Init2
OWOut DQ, 1, [$55, $28, $FE, $DA, $3E, $0, $0, $C1, $4E, $FF, $FF, $7F] 'SENSOR 2 !!!!!!!!! not reading yet !!!!
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $48] 'SENSOR 2 !!!!!!!!! not reading yet !!!!
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $B8] 'SENSOR 2 !!!!!!!!!
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE] 'SENSOR 2 !!!!!!!!!
Pause 1000
OWOut DQ, 0, [Temperature.Byte0, Temperature.Byte1, 0, 0, DS18B20_12bit]


Main
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $44] ' Start temperature conversion Sensor 1

WaitLoop:
While not DQ
Wend

OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE]
OWIn DQ, 0, [Temperature.Byte0, Temperature.Byte1]
GoSub Convert_Temp
GoSub DisplayTemp

Part2
OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $44] ' Start temperature conversion Sensor 2

WaitLoop2:
While not DQ
Wend"



I hope it's good...will see !

I try to read serial number in my DS18B20:
first sensor 28D698D7400F8
second sensor 28FED6D64002B
third sensor 2880DC3C2009E

but how I put it in the code with $ ?