Hi
I am trying to read the PWM counter register in MC56F827xx MCU (PWMA_SMnCNT) at a PWM reload ISR event (please see the attached code). It should read zero all the time as the reload event happens when the counter is reset, but, instead I read 143. Is there a delay once the Reload ISR is called and the counter register is read? Am I reading it correctly? Please help.
Thanks.
Rishad
Hi, Md,
I have reviewed your code, you enable Full Reload interrupt, in the ISR of Full Reload interrupt, you read the PWMA_SM0CNT;. From theory, the tick variable should be the value as PWMA_SM0INIT, which is zero.
As you know it takes time for the DSC core to execute ISR, for example, PC, SR register are stored to stack, jump to ISR, because you use the "#pragma interrupt saveall", all the DSC core registers have to be put into stack,that is why the delay exists and you get non-zero value when you read PWMA_SM0CNT;, it means that the PWMA_SM0CNT reaches up to 143 when you read it.
Pls delete the #pragma interrupt saveall and use #pragma interrupt on, have a try.
I suggest you toggle a GPIO in the ISR and compare the PWM and GPIO timing.
Hope it can help you
BR
Xiangjun Rong