Please help! Comparator function 12F635


Closed Thread
Results 1 to 3 of 3
  1. #1

    Exclamation Please help! Comparator function 12F635

    Hi, I have couple of 12F635 and I am trying to build an project with them where they send an RF signal when one particular pin is made high by an PIR sensor module.
    I am planning to run this PIC on 3AA batteries 4.5V total. As an added feature I would like to make its any one pin high if the voltage falls below a certain predefined level (Anything between 2 to 4.5 volts-set in the code) and PIC to stay asleep untill either PIR puts its pin high or voltage falls below certain level.
    I need guidence on two things:
    1) Interrupt
    2) Voltage check
    I have read about both of the above topics but I am still confused with the voltage check mainly. I have never done anything like this before and would like some guidance on how to go about the code for this.
    Any help will be appreciated.
    Thanks
    Last edited by FromTheCockpit; - 30th October 2009 at 16:18.

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Here is a PLVD interrupt example that was done with that chip.

    http://www.picbasic.co.uk/forum/showthread.php?t=6927

    Darrell Taylor Interrupts here: http://darreltaylor.com/DT_INTS-14/intro.html

    Darrell has included a HLVD_INT -- High/Low Voltage Detect in his interrupt rountines, but it needs a pic18 device.

    http://darreltaylor.com/DT_INTS-18/home.html
    http://www.scalerobotics.com

  3. #3


    Did you find this post helpful? Yes | No

    Question

    Ok, I have read the code. I have to say, it opened few more doors in my brain. Few questions though:
    1) What is the external circuit at ULPWU pin?
    2) Why is global interrupt not enabled and there is no statement "ON_INTERRUPT"?
    3) Do I need the above two statements IF I want to monitor more pins? My plan is to attach an PIR sensor to one pin and when the sensor makes the pin high, PIC should wake up and send data via RF transmitter and goes back to sleep again. It should only send data if PIN IS MADE HIGH.

    I have ammended the code at the link above to suit my needs, please excuse silly mistakes (if any) as its my first attempt on interrupts and I request your feed back please. Thanks
    So here I go:

    Suppose PIR attached to GPIO.1

    @ DEVICE PIC12F635,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_ OFF
    @ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,WUREN_OFF,PROTECT_OFF

    SYMBOL PLVD_LED = GPIO.2

    OSCCON = %01100000 ' Internal 4MHz select
    OPTION_REG = 128 ' internal pull-ups off
    CMCON0 = 7 ' disable comparator
    VRCON = 0 ' disable internal Vref

    GPIO = %00000000 ' LED off on boot
    TRISIO = %00000001 ' GPIO.0 = input, rest outputs
    PIR1 = 0 ' clear peripheral int flags
    PCON.5 = 1 ' ultra low power wakeup enabled

    Main:
    GPIO.0 = 1 ' set data latch on GPIO.0
    TRISIO.0 = 0 ' GPIO.0 = output (charging cap)
    PAUSEUS 24 ' charge cap for 24uS
    TRISIO.0 = 1 ' GPIO.0 = input to discharge cap
    IOCA.0 = 1 ' int on change enabled for GPIO.0
    IOCA.1=1 ' int on change enabled for sensor @ GPIO.1
    INTCON = %00001000 ' global ints disabled, int on change enabled
    @ SLEEP ' put PIC to sleep
    INTCON.0 = 0 ' clear wake up on change int flag
    GOSUB Test ' go test for under voltage condition AND send data if pin is made high by sensor
    GOTO Main

    Test:
    INTCON.6 = 1 ' peripheral ints enabled
    While gpio.1=1
    serout (data)---'My data goes here
    pause 500
    wend
    LVDCON = %00010101 ' enable PLVD. set trip point to 4.0V

    ' enable PLVD interrupt only when PLVD internal Vref is stable
    IF LVDCON.5 = 1 THEN PIE1.6 = 1 ' if stable, enable

    IF PIR1.6 = 1 THEN ' voltage <= 4.0V?
    HIGH PLVD_LED ' yes. indicate voltage is <= 4.0V
    PIR1.6 = 0 ' clear int flag
    ELSE
    LOW PLVD_LED ' else, indicate voltage is > 4.0V
    ENDIF
    LVDCON = 0 ' PLVD disabled before returning to sleep
    INTCON.6 = 0 ' peripheral ints disabled
    PIE1 = %00000000 ' low voltage detect int disabled
    RETURN

Similar Threads

  1. ULPWU & PLVD on 12F635 & 16F684
    By dsicon in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 24th November 2009, 01:38
  2. 12f635 & fan regulator
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th August 2009, 22:10

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