Skip to content
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-ctrl: fix disable if duty cycle is 0 #422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sstepansky
Copy link
Contributor

No description provided.

@gtxaspec
Copy link
Collaborator

gtxaspec commented Jan 6, 2025

this won't work, on some devices 0 duty is full blast. which is why we have reverse. i'll have to dig through later and find the problem commit.

@sstepansky
Copy link
Contributor Author

sstepansky commented Jan 6, 2025

Maybe it's just me, I'm a little confused about the "reversed" thing... I think I assumed it was related to "active low" pins, to get the correct behavior.

I'll try to explain my understanding of this.

Let's assume we're using REVERSE=0, so the pin is reversed and we enter the if at L#211.
Next, L#213 has an -e argument, thus enabling the channel, not disabling it (as seen by running pwm -c 1 -q). It looks like it's disabled because the previous line sets the duty cycle to 0. To disable the channel (as seen in pwm -c 1 -q) we have to use the -d argument. So, if that's to be changed, then both branches if and else are the same.

For example, my cam's white pin is 50o. To turn it on at a faint 5% I run pwm-ctrl -r 50 5. Not using the "reversed" argument results in a very bright light, not the faint light. After that, to turn it off I used pwm-ctrl -r 50 0, again using -r.
Now run pwm -c 1 -q to check:

PWM Channel 1 Status:
Enabled: Enabled
Polarity: Inversed
Duty: 0 ns
Period: 1000000 ns

It's enabled.

Run pwm -c 1 -d to manually disable it, and then check status with pwm -c 1 -q

PWM Channel 1 Status:
Enabled: Disabled
Polarity: Inversed
Duty: 0 ns
Period: 1000000 ns

Running the command to set 0% duty cycle but with pin 49O results in

PWM Channel 0 Status:
Enabled: Disabled
Polarity: Normal
Duty: 0 ns
Period: 1000000 ns

It's disabled, ok here.

The part to enable pwm, from L#219 on, seems a little bit strange, because if REVERSE=0 it is first disabled, and then enabled in the last call to pwm. If REVERSE=1 it's enabled twice.

Please shed some light on this (pun intended).

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

Successfully merging this pull request may close these issues.

2 participants