cancel
Showing results for 
Search instead for 
Did you mean: 

Maximum value of PWM period

NPal.2
Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PatrickF
ST Employee

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.

View solution in original post

6 REPLIES 6
Paul1
Lead

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. .

S.Ma
Principal

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

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.

PatrickF
ST Employee

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.

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

Hi @PatrickF​ : Thanks for the answer. Coming back to it , is there lower limit too? I can't seem to set the PWM period for 10ms. It shows up response as Device or resource busy and further going down to 1ms , it straight away says invalid argument.