Skip to content

pulseio.PulseIn.paused incorrectly reporting state #6981

@sangdrax8

Description

@sangdrax8

CircuitPython version

Adafruit CircuitPython 7.3.3 on 2022-08-29; Adafruit Feather RP2040 with rp2040

Code/REPL

import board
import pwmio
import pulseio
import time

# create a PWMOut object on Pin D6.
# duty_cycle (cycle/65535)
print("setting up pwm")
pwm = pwmio.PWMOut(board.D5, frequency=910 )
pwm.duty_cycle = 2**14
# create a PWMin object on Pin D5.
print("setting up pulses")
pulses = pulseio.PulseIn(board.D6,maxlen=100)
pulses.pause()
PULSE_PAUSED = True
pulses.clear()

PULSE_READ_TIME = time.monotonic_ns()
PULSE_READ_DURATION = 9*(10**6)

while True:
    now = time.monotonic_ns()
    if PULSE_PAUSED:
        print("unpausing")
        pulses.resume()
        PULSE_PAUSED = False
        PULSE_READ_TIME = now
        print("should be unpaused")
        print("paused state: ", pulses.paused)
    if  PULSE_READ_DURATION <= now - PULSE_READ_TIME:
        pulses.pause()
        PULSE_PAUSED = True
        if (len(pulses) > 1):
            pulses.popleft()
            pulses.popleft()
            for x in range(len(pulses)-1)[::2]:
                print(pulses[x], pulses[x+1])
            print("\n")
        pulses.clear()
        time.sleep(.5)

Behavior

pwmtest.py output:
setting up pwm
setting up pulses
unpausing
should be unpaused
paused state:  True
277 835
277 835
277 835
278 834
278 834
278 834
278 834

Description

  • Resume doesn't change the state of the pulses.paused boolean, even though it does resume.

Additional information

I am trying to test out PWM reading with pulsesio.pulsein. I have generated a PWM signal, and can read it. However as I started to try and use time.monotonic_ns instead of sleeps commands, I started having issues with the paused boolean. I switched to a global boolean and I manually set it each time I pause or resume, and this works fine. I believe the pause and resume are functional since I bumped up my maxlen to 100, and I don't fill it up during a pause after each read of .5 seconds.

I am brand new to both circuitpython as well as this board. As best I understand it, the print for "paused state" after the resume on line 29 should read False, but it is always True (even though it does resume).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions