Mark J
- 31st August 2007, 15:34
Hi everyone,
I have been scanning through this forum for quite a while and upto now never really needed to make my own post as after a good search, ive usually found what ive been after thanks to the helpfull posts on here etc.
Im currently making an Aquarium temperature sensor project that will use 2 sensors and also turn on and off multiple PC fans to help keep things cool etc.
I have seen a few posts regarding the temp sensors, but none with this sensor and also with the 18F2455 PIC.
Ive got the majority of the code working, and sort of got the temp sensor working right with the PIC chip BUT,
If I use the VDD as the AD reference, and use the DEC3 Temp to display it on the LCD it only shows it as for example '023' which is pretty much what I would expect due to the temp in the living room where I am etc.
The thing I cant suss with the VDD reference is to get it so I can get the fractional degrees as well.
If I use the Vref+ pin and set the input reference voltage to 2.5V I do get the fractional degrees but the temp just seems way off which leads me to think ive got something wrong in my ADCON settings etc.
The more I look at the ADCON0, ADCON1 & ADCON2 the more I get confused and just cant see the wood for the trees so to speak.
I have tried numerous settings but I just cant seem to understand the datasheet things for them as I am pretty much a newbie at all this stuff and only really played with a 12F675 (think its those ones off the top of my head)
I have stripped everything unrelated out of the code so all it does is display the temp from a single probe so that I can post it here and not have a huge amount of code of which 99% would be irrelevant etc.
I have seen the thread by Savnik and used the loops etc to get a means adjusted temp etc, but I am not getting the correct temps which leads me to believe it is to do with the ADCON's etc.
Savniks thread: http://www.picbasic.co.uk/forum/showthread.php?t=5826&highlight=LM35DZ
I have put my meter on the AD pin and ground and read the results and looking at the readout on there it shows what I believe are the correct temp values as when I blow on or hold the probe in my fingers, I can see the values going up and down etc.
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
@ errorlevel -202
'************************************************* ***************
' LCD should be connected as follows:
' LCD PIC
' DB4 PortB.0
' DB5 PortB.1
' DB6 PortB.2
' DB7 PortB.3
' RS PortB.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.5
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo Ground
' Setup the ports for the LCD (as not set to the default layout as set in PBP)
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 4
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 5
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50
'************************************************* ***************
DEFINE ADC_BITS 10 ' Set ADC to 10 bit
'************************************************* ***************
' 76543210
ADCON0 = %00000011 'Set ADCON0
ADCON1 = %00001101 'Set AN0 & AN1 for A/D input & Vref to VDD
ADCON2 = %10101111 'Set ADC results to right justified
TRISA = %00001011 'set PORTA as all output except RA0,RA1 &RA3
TRISB = %00000000 'set PORTB as all output
TRISC = %00000111 'set PORTC RC0,RC1 & RC2 as inputs for the buttons
'************************************************* ***************
Temp1_C VAR word 'Store for the Final Temperature in Celcius for probe 1
'************************************************* ***************
code_start:
pause 100
LCDOUT $FE,1
main:
lcdout $FE,$80,"Temp:",DEC3 Temp1_C
gosub Read_temp
goto main
Read_temp:
i var byte
samples var word
VAL var word
samples = 0
Temp1_C = 0
for i=1 to 10
ADCIN 0,VAL 'Read in sensor temp
pause 50
samples = samples + VAL
next i
Temp1_C = samples/10
Temp1_C=(Temp1_C*/500)>>2
return
I hope my codes not toooooo messy for anyone to understand lol! I just tend to block things in and then go in afterwards and smarten it up (I blame Malc-C lol!! as he has taught me the dark side!!!!! Just kidding m8y! hope to chat on Skype again soon!)
Many thanks in advance for any help in getting this working correctly.
I have been scanning through this forum for quite a while and upto now never really needed to make my own post as after a good search, ive usually found what ive been after thanks to the helpfull posts on here etc.
Im currently making an Aquarium temperature sensor project that will use 2 sensors and also turn on and off multiple PC fans to help keep things cool etc.
I have seen a few posts regarding the temp sensors, but none with this sensor and also with the 18F2455 PIC.
Ive got the majority of the code working, and sort of got the temp sensor working right with the PIC chip BUT,
If I use the VDD as the AD reference, and use the DEC3 Temp to display it on the LCD it only shows it as for example '023' which is pretty much what I would expect due to the temp in the living room where I am etc.
The thing I cant suss with the VDD reference is to get it so I can get the fractional degrees as well.
If I use the Vref+ pin and set the input reference voltage to 2.5V I do get the fractional degrees but the temp just seems way off which leads me to think ive got something wrong in my ADCON settings etc.
The more I look at the ADCON0, ADCON1 & ADCON2 the more I get confused and just cant see the wood for the trees so to speak.
I have tried numerous settings but I just cant seem to understand the datasheet things for them as I am pretty much a newbie at all this stuff and only really played with a 12F675 (think its those ones off the top of my head)
I have stripped everything unrelated out of the code so all it does is display the temp from a single probe so that I can post it here and not have a huge amount of code of which 99% would be irrelevant etc.
I have seen the thread by Savnik and used the loops etc to get a means adjusted temp etc, but I am not getting the correct temps which leads me to believe it is to do with the ADCON's etc.
Savniks thread: http://www.picbasic.co.uk/forum/showthread.php?t=5826&highlight=LM35DZ
I have put my meter on the AD pin and ground and read the results and looking at the readout on there it shows what I believe are the correct temp values as when I blow on or hold the probe in my fingers, I can see the values going up and down etc.
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
@ errorlevel -202
'************************************************* ***************
' LCD should be connected as follows:
' LCD PIC
' DB4 PortB.0
' DB5 PortB.1
' DB6 PortB.2
' DB7 PortB.3
' RS PortB.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.5
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo Ground
' Setup the ports for the LCD (as not set to the default layout as set in PBP)
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 4
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 5
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50
'************************************************* ***************
DEFINE ADC_BITS 10 ' Set ADC to 10 bit
'************************************************* ***************
' 76543210
ADCON0 = %00000011 'Set ADCON0
ADCON1 = %00001101 'Set AN0 & AN1 for A/D input & Vref to VDD
ADCON2 = %10101111 'Set ADC results to right justified
TRISA = %00001011 'set PORTA as all output except RA0,RA1 &RA3
TRISB = %00000000 'set PORTB as all output
TRISC = %00000111 'set PORTC RC0,RC1 & RC2 as inputs for the buttons
'************************************************* ***************
Temp1_C VAR word 'Store for the Final Temperature in Celcius for probe 1
'************************************************* ***************
code_start:
pause 100
LCDOUT $FE,1
main:
lcdout $FE,$80,"Temp:",DEC3 Temp1_C
gosub Read_temp
goto main
Read_temp:
i var byte
samples var word
VAL var word
samples = 0
Temp1_C = 0
for i=1 to 10
ADCIN 0,VAL 'Read in sensor temp
pause 50
samples = samples + VAL
next i
Temp1_C = samples/10
Temp1_C=(Temp1_C*/500)>>2
return
I hope my codes not toooooo messy for anyone to understand lol! I just tend to block things in and then go in afterwards and smarten it up (I blame Malc-C lol!! as he has taught me the dark side!!!!! Just kidding m8y! hope to chat on Skype again soon!)
Many thanks in advance for any help in getting this working correctly.