Skip to main content
NPal.2
Associate III
September 16, 2021
Solved

Maximum value of PWM period

  • September 16, 2021
  • 3 replies
  • 2079 views

Hi all,

I have configured TIM1_CH3N as a pwm channel.

I am trying to do some PWM functionality here.

I am following current tutorial here. When i tried to provide a period of 10 sec it fails to take up the value.

I get following error :

root@stm32mp157a-visionsom-rgb-emmc-mx:/usr/local/firmware_demos# echo 10000000000 > /sys/class/pwm/pwmchip4/pwm2/duty_cycle pwm2
sh: write error: Invalid argument

100000000

Is there some limit to what value we can provide here?

This topic has been closed for replies.
Best answer by PatrickF

Hi,

this is a Linux framework limitation which is using a 32-bits parameter with fixed 1us resolution. So maximum period and duty_cycle are 2^32, i.e. about 4.3 seconds.

I'm not expert, but there is probably other way under Linux (e.g a task started every 1 second which will then manage a GPIO)

Another solution (e.g. if you want TIMx specific features like multichannel, inverted output, etc...) is to handle the TIM with Cortex-M4, then you have full management of TIM count-clock/prescaler/counter/etc...

Regards.

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

3 replies

Paul1
Senior III
September 16, 2021

Haven't looked in detail at STM32 you are using, but possibly PWM limited to counter (16bit=65535), with prescaler (16bit=65535).

Increase the prescaler (16bit) for slower counting, or change the PWM clock source.

i.e. 100000000 = 10000*10000 = Prescale 10000 * Period 10000

i.e. 100000000 = 50000*2000 = Prescale 2000 * Period 50000

etc.

i.e. .

NPal.2
NPal.2Author
Associate III
September 17, 2021

Hi @Community member​ : Thanks for response. It seems that on Linux front one does not have much control over these. I believe this can be controlled finely on the bare metal front. I am looking for a solution on the Linux front.

S.Ma
Principal
September 17, 2021

Seems to be a good cubemx opportunity to improve....

PatrickF
PatrickFBest answer
Technical Moderator
September 17, 2021

Hi,

this is a Linux framework limitation which is using a 32-bits parameter with fixed 1us resolution. So maximum period and duty_cycle are 2^32, i.e. about 4.3 seconds.

I'm not expert, but there is probably other way under Linux (e.g a task started every 1 second which will then manage a GPIO)

Another solution (e.g. if you want TIMx specific features like multichannel, inverted output, etc...) is to handle the TIM with Cortex-M4, then you have full management of TIM count-clock/prescaler/counter/etc...

Regards.

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.NEW ! Sidekick STM32 AI agent, see here
NPal.2
NPal.2Author
Associate III
September 17, 2021

Hi @PatrickF​ Thanks for the clarity. I will use these inputs to solve things at my end. This really helps.