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

PWMOut on RPi Pico not able to run at full duty cycle #4189

Closed
jedgarpark opened this issue Feb 12, 2021 · 0 comments · Fixed by #4192
Closed

PWMOut on RPi Pico not able to run at full duty cycle #4189

jedgarpark opened this issue Feb 12, 2021 · 0 comments · Fixed by #4192

Comments

@jedgarpark
Copy link

jedgarpark commented Feb 12, 2021

I've run into an issue w PWMOut on RP2040 Pico board while using adafruit_motor. Seems that setting the PWM pins to full duty cycle of 0xFFFF fails to turn the motor, but 0xFFFE turns it just fine. This means the adafruit_motor throttle = 1.0 or throttle = -1.0 values don't work. I found that throttle = 0.9999998 works, but 0.9999999 does not.

I'm using GP28 and GP27 on the Pico.

Running adafruit-circuitpython-raspberry_pi_pico-en_US-20210212-08f30fe.uf2
Library from this bundle adafruit-circuitpython-bundle-6.x-mpy-20210212

here's the code I'm running:

# This example uses an L9110 H-bridge driver to run a DC Motor.
#  https://www.adafruit.com/product/4489

# Hardware setup:
#   DC motor via L9110 H-bridge driver on two PWM pins that are on their own channels
#   e.g., RP2040 Pico pins GP28, GP27

import time
import board
import pwmio
from adafruit_motor import motor

PWM_PIN_A = board.GP28  # pick any pwm pins on their own channels
PWM_PIN_B = board.GP27

# DC motor setup
pwm_a = pwmio.PWMOut(PWM_PIN_A, frequency=50)
pwm_b = pwmio.PWMOut(PWM_PIN_B, frequency=50)
motor1 = motor.DCMotor(pwm_a, pwm_b)


print("Forwards slow")
motor1.throttle = 0.5
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Stop")
motor1.throttle = 0
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Forwards")
motor1.throttle = 1.0  # 0.9999998 works, 0.9999999 does not
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Stop")
motor1.throttle = 0
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Backwards")
motor1.throttle = -1.0
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Stop")
motor1.throttle = 0
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Backwards slow")
motor1.throttle = -0.5
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Stop")
motor1.throttle = 0
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")
time.sleep(1)

print("Spin freely")
motor1.throttle = None
print("throttle:", motor1.throttle)
print(hex(pwm_a.duty_cycle), hex(pwm_b.duty_cycle)+"\n")

print('pwmio test 0XFFFF \n')
pwm_a.duty_cycle = 0xFFFF
pwm_b.duty_cycle = 0x0000
time.sleep(4)

print('pwmio test 0XFFFE \n')
pwm_a.duty_cycle = 0xFFFE
pwm_b.duty_cycle = 0x0000
time.sleep(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants