Interrupts latency

Discussion in 'Embedded Systems and Microcontrollers' started by atferrari, Jun 7, 2007.

  1. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    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.
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    a. I should think so. The latency is independent of one or two cycle instructions whether the trigger is internal or external. The reason external interrupt events having different latencies is because the events are asynchronous to the clock and the latencies depend on which point in time the events occurred and therefore sampled. For internal events, all of them are synchronous to the clock, which should result in fixed latencies.

    b. For external interrupt events, I couldn't think of an easy one. It's probably possible with an output pin and a comparator or two. There shouldn't be any difference in latency for internal interrupt events.

    If you were referring to internal latency difference, could you elaborate more on your setup/code/sim?
     
  3. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    The point is: evrything except the restarting of TMR1 is inside the ISR what makes it subject to latency effects. And that's what I want to escape from.
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    From what you have indicated, it sounds like the ISR contains the bulk of the code in the program.

    As a rule, the code inside an ISR is kept as spartan as possible as a means of preventing any problems with interrupt latency.

    It would be helpful if you could post a copy of your source code.

    hgmjr
     
  5. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    I take it that you are experiencing different latencies for the same internal interrupt event. is this right? If so, I think it would be better if you post your code and we can have a look.
     
  6. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    Found the solution.

    Gracias for all your help and your time!

    Code ( (Unknown Language)):
    1.  
    2.    ;009 ISR HIGH.ASM
    3.  
    4. ;High priority interrupts service routine
    5.  
    6. ;Interrupts desabled. STATUS, W & BSR saved automatically in the fast stack.
    7. ;------------------------------------------------------------------------------
    8. ;actual interrupts service code starts here
    9.  
    10.     RLNCF TMR1L,W           ;make W =PC offset =(value of TMR1L *2)
    11.     ADDWF PCL,F             ;springboard ready
    12.     NOP                     ;pontoons
    13.     NOP                     ;for the
    14.     NOP                     ;PC to
    15.     NOP                     ;land
    16.     NOP                     ;HERE (4)
    17.     NOP                     ;or HERE (5)
    18.     BTG PIN_CLK             ;toggle pin to materialize the clock
    19.  
    20.     ;let's load the oposite value of HALF_T to CCP1
    21.  
    22.     BTFSS LOAD_HALF_T1      ;=1, must load...
    23.     BRA LOAD_HALF_T2_VALUES ;=0, load HALF_T2 values to CCP1
    24.  
    25.     MOVFF HALF_T1_H,CCPR1H  ;... HALF_T1 values
    26.     MOVFF HALF_T1_L,CCPR1L  ;loaded to CCP1 registers.
    27.  
    28. HOUSEKEEPING_N_LEAVE
    29.     BTG LOAD_HALF_T1        ;next time will load the other HALF_Tx value
    30.     BCF PIR1,CCP1IF         ;=0 clears CCP1 compare match interrupt flag
    31.     RETFIE FAST            
    32.  
    33. ;STATUS, W & BSR retrieved from the fast stack. Back to main line code
    34. ;with interrupts enabled.
    35.  
    36. LOAD_HALF_T2_VALUES
    37.     MOVFF HALF_T2_H,CCPR1H  ;HALF_T2 values
    38.     MOVFF HALF_T2_L,CCPR1L  ;loaded to CCP1 registers.
    39.     BRA HOUSEKEEPING_N_LEAVE
    40.  
    41. ;actual interrup service code ends here
    42. ;------------------------------------------------------------------------------
    43.  
    44.  
    Simple, isn't it?
     
Loading...