stepper motor - using single PIO - guidance #14501
Replies: 1 comment 2 replies
-
In your code X is the steps count. So in every interrupt you may add the X value to a micropython class In the So you have So in your stepper class you may at any time get the actual steps count value by something like: def steps(self):
for _ in range(self.qenc.rx_fifo()):
self.qenc.get()
return self.steps_count + self.qenc.get() which reads the RX FIFO as often as needed to get the next pushed value and adds the stored |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm trying t implement PIO-based stepper motor controller capable of driving _ 8 _ independent motors.
Seen quite a few approaches, but most of them use more than one PIO per stepper which doesn't suit my needs.
I know that I might be jus trying to implement something that's beyond capabilities of Pico Pi running micropython - so the first question is - is it at all feasible (given some concessions like max motor speed etc.) ?
So far I have managed to write such PIO method (after days of banging my head against the wall and reading all examples of PIO on the internet :D - taking some inspiration from https://github.com/ktritz/stepper_pio which unfortunately is writen for Circuitpython ):
And that works when state machine is provided with 32bit value combined by merging two 16bit numbers - first containing steps, second the delay. I calculate acceleration - full speed - deceleration array containing sequence of such values and retrieving them from within IRQ:
So that kind of works - probably using DMA would speed up acceleration phase (when IRQ is raised frequently),
I should also add direction pin support in PIO (sacrificing one bit form either step delay or step count). All hintns regarding those things would be much appreciated.
Though - my biggest problem for now is how can I keep track of the amount of steps taken so I can access them from within regular micropython code. Tried to add
push()
in the "loop" so I can userx_fifo()
and 'get()` and methods to increment the step counter accordingly, but that messes up Y register since I use ISR as a temp Y value storage so I can reuse it in consecutive delays in between the steps. Is it at all possible to keep accurate step count using only one PIO - and if so, how shall I modify the code to be able to do this ?Beta Was this translation helpful? Give feedback.
All reactions