Kreasteve

Async PIO Counter

Mar 14th, 2023
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import adafruit_pioasm
  2. import rp2pio
  3. import time
  4. import array
  5. import board
  6.  
  7. counter = """
  8. .side_set 1 opt
  9.    set y, 0
  10.    mov y, !y
  11.     in y,32         ; just to calm circuitpython: "RuntimeError: No in in program"
  12. .wrap_target
  13. loop:
  14.    wait 1 pin 0    side 0
  15.    wait 0 pin 0    side 1
  16.    jmp y-- loop  
  17. """
  18.  
  19. in_str = """
  20.    in y, 32
  21. """
  22.  
  23. asm = adafruit_pioasm.assemble(counter)
  24. in_asm = adafruit_pioasm.assemble(in_str)
  25.  
  26. sm = rp2pio.StateMachine(
  27.     program=asm,
  28.     frequency=125000000,
  29.     first_sideset_pin=board.LED,
  30.     sideset_enable=True,
  31.    
  32.     #INPUT
  33.     first_in_pin=board.GP0,
  34.     in_pin_count=1,
  35.     pull_in_pin_up=1,
  36.    
  37.     auto_push=True,
  38.     wrap_target = 3
  39. )
  40.  
  41. for i in range(10):
  42.     sm.run(in_asm)
  43.    
  44.     #while sm.in_waiting: #WTF? sm.in_waiting is allways 8 !!
  45.     if True:
  46.         print(sm.in_waiting, end=" ")
  47.         buffer = array.array('L', [0])
  48.         sm.readinto(buffer)
  49.         print(buffer)
  50.     time.sleep(1)
  51.  
  52. time.sleep(50)
  53.  
Add Comment
Please, Sign In to add comment