Dear all,
I would like to generate a periodic interrupt every 1ms on S12ZVMC256 without using RTI module because RTI was used for another purpose. S12ZVMC256 does not have PIT module. How to have periodic interrupt every 1ms ? Can I use Timer Module (TIM16B4CV3) for interrupt to instead of RTI here ?
Thank you so much all guys !
Hi Huu,
I could imagine three basic options how to generate 1ms interrupt when RTI is not available:
Attached is simple example code for S12ZVML TIM0 module which generates the interrupt every 500us.
If you would like to use just a period interrupt and you don’t need toggling with output pin, please set an appropriate bit in OCPD register. It will disable the timer channel from the port and you can use that pin for something different.
Attached is also simple example code for API include trimming via TIM0 module.
The PWM initialization may look for example like:
//==============================================================================
// PWM_Init
//==============================================================================
void PWM_Init(void)
{
//8MHz bus clock
//for example we want to generate initial PWM wave on PWM01 channel 1kHz and
//two 8bit channels 6 and 7 are concatenated into one 16bit channel
PWMPOL = 0xC0; //polarity - PWM channel 67 is high at the beggining of period, then low
PWMCLK = 0x00; //select clock source A for channel 6-7
PWMPRCLK = 0x01; //prescaler for clock A -> BusClock/2 = 8MHz/2 = 4MHz
PWMCAE = 0x00; //channel 67 operate in left aligned output mode
PWMCTL = 0x8C; //we use 16bit PWM 67, disable clock in wait and freeze mode
PWMCNT67 = 0x0000;//reset the counter of PWM67
PWMPER67 = 4000; //PWMPER67 = clock / PWM7frek = 4000000 / 1000 = 4000
PWMDTY67 = PWMPER67/2; //ensure duty cycle 50%
PWME = 0x80; //enable PWM67
}
I hope it helps you.
Have a great day,
Radek
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------