Skip to content

duty_cycle getter doesn't return what setter was given #52

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
DrRob opened this issue Apr 27, 2023 · 6 comments · Fixed by #53
Closed

duty_cycle getter doesn't return what setter was given #52

DrRob opened this issue Apr 27, 2023 · 6 comments · Fixed by #53
Labels

Comments

@DrRob
Copy link
Contributor

DrRob commented Apr 27, 2023

Hi, why does the setter have value + 1 in line 91?:

value = (value + 1) >> 4

There isn't a corresponding adjustment in the getter, so for example if I set duty_cycle to 0x7fff and then read it back I get 0x8000.

Thanks!
Rob.

@tekktrik
Copy link
Member

@tannewt Looks like this was in the original commit for the library, curious if you know or remember why the getter and setter would be different?

@tannewt
Copy link
Member

tannewt commented Apr 28, 2023

I don't remember. Sorry!

It would make more sense to read the same value back.

@tekktrik tekktrik added bug and removed question labels May 1, 2023
@tekktrik
Copy link
Member

tekktrik commented May 1, 2023

Thanks @tannewt!

Looks like it might be a bug @DrRob, are you interested in submitting a PR to fix it?

@DrRob
Copy link
Contributor Author

DrRob commented May 1, 2023

I'll try, but I'm puzzled about why the value + 1 part doesn't result in a requested duty cycle of zero actually being on for 1/4096th of the period. (It doesn't - I checked with an oscilloscope.)

@DrRob
Copy link
Contributor Author

DrRob commented May 1, 2023

Actually I got that wrong - if a duty cycle of zero is requested, then (0 + 1) >> 4 == 1 >> 4 == 0, so both the LEDn_ON and LEDn_OFF registers are set to zero, which probably explains why the output is off all the time as expected...

...HOWEVER, the datasheet says, "The LEDn_ON and LEDn_OFF count registers should never be programmed with the same values." LEDn_OFF should be set to 0x1000 for fully off.

I'll try to fix it according to the datasheet instructions.

@DrRob
Copy link
Contributor Author

DrRob commented May 2, 2023

I'm a bit rusty with git but I think I've just submitted a PR for this.

@tekktrik tekktrik linked a pull request May 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants