BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Oct 22, 2018 1:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Fri Nov 22, 2013 9:54 pm 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
Hi,

OK I see,

OK first to see if the DS is converting OK how many times does the LCD update each second ?, should be around 700ms(0.7 of a second) time to do each conversion so if the LCD is updating much faster than this rate then the DS may not be communicating with the Nano correctly,

Does the reading you mention change when you warm up or cool down the DS sensor ?

What exactly do you need from the DS18B20 ?,

Is it just to display the temperature on the LCD ?, in C or F ?, how many decimal places are needed so for example just 20 deg or 20.0 deg ?, will the reading ever be so low as to go into -Deg ?,

Thanks

Dave
BasicMicroUK

http://www.basicmicro.co.uk


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Fri Nov 22, 2013 10:04 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Thanks for your help. that's reduced the decimal places and it now says 157 deg c which is a start but strange as I'm sure my room is not more than 21 deg c :-)


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Fri Nov 22, 2013 10:15 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Yes reading changes when I put my finger on it.
Initially just to display room temperature on the display in c.
Later (one step at a time) I will look into getting into - figures.
Happy with 20c but curious on how to get 20.0c.
I can see it refreshing about every 1 second, but have tried putting a pause 1000 and 2000 loop in, it slowed down but no change in displayed results. Thanks to all again


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Sat Nov 23, 2013 2:36 am 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
OK well the reading you getting indicates the scaling of the output from the DS18B20 is incorrect,

This IC has various modes for conversion that can be set by writing to the configuration section of the IC, the modes determines the resolution of the temperature conversion, you can select 9, 10, 11 or 12 bits of conversion and the higher the number of bits the more resolution the result will have so for example in 9 bit mode each output number is equivalent to 0.5 degC and this conversion is quite fast and you can get around 10 updates a second, now in 12 bit mode each output number is equivalent to 0.0625 degC and this conversion takes around a second per conversion,

Now in the code you supplied there was no initialisation code for the DS18B20 and we know that the conversion on your system takes around a second per reading so this would indicate your DS18B20 is set to 12 bit conversion mode and also right out of the factory this is the default mode the IC will come set to BUT the conversion section of the code simply takes the raw value and divides it by 2 indicating it was set up for the DS18B20 running in 9 bit mode, so if rather than dividing by 2 as your doing now you instead divide by 16 the result should be correct, to look at this lets see how this would convert with the value your getting now, your result was 176.5 and we know that was divided by 2.0 in your code so if we double that it gives us a value of 353 and that would be the RAW value out of the IC so now if you take that raw value and divide by 16 you get 22.0 and that's far more like the temperature of your room,

The full data sheet for the DS18B20 can be downloaded here :- http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

As you will see if you freeze the IC negative values need a little more for work to them to display correctly but lets get you going in + degC mode first, after all if you ever get to - temperatures in your tank I doubt the fish will need feeding anymore !,

Next week I will tell you how to program a custom character on your LCD to display the degC symbol,


Many thanks

Dave
BasicMicroUK

http://www.basicmicro.co.uk


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Sun Nov 24, 2013 7:04 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I have a routine to display floating point and want if you can given a try.

Just gosub temp_display to the routine with the information in the loaded in the convert variable.


regards,
tauro0221


'*****************Routine to display a floating point **************
temp_display

cnv_1 var long
cnv_2 var long

cnv_1 = (toint(convert*100.0))
cnv_2 = cnv_1 /100 : cnv_2 = cnv_2 * 100
cnv_2 = cnv_1 - cnv_2 : cnv_1 = cnv_1/100
Serout s_out, i9600,["convertion = ",dec cnv_1,".",dec cnv_2, 13 ]
return
'*********************************************************************


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Tue Nov 26, 2013 1:28 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
hi Dave and Tauro. thanks again for your help. The custom character is ok i think as i came up with this
Code:
lcdwrite p0\p1\p7\p6\p5\p4,[cgram+0,0x08,0x14,0x08,0x00,0x03,0x04,0x04,0x03,scrram+0] 'custom character deg c
   lcdwrite p0\p1\p7\p6\p5\p4,[scr,scrram+79,0]   'cc position

it seems to work, if there is a better way please feel free to suggest.
i am still struggling Dave, to configure it to 9bit. I have tried the following code at the start with no luck, the 00011111 being the 9bit part.
Code:
owout P13,1,main,[$cc,$44,$00,$00,%00011111]

for a +0.5 result the data sheet suggest a hex code of 0008h, where does the initialisation code get inserted to make it 9bit and reduce the zeros after the decimal point?
thanks


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Fri Nov 29, 2013 6:43 pm 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
Hi

Well the resoloution of the DS IC does not make any effect on the number of places the printout will be shown to as you convert the binary temp from the IC to a real format so in order to limit the display decimal places simply add a "\1" to the end of "real convert" in the display line as shown below,

Old Line :-

Code:
LCDWRITE  p8\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd, "Temperature = ", SCRRAM+40, real convert, " deg C"]

New line :-

Code:
LCDWRITE  p8\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd, "Temperature = ", SCRRAM+40, real convert\1, " deg C"]

That will make the display show to 1 decimal place for example "22.3 deg C",

Your LCD Custom character set-up looks fine,

Let us know how you get on,

Many thanks

Dave
BasicMicroUK

http://www.basicmicro.co.uk


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Mon Dec 02, 2013 1:42 am 
Offline
Master

