ON INTERRUPT not working


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default ON INTERRUPT not working

    My program runs OK the first time, but interrupt does not go to start. It wakes from sleep (clock is active) but just idles. What am I doing wrong? This is the program:

    '* Notes : Power up starts the time and turns on a FET *
    '* : switch. After 15 minutes, the FET switch is *
    '* : is turned off. If the stop switch is pressed *
    '* : while the timer is running, the FET is turned off;*
    '* : and the timer goes to sleep. The start switch *
    '* : (interrupt) wakes the timer and starts it. *
    '************************************************* ***************
    REM device = 12F675
    CMCON = 7 ' SETS DIGITAL MODE
    ANSEL = 0 ' GPIO.0 TO GPIO.3 SET AS DIGITAL
    OPTION_REG = 0 ' WEAK PULLUPS ENABLED
    TRISIO = %00001100 ' GPIO.2 AND GPIO.3 SET AS INPUT
    IOC = %00000100 ' INTERRUPT ENABLED ON GPIO.2
    VRCON.7 = 0 ' TURN OFF VOLTAGE REFERENCE
    N VAR WORD ' VARIABLE N DEFINED
    ON INTERRUPT GOTO AGAIN
    INTCON = %10010000 ' INTERRUPT ENABLED
    ' ************************************************** ***********

    START:
    INTCON.1=0 ' Clear GP2/INT flag

    HIGH GPIO.0
    FOR N=1 TO 900
    IF GPIO.3=0 THEN SLEEPNOW
    PAUSE 1000
    NEXT N
    SLEEPNOW:
    LOW GPIO.0
    SLEEP 1 ' WDT is turned off so I think it does not wake uP.
    AGAIN:
    GOTO START
    resume
    END

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi,Russ

    Just a minute ... I'm looking for a solution, and then will explain you the "why"

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Russ

    That should run ...

    Code:
    '****************************************************************
    '* Notes : Power up starts the time and turns on a FET *
    '* : switch. After 15 minutes, the FET switch is *
    '* : is turned off. If the stop switch is pressed *
    '* : while the timer is running, the FET is turned off;*
    '* : and the timer goes to sleep. The start switch *
    '* : (interrupt) wakes the timer and starts it. *
    '************************************************* ***************
    REM device = 12F675
    
    CMCON = 7 ' SETS DIGITAL MODE
    ANSEL = 0 ' GPIO.0 TO GPIO.3 SET AS DIGITAL
    VRCON.7 = 0 ' TURN OFF VOLTAGE REFERENCE
    OPTION_REG.7 = 0 ' WEAK PULLUPS ENABLED
    GPIO   = %00001100
    TRISIO = %00001100 ' GPIO.2 AND GPIO.3 SET AS INPUT
    
    N VAR WORD ' VARIABLE N DEFINED
    
    
    '************************************************************* 
      PAUSE 300                              'let's supply stabilize ...
      
     
     Start:
    
     N = 0
     HIGH GPIO.0                            'Lit The Light                
     
         While ( N <  3126  AND GPIO.3 )   ' Do that while GPIO.3 is High
                                                  ' AND time not finished
            NAP 4                               'Sleep for .288 sec
            N = N+1
            
         WEND                                   ' We've read enough !!!  
                                                   
     LOW GPIO.0                                  'Ligts off !!!
    
     INTCON = %00010000                    ' INTERRUPT ENABLED ON GPIO.2, but NOT GIE !!!
    
     @ Sleep                                     ;Real ASM sleep
     @ nop
     
     INTCON.1 = 0                                  'cancel interrupt flag
     GOTO Start
     
     END
    Last edited by Acetronics2; - 11th April 2008 at 20:35. Reason: forgotten the I Flag ... booooooo
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Thank you. I see you don't like the "on interrupt" command; I don't either any more.

    I tried your program and it works exactly the same as mine: the first pass is OK but interrupt does not go to start.

    Any other thoughts?

    Russ
    Last edited by Russ Kincaid; - 11th April 2008 at 22:59.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    ON INTERRUPT will work, it just need some care when you write your code. But sometimes, you don't need to use it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    OH, my. I found part of my problem: I was loading the hex file from the Melabs folder but Microcode Studio was saving in a different folder. No wonder nothing I did made any difference! I will have to start over and do it again.

    BTW, your program does not go to sleep, at least not in 20 minutes.

    Russ

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, Russ

    THAT Works ( in the real World ...LOL ) ... but, for the moment, I Can't use GPIO.3 !!!

    so, it works with GPIO.4 ...

    I'm digging for what I've forgotten ...

    Code:
    '****************************************************************
    '* Notes : Power up starts the time and turns on a FET *
    '* : switch. After 15 minutes, the FET switch is *
    '* : is turned off. If the stop switch is pressed *
    '* : while the timer is running, the FET is turned off;*
    '* : and the timer goes to sleep. The start switch *
    '* : (interrupt) wakes the timer and starts it. *
    '************************************************* ***************
    REM device = 12F675
    
    'DEVICES------------------------------------------------------------------
    @   __Config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF 
    
    CMCON  = 7 ' SETS DIGITAL MODE
    ADCON0 = 0
    ANSEL  = 0 ' GPIO.0 TO GPIO.3 SET AS DIGITAL
    VRCON.7 = 0 ' TURN OFF VOLTAGE REFERENCE
    OPTION_REG.7 = 0 ' WEAK PULLUPS ENABLED
    WPU = %00011100
    GPIO   = %00011100
    TRISIO = %00011100 ' GPIO.2 AND GPIO.3 SET AS INPUT
    INTCON = 0
    N VAR WORD ' VARIABLE N DEFINED
    
    '************************************************************* 
      PAUSE 300                              'let's supply stabilize ...
      
     Start:
     N = 0
     HIGH GPIO.0                            'Lit The Light                
           
         While  ( N < 3126 ) AND GPIO.4        ' Do that while GPIO.4 is High   3126
                                            ' AND time not finished
            PAUSE 288                             'Pause for .288 sec
            N = N+1
            
         WEND                                   ' We've read enough !!!  
                                                   
     LOW GPIO.0                                  'Ligts off !!!
     
     INTCON = %00010000             ' INTERRUPT ENABLED ON GPIO.2, but NOT GIE !!!
     
     @ Sleep                                     ;Real ASM sleep
     @ nop
     
     INTCON = 0                                  'Interrupt disabled
     GOTO Start
     
     END
    Alain

    PS : May be GPIO.3 is "locked" by the reset system of my EasyPic5 ???
    rePS : YESS ... works fine with GPIO.3 ... when J7 is correctly set !!!
    Last edited by Acetronics2; - 12th April 2008 at 18:06.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  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