Need help with LM34 and 12F675


Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52

    Default Need help with LM34 and 12F675

    I'm trying to build a fan controller for a solar heater that I built but I can't seem to get it to work. I've tried everything I can think of and now I need help.
    Yes probably that kind too. I was sane before I started this.
    I'm using an LM34 temperature sensor which outputs 10mv/deg F from 5F (50mv) to 300F (3000mv) and a 12F675.
    Attached is a text file with the code and it is also listed below.
    Any help would be appreciated. I'm trying to make it come on at 115F and go off at 80F, settable in a constant at the beginning of the code. Later I want to add PWM for servo operated dampers.
    Any help will be appreciated.

    Code:
    'Modified from file found at Renolds Electronics
    'http://www.rentron.com/PIC12C67XAD.htm
    'LM34
    'PIN  NAME     Purpose
    ' 1    VDD      +5v
    ' 2   Output    10mv/degF, +5° to +300°F = 50mv-3000mv
    ' 3    VSS      GND      
    ' 
    'PIC12F675 
    ' PIN  NAME     Purpose
    '  1    VDD      +5v
    '  8    VSS      GND
    '  5   GPIO.2   PWM out to servo
    '  6   GPIO.1   Output to NPN transistor sinking relay.
    '  7   GPIO.0   A/D input from center leg of LM34
    '******************* Fuses, Defines, Variables & Constants ******************
    @ device pic12F675, intrc_osc_noclkout, wdt_off, pwrt_on, mclr_off, bod_off, protect_off
    define OSC 4        'Use 4mhz osc  
    CMCON=7             '(%00000111) Turn off analog comparators
    TRISIO=%001001      '(Dec 9)Port direction register. 1=input, 0=output Note TRISIO.3 is always an input.
    RESULT   VAR BYTE	'A/D CONVERSION RESULT STORAGE BYTE
    ADCON1=6		    '(%00000110) SET GP.0 TO ANALOG INPUT, Vref = Vdd, ALL ELSE = DIGITAL I/O
    HighTemp var byte   'High temperature setpoint 
    LowTemp  Var byte   'Low  temperature setpoint
    Relay    var GPIO.1 'Output pin tp transistor
    'PWMOut   var GPIO.2 'Pin 5 used to drive damper servos 'To be implemented later
    HighTemp = 115      'Relay turn on Temp
    LowTemp = 80        'Relay turn off temp
    '************************ Main ************************
    MAIN:
        GOSUB GETVAL		'SETUP A/D
            pause 500       'Wait 500ms 
        gosub Setrelay      'Turn on or off relay
            pause 500        
        GOTO MAIN           'Start over
    '************************
    GETRESULT:
            PAUSEUS 50	   'WAIT FOR A/D CHANNEL SETUP (50 uS)
            ADCON0.2 = 1   'START CONVERSION BY SETTING GO/DONE-BIT (HIGH)
    '************************
    LOOP:                  'WAIT FOR GO/DONE BIT TO BE CLEARED
        IF ADCON0.2=1 THEN 'CHECK GO/DONE BIT (0=DONE)
            GOTO LOOP      'NOT FINISHED CONVERTING, THEN LOOP UNTIL DONE
        ENDIF			   'IF STATEMENT SATISFIED, ADCON0.2 = 0 (DONE)
    RETURN			       'FINISHED CONVERSION, RETURN TO GETVAL ROUTINE
    '************************
    GETVAL:
            ADCON0=%10000001 'SET A/D Fosc/32,[4MHz], CHANNEL-0 = ON
        GOSUB GETRESULT	   'START THE CONVERSION
            RESULT = ADRES 'STORE THE A/D CONVERSION VALUE IN RESULT
    RETURN			       'RETURN TO MAIN ROUTINE, START OVER
    END			
    '************************
    SetRelay:       'Turn on or off relay with hysterisis                                 
        select case RESULT
            case RESULT <= lowTemp
                low relay
           'PWM GPIO.2, 127, 100 'Need 1ms wide pulse at about 40-50 per second. To be implemented later 
            case RESULT > LowTemp and Temp > HighTemp
                low Relay
           'PWM GPIO.2, 25, 100 'Need 1ms wide pulse at about 40-50 per second. To be implemented later                   
        end select 
    'PWM GPIO.2, 127, 100  'Send 50% (127) duty cycle pwm signal out pin 5 for 100 cycles                                                                    
    return             
        END
    Attached Files Attached Files

Similar Threads

  1. 12f675 sensing temperature...
    By rossfree in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th April 2007, 00:11

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