8000 Frequency related pulseio PWMOut.duty_cycle does not retain set values accurately · Issue #1118 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Frequency related pulseio PWMOut.duty_cycle does not retain set values accurately #1118

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

Closed
DuckRogers opened this issue Aug 15, 2018 · 6 comments

Comments

@DuckRogers
Copy link

In general, PWMOut.duty_cycle does not retain or increment or set values correctly.

It is also frequency dependent, so the amount of incorrectness changes with frequency.

It may be that frequency changes are simply compounding the initial value inaccuracy.

May or may not be related to #1106

And now for some examples:
image
image
image
image

@tannewt
Copy link
Member
tannewt commented Oct 8, 2018

Does this still happen with 3.0.2? Thanks!

@tannewt tannewt added this to the 3.x milestone Oct 8, 2018
@DuckRogers
Copy link
Author

Unfortunately, it still happens. I finally got a chance to test this again (on 3.1.1)
Caveat: I am running it on a M4 Feather now instead of a Metro, doubt that would change it, but...

@tannewt
Copy link
Member
tannewt commented Nov 27, 2018

Now that I read this I realize its by design. The number you read back is the actual duty cycle being output. As you've found, the accuracy varies somewhat with frequency. This is due to the top value of the underlying counter varying to achieve the target frequency. I think this is how it should work, if we store the input value and then return it we'd be giving false info back.

If you want to ensure even steps from your end I recommend storing the last set value. Will that work for you?

I'm closing this now but we can continue the conversation as needed to get you going.

@tannewt tannewt closed this as completed Nov 27, 2018
@DuckRogers
Copy link
Author
DuckRogers commented Nov 27, 2018 via email

@tannewt
Copy link
Member
tannewt commented Nov 28, 2018

Sorry, I meant to say the read back value may be different from the set value. The returned value should always be the same for a given frequency, set value and underlying timer. Its due to resolution loss in the underlying capture/compare value that drives the duty cycle.

@DuckRogers
Copy link
Author
DuckRogers commented Nov 28, 2018 via email

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

No branches or pull requests

2 participants
0