Troubled with Instant Ints and TMR2


Closed Thread
Results 1 to 28 of 28

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    mmm, can you (or someone else) try the following for me? Try both with a 4 MHz and then with a 20MHz crystal. You just need to change the DEFINE OSC and the code will automatically change for you (config fuses, Prescaller and PR2). Sit a scope on PinActivar (PORTB.0) and measure the frequency. It has to be close of 4KHz

    Code 1 with ON INTERRUPT
    Code:
            DEFINE OSC 4   ' select 4 or 20
            PinActivar      VAR portb.0
            
            LoopCount  VAR WORD
            TMR2IF VAR PIR1.1
                
            TRISB = 0
            portb = 0
            INTCON  = %11000000
            PIE1    = %00000010
            PIR1    = %00000000
            OPTION_REG = %00000000 
            PinActivar = 0
            
    @   IF (OSC==20)        
    @       __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            pr2 = 155 
            T2CON = %00000101   ' TMR2 Prescale 1:4
    @       ELSE
    @       __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            PR2 = 118
            T2CON = %00000100 ' TMR2 prescale 1:1    
    @       ENDIF        
    
            ON INTERRUPT GOTO Sample
    
    MAIN:
            GOTO MAIN
    
    disable   
    Sample:
            TOGGLE PinActivar
            tmr2if=0
    resume  
    enable
    Code 2, with DT-INT
    Code:
            DEFINE OSC 4 ' select 4 or 20
            
            INCLUDE "c:\pbp_prog\Include_routines\DT_INTS-14.bas"
            INCLUDE "c:\pbp_prog\Include_routines\ReEnterPBP.bas"
    ASM
    INT_LIST  macro    ; IntSource,    Label,  Type, ResetFlag?
            INT_Handler   TMR2_INT,  _Sample,   PBP,  YES
        endm
        INT_CREATE
    ENDASM 
            PinActivar      VAR portb.0
    
            TRISB = 0
            portb = 0
            OPTION_REG = %00000000 
    
    @   IF (OSC==20)        
    @       __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            pr2 = 155           ' load tmr2 PR2 to reset every 125 uSec
            T2CON = %00000101   ' TMR2 Prescale 1:4
    @       ELSE
    @       __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            PR2 = 118
            T2CON = %00000100   ' TMR2 prescale 1:1    
    @       ENDIF             
    
    @       INT_ENABLE  TMR2_INT
    MAIN:
            GOTO MAIN
    
       
    Sample:
            toggle pinactivar
    @ INT_RETURN
    i'm curious to knwo if there's any significant difference between the above, and how much. I feel them equal @20MHz, but some doubt on 4MHz.

    Obviously this code don't do anything interesting... i'm just curious...

    As i said, i can't check anything it here.
    Steve

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

  2. #2


    Did you find this post helpful? Yes | No

    Default Maybe this would work better tha Instant Interrupts here!

    Quote Originally Posted by mister_e View Post
    Code 1 with ON INTERRUPT
    Code:
            DEFINE OSC 4   ' select 4 or 20
            PinActivar      VAR portb.0
            
            LoopCount  VAR WORD
            TMR2IF VAR PIR1.1
                
            TRISB = 0
            portb = 0
            INTCON  = %11000000
            PIE1    = %00000010
            PIR1    = %00000000
            OPTION_REG = %00000000 
            PinActivar = 0
            
    @   IF (OSC==20)        
    @       __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            pr2 = 155 
            T2CON = %00000101   ' TMR2 Prescale 1:4
    @       ELSE
    @       __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            PR2 = 118
            T2CON = %00000100 ' TMR2 prescale 1:1    
    @       ENDIF        
    
            ON INTERRUPT GOTO Sample
    
    MAIN:
            GOTO MAIN
    
    disable   
    Sample:
            TOGGLE PinActivar
            tmr2if=0
    resume  
    enable
    Mister_E i am going to test with the ON INTERRUPT way because it might work better here, i am not doing much code between Samples so this could work fine. Thanks for the idea...

    The DT option as you can read at Darrels link will not work either.

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