DT_instantINT 16f690 not working... what am I doing wrong?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427

    Default DT_instantINT 16f690 not working... what am I doing wrong?

    Hey group,
    I am finally tackling DT's instant INT's

    I have been able to get his LED blink sample working using INT_INT (pin RA2 on the 16F690, the external INT pin)
    using this code...
    Code:
    include "ALLDIGITAL.pbp"
    INCLUDE "DT_INTS-14.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"        ; Include if using PBP interrupts
    
    wsave               VAR BYTE    $70     SYSTEM  ' alternate save location for W 
    
    DEFINE OSC 4
    
    TrisA = %00000100
    TrisB = %00000000
    TrisC = %00000011
    LED0   VAR  PORTC.0   'this LED is controlled by the "INT" pin, 16F690=RA2
    LED1   var  PortC.1   'this LED is controlled by the Main program loop
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    
    Main:
      PAUSE 1000
      Toggle led1
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED0
    @ INT_RETURN
    But I can not get the interupt to work using RB7(Individually controlled interrupt-onchange.
    Individually enabled pull-up.)

    I have tried several of the various INT choices and the one that seems to compile without errors is RABC_INT. But the program acts weird. I have two LED's one connected to RC0 that should be controlled by the instantINT. And another LED connected to RC1 that should be blinking at a 1 second rate controlled by the "Main" program loop.
    Here is the code for that...
    Code:
    include "ALLDIGITAL.pbp"
    INCLUDE "DT_INTS-14.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"        ; Include if using PBP interrupts
    
    wsave   VAR BYTE    $70 SYSTEM  ' alternate save location for W 
    
    DEFINE OSC 4
    
    TrisA = %00000000
    TrisB = %10000000
    TrisC = %00000000
    CM1CON0 = 0           'turn off the comparator 1
    CM2CON0 = 0           'turn off the comparator 2
    OPTION_REG.7=1        'Turn OFF weak pull ups
    
    
    LED0   VAR  PORTC.0   'this LED is controlled by the "INT" pin, 16F690=RA2
    LED1   var  PortC.1   'this LED is controlled by the Main program loop
    IOCB.7=1
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RABC_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   RABC_INT     ; enable external (INT) interrupts
    
    Main:
      PAUSE 1000
      Toggle led1
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED0
    @ INT_RETURN
    LED0 controlled by the "Main" program loop is working correctly.
    LED1 (should be controlled by RB7 INT) does not work correctly... it blinks erratically. ON dim, ON bright and OFF
    and the LED1 ONLY blinks if in include this line of code... IOCB.7=1

    What am I doing wrong??
    How does one know which INT to use??

    My goal is to impliment instantINT using a rotary encoder on RB6 & 7, and a third INT for the encoder push-button on RB5.

    HELP! please
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DT_instantINT 16f690 not working... what am I doing wrong?

    IOCB.7=1 is correct (you are enabling that pin for interupt on change interrupts)

    You will also need to enable Weak pullups...
    OPTION_REG.7 = 0
    WPUB.7 = 1 '

    I normally use a variable mapped to the associated interrupt bit like this...

    IOC_FLAG VAR INTCON.0 ' Alias RABIF interrupt flag bit

    ...then it's easier to track clearing it, for example...

    IOC_FLAG = 0 ' Clear the int-on-change flag bit

    (the flag needs to be cleared before you enable with @ INT_ENABLE RABC_INT )

    also it's a good idea to put a wend in at the beginning of your program to ensure things have settled. So pulling the sequence together would look something like this

    Code:
    ASM
    INT_LIST  macro ; IntSource,    Label,         Type, ResetFlag?
        INT_Handler  RABC_INT,  _Switch_Interrupt,  PBP,  YES
        end
    
        INT_CREATE       ; Creates the interrupt processor
    ENDASM
    '
    IOC_FLAG = 0          ' Clear the int-on-change flag bit
      '
    WHILE SW1 = 0 : WEND  ' Wait until all sw has settled and is at logic 1 before proceeding
    '
    @ INT_ENABLE RABC_INT   ; Now things have settled,eEnable 'Int On Change' interrupts

    If it's still not working, get a DVM onto RB7 and make sure it's sitting at supply voltage. RB7 is also the EUSART TX pin, so if you're using anything with serial output, that could cause you grief, from recollection, it can be disabled something like this...

    RCSTA.7 = 0


    It sounds like your LED1 is actually toggling fine...it's just that it's toggling at one helluva lick (hence dim)....better to put a pause in your interrupt routine to give it a breather between on & off...

    Code:
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED0
    pause 250
    @ INT_RETURN
    Hope that helps a little.
    Last edited by HankMcSpank; - 6th November 2011 at 01:39.

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: DT_instantINT 16f690 not working... what am I doing wrong?

    Thanks Hank...
    I added what you suggested and it is working better... BUT LED0 is still not ON fully when it is on. I looked at it with an O-scope and it is actually a square wave at 2.9 KHz... which makes me think it is constantly re-triggering the interrupt at that 2.9KHz rate (or something??)

    Here is my code as it stands...
    Code:
    #CONFIG
      __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    #endconfig
    
    
    include "ALLDIGITAL.pbp"
    INCLUDE "DT_INTS-14.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"        ; Include if using PBP interrupts
    
    wsave   VAR BYTE    $70 SYSTEM  ' alternate save location for W 
    
    DEFINE OSC 4
    
    TrisA = 00000000
    TrisB = 00000000
    TrisC = 00000000
    OPTION_REG.7=0        'Turn On weak pull ups
    WPUB.7 = 1
    
    LED0   VAR  PORTC.0   'this LED is controlled by the "INT" pin, 16F690=RA2
    LED1   var  PortC.1   'this LED is controlled by the Main program loop
    IOC_FLAG VAR INTCON.0
    
    IOCB.7=1
     
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RABC_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    IOC_FLAG = 0
    @   INT_ENABLE   RABC_INT     ; enable external (INT) interrupts
    
    Main:
      PAUSE 500
      Toggle led1
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
    IOC_FLAG = 0
    toggle LED0
    
    @ INT_RETURN
    Also... i am using a pulse generator that allows me to generate 1,10,100,1000 Hz and that is what I am using to feed RB7 (the source of the INT)

    I have looked at the pulse signal feeding the INT and it is clean.

    anyone?

    PS. when you post code to the forum it seems to not like "%" and deletes some of the bits after the %. There are %'s in my actual code.
    Last edited by Heckler; - 6th November 2011 at 05:53.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: DT_instantINT 16f690 not working... what am I doing wrong?

    Hi,
    When using the Interrupt On Change feature you must read the pins in interrupt handler in order to end the mismatch condition. You're not doing that as far as I can see so the interrupt refires as soon as it exits which is why you get the 2.9kHz squarewave output.

    /Henrik.

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: DT_instantINT 16f690 not working... what am I doing wrong?

    Henrik... BINGO!

    Go get yourself a doughnut... (or whatever sweet treat you good people of Sweden like to enjoy at celebrations!)

    that was it...

    I just added this line to my INT handler...
    Code:
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
    myvar = PortB
    IOC_FLAG = 0
    toggle LED0
    
    @ INT_RETURN
    And now I have 2 LED's blinking at different rates, one controlled by the rate of the INT, the other at a fixed rate controlled by the PAUSE command in the Main program loop.

    I spent a couple of hours testing and troubl shooting and pulling my hair out... on this last evening. Why? was it for a special important project? NO... I just wanted to get my brain around the DT INT's and be able to use them and under stand them. My signature line really says it for me.
    Last edited by Heckler; - 6th November 2011 at 14:39.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

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