[S12ZVC] Making PWM with higher resolution

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

[S12ZVC] Making PWM with higher resolution

887 次查看
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?

标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

682 次查看
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 项奖励
回复

682 次查看
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 项奖励
回复