I have two pins that want to send data, and I want to synchronize these sends with a clock that pulses the cycle after I send each bit, and another pin that pulses once after the 8th bit is sent on each pin. With one PIO, I do this:
That works just great. With two pins going out, it becomes a little trickier. I can't do "out pins, 2" because my data starts out in two different bytes. I guess I could mix the bytes, but "(byte1 & 1) | ((byte2 << 1) & 2) | (byte1 << 2 & 4) ..." so that the first nibble of two bits has the first bit from each byte, and the second has the second bit, etc. But that operation to combine the bytes seems slow.
So another notion I had was that I should use two state machines. The second machine would
So, I had questions, naturally.
Code:
; Pin assignments:; - srclk is side0; - rclk is side1 (for the lulz); - ser is out0; Autopull should be enabled. Eight bits at a time are pushed and ; then the outputs are flashed. Set the clock divider such that the; PIO runs at 10MHz or slower. set x, 7 side 0b10 ; moves anything in the shift register into the storage registerbitloop: out pins, 1 side 0b00 ; srclk low jmp x-- bitloop side 0b01 ; srclk high, accepts the bit on pins, shifts the bits we've already pushed
So another notion I had was that I should use two state machines. The second machine would
- Wait for an interrupt
- Write one byte at a time until 8 bytes had been written
- Go back to waiting.
So, I had questions, naturally.
- The goal is to send two bytes, serially, one on pin 1 and one on pin 2. Each value should be on the pin for two cycles. On the first cycle, a third pin should be low, then on the second cycle, high. After eight bits have been sent on each pin, a fourth pin should be set high for one cycle. Is there a better way to do this?
- Supposing there is not a better way to do this, is it the case that passing an interrupt between state machines is a single-cycle operation?
- Is there another way, besides interrupts, to synchronize two state machines?
- Further question: is there a way to synchronize two state machines with a clock pin? That is, wait until both state machines are ready, and then, when pin0 goes high, reliably start both machines running on the next cycle? As you can see in my above code, I'm doing this with side output from the PIO, but I wonder if there is a better way.
Statistics: Posted by jags84 — Thu Apr 04, 2024 11:46 pm