Joined: Sun Jan 03, 2010 4:01 pm
Posts: 134
Location: Eau Claire, WI
Hey guys, been watching the progress and looks like you just about have everything worked out but the temp sensor seems to be creating a bit of a challenge ;)

I've been doing some work with temp sensors and may I suggest the LM34/LM35 (the LM35 I think used centigrade) as these devices output a voltage that is linear to the current temp.

Ex for LM34 which works in F:

.351 Vdc= 35.1 degrees F
.688 Vdc= 68.9 degree F

The LM34/35 are commonly stocked parts which cause anywhere from $2 to $6 (accuracy = $$$)

If you want to keep with the current part that is fine; work the code out for us (me actually)as I have some samples of the temp sensor you are using and I would like to test the accuracy against the LM34.


Here is a code example for working with floating point code (from my memory):

FLOOR_TEMP VAR FLOAT

FLOOR_TEMP=75.0 ;need to add the zero to stop compiler error
FLOOR_TEMP=0.5 ;need to add the zero to stop compiler error

SEROUT i9600,["The Floor Temp is:",REAL FLOOR_TEMP\2,13] ;display two decimal places


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Wed Dec 04, 2013 3:06 pm 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
YES the LM can be usefull in some applications but you need good ADC conversion to stop jitter, have you a working set-up ?,

Dave
BasicMicroUK

www.basicmicro.co.uk


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Wed Dec 04, 2013 4:21 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I used it to read my amplifier heat sink temperature and shut down it if the temperature reached the tripping point. I it is very stable. Simple to use.


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Wed Dec 04, 2013 6:17 pm 
Offline
Master

Joined: Sun Jan 03, 2010 4:01 pm
Posts: 134
Location: Eau Claire, WI
As Tauro pointed out a heatsink seems to be the trick to stabilizing values when using an LM34/35. While using the ADIN16 command I did have to do some "smoothing" to deal with some "random" values being reported by the Nano-18s with the ADC conversion.

On question of smooth ADC conversions I have found the Microchip ADCs to be rock stable when measuring some very low voltages (like the less than 100mv from a load cell used in a weight scale project I am working on).


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Mon Jan 06, 2014 1:28 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
hi all, back onto the project after the holidays and this is how far ive got. After lots research i came across this page
http://www.picbasic.co.uk/forum/archive/index.php/t-17975.html and decided to use and mod their code. the result is
Code:
lcdinit p0\p1\p7\p6\p5\p4,p2
Lcdwrite p0\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd,scr,twoline,"  temp orig "]

count_remain var byte
R_Temp VAR WORD       ' RAW Temperature readings
TempC VAR WORD       ' Temp in deg C
Float VAR WORD          ' Holds remainder for + temp C display
Cold_Bit VAR R_Temp.Bit11 ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Real_Cold CON 1       ' Define Real_Cold = 1
Deg CON 223          ' Data to display Deg ° symbol
Sign VAR BYTE          ' +/- sign for temp display
Dummy VAR BYTE          ' Dummy for Div32

clear

main         
        owout P13,1,main,[$cc,$4e,$00,$00,$1f]    'writes configreg 9bit
        owout P13,1,main,[$cc,$44]             'skip then convert temp
      wait
        owin P13,0,[count_remain]            'check for busy converting
      if count_remain = 0 then wait         'wait loop
        owout P13,1,main,[$cc,$be]             'skip then read scratch pad (temperature)
        owin P13,0,[R_temp.LOWBYTE, R_temp.HIGHBYTE]
        gosub convert_temp
      'LCDWRITE  p0\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd,scr,twoline, "Temp=", real convert," t0=",dec tofloat temp.byte0]', SCRRAM+40, real convert, " C"]
      'LCDWRITE  p0\p1\p7\p6\p5\p4,p2, [scr,scrram+40,"config=",bin configreg] '"t1=",dec tofloat temp.byte1," th=",dec tofloat th," tl=",dec tofloat tl,
pause 500
goto main

Convert_Temp: ' +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
TempC = tempc/ 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((R_Temp.Lowbyte & $0F) * 625)/100 ' Lower 4-bits of result * 625

LCDWRITE  p0\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd,scr,twoline, "Temp= ",Sign,DEC TempC,".",DEC2 Float,Deg,"C"]
LCDWRITE  p0\p1\p7\p6\p5\p4,p2, [scr,scrram+40,"Raw ", IBIN16 R_Temp]
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
TempC = tempc/ 10 ' Use Div32 value to calculate precise deg C
LCDWRITE  p0\p1\p7\p6\p5\p4,p2, [lcdclear,homelcd,scr,twoline, "Temp= ",Sign,DEC TempC DIG 4,DEC TempC DIG 3,".",DEC TempC,Deg,"C"]
lcdwrite p0\p1\p7\p6\p5\p4,[scr,scrram+40, "Raw ", IBIN16 R_Temp]
RETURN

END


it seems to work after changing their
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
to
TempC =TempC/10

dont know if this is correct but seems to give me a room temperature of 20 deg

the problem now is that the negative part does not work or half works. i can see the raw binary value change when it goes below 0. but the temperature reading stays at -00.0c.
i am using a can of air duster, upside down which sprays a very cool liquid.
Any idea?


Top
 Profile  
 
 Post subject: Re: hardware question with nano28 ds18b20, ds1307, lcd
PostPosted: Mon Jan 06, 2014 1:52 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Just to add i also noticed on debug that when positive, tempc displays a decimal 20, but on negative stays at 0.
The can of air duster is to cool the sensor. thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO