Skip to content

pulseio pulsein freezing #4916

@rsolow

Description

@rsolow

Firmware

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Metro M4 Express with samd51j19

Code/REPL

import board
import pwmio
import pulseio
import time
import countio

def send_signal(freq,dc):
    pwm = pwmio.PWMOut(board.D5, frequency=freq)
    pwm.duty_cycle = int(65535*dc)

    print('Sending Signal')

def capture_cycles(p, num_cycles, timeout):
    p.clear()
    p.resume()
    start = time.time()
    while len(p) < num_cycles:
        if time.time() - start < timeout:
            pass
        else:
            print('TIME OUT')
            break

    p.pause()
    pulses = [p[i] for i in range(len(p))]
    return pulses

def measure_cycles(p, num_cycles, timeout):
    pulses = capture_cycles(p, num_cycles, timeout)
    total_time = sum(pulses)
    total_low = sum(pulses[::2])
    duty_cycle = total_low/total_time*100
    return duty_cycle, total_time, len(pulses)

def recieve_signal(num,timeout):
    p = pulseio.PulseIn(board.TX, maxlen=num)

    print('\nMeasuring PWM input (%s pulses):'%num)
    duty_cycle, total_time, total_pulses = measure_cycles(p, num, timeout)
    print('Duty cycle (percentage): %.2f' % duty_cycle)
    print('Total Run Time (s): %.2f' % (total_time/1000000))
    print('Total Pulses Captured: ', total_pulses)

#metro m4
f = 300
send_signal(f,.7)
recieve_signal(5000,20)

Behavior

Output data from pulsein test, shows that regardless of maxlen pulsein stops appending after 1s of data collected

Description

I send a pwmout signal from one pin connected to another pin that is reading pulsein. I can change the frequency of the pwmout signal and the number of elements pulsein will freeze at changes, but consistently freezes after one seconds worth of total data is collected by pulsein.

Additional Info

I'm using pulseio pulsein to read pulses coming off a tachometer on a motor to measure rpm. I read the pulses fine for one second of data collection, but after one second pulsein stops appending new pulses. I'll set maxlen to some large number, but after one seconds worth of data is collected no new pulses are captured and I never reach maxlen. Pulsein is not freezing at a consistent length, it's not that pulsein reaches x number of elements and then stops appending, but after one second of total data is collected. I've recreated the issue on an Metro M4 and that example code is what is included in this issue report.

[edited by @jepler to fix code formatting]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions