PWM output error using IMXRT SDK

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

PWM output error using IMXRT SDK

Jump to solution
1,429 Views
mayli-r51601
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

Labels (1)
0 Kudos
1 Solution
1,423 Views
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

View solution in original post

0 Kudos
2 Replies
863 Views
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 Kudos
1,424 Views
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 Kudos