sandstein
Posts: 6
Joined: Wed Nov 18, 2015 9:55 pm

pwm via /sys/class/pwm/pwm0

Wed Dec 16, 2015 8:56 pm

Hi

I have just enabled the pwm with "dtoverlay=pwm-2chan" in the config.txt on raspbian with a 4.1.7-v7+ kernel.

It gives me a nice directory /sys/class/pwm/pwmchip0 after exporting channel 0 via a "echo 0 > export"
No i have set up the pwm:
cd pwm0
echo 20000000 > period
echo 1000000 > duty_cycle
echo 1 > enable

But unfortunatly i can not see anything on output gpio18 checked with an oszilloscope. I think i read somewhere
that i need to play sound once to get the clock enabled for pwm but also starting aplay does not change anything.
My question now is what am i missing to get working hw pwm output?

Thanks
Tim

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: pwm via /sys/class/pwm/pwm0

Wed Dec 16, 2015 9:19 pm

I don't know.

However there are alternative methods to start PWM on the hardware channels, e.g. http://abyz.co.uk/rpi/pigpio/pigs.html#HP

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: pwm via /sys/class/pwm/pwm0

Thu Feb 18, 2016 2:40 pm

sandstein wrote:what am i missing to get working hw pwm output?
This works for me on a rPi2 running Jessie:

Code: Select all

speaker-test -Dhw:CARD=ALSA,DEV=0 -f300 -c1 -p100 -P2 -l1 > /dev/null 2>&1

mishal
Posts: 1
Joined: Thu Mar 10, 2016 7:42 pm

Re: pwm via /sys/class/pwm/pwm0

Thu Mar 10, 2016 7:46 pm

In order to avoid pinmux conflict one must either use audio DT-overlay or pwm DT-overlay.
so the first step is to comment dtparam=audio=on
Second - is to switch clock to pwm. How? I don't know.

Return to “Interfacing (DSI, CSI, I2C, etc.)”