How to output 50Hz PWM signal on KV11Z

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

How to output 50Hz PWM signal on KV11Z

Jump to solution
1,363 Views
le27
Contributor I

Hello, I am using KV11Z and using the example ftm_simple_pwm. In the example, 24kHz can make the LED gradually brighter and darker. I want to output a 50Hz PWM modification signal.

So, I tried to change the frequency to 50Hz, but I didn't get any signal when I used the dialogue.

Want to know where is the problem?

thanks,

le27_0-1629170663428.png

le27_1-1629170697060.png

le27_2-1629170722656.png

le27_3-1629170766141.png

le27_5-1629170847185.png

le27_6-1629170880440.png

 

0 Kudos
Reply
1 Solution
1,344 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi le27,

Peripherals tool can help know what is the suitable value of prescaler.

FTM Peripherals tool.png

You shall get error by using kFTM_Prescale_Divide_1 of FTM_GetDefaultConfig. Please change the prescale :
config->prescale = kFTM_Prescale_Divide_32;

prescale.png

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

6 Replies
1,345 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi le27,

Peripherals tool can help know what is the suitable value of prescaler.

FTM Peripherals tool.png

You shall get error by using kFTM_Prescale_Divide_1 of FTM_GetDefaultConfig. Please change the prescale :
config->prescale = kFTM_Prescale_Divide_32;

prescale.png

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

1,325 Views
le27
Contributor I

Thank you for your reply and guidance. I followed the method and modified config->prescale = kFTM_Prescale_Divide_1 to config->prescale = kFTM_Prescale_Divide_32; directly in the file of fsl_ftm.c. It can be observed that the LED on the control board changes gradually according to the change of duty_cycle Bright and gradually dimming, there is no problem, and the PWM output signal with a frequency of 50 Hz can be reached through the oscilloscope.

le27_1-1629862858991.png

Then try to add ftmInfo.prescale = kFTM_Prescale_Divide_32; to the file of ftm_simple_pwm. I want to set the prescale from this, but maintain config->prescale = kFTM_Prescale_Divide_1 in the fsl_ftm.c file; the execution result shows that no PWM signal is generated, which is not clear. Is there a mistake in the use of the program?

 

le27_2-1629863737642.png

 

le27_0-1629862680160.png

At present, i am also trying to modify the program to achieve a fixed frequency and adjustable duty cycle PWM output signal.

 

Thanks,

0 Kudos
Reply
1,307 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

The arrow in my picture is a bit misleading.
Please put  ftmInfo.prescale = kFTM_Prescale_Divide_32; between FTM_GetDefaultConfig and FTM_Init

0 Kudos
Reply
1,296 Views
le27
Contributor I

Hi Robin
Now it is possible to generate a PWM signal, but encountered it again.
Set to 50Hz PWM frequency, it is only 71Hz from the observation.


prescale32_50Hz.PNG71Hz_.jpg

 

I don't know why the 50Hz PWM signal is not generated. I think this is caused by the delay. I go to DELAY place to modify it. From the original 80,000 to 115400, the KV11Z development board can be generated from the file is a 10M crystal oscillator, calculate i=1 =0.1us, the direction is estimated to be 115400 by trial and error, and set the fixed duty cycle to 50%.

fix_hz.PNG

fix_hz_z.PNG

Finally, the required Hertz PWM signal and duty cycle can be obtained. But I still don't know if this is the correct way. I think it should only be necessary to adjust FTM_SetupPwm (BOARD_FTM_BASEADDR, &ftmParam, 1U, kFTM_CenterAlignedPwm, 50U, FTM_SOURCE_CLOCK); the PWM frequency value in this row can be used to obtain the desired PWM frequency.
I need help in this regard, thank you.

50Hz.jpg50Hz_50duty.jpg

0 Kudos
Reply
1,348 Views
myke_predko
Senior Contributor III

@le27 

Do you ever check the results of "FTM_SetupPwm"?  First off it has a number of asserts which may cause the application to hang without any kind of indication.  Secondly, "FTM_SetupPwm" may return an error value but continue executing as if there wasn't a problem.  

I believe the most likely error will be that FTM_SetupPwm is returning an error code because the calculation done by "FTM_SetupPwm" for 50Hz results in values which can't be generated by the hardware.  

That's a very low speed - you're probably going to have to create your own PWM using a timer.  

Good luck!

0 Kudos
Reply
1,324 Views
le27
Contributor I

The program continues as you said, as if no error has occurred, and no signal is generated through the oscilloscope. This time, a problem that requires frequency setting prescale has been discovered.
Thank you for your blessing and reply.

0 Kudos
Reply