Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

MicroPython • Re: use PIO to set multiple pins at 40 kHz [SOLVED]

$
0
0
Hi hippy,

Thanks for the tip! It now puts out an adjustable block pulse at 40 kHz on four pins! I adjusted your code a little (see below), as the docs say that multiple pins should be declared as a tuple, and I have the pull_thresh set to the number of pins. Haven't tested if the out_shiftdir is needed, but the pull(block) probably did the magic (together with out... and mov...). Had to increase the freq of the sm to account for 7us of time it takes for every sm.put... to process. I hope I can get away with that. Hardware to build the project is on its way! Will know soon. Thanks again mate!

Code:

@asm_pio(out_init     = tuple([PIO.OUT_LOW] * len(pioPins)),         autopull     = True,         pull_thresh  = len(pioPins),         out_shiftdir = PIO.SHIFT_RIGHT        )def pio_speaker_state(LEN=len(pioPins)):    pull(block)    out(x, LEN)     # Get the bits to output    mov(pins, x)    # Output the bits    nop() [1]    sm = StateMachine(0, pio_speaker_state, freq=6700000, out_base=pioPins[0])# Start statemachine, it will wait for data on its FIFOsm.active(1)while Active: # Active is a bool that can be set to False by button.irq that triggers a handler to do so    sm.put(ptn_ar[current_pattern]) # where ptn_ar[current_pattern] contains array.array('B', L) with L = list of 24 1-byte ints

Statistics: Posted by eToiPi — Tue Jun 04, 2024 10:52 pm



Viewing all articles
Browse latest Browse all 4829

Trending Articles