Git Product home page Git Product logo

Comments (9)

fivdi avatar fivdi commented on September 26, 2024

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.

joan2937 avatar joan2937 commented on September 26, 2024

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.

fivdi avatar fivdi commented on September 26, 2024

Is the intended behavior good?

from pigpio.

joan2937 avatar joan2937 commented on September 26, 2024

Who's to say? If the duty cycle is zero the frequency is irrelevant anyhow.

from pigpio.

fivdi avatar fivdi commented on September 26, 2024

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.

nachoplus avatar nachoplus commented on September 26, 2024

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.

fivdi avatar fivdi commented on September 26, 2024

@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.

joan2937 avatar joan2937 commented on September 26, 2024

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.

nachoplus avatar nachoplus commented on September 26, 2024

OK. I have adopted the solution proposed by @fivdi . Thank you very much for supporting!

from pigpio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.