Page 1 of 1

Which pin(s) on RPi 3B is PWM capable

Posted: Thu Jun 02, 2016 10:46 pm
by OcoBri
And is there more than one PWM-capable pin? Most tutorials I find don't specify which model of Raspberry Pi they are using. I would like to operate more than one servo from my Pi, in addition to some motors controlled via an L298. Do I need some other intermediate hardware, or can this be done directly from the Pi 3B?
Thank you!

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Jun 03, 2016 12:27 am
by MarkHaysHarris777
OcoBri wrote:And is there more than one PWM-capable pin?
See this link.

There are two PWM channels on the PI 3B. Typically the user only has real access to channel 0, so that leaves really only one (1) PWM pin (by default) which you have access to: pin12 GPIO18.

Having said that, there are other pins... see the link above... and with pigpio there are many (somehow) I haven't played with it yet... but that's on my back-burner.

Again, I don't yet know how pigpio works--- but it is possible to 'create' your own PWM capability with your own software! Although, its not the same as having a dedicated oscillator for the purpose. PWM does not have to run fast... even low audio frequencies work well... heck even frequencies above 8Hz are useful; and you can generate those yourself easily handling the duty cycle yourself. Basically, you make your own oscillator running in one thread, and then you communicate to that thread via interprocess comms to handle the duty cycle! (I'm not sure yet, but I think that is what Joan is doing with pigpio; I might be wrong of course).

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Jun 03, 2016 1:41 am
by mthomason
Personally, I'd be tempted to simplify it by using one of these

https://www.adafruit.com/product/815

(Or if you want a cheaper Chinese clone, http://www.aliexpress.com/item/1pc-PCA9 ... 64717.html)

I've driven that from Arduinos and ESP8266s before, and as it's I2C it ought to be easy enough from a Pi too. As it also handles power and ground in standard 3-pin servo connections, it can make wiring up multiple servos a lot easier too.

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Jun 03, 2016 5:32 am
by rpdom
MarkHaysHarris777 wrote:
OcoBri wrote:And is there more than one PWM-capable pin?
See this link.

There are two PWM channels on the PI 3B. Typically the user only has real access to channel 0, so that leaves really only one (1) PWM pin (by default) which you have access to: pin12 GPIO18.
As an update to that, both Hardware PWM channels are available for use - if you don't need to use audio from the A/V jack as they are both used for that as well.

pigpio and others can use a form of software PWM on any gpio pin. It's not quite got the fine resolution of the hardware PWM and takes up some CPU time, but is fine for most things.

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Jun 03, 2016 6:17 am
by MarkHaysHarris777
rpdom wrote:
MarkHaysHarris777 wrote:
OcoBri wrote:And is there more than one PWM-capable pin?
See this link.

There are two PWM channels on the PI 3B. Typically the user only has real access to channel 0, so that leaves really only one (1) PWM pin (by default) which you have access to: pin12 GPIO18.
As an update to that, both Hardware PWM channels are available for use - if you don't need to use audio from the A/V jack as they are both used for that as well.

pigpio and others can use a form of software PWM on any gpio pin. It's not quite got the fine resolution of the hardware PWM and takes up some CPU time, but is fine for most things.
Thanks for the clarification; also thanks for confirming for me that the audio uses the PWM ! I thought so, but wasn't sure.

:)

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Jun 03, 2016 7:51 am
by joan
pigpio (and others) will provide hardware timed PWM on all the GPIO connected to the expansion header. Once started the PWM uses no CPU time. It has less resolution and restricted frequencies compared to the two hardware PWM channels. The default of 800Hz 250 steps is pretty much the same as an Arduino.

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Jun 03, 2016 8:54 pm
by OcoBri
Thanks everyone!

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Nov 04, 2016 2:27 pm
by ravitptc
Please clarify me clearly..
One PWM is from GPIO 18 (12th Pin)
Which is the another one?

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Nov 04, 2016 2:44 pm
by rpdom
ravitptc wrote:Please clarify me clearly..
One PWM is from GPIO 18 (12th Pin)
Which is the another one?
The other PWM is from GPIO 13 (pin 33)
http://pinout.xyz/pinout/pin33_gpio13#

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Nov 04, 2016 2:52 pm
by joan
To be pedantic GPIO 12/13/18/19 all have hardware PWM and are available on Pis with the 40 pin expansion header (pins 32/33/12/35). However 12/18 share a setting as do 13/19.

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Fri Nov 18, 2016 9:55 pm
by GnuReligion
Joan:

My experience with the WiringPi library is, indeed, that 4 PWM pins are addressable, but only 2 are unique.

The gpio utility, as well as with C library yield the same results.
Pins 33+35 (bcm 13+19, wpi 23+24) reflect identical signals, as do Pins 12+32 (bcm 18+12, wpi 1+26).

To put too fine a point on it, when I write a PCM signal to pin 12, it is mirrored simultaneously on pin 32. They are linked.

Disappointing. Had hoped to control my 3-color LED strip, but must use softPWM, which is not nearly as good.

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Sat Nov 19, 2016 11:16 pm
by BMS Doug
GnuReligion wrote:Joan:

My experience with the WiringPi library is, indeed, that 4 PWM pins are addressable, but only 2 are unique.

The gpio utility, as well as with C library yield the same results.
Pins 33+35 (bcm 13+19, wpi 23+24) reflect identical signals, as do Pins 12+32 (bcm 18+12, wpi 1+26).

To put too fine a point on it, when I write a PCM signal to pin 12, it is mirrored simultaneously on pin 32. They are linked.
Yes, that is exactly what Joan said.
GnuReligion wrote:Disappointing. Had hoped to control my 3-color LED strip, but must use softPWM, which is not nearly as good.
Did you try PIGPIO? It is hardware timed with a level of discrimination that should be more than good enough for 3 Colour LED.

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Sun Feb 03, 2019 5:02 pm
by krrishdheeraj
Thank you

Re: Which pin(s) on RPi 3B is PWM capable

Posted: Sun Feb 03, 2019 6:31 pm
by rpdom
I have used software PWM generated by a simple C program that was reasonably controllable. But now I just use addressable LED strings so only one GPIO with PWM or PCM, or two general GPIOs (clock and data) are required.