+ Reply to Thread
Results 1 to 24 of 24
  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default DT Interrupts not Working with PIC16F19197

    Hi, I'm banging my head against the walls trying to figure this one out. I'm trying to implement this very simple DT interrupt to toggle a LED,

    http://www.picbasic.co.uk/forum/show...7472#post17472

    The problem is that the program never goes to the interrupt handler ToggleLED1. I can make a LED blink in the MAIN loop, but it won't go to the Int handler. This chip is pretty new, so I'm wandering if the DT_INTS-14.bas or ReEnterPBP.bas files need any changes. I have tried playing with the other registers related to TMR1 like T1CLK, but nothing works. Any help is greatly appreciated. Thanks. Robert

    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $31                ; Prescaler=8, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    where is the code to set tmr1 on, and at what clk source .......
    This is more entertaining than Free to Air TV

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    I added the following code and still doesn't work.

    Code:
    T1CLK = %00000010        'TIMER1 CLOCK SELECT TO Fosc
    PIE4.0 = 1                        'TIMER1 OVERFLOW INTERRUPT ENABLE BIT
    INTCON = %11000000      'ENABLE INTERRUPTS
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    my bad , missed the ticon line


    dt ints defined timer 1 like this
    #define TMR1_INT PIR1,T1IF, PIE1,T1IE ;-- TMR1 alternate sym
    or this
    #define TMR1_INT PIR1,TMR1IF, PIE1,TMR1IE ;-- TMR1 Overflow

    your chip is different again

    needs another variation
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Quote Originally Posted by richard View Post
    my bad , missed the ticon line


    dt ints defined timer 1 like this
    #define TMR1_INT PIR1,T1IF, PIE1,T1IE ;-- TMR1 alternate sym
    or this
    #define TMR1_INT PIR1,TMR1IF, PIE1,TMR1IE ;-- TMR1 Overflow

    your chip is different again

    needs another variation
    Ooh no, great!
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Quote Originally Posted by richard View Post
    my bad , missed the ticon line


    dt ints defined timer 1 like this
    #define TMR1_INT PIR1,T1IF, PIE1,T1IE ;-- TMR1 alternate sym
    or this
    #define TMR1_INT PIR1,TMR1IF, PIE1,TMR1IE ;-- TMR1 Overflow

    your chip is different again

    needs another variation
    Is there any chance that someone that knows assembly can update these DT interrupts for the new generation of 8 bit PICs? I could help, but my skills in assembly are not too good.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    try adding this interrupt definition to the dt_ints-14.bas at the top of the definitions

    #define T1_197_INT PIR4,TMR1IF, PIE4,TMR1IE ;-- TMR1 - 16f19197 *


    then rename your interrupt names
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    becomes
    INT_Handler T1_197_INT, _ToggleLED1, PBP, yes

    ditto for other instances
    int enable /disable
    This is more entertaining than Free to Air TV

  8. #8
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Quote Originally Posted by richard View Post
    try adding this interrupt definition to the dt_ints-14.bas at the top of the definitions

    #define T1_197_INT PIR4,TMR1IF, PIE4,TMR1IE ;-- TMR1 - 16f19197 *


    then rename your interrupt names
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    becomes
    INT_Handler T1_197_INT, _ToggleLED1, PBP, yes

    ditto for other instances
    int enable /disable
    Hmm, it compiled okay, but it didn't work.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    i don't see any

    INT_ENABLE T1_197_INT

    Post the code, I don't have one of those chips and can't compile for it either
    still on 3.0xxx
    Last edited by richard; - 19th August 2019 at 05:10.
    This is more entertaining than Free to Air TV

  10. #10
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Quote Originally Posted by richard View Post
    i don't see any

    INT_ENABLE T1_197_INT

    Post the code, I don't have one of those chips and can't compile for it either
    still on 3.0xxx
    Here is the code just to test it,

    Code:
    DEFINE OSC 32                       'Define Oscillator to 32 MHz 
    OSCFRQ = %00000110                  'DEFINE OSCFRQ TO 32 MHZ
    
    LED1   VAR  PORTB.1
    
    wsave var byte $20 system ;location for W if in bank0
    'wsave var byte $70 system ;location for W if in bank0
    
    wsave1 var byte $A0 system ;location for W if in bank0
    wsave2 var byte $120 system ;location for W if in bank0
    wsave3 var byte $1A0 system ;location for W if in bank0
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    TRISB = $00
    TRISC = $00
    TRISE = $00
    PORTB = $00
    PORTC = $00
    PORTE = $00
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   T1_197_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @ INT_ENABLE  T1_197_INT     ; enable Timer 1 interrupts
    
    T1CLK = %00000010
    'PIE4.0 = 1      'TIMER1 OVERFLOW INTERRUPT ENABLE BIT
    'PMD1.1 = 0      'TIMER1 MODULE ENABLED
    'INTCON = %11000000
    
    T1CON = $31                ; Prescaler=8, TMR1ON
    
    
    Main:
        toggle PORTC.1
        PAUSE 1000
        
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
    '    T1CON.0 = 0          'MIGHT NOT BE NECESSARY
    
        TOGGLE PORTE.1
    '    IF PORTB.7 = 0 THEN
    '        PORTB.7 = 1
    '    ELSE
    '        PORTB.7 = 0
    '    ENDIF
        'PORTC.0 = 1
        
    '    TOGGLE PORTC.0
    '    TOGGLE PORTC.1        'LED indicators to on
        PAUSE 500
        
    '    TMR1L = 0               'Reset Timer1
    '    TMR1H = 0
    '    PIR4.0 = 0          'CLEAR TIMER1 OVERFLOW
    '    PIR5.0 = 0          'CLEAR TIMER1 GATE OVERFLOW
    '    T1CON.0 = 1         'MIGHT NOT BE NECESSARY
         
    @ INT_RETURN
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    try this


    Code:
    DEFINE OSC 32                       'Define Oscillator to 32 MHz 
    OSCFRQ = %00000110                  'DEFINE OSCFRQ TO 32 MHZ
    
    LED1   VAR  PORTB.1
    
    
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    TRISB = $00
    TRISC = $00
    TRISE = $00
    PORTB = $00
    PORTC = $00
    PORTE = $00
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   T1_197_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @ INT_ENABLE  T1_197_INT     ; enable Timer 1 interrupts
    
    T1CLK = 1     ' FOSC/4
    PIE4.0 = 1      'TIMER1 OVERFLOW INTERRUPT ENABLE BIT
    PMD1.1 = 0      'TIMER1 MODULE ENABLED
    INTCON = %11000000
    
    T1CON = $31                ; Prescaler=8, TMR1ON
      led1 =1  ; prove led works
        PAUSE 1000
    Main:
        toggle PORTC.1
        PAUSE 1000
        
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
        TOGGLE led1
    
         
    @ INT_RETURN
    Last edited by richard; - 19th August 2019 at 05:30. Reason: not sure where porte1 fits in
    This is more entertaining than Free to Air TV

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    back in an hour, just replacing my disappointing led [40w replacement fluro tubes] with some nice 24w daylight led ceiling fittings in the workshop
    This is more entertaining than Free to Air TV

  13. #13
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    It works!!!!! Thanks a million.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    It works!!!!!
    goodo
    not the most elegant solution modifying dt ints like that, i'm sure dt would have found a way to identify that chip for a conditional compile to keep things nice
    This is more entertaining than Free to Air TV

  15. #15
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Quote Originally Posted by richard View Post
    goodo
    not the most elegant solution modifying dt ints like that, i'm sure dt would have found a way to identify that chip for a conditional compile to keep things nice
    I know. It's a real shame that we lost him.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  16. #16
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Hmm, the interrupt works well right after the chip is reprogrammed. However, if I reset the power a few times, the chip gets hung up. It looks like it doesn't reenter the interrupt handler. It looks to me like it is not clearing the overflow bit, or that is not resetting the TMR1L and TMR1H bytes. Even if I do this resetting in the code, the interrupt is not working.

    ON INTERRUPT works well, but with a big lag of course. The DT interrupts don't work well with this new chip. Can somebody provide an updated version of the DT interrupts for this chip and TMR1? Thanks.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    the modified dt ints is highly unlikely to be the issue, if it was the isr would never work.
    its far more likely your startup code is failing to setup all necessary conditions for the isr to run.

    reading the datasheet i see no differences in the tmr1 overflow interrupt mechanism from any other ec pic16 other than the
    "settings" have moved to pir/e 4, and the clk source is in a separate reg from t1con.
    This is more entertaining than Free to Air TV

  18. #18
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    The code is very simple as shown below. What can be the problem then? ON INTERRUPT works every time.

    Code:
    DEFINE OSC 32                       'Define Oscillator to 32 MHz 
    OSCFRQ = %00000110                  'DEFINE OSCFRQ TO 32 MHZ
    
    LED1   VAR  PORTB.1
    
    wsave var byte $20 system ;location for W if in bank0
    'wsave var byte $70 system ;location for W if in bank0
    
    wsave1 var byte $A0 system ;location for W if in bank0
    wsave2 var byte $120 system ;location for W if in bank0
    wsave3 var byte $1A0 system ;location for W if in bank0
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    TRISB = $00
    TRISC = $00
    TRISE = $00
    PORTB = $00
    PORTC = $00
    PORTE = $00
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   T1_197_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @ INT_ENABLE  T1_197_INT     ; enable Timer 1 interrupts
    
    T1CLK = %00000001
    T1CON = $31                ; Prescaler=8, TMR1ON
    
    Main:
        toggle PORTC.1
        PAUSE 1000
        
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
        TOGGLE PORTC.0
    @ INT_RETURN
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  19. #19
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    wsave var byte $20 system ;location for W if in bank0
    'wsave var byte $70 system ;location for W if in bank0


    wsave1 var byte $A0 system ;location for W if in bank0
    wsave2 var byte $120 system ;location for W if in bank0
    wsave3 var byte $1A0 system ;location for W if in bank0
    chips with auto context save need none of that , it just wastes time and space


    see if you can trip this up
    Code:
    DEFINE OSC 32                       'Define Oscillator to 32 MHz 
    OSCFRQ = %00000110                  'DEFINE OSCFRQ TO 32 MHZ
    
    
    LED1   VAR  PORTB.1
    
    
    
    
    
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    
    TRISB = $00
    TRISC = $00
    TRISE = $00
    PORTB = $00
    PORTC = $00
    PORTE = $00
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   T1_197_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    
    T1CON = 0; stop timer
    pir4.0=0;  clear int flag
    pie4.0=1; enable int
    intcon=$c0  ;enable  gie, pie
    T1CLK = %00000001
    T1CON = $31                ; Prescaler=8, start timer
    
    
    Main:
        toggle PORTC.1
        PAUSE 1000
        
    GOTO Main
    
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
        TOGGLE PORTC.0
    @ INT_RETURN
    This is more entertaining than Free to Air TV

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    the int_enable macro is pretty simple, if the timer is stopped i can't see why it would fail
    assuming the dtint file modded properly

    Code:
    ;---[Enable an interrupt source]--------------------------------------------
      ifndef INT_ENABLECLEARFIRST
        #define INT_ENABLECLEARFIRST 1             ; default to Clear First
      endif          ; use DEFINE INT_ENABLECLEARFIRST 0 to NOT clear First
      
    #INT_ENABLE  macro  FlagReg, FlagBit, EnableReg, EnableBit
          ifdef FlagBit
            ifdef INT_ENABLECLEARFIRST
              if (INT_ENABLECLEARFIRST == 1)       ; if specified
                MOVE?CT 0, FlagReg, FlagBit        ;   clear the flag first
              endif
            endif
            MOVE?CT  1, EnableReg, EnableBit       ; enable the INT source
          else
            INT_ERROR  "INT_ENABLE"
          endif
        endm
    This is more entertaining than Free to Air TV

  21. #21

    Default Re: DT Interrupts not Working with PIC16F19197

    One thing you might want to try...

    The 16F19197 has LAT registers. Use those to toggle the pins instead of the PORT registers.
    Unfortunately you can't use 'TOGGLE LATC.0' since TOGGLE expects a PORT register and modifies other registers based on that.

    The quickest way to toggle a bit is probably to XOR it with 1...
    Code:
    LATC = LATC ^ $01     ' toggle bit 0
    LATC = LATC ^ $02     ' toggle bit 1
    Changing the LAT register has the added bonus in that you don't care if the pin has analog functions or not.
    It'll drive the pin high and low regardless of any ANSEL setting.

  22. #22
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Hmm, it works okay but if I reset the power a few times now it won't go to the handler again. I was thinking that I might have a defective PIC, but ON INTERRUPT works good.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  23. #23
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: DT Interrupts not Working with PIC16F19197

    sounds like power issues

    unstable/slow rise vcc ?
    decoupling caps ?
    rc network on reset pin ?
    add a reset switch ?
    This is more entertaining than Free to Air TV

  24. #24
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    634

    Default Re: DT Interrupts not Working with PIC16F19197

    Quote Originally Posted by richard View Post
    sounds like power issues

    unstable/slow rise vcc ?
    decoupling caps ?
    rc network on reset pin ?
    add a reset switch ?
    Yes, I think that is the case.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Similar Threads

  1. Replies: 6
    Last Post: - 28th July 2011, 21:34
  2. SERIN Not Working, SEROUT Working
    By cc1984 in forum Serial
    Replies: 11
    Last Post: - 26th October 2010, 19:16
  3. Cant get DTs interrupts working
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th April 2010, 14:11
  4. Instant interrupts not working
    By mel4853 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th January 2010, 05:43
  5. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10

Members who have read this thread : 21

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