Skip to content

Restarting PIO creates phantom 0 inputs #4983

@dmcomm

Description

@dmcomm

CircuitPython version

Adafruit CircuitPython 7.0.0-alpha.4-7-g58fdf9e94 on 2021-07-09; Raspberry Pi Pico with rp2040

Code/REPL

import array
import board
import time
import rp2pio

pinIn = board.GP1

program = array.array("H", [0x4001]) #in pins 1
sm = rp2pio.StateMachine(
	program,
	frequency=1_000_000,
	first_in_pin=pinIn,
	auto_push=True,
)
print("frequency", sm.frequency)
time.sleep(3)
buffer=array.array("L", [0] * 4)
zeroCount = 0
oneCount = 0
restartTime = time.monotonic()
print("start")
while True:
	if time.monotonic() - restartTime > 20:
		restartTime = time.monotonic()
		print("restarting")
		sm.restart()
	while sm.in_waiting < 4:
		pass
	sm.readinto(buffer)
	for item in buffer:
		if item == 0:
			zeroCount += 1
			if zeroCount % 100000 == 0:
				print("zeros", zeroCount)
		elif item == 0xFFFFFFFF:
			oneCount += 1
			if oneCount % 100000 == 0:
				print("ones", oneCount)
		else:
			b = bin(item)
			print("0" * (34 - len(b)) + b[2:], end=" ")
			print()

Behavior

When the pin is grounded, as expected:

zeros 100000
zeros 200000
zeros 300000
zeros 400000
restarting
zeros 500000
zeros 600000
zeros 700000
zeros 800000
zeros 900000
restarting
zeros 1000000
zeros 1100000

When the pin is tied to 3V3:

ones 100000
ones 200000
restarting
11111110000000111111111111111111 
ones 300000
ones 400000
ones 500000
restarting
11111111111000011111111111111111 
ones 600000
ones 700000
restarting
11111111111100001111111111111111 
ones 800000
ones 900000

Description

No response

Additional information

This doesn't seem to happen in MicroPython. Edit: Though actually, my program isn't quite doing the same thing, so I should check that a bit more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrp2040Raspberry Pi RP2040

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions