µTasker Forum
µTasker Forum => µTasker general => Topic started by: Raffaele on October 01, 2020, 05:46:19 AM
-
Hi,
simple question, I'm trying to generate a PWM signals with 50% duty cycle, between 650kHz-750kHz on a KL03.
For example at 600kHz I use
pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_1);
pwm_setup.pwm_frequency = PWM_TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(650000), 1);
pwm_setup.pwm_value = _PWM_PERCENT(50, pwm_setup.pwm_frequency);
PWM_SYS_CLK should be 8MHz. But I don't get the right value, my PWM is at 990kHz.
What am I doing wrong?
-
Hi
The problem is the use of the
PWM_TIMER_US_DELAY() macro
since this is for passing us resolution.
That means that it will do 1us (1MHz), 2us (500kHz), 3us (333kHz) etc. but won't allow your frequency of 650kHz.
Use instead
pwm_setup.pwm_frequency = PWM_FREQUENCY(650000, 1);
which will give 666.66kHz (next best)
Regards
Mark
-
great, that worked
thank you