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

pulseio.PulseIn.paused incorrectly reporting state #6981

Closed
sangdrax8 opened this issue Oct 3, 2022 · 1 comment
Closed

pulseio.PulseIn.paused incorrectly reporting state #6981

sangdrax8 opened this issue Oct 3, 2022 · 1 comment
Labels

Comments

@sangdrax8
Copy link

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).

@sangdrax8 sangdrax8 added the bug label Oct 3, 2022
@dhalbert
Copy link
Collaborator

dhalbert commented Oct 5, 2022

This was fixed on the 8.0.0 development line in #6450 and perhaps should have been backported to 7.3.x. Try with the 8.0.0-beta.1 release, and I think it will work for you. There are a number of other PulseIn improvements in #6450.

@dhalbert dhalbert closed this as completed Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants