JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Using the PWM pin

Mon Jan 06, 2014 8:31 pm

How do I use the PWM pin on my pi? I'm using RPi.GPIO

Is it just the same as the use of any other pin? In which case it would be really simple to write a function to do it given a mark:space ratio.

Also which pin number is it?

Thanks

User avatar
croston
Posts: 701
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Using the PWM pin

Mon Jan 06, 2014 10:06 pm

Have a read of this page --> http://sourceforge.net/p/raspberry-gpio ... /wiki/PWM/

RPi.GPIO will do software PWM on any channel.

JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Re: Using the PWM pin

Tue Jan 07, 2014 9:54 am

That page implies I can do that on any pin (I am aware that I can softare PWM), but isn't there a specific pin designed for PWM?
Will using the module used on that page exploit the advantages of using that specific pin? (providing, of course, that I set it to the correct pin)
And which pin is it!?

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

Re: Using the PWM pin

Tue Jan 07, 2014 12:15 pm

Gpio 18 is the only accessible gpio which has a dedicated PWM function.

wiringPi (as far as I'm aware) is the only library which uses that function.

What are you trying to do?

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: Using the PWM pin

Tue Jan 07, 2014 12:37 pm

joan wrote:Gpio 18 is the only accessible gpio which has a dedicated PWM function.

wiringPi (as far as I'm aware) is the only library which uses that function.

What are you trying to do?
Question please, is the GPIO 18 pin, 3.3 or 5 volts?

User avatar
croston
Posts: 701
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Using the PWM pin

Tue Jan 07, 2014 12:38 pm

All GPIO pins on the Raspberry Pi are 3.3V. If you use 5V, you are at risk of damaging your Pi.

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

Re: Using the PWM pin

Tue Jan 07, 2014 12:42 pm

All gpios are 3.3V.

The Pi has a 5V rail (I think it is the unregulated input supply) which is brought out to several pins. The 3.3V rails, 5V rails, and ground rails are not controllable by software.

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: Using the PWM pin

Tue Jan 07, 2014 12:47 pm

Thank you.

JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Re: Using the PWM pin

Tue Jan 07, 2014 4:12 pm

joan wrote:Gpio 18 is the only accessible gpio which has a dedicated PWM function.

wiringPi (as far as I'm aware) is the only library which uses that function.

What are you trying to do?

Thank you for your relevant answer :)

speed control of a pc case fan. From what I've been trying with LEDs, I'm happy to use software PWM to be honest, unless there's any reason I shouldn't?

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

Re: Using the PWM pin

Tue Jan 07, 2014 7:04 pm

Any Pi library you can find with PWM support will be good enough to drive a fan (any PWM jitter will be contained by the motor inertia).

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: Using the PWM pin

Fri Jan 24, 2014 9:26 pm

The hardware PWM (on pin 18, AKA GPIO 1) does the PWM in hardware, so the chip takes care of it silently in the background. The software PWM provided by WiringPi requires the processor to continually switch the state of the pin, so you need a program to be running the entire time in order to do this. As I have read, each pin doing software PWM requires about 0.5% of the CPU to accomplish this. This also means you can't do it from a shell script or the command line; it has to be Python or C, as far as I know.

If you don't mind the small amount of constant CPU usage and will have a program running continually to control your speed anyway, you can use either. If you do mind the extra CPU load or intend to "set it and forget it" by letting your program or script exit until you change the PWM duty cycle (in your case, fan speed) then use the hardware PWM.

DominusPi
Posts: 39
Joined: Mon Nov 18, 2013 5:31 pm

Re: Using the PWM pin

Sat Jan 25, 2014 10:48 pm

PWM = Pulse-width modulation right ?

http://www.youtube.com/watch?v=uUn0KWwwkq8

Best I can do for you ;)
Cheers !

Return to “Automation, sensing and robotics”