Hi, I would like to do a cap-sensor again but with PIO for better resolution.
Two GPIOs are used. One (16) is output and coupled via a 1 Megaohms resistor to the metal pad. The second (17) is coupled directly to the metal pad. The time needed to charge the capacity of the pad is measured. With increased capacity a longer time is needed.
I need to jump on pin state. Something like
Where can I find the docu about PIO assembler?
Thank you very much!
Code: Select all
title= "pioTouchA" # from Example of using PIO for PWM, and fading the brightness of an LED from machine import Pin from rp2 import PIO, StateMachine, asm_pio from time import sleep @asm_pio(sideset_init=PIO.OUT_LOW) def cap_prog(): mov(y, osr) .side(1) # ISR must be preloaded with max #mov(x, osr) .side(1) # ISR must be preloaded with max label("test_pin") # count down y, until inPin is high nop() jmp(pin, "is_set") # does not work! #nop()  jmp(y_dec, "test_pin") # tested label("is_set") mov(isr, y) .side(0) # pin low push(block) class PIOCAP: def __init__(self, sm_id, outPin, inPin, max_count, count_freq): self._sm = StateMachine(sm_id, cap_prog, freq=2 * count_freq, sideset_base=Pin(outPin), jmp_pin=Pin(inPin)) # Use exec() to load max count into ISR self._sm.put(max_count) self._sm.exec("pull()") #self._sm.exec("mov(isr, osr)") self._sm.active(1) self._max_count = max_count # Pin 16 is output #cap = PIOCAP(0, 16, 17, max_count=(1 << 16) - 1, count_freq=10_000_000) cap = PIOCAP(0, 16, 17, max_count=(1000), count_freq=10_000_000) while True: print(cap._sm.get()) sleep(0.01)