Using the DS1820 Temp Sensor?

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

Using the DS1820 Temp Sensor?

#1 Post by Fritzables » 30 Mar 2009 07:19

Hi to All,

The board I purchased (EASYdsPIC4) came with a DS-1820 Temp Sensor.

I would like to experiment with this device by making a simple unit that displays ambient temperature.

Is it just a matter of reading the value of it's output directly using something like ADC_Read() or does it require more specialised code?

Fritzables.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#2 Post by p.erasmus » 30 Mar 2009 14:44

The DC 1820 is a digital Temperature sensor you have to use the One wire Lib to communicate with the sensor.
look in the examples for your board One wire Example and you will see how its is done

Hope this helps you
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

mefleming55
Posts: 55
Joined: 27 Dec 2006 23:16
Location: Portland, Oregon, Earth
Contact:

One Wire DS1820

#3 Post by mefleming55 » 30 Mar 2009 21:54

Fritz --- below is how we use it for the dsPIC33FJ256GP710 chip.

program dsPIC33_One_Wire
dim rx1 as word
dim i, j1, j2 as byte
text as char[10]
tmp_sign as byte
main:
AD1PCFGH = 0xFFFF
AD1PCFGL = 0xFFFF
TrisD=$0000
PortD=$FFFF
Uart2_Init(9600)
'clearbit(portD,7) ' enable comm2 mux -- only needed if writing to DL3000
'clearbit(portD,13) ' enable USB
clearbit(portd,5) ' pulse uart in enable.
setbit (portD,15) ' enable rs232 buffer chip max3222
Uart2_Write_Char("8")
delay_ms(300)
do
Ow_Reset(PORTD, 14) ' onewire reset signal
Ow_Write(PORTD, 14, $CC) ' issue SKIP ROM command to DS1820
Ow_Write(PORTD, 14, $44) ' issue CONVERT T command to DS1820
Delay_ms(500)
i = Ow_Reset(PORTD, 14)
Ow_Write(PORTD, 14, $CC) ' issue SKIP ROM command to DS1820
Ow_Write(PORTD, 14, $BE) ' issue READ SCRATCHPAD command to DS1820
Delay_ms(500)
j1 = Ow_Read(PORTD, 14) ' get result LSB
j2 = Ow_Read(PORTD, 14) ' get result MSB
if j2 = $FF then
tmp_sign = "-" ' temperature sign
j1=($FF-j1)
else
tmp_sign = "+"
end if
j2 = (j1 and $01) * 5 ' get decimal value
j1 = j1 >> 1 ' get temp value
WordToStr(j1, text) ' whole number
Uart2_Write_Char(tmp_sign)
Uart2_Write_Char(text[3])
Uart2_Write_Char(text[4])
WordToStr(j2, text) ' decimal
Uart2_Write_Char(".")
Uart2_Write_Char(text[4])
'Delay_ms(500)
Uart2_Write_Text("<-->")
Uart2_Write_Char(13)
' Uart2_Write_Char(10)
If TestBit(PortD,4)=1 then clearbit(portd,4)else setbit(portd,4) end if ' LED

'if Uart2_Data_Ready = 1 then
' rx1 = Uart2_Read_Char()
'Uart2_Write_Char(rx1)
' end if
loop until false ' endless loop
end.
http://www.micro2cloud.com

mefleming55
Posts: 55
Joined: 27 Dec 2006 23:16
Location: Portland, Oregon, Earth
Contact:

One Wire DS1820

#4 Post by mefleming55 » 30 Mar 2009 21:57

Fritz --- below is how we use it for the dsPIC33FJ256GP710 chip.

program dsPIC33_One_Wire
dim rx1 as word
dim i, j1, j2 as byte
text as char[10]
tmp_sign as byte
main:
AD1PCFGH = 0xFFFF
AD1PCFGL = 0xFFFF
TrisD=$0000
PortD=$FFFF
Uart2_Init(9600)
'clearbit(portD,7) ' enable comm2 mux -- only needed if writing to DL3000
'clearbit(portD,13) ' enable USB
clearbit(portd,5) ' pulse uart in enable.
setbit (portD,15) ' enable rs232 buffer chip max3222
Uart2_Write_Char("8")
delay_ms(300)
do
Ow_Reset(PORTD, 14) ' onewire reset signal
Ow_Write(PORTD, 14, $CC) ' issue SKIP ROM command to DS1820
Ow_Write(PORTD, 14, $44) ' issue CONVERT T command to DS1820
Delay_ms(500)
i = Ow_Reset(PORTD, 14)
Ow_Write(PORTD, 14, $CC) ' issue SKIP ROM command to DS1820
Ow_Write(PORTD, 14, $BE) ' issue READ SCRATCHPAD command to DS1820
Delay_ms(500)
j1 = Ow_Read(PORTD, 14) ' get result LSB
j2 = Ow_Read(PORTD, 14) ' get result MSB
if j2 = $FF then
tmp_sign = "-" ' temperature sign
j1=($FF-j1)
else
tmp_sign = "+"
end if
j2 = (j1 and $01) * 5 ' get decimal value
j1 = j1 >> 1 ' get temp value
WordToStr(j1, text) ' whole number
Uart2_Write_Char(tmp_sign)
Uart2_Write_Char(text[3])
Uart2_Write_Char(text[4])
WordToStr(j2, text) ' decimal
Uart2_Write_Char(".")
Uart2_Write_Char(text[4])
'Delay_ms(500)
Uart2_Write_Text("<-->")
Uart2_Write_Char(13)
' Uart2_Write_Char(10)
If TestBit(PortD,4)=1 then clearbit(portd,4)else setbit(portd,4) end if ' LED

'if Uart2_Data_Ready = 1 then
' rx1 = Uart2_Read_Char()
'Uart2_Write_Char(rx1)
' end if
loop until false ' endless loop
end.
http://www.micro2cloud.com

Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

#5 Post by Fritzables » 31 Mar 2009 08:13

G'Day mefleming55,

This is great.... thanks a million for this.

Pete

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”