-
Notifications
You must be signed in to change notification settings - Fork 287
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
Analog Pins don't correctly switch to Digital #665
Comments
Can you please state the version of firmware that shows the issue, eg the output of |
Using mu version 1.0.2
Also, only one pair of pins is required to show the issue. This code fails in the same way: |
And, just to complete the issue, the following code with the write_analog replaced with a write_digital stops correctly after 2 seconds. This shows the hardware works as epected. |
Thanks for the further info. I didn't test it out but I suspect the issue is that once a pin goes into analog mode it's staying in analog mode even if it has a Does it work if you set the analog value to 0 before doing the digital write, like: from microbit import *
pin12.write_analog(600)
pin8.write_digital(0)
sleep(2000)
pin12.write_analog(0) # add this
pin12.write_digital(1)
pin8.write_digital(1) |
Yes "PWM dirver ... keeps outputing the analog signal" I think you've hit the problem on the head. Making the suggested change does indeed fix it. I'll use this as the preferred workaround until it is fixed in the code. |
We're using 4 pins to control 2 dc motors, 2 pins for each motor. PWM on one pin or the other depending on direction. The other pin is set to a 0 (write_digital). To coast to a stop, set both pins to 0 - this always works regardless of analog or digital. To use regenerative braking, set both pins to 1 - this goes wrong if use write_digital and only works by using write_analog with 1023 for PWM.
The following complete program "should" work I think to set both pins to high after driving the motors forward with PWM value of 600. However, instead of the motors stopping, they start moving backwards slowly. If the "write_digital(1) are replaced with "wire_analog(1023)" then it all works as it should.
from microbit import *
pin12.write_analog(600)
pin8.write_digital(0)
pin16.write_analog(600)
pin14.write_digital(0)
sleep(2000)
pin12.write_digital(1)
pin8.write_digital(1)
pin16.write_digital(1)
pin14.write_digital(1)
The text was updated successfully, but these errors were encountered: