Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Questions about interrupts latency and ISR

Status
Not open for further replies.

atferrari

Full Member level 4
Joined
Jun 29, 2004
Messages
237
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Location
Buenos Aires - Argentina
Activity points
1,996
Micro 18F452

I have implemented a clock, with the module CCP1 (compare mode) against TMR1 (counter mode).

To get a fixed duty cycle in RC2 pin, upon matching TMR1, the ISR loads alternatively two values in the CCPR1H:L registers.

Above ISR is high priority. Another one, running in low priority have no problems to coexist.

Regarding the latency, in the manual, I read:

For external interrupt events, such as the INT pins or the PORTB input change interrupt, the interrupt latency will be three to four instruction cycles.

The exact latency is the same for one or two-cycle instructions.


Having run all this through MPSIM I found a variation in the time elapsed between successives entries to the ISR, with the adequate allowance for the actual value loaded in the CCPR1 registers which seems to be of 1 or 2 Tcy.

My questions:

a) The paragraph in bold, is it actualy including the rest of the interrupts as well? Found it quite unclear.

b) Is it any way to compensate the differences in time elapsed between succesive entries to the ISR?

Help appreciated.
 

interrupt latency pic 18f

That text applies to external interrupts only, where you don't know exactly when the interrupt hits, so cannot compensate the for the exact number of cycles (the variation in the number of cycles is because it depends on during which internal cycle the interrupt happens).
In any 16F doc there is a pic about interrupt pin timing, you might want to check it, I guess it's the same as for 18Fs.

In your case the CCP is an internal interrupt, happening always at the same internal cycle, which means you can compensate for it.

The text in bold IMHO talks about the running instruction when the interrupt happens.
 

    atferrari

    Points: 2
    Helpful Answer Positive Rating
Varying latency - PIC 18F - Problem solved

Found the solution to cope with a latency of 2 or 3 Tcy.

Code:
   ;009 ISR HIGH.ASM

;High priority interrupts service routine

;Interrupts desabled. STATUS, W & BSR saved automatically in the fast stack.
;------------------------------------------------------------------------------

;actual interrupts service code starts here

    RLNCF TMR1L,W           ;make W =PC offset =(value of TMR1L *2)
    ADDWF PCL,F             ;springboard ready
    NOP                     ;pontoons
    NOP                     ;for the
    NOP                     ;PC to
    NOP                     ;land
    NOP                     ;HERE (4)
    NOP                     ;or HERE (5)
    BTG PIN_CLK             ;toggle pin to materialize the clock
    
    ;let's load the oposite value of HALF_T to CCP1

    BTFSS LOAD_HALF_T1      ;=1, must load...
    BRA LOAD_HALF_T2_VALUES ;=0, load HALF_T2 values to CCP1
    
    MOVFF HALF_T1_H,CCPR1H  ;... HALF_T1 values
    MOVFF HALF_T1_L,CCPR1L  ;loaded to CCP1 registers.

HOUSEKEEPING_N_LEAVE
    BTG LOAD_HALF_T1        ;next time will load the other HALF_Tx value
    BCF PIR1,CCP1IF         ;=0 clears CCP1 compare match interrupt flag
    RETFIE FAST             

;STATUS, W & BSR retrieved from the fast stack. Back to main line code
;with interrupts enabled.

LOAD_HALF_T2_VALUES
    MOVFF HALF_T2_H,CCPR1H  ;HALF_T2 values
    MOVFF HALF_T2_L,CCPR1L  ;loaded to CCP1 registers.
    BRA HOUSEKEEPING_N_LEAVE

;actual interrup service code ends here
;------------------------------------------------------------------------------

Simple, isn't it?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top