Comments (9)
The above code always sets PWMduty to 500000. Does setting PWMduty to 0 when PWMfreq is 0 help? Does the call to hardware_PWM always return 0 or is an error code returned when PWMfreq is 0?
from pigpio.
Strange as it may seem that is actually the intended behaviour.
See http://abyz.co.uk/rpi/pigpio/python.html#get_PWM_frequency
Returns the frequency (in Hz) used for the GPIO.
For normal PWM the frequency will be that defined for the GPIO by set_PWM_frequency.
If a hardware clock is active on the GPIO the reported frequency will be that set by hardware_clock.
If hardware PWM is active on the GPIO the reported frequency will be that set by hardware_PWM.
As hardware PWM is not active (0 switches it off) the default PWM frequency (or that set by set_PWM_frequency) is returned.
from pigpio.
Is the intended behavior good?
from pigpio.
Who's to say? If the duty cycle is zero the frequency is irrelevant anyhow.
from pigpio.
Yes, if the duty cycle is 0 the frequency is irrelevant. However, although I haven't tested it, I'd expect get_PWM_dutycycle to return 500000 in the above code. A frequency of 800Hz and a duty cycle of 50% implies 800 pulses per second, but in this case there are 0 pulses.
from pigpio.
I have not opinion about what is the good behavior. I just want a proper way to check when PWM pulse are stopped.
If I initialize soft PWM with pi.set_PWM_frequency(13,0) in the above test code then get_PWM_frequency() return 10Hz (seen to be the soft PWM lower limit).
Alternative if I use dutycycle=0 to stop PWM and check it using get_PWM_dutycycle(13) the code raised a pigpio.error: 'GPIO is not in use for PWM' if freq is also set to 0...
from pigpio.
@nachoplus why not leave the frequency as is and set the duty cycle to 0 to turn PWM off?
The output of the following program:
import pigpio
pi=pigpio.pi()
pi.set_mode(13, pigpio.OUTPUT)
# PWM on
pi.hardware_PWM(13,1000,500000)
print "get_PWM_frequency()/get_PWM_dutycycle()",pi.get_PWM_frequency(13),"/",pi.get_PWM_dutycycle(13)
# PWM off
pi.hardware_PWM(13,1000,0)
print "get_PWM_frequency()/get_PWM_dutycycle()",pi.get_PWM_frequency(13),"/",pi.get_PWM_dutycycle(13)
is:
get_PWM_frequency()/get_PWM_dutycycle() 1000 / 500000
get_PWM_frequency()/get_PWM_dutycycle() 1000 / 0
If pi.get_PWM_dutycycle(13)
returns 0, PWM pulses are stopped.
from pigpio.
I am reluctant to change a defined interface without a very good reason. For all I know people may be depending on the currently defined interface in their code.
@fivdi gives a solution. It seems good to me.
So I will not change the interface.
from pigpio.
OK. I have adopted the solution proposed by @fivdi . Thank you very much for supporting!
from pigpio.
Related Issues (20)
- more detailed documentation required about gpioWaveCreatePad HOT 5
- serOpen() serFlags? HOT 1
- Python DHT11 Example: DHT11 Class __iter__ does not work.
- How to access MCP23008 expander GPIOs?
- CM4 HDMI Audio + pigpio conflict? HOT 9
- general on pigpiod daemon HOT 4
- pigpio callback issue with threads
- Can create SPI wave in nano seconds resolution? HOT 10
- Initialization issue on debian 12 bookworm HOT 2
- `git pull` or `git clone` actions return 'https://github.com/joan2937/pigpio/': SSL certificate problem: certificate is not yet valid HOT 1
- Possible issue with wave function on PI 4 8GB bullseye 64bit HOT 39
- pigpio probably won't work on Pi5 (or later Pi's) HOT 4
- Allow get/set of slew rate and hyst bits for gpio HOT 3
- Uninstalling pigpiod attempted to remove /opt
- pigpio will not run on a Pi 5 HOT 23
- Failed on Rpi2 and AlpineLinux HOT 2
- Unclean PWM at certain frequencies. HOT 1
- i2c (am2320) works with pigpio and not pigpiod - could definition of i2c_open() be wrong?
- C pigpio timer inaccuracy on raspbery pi 4 with raspian
- Pigpio BB Serial Read CPU Resource vs. RPI version HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pigpio.