Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using the DS18B20 with Oshonsoft

Status
Not open for further replies.

bryan1

Well-Known Member
G'day Guy's,
I had a look on the yahoo forum only to find the DS18B20 in one or 2 threads and they didn't provide much of a guide for using them.

Now as I'm getting 4 of those ones with a 3 metre lead ones in a SS can my project is going to be setting up using the Oshonsoft software for a HERMS homebrew setup. With the tax going up EVERY year on beer it is time for me to start making my own and after 2 kit brews it time to go AG (All Grain).

As the temps will vary between 65C and boiling I will be encasing each sensor in some sealed brass tube to protect the wires. This will be an on going process and I'm sure I'll endup running out of code space on a '877 so may start directly on '4550 and get USB going, then the fun will start learning VB to get some software done so one can monitor everything via a computer screen.

Ok to get the ball rolling does any member have some working code to share using multiple DS18B20's as I'm sure it will save me quite a few headaches.

Regards Bryan
 
I posted some asm code a while back and Mike K8LH was good enough to help optimize and comment it. There's also some good links to an explanation of the SearchROM algorithm. See this thread. I think the critical bit will be getting the timing right for the read and write bit routines.

Mike.
 
Bug with using Single

G'day Guy's,
Well got a new circuit board made up today and got one of DS18B20's in the mail so been playing with some code. Anyway for a start I just used the low level example off the oshonsoft site and found the temp to be way out. Anyway post #3590 on the yahoo forum shows an example so I looked at the routine and wrote it my way into my code which compiled OK in Oshonsoft. Now as I'm using my ICD2 for programming I need to open the asm file and put in the configuration for the chip then just hit quick build.

Now the quick build failed with 4 errors

Error[113] C:\OS STUFF\NEW PROJECTS\ONE WIRE 648A\ONE WIRE 648A.ASM 189 : Symbol not previously defined (FLO2432)
Error[113] C:\OS STUFF\NEW PROJECTS\ONE WIRE 648A\ONE WIRE 648A.ASM 190 : Symbol not previously defined (FPM32)
Error[113] C:\OS STUFF\NEW PROJECTS\ONE WIRE 648A\ONE WIRE 648A.ASM 216 : Symbol not previously defined (FPM32)
Error[113] C:\OS STUFF\NEW PROJECTS\ONE WIRE 648A\ONE WIRE 648A.ASM 233 : Symbol not previously defined (INT3224)


Here is the code

Code:
Define CONF_WORD = 0x3f30

Define CLOCK_FREQUENCY = 4
AllDigital

Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 3
Define LCD_EREG = PORTB
Define LCD_EBIT = 0

Lcdinit

Define 1WIRE_REG = PORTA
Define 1WIRE_BIT = 3


Dim temperature As Word
Dim temperature1 As Byte
Dim temperature2 As Byte
Dim temperature3 As Byte
Dim centigrade As Single
Dim temp_out As Word

loop:
1wireInit
1wireSendByte 0xcc, 0x44
WaitMs 1
'loop2:
'1wireGetBit finish
'If finish = 0 Then Goto loop2
1wireInit
1wireSendByte 0xcc, 0xbe
1wireGetByte temp_out.LB, temp_out.HB
Lcdcmdout LcdClear
'-----------------------------------
centigrade = temp_out * 0.0625
temperature = centigrade * 10
temperature1 = temperature / 100
temperature = temperature Mod 100
temperature2 = temperature / 10
temperature = temperature Mod 10
temperature3 = temperature

Lcdcmdout LcdLine1Home
Lcdout #temperature2, ".", #temperature3
WaitMs 500
Goto loop

The code is no where near finished as firstly I wanted to get the 12 bit resolution working but everything points to the generated asm being incorrect when the Single variable is used.

Very Frustrating

Cheers Bryan
 
hi Bryan.
The Sign byte from the DS18 contains the high order 3 bits of the temperature [ assuming you are set for 11 bit resolution]

So you should mask out the top 5 bits [ make them zero's, assuming you are working with only positive temperatures] and then multiply the 3 temperature bits by 256 and then add the result to the 'temp' byte , the result will be a Word containing the 11bit temperature

If you use tempr.HB and tempr.LB you will get the tempr Word

E.

EDIT:
This is the way I have used OSH for a DS, no floating point maths [ I dont have that option]


Code:
'test for a minus tempr
If sign.7 = 1 Then  'its a minus tempr
tempr.HB = sign
tempr.LB = temp
tempr = tempr Xor 0xffff  'convert 2s complement to binary
tempr = tempr + 1
neg = "-"
Else
tempr.HB = sign
tempr.LB = temp
neg = "+"
Endif

sign = sign And 0x07  'mask out the 5 sign 1's
tempr = (tempr * 25) / 4  'adjust binary value of DS18B20 to actual tempr


'convert binary tempr to ASCII value for display
b2avall = tempr.LB
b2avalm = tempr.HB
Gosub bin2asc

'display DS18S20 tempr
Lcdcmdout LcdLine1Home
Lcdout "C", 0dfh, "=" neg, ascbfr4, ascbfr3, ascbfr2, ".", ascbfr1, ascbfr0, " "

Goto main

BTW: have you read this thread for multiple DS18 address reading.
https://www.electro-tech-online.com/threads/multi-ds1820-owds-in-temperature-alarm.125861/
 
Last edited:
Hi Eric,
This morning I tried a couple of new routines just doing simple maths using Single and EVERY program came up with an error in Mplab with same errors I posted above. So yea it does look like there is a bug when using the FP option. Later I'm going to try maybe in vain to email Vlad with those routines and mention in detail just to see if I get a response.

Regards Bryan
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top