PWM prescale

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

PWM prescale

2,574件の閲覧回数
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 返答(返信)

846件の閲覧回数
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 件の賞賛
返信

846件の閲覧回数
StefX
Contributor I
    Yes....you are right.

Thank you all for your answers!
0 件の賞賛
返信

846件の閲覧回数
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 件の賞賛
返信