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

    is it me or you should use TMR2 instead of PR2?

    Try TMR2=TMR2+138 (or something around it) and toggle a led to know what happen

    i'm a bit rusty here... and i can't test it... damn!
    Last edited by mister_e; - 3rd October 2007 at 23:15.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Joe,
    no you didn't miss something, probably because Josuetas got a error message about a wsave beyond ram end or something like that.

    So my guess is that he comment out the offending line in those files and use a specific name for it.
    Steve

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

  3. #3


    Did you find this post helpful? Yes | No

    Unhappy Thanks for your replies

    Joe S.

    Modifications...
    i have a DT for 628A since it needs bank modification from 877A.
    In the second one i am modifing Elapsed to interrupt every 125us it is not meant for timing but for interrupting. All i did was modifing the timerconst to be $FFA7 in the case of 4Mhz Osc. I am not using this anyway you can see the TMR1 interrupt is not defined for elapsed interrupt, only TMR2.



    mister_e

    If i get this right, and from the datasheet the timer2 interrupts when Tmr2 reaches PR2 value, tmr2 "should" go to 0 after this, BUT it seemed not TO i had to turn TMR2= 0 in the interrupt routine, Otherwise i was getting weird interruptions (watched it on my osciloscope)




    Still cant get my 125us interrupt with 4Mhz internal OSC this should be possible unless DT´s routines take more than 125 instructions to work (just my guess),.. Patience....Again i am sure HE knows

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

  5. #5


    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!!

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

  7. #7


    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.

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Josuetas View Post
    Still cant get my 125us interrupt with 4Mhz internal OSC this should be possible unless DT´s routines take more than 125 instructions to work (just my guess),.. Patience....Again i am sure HE knows
    This page might explain it.
    http://darreltaylor.com/DT_INTS-14/kudos.html
    Especially the last paragraph.
    <br>
    DT

  9. #9


    Did you find this post helpful? Yes | No

    Red face Ok now thats bad news

    So Darrel if i made this with just an ASM interrupt i would be able to get my 125uS since i wouldnt need the Reenter Context Saving...


    BUT please o please can you help me?..

    I use to get to this point where: i dont know any assembler!!!
    even worst
    A bit Array of 120 samples in Assembler .... mmm..... mmmmm....

    By the way would you consider (in my case) the pauseus 125 Take Sample option?

    Please some lead to solve this matter.

    Thanks again

    DJC

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    >> So Darrel if i made this with just an ASM interrupt i would be able to get my 125uS since i wouldnt need the Reenter Context Saving...
    Correct.

    >> A bit Array of 120 samples in Assembler .... mmm..... mmmmm....
    In ASM, you would just shift the bits into a byte var. After 8 bit's move to the next byte. After 15 bytes you're done.

    >> By the way would you consider (in my case) the pauseus 125 Take Sample option?

    YES!
    Your program just sits in a loop anyways, waiting for the sample to finish.
    No need to use interrupts, if it's not doing anything in the first place.

    Or, you can still use the timer. Just poll the TMR2IF Flag.
    <br>
    DT

  11. #11


    Did you find this post helpful? Yes | No

    Default Thanks for your advise Darrel

    I will keep working on the interrupt option... This is supposed to detect DTMF (we talk about it before) so for it to work in the background of anything else is the best choice.

    Everything is so complicated in ASM!.. thanks god there is picbasic.

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here's a quick untested stab at an ASM handler.

    Change the Handler type to ASM
    Code:
    Samples      VAR BYTE[15] BANK0 SYSTEM
    SamplePTR    VAR BYTE     BANK0 SYSTEM
    SamplesAddr  CON EXT
    @SamplesAddr = Samples
    BitCount     VAR BYTE     BANK0 SYSTEM
    ByteCount    VAR BYTE     BANK0 SYSTEM
    FlagSample   VAR BIT
    TMR2ON       VAR T2CON.2
    
    ;----[Start getting the 120 samples]------------------------------------------
    GetSamples:
        FlagSample = 0
        SamplePTR = SamplesAddr
        ByteCount = 15
        BitCount  = 8
        PR2 = 125 : TMR2 = 0 : TMR2ON = 1
    return
        
    ;----[TMR2 Handler]-----------------------------------------------------------
    ASM
    Sample
        MOVE?BB  SamplePTR, FSR      ; Load FSR with pointer to array
        MOVE?TT  CMCON,7, STATUS,C   ; Put sample in carry flag
        rrf      INDF, F             ; Shift in the sample bit
        decfsz   BitCount, F         ; Are all 8 bits in ?
        goto     Int_Done            ;   NO, done for now
        MOVE?CB  8, BitCount         ;   Yes, reset bitcount
        incf     SamplePTR, F        ;     Point to next byte
        decfsz   ByteCount, F        ; Are all 15 bytes done ?
        goto     Int_Done            ;   NO, done for now
        MOVE?CT  1, _FlagSample      ;   Yes, Indicate - Samples Complete
        MOVE?CT  0, _TMR2ON          ; stop the timer
    Int_Done
        INT_RETURN
    ENDASM
    DT

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