2021-09-16 04:39 AM
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?
Solved! Go to Solution.
2021-09-16 11:19 PM
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'
2021-09-16 08:23 AM
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. .
2021-09-16 06:04 PM
Seems to be a good cubemx opportunity to improve....
2021-09-16 11:02 PM
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.
2021-09-16 11:19 PM
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'
2021-09-17 12:28 AM
Hi @PatrickF Thanks for the clarity. I will use these inputs to solve things at my end. This really helps.
2021-09-30 03:18 AM
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.