Hi all,
I'm trying to play with the System Timer Module on this processor, I would like to have an interrupt every 500 us with a system clock of 120 MHz. I programmed the STM prescaler to 119 (0x77) to have 1 MHz timer clock,then I programmed the STM channel 0 compare register to 0x000001F4 (to have 500 us interrupt).What I obtained is only one interrupt is generated, then no more STM interrupr generated.
At the end of the STM ISR, I correctly clear the channel 0 interrupt flag, after that I'm no longer able to have STM interrupt.
I'm using CodeWarrior Development studio 10.6.4.
I have not seen on the MPC5644A hardware manual some particular sequence to program the registers, below my code, please can someone help me?
Best regards to you all.
STM.CR.R = 0x00007700; // Prescaler 0x77
STM.CCR0.R = 0x00000001; // Enable STM Channel 0
STM.CMP0.R = 0x000001F4; // Compare register 0 (500 us)
STM.CR.R |= 0x00000001; // Enable timer
Below the STM channel 0 ISR (now it is empty just to evaluate if the interrupt is scheduled correctly)
void STM0_Isr(void)
{
if (STM.CIR0.R && 0x00000001)
{
STM.CIR0.R = 0x00000001;
}
}
This is free-running timer thus in case counter achieves value defined in compare register, counter continues without restarting. It would be needed to stop the timer, reset counter value and enable again.
Or much better solution is to use Periodic Interrupt Timer (PIT) that be suitable for it.
Absolutely right