QTPY RP2040 PWM output on MO disrupts PWM input on MI

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Probotics
 
Posts: 7
Joined: Tue Apr 12, 2011 1:17 pm

QTPY RP2040 PWM output on MO disrupts PWM input on MI

Post by Probotics »

I don't know if this is intended and I am just not familiar enough with it but I was building a servo slower that took R/C 50hz 1-2ms pwm inputs on MI and when I had it process the signal and issue commands on MO via the servo command from the motor library it would, every four seconds or so, disrupt the PWM input on MI causing it to read zero, then gibberish for several cycles. I tried several workarounds but it looks like the only real option is using a different pin and that seems to be holding steady but I don't want to run into this issue later after x thousand cycles or something. Should I be worried about that?

hardware: level shifter and QT Py RP2040
Software 7.1.1, 7.1.2 beta tried too, same result.

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: QTPY RP2040 PWM output on MO disrupts PWM input on MI

Post by danhalbert »

Could your post your code so we can try it out?

User avatar
Probotics
 
Posts: 7
Joined: Tue Apr 12, 2011 1:17 pm

Re: QTPY RP2040 PWM output on MO disrupts PWM input on MI

Post by Probotics »

Code: Select all

# servo slower
import pulseio
import board
import pwmio
import time

from adafruit_motor import servo

p_pulseIn1 = pulseio.PulseIn(board.D0)

pwm = pwmio.PWMOut(board.MOSI, duty_cycle=0, frequency=333)
servo = servo.Servo(pwm, min_pulse=800, max_pulse=2200)
v_count = 0

while len(p_pulseIn1) == 0:
    pass

v_currentLocation = p_pulseIn1[0]

p_pulseIn1.pause()
p_pulseIn1.clear()

def get_a_pulse(vl_pulseIn):
    vl_pulseIn.resume()
    while len(vl_pulseIn) == 0:
        pass
    vl_pulseIn.pause()

def slow_pulse(vl_pulseinval, vl_currentLocation):
    if vl_currentLocation > vl_pulseinval:
        v_newLocation = max(vl_pulseinval, vl_currentLocation - 30)
    elif vl_currentLocation < vl_pulseinval:
        v_newLocation = min(vl_pulseinval, vl_currentLocation + 30)
    else:
        v_newLocation = vl_pulseinval
    v_newLocation = max(800, v_newLocation)
    servo.fraction = ((v_newLocation-800)/1400)
    vl_currentLocation = v_newLocation
    time.sleep(0.01)
    return vl_currentLocation

while True:
    get_a_pulse(p_pulseIn1)
    v_pulseIn1 = p_pulseIn1[0]
    v_currentLocation = slow_pulse(v_pulseIn1, v_currentLocation)
    v_count = v_count + 1
#    if v_pulseIn1 < 1000:
    print("pulse 1 ", v_pulseIn1)
    print("pulse out", v_currentLocation)
    print(v_count)
    p_pulseIn1.clear()
This is changed (MI to D0) which now is working without interrupts. It also has some testing stuff in there that I haven't yet stripped back out but that does not seem to change the behaviors.

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: QTPY RP2040 PWM output on MO disrupts PWM input on MI

Post by danhalbert »

I lost track of this old issue, sorry. Are you still seeing this problem? At the very least we can record it in an issue.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”