[S12ZVC] Making PWM with higher resolution

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

[S12ZVC] Making PWM with higher resolution

691 Views
daehyeonkim
Contributor II

Hello,

 

I just wonder how to make PWM signal that much higher than 1/255 resolution.

it is mentioned in the datasheet, PWM duty cycle = [ (PWMPER - PWMDTY) / PWMPER ] * 100%

but both of the register value is 8-bits sized, so that the max duty resolution can be 1/255.

I need to control at least 0.1% of duty or more. do you have any idea?

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

486 Views
RadekS
NXP Employee
NXP Employee

Hi Daehyeon,

MJW is right. You should concatenate two 8bit PWM counters into one 16bit.

Example of 16bit PWM initialization:

//==============================================================================
// PWM_Init
//==============================================================================
void PWM0_Init(void)
{
  //8MHz bus clock
  //for example we want to generate initial PWM wave on PWM01 channel 1kHz with 50% duty cycle
  //two 8bit channels 6 and 7 are concatenated to one 16bit channel                         
  PWM0POL = 0xC0;    //polarity - PWM channel 67 is high at the beginning of period, then low
  PWM0CLK = 0x00;    //select clock source A for channel 6-7
  PWM0PRCLK = 0x01;  //prescaler for clock A -> BusClock/2 = 8MHz/2 = 4MHz
  PWM0CAE = 0x00;    //channel 67 operate in left aligned output mode
  PWM0CTL = 0x8C;    //we use 16bit PWM 67, disable clock in wait and freeze mode
  PWM0CNT67 = 0x0000;//reset the counter of PWM67                      
  PWM0PER67 = 4000;  //PWMPER67 = clock / PWM7frek = 4000000 / 1000 = 4000
  PWM0DTY67 = PWMPER67/2;    //ensure duty cycle 50% 
  PWM0E =  0x80;     //enable PWM67
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Per RM, the S12ZVC contain two 4-channel 16-bit PWM modules - PWM0 gated from bus clock and PWM1 gated from core clock.

In fact, both modules are 8-channel 8-bit PWM modules, but only odd channels are routed to the external pins. Therefore, we may use only 4 channels from each module configured either as 8bit or 16bit.

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

486 Views
MJW
NXP Employee
NXP Employee

Hello,

you can concatenate two 8-bit PWM channels into one 16-bit channel.

Please refer to the description of PWMCTL (specifically: the CONxx fields) in the RM for details.

HTH,

MJW

0 Kudos