-
Notifications
You must be signed in to change notification settings - Fork 404
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
PWM set issue #42
Comments
sudo pigpiod -t1 starts the daemon with the PCM clock (the default). At the default 5 µs sampling rate the default PWM frequency is 800 Hz. So each pulse happens in a 1000000/800 or 1250 µs time slot. There are 250 steps between off and fully-on (each step equates to 1 sampling period, or 5 µs at a 5 µs sampling rate, and 1250/5 gives 250). The figure of 250 is what I refer to as the real range. For convenience you can map the 250 steps into a range of your choice, but there are still only 250 discrete steps. The C library (well the code) is the definitive statement of what happens, for instance, see http://abyz.co.uk/rpi/pigpio/cif.html#gpioSetPWMrange |
Hi thanks for the swift response, user error.... |
You will have to lower the PWM frequency or increase the sample rate. I would not suggest sampling higher than every 2 µs. Use set_PWM_frequency to lower the frequency. Remember there are two hardware PWM channels. pigpio programs them to have a million steps between off and fully on. See http://abyz.co.uk/rpi/pigpio/python.html#hardware_PWM |
Hi Thanks for the pointers - have had a quick play and it works much closer to what I want - I can't use the hardware capable PWM channels as have maybe 10-13 output channels I want to control. |
Hi Joan, |
Remember the compute modules have the same number of hardware PWM channels (2) as the other Pi's with the 40 pin expansion header. If I remember correctly the choice of a million steps was arbitrary, it could just have easily been 10 million. I do not know what resolution the underlying hardware/GPIO can manage. |
hmm - looking at http://abyz.co.uk/rpi/pigpio/python.html#hardware_PWM indicates to me that with a Pi 2 I only can access 4 GPIO's with hardware PWM but can get another 5 with the compute module. |
That's correct, however, there are only two channels. So all GPIO connected to channel 0 will have one setting and all GPIO connected to channel 1 will have another. "The same PWM channel is available on multiple gpios. The latest frequency and dutycycle setting will be used by all gpios which share a PWM channel. " |
Argh - just tested and.... you are correct!. Hmm, I wonder why this is designed this way - I would have expected and desired that I could independently PWM each channel. |
correction - expected to independently PWM each GPIO..... |
You seem to have pretty tough requirements. I suggest you post what you need from PWM in detail, e.g. number of unique channels, frequencies, and resolution on https://www.raspberrypi.org/forums/. I reckon you will need additional hardware support. There should be people who can suggest suitable hardware. |
Hi Thanks - will post my requirements - deploying a Pi for every two lights not only is overkill but expensive!! |
How about a Pi Zero for every two lights - is that more doable? 💵 💷 😄 |
Hi SlySven, I had considered that, however it seemed to me a somewhat brute force approach to solving my problem! I have resolved the expansion issue by using a pair of PCA9685 I2C bus 16 channel PWM adaptors. These are stateless -so single command to each channel to set PWM duty cycle so negligible cpu load, however I then realised my next challenge was how to handle the number of required input channels- mainly from rotary encoders which including an on-off switch would require 3 GPIO's each ...and I need ~20 channels. |
I was looking at the Compute module a short while ago - now that does have a lot more GPIO pins available (~~~120~~ exactly 45)! 😲 |
Using a new install compile and load pigpiod -t 1
from python load library and associate local pi and issue
pi.set_PWM_range(6,500)
I assumed this would give me ~2ms pulse width increments, however measuring on a scope I get
pi.set_PWM_dutycycle(6,0)
actual pulse width 0
and 0 right up to set dutycycle 3 where I get a pulse width of 4.6us
this in itself is not an issue however -
Set Actual
4 4.7
5 9.7
6 9.7
7 9.7
8 14.69
9 14.69
10 19.68
11 19.68
12 19.68
13 24.68
Ignoring absolute values as errors in my scope measurements I would have expected to the pulse width to increment consistently.
Any ideas as to what may be going wrong ?
The text was updated successfully, but these errors were encountered: