Hello everyone,
I use an FTM function to generate PWM output. I based my code on the SDK example "driver_examples => simple_PWM".
Actually to change PWM frequency I use "FTM_Deinit", then "FTM_CalculateCounterClkDiv" to modify frequency and "FTM_Init". But it's a really slow solution and it's not working properly if I modify my frequency many time too fast.
Is there a way to change dynamically the frequency (like duty cycle on the example) ? Have you got any example ?
Thanks in advance for your help.
---------------------------
MCUXpresso 11.5.0
K22FN256M1
SDK_2_11_0_MK22FN256xxx12
---------------------------
Solved! Go to Solution.
Hello @Marc852,
Best regards, Raul.
Hello @Marc852,
In the example you have function: FTM_SetupPwm(). This function has a parameter named pwmFreq_Hz, that is for PWM signal frequency in Hz.
[Function FTM_SetupPwm in main]
[Declaration of function in fsl_ftm.c]
You could experiment with that function and modify the frequency of the PWM, without the use of FTM_DeInit() and FTM_CalculateCounterClkDiv.
Regards, Raul.
Hello Raul,
Thanks for your help.
I had already seen this function but it did not work dynamically.
I tried again with FRDM-K22 demo board. I started PWM with 1 KHz and I modified it to 10 KHz with "FTM_SetupPwm()". Nothing happened on output, I kept a 1KHz frequency.
Did I made a mistake ?
I attach my test source files.
Cordially,
Marc
Hello @Marc852,
Could you please check if you are entering this condition?
[Driver fsl_ftm.c -> function FTM_SetupPWM()]
Due the range of frequency you are wanting to work, the function will not work it out. This is because the number of ticks the counter needs will overflow the mod register every time. FTM_SetupPWM() then, will only work with a lower range.
As you can read in the comment, the best solution for your range would be: Changing clock source to get the desired frequency. As you were doing in the first place.
Regards, Raul
Hello @RaRo,
That doesn’t seem to be the problem, the function return "kStatus_Success" each time.
I still tried to change frequency in lower range 1KHz => 1.1KHz but same result, the frequency keep 1KHz output.
Note: In comparaison to your screen the mod test return "kStatus_OutOfRange" instead of "kStatus_Fail".
Cordially,
Marc
Hello @Marc852,
Best regards, Raul.
Hello @RaRo,
This works perfectly by adding the function FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true) !
Looks like I missed it..
Thank you for your time and help.
Cordialy,
Marc