PWM prescale

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

PWM prescale

3,019 次查看
StefX
Contributor I
    hello, I'm using an MCS12C32 and I want to generate a 60Hz PWM signal. On paper every thing is ok, but not in the real world. I'm using a LED to test, and it blinks every 4-5 sec. Can anyobody help me? The qurtz works at 16Mhz, this means a 8Mhz bus clock(right?).


SA=BUS clk/2*PSCLA     
BUS clk=8Mhz/128=62.5Khz
SA=62.5Khz/2*512=61Hz

here is the init():

void init_pwm(void)
{




 PWMPOL_PPOL0=1; //start pol
 PWMPOL_PPOL1=1;
 PWMPOL_PPOL2=1;
 PWMPOL_PPOL3=1;
 
 
 
 PWMCLK_PCLK0=1;//ch1- SA
 PWMCLK_PCLK1=1;
 PWMCLK_PCLK2=1;
 PWMCLK_PCLK3=1;
 
 
 PWMPRCLK_PCKA0=1;//prescale bus clk  with 128     8Mhz/128=62.5Khz
 PWMPRCLK_PCKA1=1;
 PWMPRCLK_PCKA2=1;
 
 PWMPRCLK_PCKB0=1;
 PWMPRCLK_PCKB1=1;
 PWMPRCLK_PCKB2=1;
 
 PWMSCLA=0xFFFF;  //prescale SA with 512
 PWMSCLB=0xFFFF;                  

 PWMPER0=255;//perioada
 PWMPER1=255;
 PWMPER2=255;
 PWMPER3=255;

 
}

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

1,291 次查看
allawtterb
Contributor IV


StefX wrote:
SA=BUS clk/2*PSCLA     
BUS clk=8Mhz/128=62.5Khz
SA=62.5Khz/2*512=61Hz

This is the wrong way to calculate the PWM frequency.  Also, the maximum prescale by the SA clock is 512 (256 * 2).  Here is how the PWM frequency should be calculated.
 
A Clk = Bus Clk / Prescale A (Set by PWMPRCLK_PCLKA[2:0])
SA Clk = A Clk / Prescale SA (Set by PWMSCLA)
PWM Freq = SA Clk / PWM Period (Set by PWMPERx) 
0 项奖励
回复

1,291 次查看
StefX
Contributor I
    Yes....you are right.

Thank you all for your answers!
0 项奖励
回复

1,291 次查看
Steve
NXP Employee
NXP Employee
I haven't checked your code but it sounds like you're about 256 times slower than expected.
Each PWM period is 256 counts (PWMPERx) so the total repetition period is 256 clock ticks. You don't mention the value of the duty registers.
The PWM clock period is one count on the PWM counter, so you need to reduce the PWM period or increase the clock frequency.
0 项奖励
回复