How to have periodic interrupt every 1ms on S12ZVMC256 ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to have periodic interrupt every 1ms on S12ZVMC256 ?

899 Views
huuhuynhchi
Contributor III

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 !

Labels (1)
Tags (2)
0 Kudos
1 Reply

610 Views
RadekS
NXP Employee
NXP Employee

Hi Huu,

I could imagine three basic options how to generate 1ms interrupt when RTI is not available:

  1. Use one of Timer modules (TIM0 or TIM1) – common solution.
  2. Use API periodic interrupt – only when you don’t need high accuracy (Trimmed ACLK has +/-6% accuracy)
  3. Use PWM module with the external connection to any pin interrupt (Ports AD, S, P and L).

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos