First steps using PIO: viable strategies? #10887
-
I'm trying to write a driver for ZACwire devices such as the TSic 506F temperature sensor. One useful property of these sensors is that their nominal accuracy is excellent (±0.1 °C), which is necessary for some scientific applications (e.g., ensuring precise and accurate control of a chemical reaction's temperature). I've managed to write a usable driver for the pyboard based on IRQs and a Timer, but I'd like to learn how to do this using a Pico W's PIO. I've looked at the documentation and some examples from this thread, and I'm just starting to grasp the basics of PIO programming. Before I go further, I have to decide on an overall strategy to divide work between the PIO and the main system. The ZACwire protocols encodes bits as a series of 20 low pulse durations ranging from 20 to 100 microseconds. From other's examples I see how I can measure each of these durations and push them to the ISR using
I'm somewhat optimistic that option B is not unfeasible, and I sure hope it's not option C. Any general suggestions, or pointers to specific methods/functions that are well suited to this task, would be much appreciated. Of course, I'll add this to micropython-zacwire if/when it works well. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You could have a look at this class: https://github.com/robert-hh/RP2040-Examples/tree/master/pulses |
Beta Was this translation helpful? Give feedback.
-
Thanks to the examples kindly provided by @robert-hh, I got something working well on a Pico W. The driver is here, and uses two state machines:
Any comments or suggestions for improvements are welcome, and thanks again to @robert-hh. Update: Due to #8431, the DMA approach is brittle in many situations. I've moved back to using two IRQs, which still works well. I'd going to DMA if/when this issue is resolved. |
Beta Was this translation helpful? Give feedback.
Thanks to the examples kindly provided by @robert-hh, I got something working well on a Pico W. The driver is here, and uses two state machines:
sm0
) reports the low pulses durations out of the TSic.sm1
) raises an IRQ when it detects a high pulse longer than ~5 ms, which only happens in between temperature readings.sm0
and write them to a buffer arraydmabuf
. It also schedules the decoding ofdmabuf
into a temperature readingAny comments or suggestions for improvements are welcome, and thanks again to @robert-hh.
Update: Due to #8431, the…