Skip to content

Allow for transformed PWMOut-based error #67

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

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion adafruit_motor/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ def __init__(
# set a safe pwm freq for each output
self._coil = (ain2, bin1, ain1, bin2)
for i in range(4):
if self._coil[i].frequency < 1500:
if self._coil[i].frequency < 1500 and self._coil[i].variable_frequency:
self._coil[i].frequency = 2000
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this error fire if the frequency is above 1500 but not variable? Or do I misread it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely correct, the logic should be inverted to use a guard clause instead for if under and not variable: raise error.

raise RuntimeError(
"PWMOut outputs must either be set to at least "
"1500 Hz or allow variable frequency."
)
if microsteps < 2:
raise ValueError("Microsteps must be at least 2")
if microsteps % 2 == 1:
Expand Down