PIO code behaving very differently between simulator & real Pico (Wokwi 👍 , Pico 🤯 ) #17058
Replies: 7 comments 4 replies
-
Just as an experiment, have you tried switching from optional side set mode to full side set mode, in which each instruction has a side set on it? I don’t quite see how that would make a difference, but it does change the code and a bit in the configuration register, along with leaving an extra bit for delays. |
Beta Was this translation helpful? Give feedback.
-
not a solution , but a PIO emulator that I have found quite useful for testing and debugging my PIO code. |
Beta Was this translation helpful? Give feedback.
-
@rtyley Try disabling auto pull. You are both pulling and auto pulling, so your mov(x,osr) triggers another pull immediately, and the you pull yet again before the mov(y, osr) |
Beta Was this translation helpful? Give feedback.
-
You’re right that the documentation isn’t very clear about the effect of mov instructions on autopull. I’ll write a quick test to see if they trigger it or not. I can’t see anything else wrong or suspicious about your code. |
Beta Was this translation helpful? Give feedback.
-
When using autopull, it is better to replace
|
Beta Was this translation helpful? Give feedback.
-
Has this difference in runtime behavior been reported to Wokwi yet? |
Beta Was this translation helpful? Give feedback.
-
@rtyley What is the real nature of the data to be sent to this device? Is it always short streams, as in the example, or are these really long, packed string of bits in real life, for which autopull is the elegant solution?
Thanks @mendenm, the data is sent to a pair of Holtek [HT1632C](https://cdn-shop.adafruit.com/datasheets/ht1632cv120.pdf) chips, and has a format like this:
<img width="704" alt="image" src="https://github.com/user-attachments/assets/90d890c2-c621-41d6-8d26-8bcd77ba2f2a" />
```
ccc aaaaaaa dddd dddd dddd dddd dddd ...
ccc : 3 bit mode selector, 101 for 'write mode'
aaaaaaa : 7-bit memory address
dddd : a 4-bit nibble giving the lighting state for 4 leds - this can be repeated up to 96 times to cover all 96*4 LEDs the HT1632C can control
```
So the data length for sending to a single bulk-write command HT1632C can be anywhere from 14 bits, up to 394 bits, in 4-bit increments. That's for just one HT1632C chip, the PIO code is meant to drive a dual-HT1632C device, so there may be up to **788 bits** for the both of them.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wrote some PIO code to drive a pair of Holtek HT1632C chips (1 data, 1 write clock, 2 chip-select lines) - the code is behaving perfectly in Wokwi simulator, and is behaving completely differently when run on an actual RPi Pico. I tried a Pico 1 & 2, and a Pico W too... all were consistent with each other, just not making any output that I recognised as making sense.
The micropython code pushes data (number of bits to write for each Chip Select, and then the bits themselves) onto the state machine’s TX FIFO. The PIO code (included at the bottom) outputs the Data signal to GPIO Pin 10, and uses sideset to output the Write Clock, CS0 & CS1 to Pins 11,12,13 (ie Write Clock on Pin 11 is the sideset base).
In this demo example, the code runs on repeat, the same data being pushed into the TX FIFO every 1 second.
Wokwi 👍
https://wokwi.com/projects/426164473278649345 ...gives this signal, output every 1 second:
This is completely perfect to my eyes - the Write clock oscillates along, giving 22 rising edges while Chip Select 0 is low, and then does another 22 rising edges while Chip Select 1 is low. The correct data is written out to the data line (eg 101 0000000 1111 1000 0001 while CS0 is low).
Real Pico 🤯
Sticking the same code into Thonny, deploying it to a real live Pico (Micropython v.24.1), and capturing the resulting signals with a logic analyzer, gives a completely different set of signals (still output once every second):
Differences:
This signal isn't pure random noise - all 4 of these signals always look exactly the same, repetition after repetition, run after run.
What is going on?!
I don't know what I'm doing wrong!
So far as I can tell, on the physical Pico, I am monitoring the correct GPIO pins:

If I add Micropython code to set the Chip Select lines high (
pin_cs0.on()
) then I can see that happening in my logic analyzer - but the PIO sideset still seems to do nothing for the CS lines.Code
Beta Was this translation helpful? Give feedback.
All reactions