OcoBri
Posts: 11
Joined: Sun May 15, 2016 2:59 pm
Location: Manhattan Chinatown, NYC, USA

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

Thu Jun 02, 2016 10:46 pm

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!

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN

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

Fri Jun 03, 2016 12:27 am

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).
marcus
:ugeek:

mthomason
Posts: 113
Joined: Sun Apr 24, 2016 12:28 pm

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

Fri Jun 03, 2016 1:41 am

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.

User avatar
rpdom
Posts: 20037
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

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

Fri Jun 03, 2016 5:32 am

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.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN

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

Fri Jun 03, 2016 6:17 am

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.

:)
marcus
:ugeek:

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

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

Fri Jun 03, 2016 7:51 am

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.

OcoBri
Posts: 11
Joined: Sun May 15, 2016 2:59 pm
Location: Manhattan Chinatown, NYC, USA

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

Fri Jun 03, 2016 8:54 pm

Thanks everyone!

ravitptc
Posts: 2
Joined: Thu Nov 03, 2016 5:47 pm

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

Fri Nov 04, 2016 2:27 pm

Please clarify me clearly..
One PWM is from GPIO 18 (12th Pin)
Which is the another one?

User avatar
rpdom
Posts: 20037
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

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

Fri Nov 04, 2016 2:44 pm

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#

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

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

Fri Nov 04, 2016 2:52 pm

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.

GnuReligion
Posts: 2
Joined: Fri Nov 18, 2016 9:36 pm

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

Fri Nov 18, 2016 9:55 pm

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.

BMS Doug
Posts: 4423
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

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

Sat Nov 19, 2016 11:16 pm

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.
Doug.
Building Management Systems Engineer.

krrishdheeraj
Posts: 13
Joined: Tue Aug 21, 2018 4:55 pm

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

Sun Feb 03, 2019 5:02 pm

Thank you

User avatar
rpdom
Posts: 20037
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

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

Sun Feb 03, 2019 6:31 pm

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.

Return to “Automation, sensing and robotics”