I'm seeing an issue with updating the PWM period via the serial console. When I go to write a period via the sysfs I get an invalid argument error.
As I understand it, each PWM chip must have the same value for period for each submodule (ie PWMchip1:pwm0 and PWMchip1:pwm1 must have matching periods). However I'm trying to understand the nuances of setting this via the sysfs entries:
It's clear that even if both are disabled and have a 0 duty cycle, the periods can't be changed:
[root /sys/class/pwm/pwmchip1]# cat pwm0/enable 0 [root /sys/class/pwm/pwmchip1]# cat pwm1/enable 0 [root /sys/class/pwm/pwmchip1]# cat pwm0/duty_cycle 0 [root /sys/class/pwm/pwmchip1]# cat pwm1/duty_cycle 0 [root /sys/class/pwm/pwmchip1]# cat pwm0/period 50000 [root /sys/class/pwm/pwmchip1]# cat pwm1/period 50000 [root /sys/class/pwm/pwmchip1]# echo 60000 > pwm0/period [ 202.183000] ehrpwm 48300200.ehrpwm: Period value conflicts with channel 1 -sh: echo: write error: Invalid argument [root /sys/class/pwm/pwmchip1]# echo 60000 > pwm1/period [ 209.133209] ehrpwm 48300200.ehrpwm: Period value conflicts with channel 0 -sh: echo: write error: Invalid argument
However, if I remove one of the submodules, then it seems I can set a period just fine:
[root /sys/class/pwm/pwmchip1]# echo 1 > unexport [root /sys/class/pwm/pwmchip1]# ls device npwm pwm0 uevent export power subsystem unexport [root /sys/class/pwm/pwmchip1]# [root /sys/class/pwm/pwmchip1]# echo 60000 > pwm0/period [root /sys/class/pwm/pwmchip1]# echo 1 > export [root /sys/class/pwm/pwmchip1]# cat pwm1/period 50000 [root /sys/class/pwm/pwmchip1]# cat pwm0/period 60000
What seems odd to me here, is that the periods do not match. I thought they had to be the same. If that is not the case, then why can't I adjust the periods while I have both pwm0 and pwm1 exported?
Once I get in this state of both having different periods, I can continue to modify pwm0 as I wish, but pwm1 can't be modified:
[root /sys/class/pwm/pwmchip1]# echo 70000 > pwm1/period [ 287.953025] ehrpwm 48300200.ehrpwm: Period value conflicts with channel 0 -sh: echo: write error: Invalid argument [root /sys/class/pwm/pwmchip1]# echo 70000 > pwm0/period [root /sys/class/pwm/pwmchip1]# cat pwm0/period 70000 [root /sys/class/pwm/pwmchip1]# cat pwm1/period 50000
The only modification that seems to be allowed is to set pwm1 to pwm0's value. However once that occurs neither pwm1 nor pwm0 can be changed anymore.
[root /sys/class/pwm/pwmchip1]# echo 70000 > pwm1/period [root /sys/class/pwm/pwmchip1]# cat pwm1/period 70000 [root /sys/class/pwm/pwmchip1]# [root /sys/class/pwm/pwmchip1]# echo 50000 > pwm0/period [ 330.573006] ehrpwm 48300200.ehrpwm: Period value conflicts with channel 1 -sh: echo: write error: Invalid argument
I hope it's not just me, and this seems like a very odd behavior to others. Can someone please help me understand why the PWM period is working like this?