Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pwm: stm32: output signal delayed #29446

Closed
simonguinot opened this issue Oct 22, 2020 · 8 comments · Fixed by #29619
Closed

pwm: stm32: output signal delayed #29446

simonguinot opened this issue Oct 22, 2020 · 8 comments · Fixed by #29619
Labels
area: PWM Pulse Width Modulation bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: medium Medium impact/importance bug

Comments

@simonguinot
Copy link
Collaborator

Describe the bug
I encountered this bug by using PWM (timer 3, channel 3) on a STM32F070 MCU. With the default prescaler configuration (10000), and when the PWM is configured to output a signal with a rather big period (around 100ms for example), then sometimes nothing happens... But after a delay (around 10 seconds), then the PWM signal is finally outputted correctly

To Reproduce

The following code should allow to reproduce the issue:

pwm_pin_set_usec(dev, pwm, 1000000, 500000, flags);
k_sleep(K_MSEC(5000));
pwm_pin_set_usec(dev, pwm, 100000, 50000, flags);

You should observe that the first PWM configuration is applied correctly. But the second one is delayed (of around 10 seconds). During that time no PWM signal is outputted on pin. The previous PWM period/pulse is not active anymore. And after the delay, the second PWM signal is finally outputted correctly.

Expected behavior
The PWM configuration should be applied without any delay.

Impact
Among other things this bug affects the driving of PWM LEDs. Sometimes the LED blinking effects are delayed.

Additional context
It seems that decreasing the prescaler works around the issue. With a prescaler value set to 1000, I can't reproduce it anymore.

@simonguinot simonguinot added bug The issue is a bug, or the PR is fixing a bug area: PWM Pulse Width Modulation platform: STM32 ST Micro STM32 labels Oct 22, 2020
@bpbradley
Copy link
Contributor

Just chiming in to mention I have experienced this exact same issue on stm32f4 with the default prescaler. I can try to reproduce with your method soon.

@gmarull
Copy link
Member

gmarull commented Oct 22, 2020

@simonguinot what is the MCU clock speed?

@simonguinot
Copy link
Collaborator Author

@simonguinot what is the MCU clock speed?

It is 48MHz. So with the default prescaler (10000) the PWM is working at ~4800 cycles per second. On STM32F070, the timer 3 is a 16-bit counter. Then the maximum period is between 13 and 14 seconds.

@gmarull
Copy link
Member

gmarull commented Oct 22, 2020

@simonguinot
Copy link
Collaborator Author

@simonguinot can you try without preload? https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/pwm/pwm_stm32.c#L231

I observe the same issue with or without preload.

@simonguinot
Copy link
Collaborator Author

BTW, I am rusing the led-pwm sample from #29401 to reproduce the issue. At some point the LED is behaving incorrectly, staying off for long periods.

@gmarull
Copy link
Member

gmarull commented Oct 22, 2020

@simonguinot I've tried the following code on a NUCLEO-H743ZI board (prescaler set do default, i.e. 10000)

while (1) {
	pwm_pin_set_usec(pwm, ch, 1000000, 500000, 0);
	k_sleep(K_MSEC(5000));
	pwm_pin_set_usec(pwm, ch, 100000, 50000, 0);
	k_sleep(K_MSEC(5000));
}

And this is roughly what I get:

image

I see no big gaps where the PWM signal is low.

@simonguinot
Copy link
Collaborator Author

It looks good @gmarull.

Please can you have another try with this:

while (1) {
        pwm_pin_set_cycles(pwm, ch, 100, 0);
        k_sleep(K_MSEC(1000));
        pwm_pin_set_cycles(pwm, ch, 100, 100);                 
        k_sleep(K_MSEC(1000));
	pwm_pin_set_usec(pwm, ch, 1000000, 500000, 0);
	k_sleep(K_MSEC(5000));
	pwm_pin_set_usec(pwm, ch, 100000, 50000, 0);
	k_sleep(K_MSEC(5000));
}

For me, this takes 3-4 loops to trigger the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: PWM Pulse Width Modulation bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: medium Medium impact/importance bug
Projects
None yet
4 participants