LM35DZ and 18F2455 settings


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Posts
    32

    Default LM35DZ and 18F2455 settings

    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/show...ghlight=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.

    Code:
    @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.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I have not used the 18F2455 but when using a 18F4320 with a LM34 I have to put a 22uf cap from VREF to ground and a 22uf cap from the sensor output to ground to get things working accurately.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    I'll give that a try when I get a chance and see how it goes.
    At the mo, the only reason I used this chip is because I have a couple laying around here, and also I thought that in the future when I see about adding other things to the project etc, I can then use the USB functionality of the PIc to communicate to the PC for things like datalogging etc (not for a long while yet though lol! as just getting my head around the ADCON settings is hurting my brain lol!)

    Hopefully, if it is the ADCON's and we get it working right etc, at least this will hopefully help others out using these PIC's as there dosnt seem to be a lot of info from the searches ive done so far as with the 18's been a strange beast compared to the normal PIC's people use etc, so I presume it kind of keeps peopple away from trying to use them more etc.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I am starting to like the 18F4320, made my head hurt at first.
    I am working on a pyrometer with a K type thermo-couple and a LM34 for a reference. Have not looked at the data sheet for the PIC you are using, may or may not be close to the 4320. If it is, here is the pyrometer code so far, might give you some ideas.
    Code:
     DEFINE OSC 8
       OSCCON=%01111000
    
    DEFINE LCD_DREG     PORTC
    define LCD_DBIT     0
    DEFINE LCD_RSREG    PORTD
    DEFINE LCD_RSBIT    1
    DEFINE LCD_EREG     PORTD
    DEFINE LCD_EBIT     0
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    2
    DEFINE LCD_COMMANDUS    2000
    DEFINE LCD_DATAUS   50
    
    ADCON1= %00011011  
    
    temp1        var byte
    temp2        var byte
    T1	       var byte
    T2             var byte
    
    TC	VAR    WORD
    TCT    VAR    WORD
    TX	VAR    WORD
    TXI	VAR WORD
    TXIU	VAR WORD
    
    RUN:
    	HIGH PORTD.2
    	PAUSE 100
    	LOW PORTD.2
    	PAUSE 100
            gosub getT1
            GOSUB getT2
            T1 = temp1
            LCDOUT $FE,1,"LM34 ",#T1
            lcdout $FE,$C0,"TC ",#TXIU
            GOSUB D_INDEX
    	GOTO RUN
    
    getT1:
    	ADCON0= %00000001  
            ADCON2.7 = 0
    	gosub getAD
    	temp1 = ADRESH
    	return
    	
    getT2:
    	ADCON0= %00000101   
            ADCON2.7 = 1
    	gosub getAD
    	TC.highbyte = ADRESH
    	TC.lowbyte = ADRESL
    	return
    
    getAD:
    	pause 50
    	ADCON0.1 = 1
    	pause 50
    	return
    
    	END
    
    D_INDEX:
    TX = TC 
    'STEPS
    LOOKDOWN2 TX,>[898,895,892,889,886,883,879,876,873,870,867,863,860,857,854,850,_
    847,844,841,838,835,832,828,825,822,819,815,812,809,805,802,799,795,792,788,785,_
    782,778,775,772,769,765,762,758,755,751,748,744,741,737,734,731,727,724,721,717,_
    713,710,706,703,699,696,692,689,685,682,678,675,671,667,664,660,656,653,650,646,_
    643,639,635,632,628,624,620,617,614,610,606,603,599,595,592,588,584,580,577,573,_
    570,566,562,558,555,551,547,544,540,536,532,529,525,521,517,513,509,506,502,498,_
    495,491,487,483,479,475,471,468,464,460,456,453,449,445,441,437,433,429,426,422,_
    418,414,410,406,402,398,395,391,387,383,379,375,371,367,363,360,356,352,348,344,_
    340,336,332,328,324,321,317,313,309,305,301,297,293,290,286,282,278,274,270,267,_
    263,259,255,252,248,244,240,236,232,229,224,221,217,213,209,206,202,198,194,190,_
    187,183,180,176,173],TXI
    
    'TEMPERATURES
    LOOKUP2 TXI,[2500,2490,2480,2470,2460,2450,2440,2430,2420,2410,2400,2390,2380,2370,_
    2360,2350,2340,2330,2320,2310,2300,2290,2280,2270,2260,2250,2240,2230,2220,2210,2200,_
    2190,2180,2170,2160,2150,2140,2130,2120,2110,2100,2090,2080,2070,2060,2050,2040,2030,_
    2020,2010,2000,1990,1980,1970,1960,1950,1940,1930,1920,1910,1900,1890,1880,1870,1860,_
    1850,1840,1830,1820,1810,1800,1790,1780,1770,1760,1750,1740,1730,1720,1710,1700,1690,_
    1680,1670,1660,1650,1640,1630,1620,1610,1600,1590,1580,1570,1560,1550,1540,1530,1520,_
    1510,1500,1490,1480,1470,1460,1450,1440,1430,1420,1410,1400,1390,1380,1370,1360,1350,_
    1340,1330,1320,1310,1300,1290,1280,1270,1260,1250,1240,1230,1220,1210,1200,1190,1180,_
    1170,1160,1150,1140,1130,1120,1110,1100,1090,1080,1070,1060,1050,1040,1030,1020,1010,_
    1000,990,980,970,960,950,940,930,920,910,900,890,880,870,860,850,840,830,820,810,800,_
    790,780,770,760,750,740,730,720,710,700,690,680,670,660,650,640,630,620,610,600,590,_
    580,570,560,550,540,530,520,510,_
    500],TXIU
    
    RETURN
    As you can see I do not use ADCIN. I am a control freak
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    No luck,
    Tried adding the caps and no difference, and also tried your way of getting the AD values but still off, so i'm at a loss at the mo!

    will try another sensor JUST on the offchance that its that thats gone awry etc.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Maybe Darrel or Bruce will come to the rescue.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts