I used TIM1 overflow as a test interrupt
Code: Select all
tmr1Init(1); tmr1OVFAttachISR(pwm_tks);
Code: Select all
void pwm_tks(void) {
t1 = TIM1->CNT; //read the counter
pwm_t2 = TIM1->CCR1; //save the capture
pwm_pr = pwm_t2 - pwm_t0; //calculate pwm period
pwm_dc = pwm_t1 - pwm_t0; //calculate pwm duty cycle
pwm_t0 = pwm_t2; //update pwm rising edge
pwm_flg= 1; //setup the pwm flag
t2 = TIM1->CNT; //time stamp t2
}
t1 is a little bit on the high side - it is measuring the first user instruction executed, not true isr latency as I have some fluff in the isr:
Code: Select all
//isr for timer1 ovf
void TIM1_BRK_UP_TRG_COM_IRQHandler(void) {
//t1 = TIM1->CNT;
//tmr1 ovf isr
if (TIM1->SR & TIM_SR_UIF) {TIM1->SR &=~TIM_SR_UIF; _tim1_ovfisrptr();}
}