OP Carl here. I think another version of the Pico chip could mitigate some issues, but not others.Well, I hope OP gets some of the wishlist realized with RPi's next Pico chip.
- Calling something that isn't a state machine a state machine -- I think we'll just need to live with that.
- Only having two general registers--of course no matter how many registers you get, you always want more. The workaround I used was to use the osr and isr to store general values. I also discuss using constants [but if you go beyond 31, MicroPython doesn't give you an error, instead it silently truncates your constant to 5-bits], packing bits and then shifting, and slowing the state machine clock frequency down so that you need less delay counts.
- Limited instruction slots--again no matter how many you get,, you always want more. The workarounds I discuss are swapping PIO programs on the fly, using various versions of exec, and having multiple state machines sharing a program.
- what 'pull(noblock)' does when there is no value on the FIFO -- This is not documented in the MicroPython PIO manual. I did eventually find it in the C++ SDK. I don't know the answer here. Should the MicroPython manual be complete or should MicroPython users be expected to also read the C++ SDK?
- The HC-SR04 range finder not working as I expected. For the basic operation, I did just need to find the data sheet and read it; I really didn't realize that this $2 item had its own microcontroller and could therefore be arbitrarily complex. I hope others can learn from my naiveite. I also had problems HC-SR04's voltage supply. I got one as part of a kit that used 3.3v, but it's not rated for 3.3v. After it stopped working well, I tried giving it 5v, but then read that this could damage the Pico. I ended up buying a new dual-voltage HC-SR04+. Again, for you experienced folks this may be obvious, but I hope that less experienced folks can learn from my mistake here and save themselves some headaches.
- Constants via 'set' only being 0 to 31 -- it would be nice if they could be bigger. I end up pulling values into registers instead. (In Part 2, I also show how can shift a bunch of small constants into a bigger one. That works, but eats up instruction slots.)
- It would be nice to add "not_pin" and "x_eq_y".
- `jmp x_dec` ends with x equal to 4,294,967,295. This is fine. I just found it surprising.
- All pins are named 'pin' or 'pins' inside the PIO code -- maybe this could be improved -- in the meantime Part 2 includes a cheatsheet that goes through every instruction and shows how the definition of 'pin'/'pins' is determined.
- Using push-to-print debugging (that is, pushing constants or other values on to the FIFO and then having the MicroPython program print the values out.) I don't know that PIO could do more. I don't see it getting its own "debug_print".
-- Carl
[I know some people don't like medium.com as a blogging platform. I find it very convenient and have all monetization/paywall turned off.]
Statistics: Posted by carlk — Fri Jan 24, 2025 3:13 am