Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware PWM #9

Closed
shtaif opened this issue Sep 20, 2016 · 7 comments
Closed

Hardware PWM #9

shtaif opened this issue Sep 20, 2016 · 7 comments
Labels

Comments

@shtaif
Copy link

shtaif commented Sep 20, 2016

Hello,

I become more and more confused as PWM seems to me less and less an absolute term.
You declare the word "hardware" a lot in the library, but at the same time, I saw a table that deals with percentages of CPU consumed by varying PWM configurations.

Isn't "Hardware PWM" CPU-independent?
Also, some other library claimed there are only 4 PWM pins on RPI 3 board, while my tests had shown that I could only utilize 2 of them independently, while finally this library seems to be offering all GPIO pins on the board to produce PWM signals.

I'm dazzled with confusion. I'm trying to build a NodeJS quadcopter (so 4 PWM controlled brushless motors) with decent performance and code clarity to be future extension capable.

If you could please help me understand those differing PWM approaches I'll be very thankful...

@shtaif
Copy link
Author

shtaif commented Sep 21, 2016

BTW, sorry if it came out critical/offensive, criticism wasn't my intention at all, but a call for help understanding these different mechanisms, their pros and cons.

@tralves
Copy link

tralves commented Sep 21, 2016

I am no expert here. Just adding my 2 cent.

I don't have a RPI 3, but didn't find any documentation stating that it has 4 PWM pins, only 2. You will need as much responsiveness and preciseness as possible to control the quadcopter motors, so software PWM (which this lib provides) probably won't work...

I think that for your case you'll want an external driver such as the PCA9685: https://www.adafruit.com/products/815.

Also, I would advice to check out the johnny-five.io project. Has lots of examples and provides a clearer API.

@fivdi
Copy link
Owner

fivdi commented Sep 24, 2016

Hardware PWM

The PWM controller on all variants of the Raspberry Pi has two independent channels. Each channel is available on multiple GPIOs (see section 9.5 on page 140 of BCM2835 ARM Peripherals):

GPIO12 PWM channel 0
GPIO13 PWM channel 1
GPIO18 PWM channel 0
GPIO19 PWM channel 1
GPIO40 PWM channel 0
GPIO41 PWM channel 1
GPIO45 PWM channel 1
GPIO52 PWM channel 0
GPIO53 PWM channel 1

On a Raspberry Pi 3, GPIO12, GPIO13, GPIO18, and GPIO19 are broken out to the GPIO header. This is why four hardware PWM pins are available on the Raspberry Pi 3. Note that all GPIOs which share a PWM channel will use the same frequency and duty cycle.

hardwarePwmWrite can be use to control hardware PWM on these GPIOs.

Hardware Timed PWM

hardwared timed PWM is available on any of GPIO0 through GPIO31. The pulses are timed using the DMA and PWM/PCM hardware peripherals. Hardware timed PWM may not be as precise as hardware PWM but it's still very good. This is NOT the same as software PWM. Software PWM on the Raspberry Pi provides very poor and imprecise results.

pwmFrequency and pwmWrite can be used to control hardware timed PWM on any of GPIO0 through GPIO31

@tralves

so software PWM (which this lib provides) probably won't work...

This module does NOT provide software PWM. It provides hardware PWM on all pins where it's available and hardware timed PWM on GPIO0 through GPIO31. Hardware PWM and hardware timed PWM are not the same thing as software PWM. Whether it fulfills the requirements @shtaif has is a different question. I'd give it a try.

Also, I would advice to check out the johnny-five.io project. Has lots of examples and provides a clearer API.

The goal of the pigpio module was to provide an API that's a complete as possible rather than as clear as possible.

@fivdi
Copy link
Owner

fivdi commented Sep 29, 2016

@shtaif hopefully things are a clearer now. There's nothing actionable here so I'm going to close this one.

@fivdi fivdi closed this as completed Sep 29, 2016
@shtaif
Copy link
Author

shtaif commented Oct 3, 2016

I've been researching this PWM functionality mystery for some time (except looking in the Pi's hardware datasheets because I don't understand a thing written there),
but @fivdi just nailed it for me, the best answer I could get.

Actually, to be on the safe side I ordered this external PWM driver:
https://www.adafruit.com/products/2327

However, before I assemble it I'm gonna attempt relying on pigpio's hardware-timed PWM first and see how the motor control turns out.

@shtaif
Copy link
Author

shtaif commented Oct 3, 2016

For clarification, the hardware-timed PWM does consume a constant amount of CPU percentage as long as it's active, right?

@fivdi fivdi added the question label Feb 3, 2018
@Pluscrafter
Copy link

yes and hardware-timed PWM isn't accurate as HardwarePWM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants