PWM output error using IMXRT SDK

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

PWM output error using IMXRT SDK

跳至解决方案
2,583 次查看
xiumei_li
NXP Employee
NXP Employee

Customer has problem for PWM generation with SDK demo code, which can generate 2000,3000 and 5000Hz PWM properly, but failed to generate 500Hz PWM. Pls assign this ticket to dean jia, who has got email about it. Thanks. 

 

 

Regards,

May

标签 (1)
0 项奖励
回复
1 解答
2,577 次查看
dean_jia
NXP Employee
NXP Employee

Hi May,

A PWM counter's modulo would be the ratio between the counter clock frequency and the target PWM frequency. The modulo  has a maximum value of 65,536, as the counters are 16-bit length.

In the example the IPG clock is 50MHz, and the counter prescaler bit field is 0, and the target PWM frequency is 500Hz. So the ratio is 50,000,000 / (2^0) /500 = 100,000 > 65,536

To solve the problem the prescaler is supposed to be configured to a proper value. For example, let's configure the IPG clock to be the conventional 150MHz, and the prescaler to be 8.

 

    CLOCK_SetDiv(kCLOCK_AhbDiv, 0x0); /* Set AHB PODF to 0, divide by 1, 600Mz/1=600MHz */
    CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 3, divede by 4, 600MHz/4=150MHz */
    pwmConfig.prescale = kPWM_Prescale_Divide_8;

 

With these modifications, the ration would be 150,000,000 / 8 /500 = 37,500 < 65,536, which is acceptable by a counter's modulo.

 

Best Regards,
Dean

在原帖中查看解决方案

0 项奖励
回复
2 回复数
2,017 次查看
Devaharsha
Contributor III

Hi,

The PWM example in SDK generates a 1KHz signal from PWM submodule_0 and submodule_1 in complementary mode. I want to run a servo motor using PWM. The servo uses a 50Hz signal i.e. 20ms.

So, anyone can help me where the modification is required for the same? 

I am using imxrt 1176. 

Thanks in advance. 

0 项奖励
回复
2,578 次查看
dean_jia
NXP Employee
NXP Employee

Hi May,

A PWM counter's modulo would be the ratio between the counter clock frequency and the target PWM frequency. The modulo  has a maximum value of 65,536, as the counters are 16-bit length.

In the example the IPG clock is 50MHz, and the counter prescaler bit field is 0, and the target PWM frequency is 500Hz. So the ratio is 50,000,000 / (2^0) /500 = 100,000 > 65,536

To solve the problem the prescaler is supposed to be configured to a proper value. For example, let's configure the IPG clock to be the conventional 150MHz, and the prescaler to be 8.

 

    CLOCK_SetDiv(kCLOCK_AhbDiv, 0x0); /* Set AHB PODF to 0, divide by 1, 600Mz/1=600MHz */
    CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 3, divede by 4, 600MHz/4=150MHz */
    pwmConfig.prescale = kPWM_Prescale_Divide_8;

 

With these modifications, the ration would be 150,000,000 / 8 /500 = 37,500 < 65,536, which is acceptable by a counter's modulo.

 

Best Regards,
Dean
0 项奖励
回复