Question

I am using Beaglebone not Beaglebone Black.

I just tried to output a PWM and I expected potential frequencies of some megaherz on such a fast device.
I found out that 100HZ is the exact maximum I can set through sysfs.
I started digging online for examples and they did not mention a limit but they also did not show an value faster than 100HZ.

Example:

root@beaglebone:/sys/class/pwm/ehrpwm.0:0# echo 10000000 >  period_ns 
root@beaglebone:/sys/class/pwm/ehrpwm.0:0# echo 1000000 >  period_ns 
-sh: echo: write error: Invalid argument
root@beaglebone:/sys/class/pwm/ehrpwm.0:0# echo 200 >  period_freq 
-sh: echo: write error: Invalid argument
root@beaglebone:/sys/class/pwm/ehrpwm.0:0# echo 101 >  period_freq 
-sh: echo: write error: Invalid argument
root@beaglebone:/sys/class/pwm/ehrpwm.0:0# echo 100 >  period_freq 
root@beaglebone:/sys/class/pwm/ehrpwm.0:0#

Any 10cent AVR can do a faster PWM than that.
Is there some trick I missed?
Do I really have to create a custom PWM by manuallz toggling GPIO if I want a faster frequency than 100 HZ ?!

Was it helpful?

Solution

I actually found the solution just shortly after opening my question.
I will post it here as I think this might actually cause more than just me to wonder :)

The PWM frequency is of course not limited like that on a 1GHZ device, the kernel driver is just not working in the same way one would expect.

If you enter a duty_percent value (like 1 percent) then the driver seems to just calculate the duty_ns value out of it and forget about percent afterward.
A normal user would think he is in "percent mode" but actually the percentage file is just bound to a wrapper to help.
The same counts for the frequency!
If you now change the frequency to a higher value then then the kernel checks if the duty_ns cycle period fits into the new total period_ns!
It ignores that you actually set a percentage!

So of course you can not have an on-period which is larger than the whole period, so it fails.

Long text short summary:
Always set duty_cycle to zero BEFORE you set the frequency if the previous value will not fit into the new period, this avoids frustration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top