LM35DZ and 18F2455 settings


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Hope so, as im quite attached to my hair lol!!
    Runs fine when using the VDD as the Vref source, just cant seem to get the fractional digit at all.
    Been running it using the VDD for about 5 mins, and it sits at around 22C which at a guess is our room temp lol, and when I hold the sensor inbetween my fingers the temp rises nicely, and when put down again it drops and settles again at 22.

    It is just when I try to use the Vref+ (AN3) it goes toes up (not the usual saying, but kiddy friendly)

    For a generic temp reader, it would be fine as it is, but for a marine aquarium, I want to be able to get finer readings so that I can use the fans to reduce the temp if the water level rises say 0.5C as stability is the key in marine keeping etc.

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


    Did you find this post helpful? Yes | No

    Default

    Not sure if you can get the 0.5 with this. If you do you will have to do a floating point routine or some other trick. +- 1 degree for these LM34s is the rating(I think).

    Have you seen this?
    http://www.rentron.com/PicBasic/LM34.htm
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    yeah I have read through that a few times, and it helped me in the first place with the sensor etc, also read the link above in my first post as Savnik was trying to do the same thing but with a 16F chip and a couple of guys helped him to sort it out, which is the base for mine, but obviously on that thread, they dont say how they are using it (ie VDD or a Vref pin)

  7. #7
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default LM34 with 16F876 also for an Aquarium

    I use two LM34s with a 16f876 and it's been rock solid with the following snippetts....
    Code:
    DEFINE LOADER_USED	1
    DEFINE OSC 4
    DEFINE ADC_BITS 8             ' Set A/D for 8-bit operation
    DEFINE ADC_CLOCK 3            ' Set A/D clock 
    DEFINE ADC_SAMPLEUS 50        ' Set A/D sampling time @ 50 uS
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
                               'Subroutine to get room temperature
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    
    
    roomdegrees:
        
        FOR sample = 1 TO 20    ' Take 20 samples
            ADCIN 2, roomtemp       ' Read channel 2 into temp variable
            samples = samples + roomtemp ' Accumulate 20 samples
        NEXT sample
            roomtemp = samples/20
            samples = 0             ' Clear old sample accumulator
        SerOut2 PORTC.6,SPbaud, [$00, $80, $29,roomtemp] 'update siteplayer with room temperature
        if r7sched = 0 then return                 'manual control = 0, auto control = 1
        if roomtemp >= roomspt + 1 then
        SerOut2 PORTC.6,SPbaud, [$00, $80, $3C,1] 'update siteplayer with exhaust status on
        checkrelays = 1
        endif
        if roomtemp <= roomspt - 1 then
        SerOut2 PORTC.6,SPbaud, [$00, $80, $3C,0] 'update siteplayer with exhaust status off
        checkrelays = 1
        endif
        return
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
                               'Subroutine to get tank temperature
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    
    tankdegrees:
        
        FOR sample = 1 TO 20    ' Take 5 samples
            ADCIN 4, watertemp       ' Read channel 4 into watertemp variable
            samples = samples + watertemp ' add 5 samples
        NEXT sample
            watertemp = samples/20
            samples = 0             ' Clear old samples
        SerOut2 PORTC.6,SPbaud, [$00, $80, $28,watertemp] 'update siteplayer with water temperature
        if r8sched = 0 then return                        'manual control = 0, auto control = 1
        if watertemp > waterspt then
        serOut2 PORTC.6,SPbaud, [$00, $80, $3D,0] 'update siteplayer with heater status off
        checkrelays = 1
        endif
        if watertemp <= waterspt - 1 then
        SerOut2 PORTC.6,SPbaud, [$00, $80, $3D,1] 'update siteplayer with heater status on
        checkrelays = 1
        endif
        return
    I know you're using a different micro but maybe this will help some.

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