Help with Analog Interrupt


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's something to start with. I've converted the assembler example in the app note to PBP for you with one exception. It does not use interrupts. This just uses the ultra low-power wake-up feature to wake from sleep. Global interrupts are disabled.

    With a 10K / 1uF RC network on RA0, it wakes up & toggles RC5 ~ once every 34 seconds.
    Code:
    @ device  pic16F688, intrc_osc_noclkout, wdt_off, mclr_off, protect_off
     ' Note: Default internal osc is set to 4MHz
    
    SleepyTime: 
        'BCF STATUS, RP0 ;Bank 0
        'BSF PORTA, 0 ;Set RA0 data latch
         PORTA.0 = 1
         
        'MOVLW H’7’ ;Turn off
        'MOVWF CMCON0 ;comparators
         CMCON0 = 7
         
        'BSF STATUS, RP0 ;Bank 1
        'BCF ANSEL, 0 ;RA0 to digital I/O
         ANSEL.0 = 0
         
        'BCF TRISA, 0 ;Output high to
         TRISA.0 = 0
         
        'CALL CapDelay ;charge capacitor
         PAUSE 100 ' change to suite your RC circuit
         
        'BSF PCON, ULPWUE ;Enable ULP Wake-Up
         PCON.5 = 1
        
        'BSF IOCA, 0 ;Select RA0 IOC
         IOCA.0 = 1
        
        'BSF TRISA, 0 ;RA0 to input
         TRISA.0 = 1
         
        'MOVLW E’10001000’ ;Enable interrupt
        'MOVWF INTCON ;and clear flag
         INTCON = %00001000 ' Note bit 7 is clear since we're not vectoring to an int handler
         
        'SLEEP ;Wait for IOC
         @ SLEEP
         
         INTCON.0 = 0  ' clear int flag on wake-up
    
    Main: ' Do whatever you need here on wakeup
         ' insert your code here
         
         TOGGLE PORTC.5  ' do your stuff here before entering sleep mode again
         GOTO SleepyTime ' do the ultra low-power wake-up thing again afterwards
         END
    An interesting note on this one is that is works whether you clear the int flag or not!
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Nov 2006
    Posts
    70


    Did you find this post helpful? Yes | No

    Default Thanks!

    Above and beyond, Bruce. You are the greatest.

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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