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

    oups... missed the Elapsed timer... i'll read the according posts/thread about it as i never used it.

    Sorry
    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

    Lightbulb I just doesnt work.. Impossible?

    Ok i figured out a way to measure my interrupts.

    The interrupt routine simply Toggles a pin of the micro on each interrupt and i measure such pin with my oscilloscope. The frequency of sampling is wrong.

    Problems:

    1. The TMR2 doesnt just go back to 0 after reaching PR2 value.. i had to set it to 0 otherwise i get unwanted interrupts.

    2. I cant believe this to be impossible so i made a small RX int.... when i press "1" PR increases by one.. else it goes down one, so i can sweep controlling by my keyboard. RESULT: No No it doesnt work.... i never get to my 125us interrupt it suddenly jumps back to the lower frequency after a point.

    Is 125us to much to ask for 4Mhz.. teorically i would say No.. 125 instructions are a lot of instructions... and i am only sampling at this point of my software so: what could be the problem?

    I cant use other OSC since i am using internal OSC and A7 pin for other purpouses... Since i am only sampling would something like pauseuS 125 : sample work?... What should be the timing consideration in this case?

    i still need someting like:

    Code:
    Sample:
        pauseus 125
        Samples [NumSamples] = CMCON.7
        NumSamples = NumSamples + 1
        IF NumSamples = 120 THEN return
        goto Sample
    How many instructions take this sub to work? i guess i have to take them into account for my timing to be correct!!!

    Thanks on any help.. Interrupt 125uS 4Mhz still in need!!

  3. #3
    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.

  4. #4


    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