Provisioning PWM Pins

120 views
Skip to first unread message

Amura.cXg

unread,
Jul 15, 2015, 11:06:24 AM7/15/15
to pi...@googlegroups.com
I've been playing around with some PWM code for the RaspberryPi and I came across the provisionPwmOutputPin(Pin pin, int defaultValue) method. What exactly is the defaultValue? I'm guessing it's the duty cycle, if that's the case what are the units?

For context, I'm working towards building a Java app to control LED strips through SPI using a MCP23S17. Right now I'm just experimenting with PWM on the GPIO header (I'm waiting for the ICs to come via mail) and wanted to give the provisionPwmOutputPin method a try.

Andrew Quesnel

unread,
Jul 15, 2015, 11:50:33 PM7/15/15
to pi...@googlegroups.com
I had some time to play with my Pi again and I tried provisioning a PWM pin and I got an error saying that the pin can't be set to that mode. This is the code I tried:
final GpioController _gpio = GpioFactory.getInstance();
_gpio.provisionPwmOutputPin(RaspiPin.GPIO_00, 100);

I was able to setup softPWM for GPIO pin 0 but I don't see how I can get PWM using the MCP23S17.

Any thoughts on either method? Will provisionPwmOutputPin work with the MCP23S17 or is there a way to setup softPWM for the MCP23S17?

On Wed, Jul 15, 2015 at 9:06 AM, Amura.cXg <amur...@gmail.com> wrote:
I've been playing around with some PWM code for the RaspberryPi and I came across the provisionPwmOutputPin(Pin pin, int defaultValue) method. What exactly is the defaultValue? I'm guessing it's the duty cycle, if that's the case what are the units?

For context, I'm working towards building a Java app to control LED strips through SPI using a MCP23S17. Right now I'm just experimenting with PWM on the GPIO header (I'm waiting for the ICs to come via mail) and wanted to give the provisionPwmOutputPin method a try.

--
You received this message because you are subscribed to a topic in the Google Groups "Pi4J" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pi4j/FiNcq9iPAT4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pi4j+uns...@googlegroups.com.
Visit this group at http://groups.google.com/group/pi4j.
To view this discussion on the web visit https://groups.google.com/d/msgid/pi4j/3ccec0db-3c38-4cbe-a657-3ee07b0d402c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,
Andrew Quesnel

Robert Savage

unread,
Jul 29, 2015, 10:31:16 AM7/29/15
to Pi4J, amur...@gmail.com, amur...@gmail.com
Take a look at this source file and you can see which RPi pins support PWM in Pi4J. 

Pi4J only supports hardware enabled PWM pins.  It does not emulate or use softPWM for Pi4J provisioned pin objects.
As for the MCP23S17, I don't think there is any Pi4J supported method to use softPWM.

Depending on your application softPWM may not may not be sufficient.  The timing cannot be guaranteed on a non real time OS.

Alternatively or if you need more PWM pins that what the RPi hardware natively supports, you could use a real PWM expander chip.

Pi4J includes support for the PCA9685 chip.

Here is a dev board with this chip on Adafruit:

Here is an example program using the Pi4J PCA9685 expander:
Reply all
Reply to author
Forward
0 new messages