Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:04 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Pimoroni Motor 2040

Author Message
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:46am 22 Oct 2022
Copy link to clipboard 
Print this post

Using the PIO for QEI (quadrature encoder interface)




Craig
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 277
Posted: 01:41pm 22 Oct 2022
Copy link to clipboard 
Print this post

Absolutely fascinating.  Is there any possibility of programming this with Micromite Basic instead of Python whilst keeping the PIO operational? Probably a big ask...
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 02:12pm 22 Oct 2022
Copy link to clipboard 
Print this post

  circuit said  Absolutely fascinating.  Is there any possibility of programming this with Micromite Basic instead of Python whilst keeping the PIO operational? Probably a big ask...


It's a question for our resident PIO wizards. I seem to remember Volhout doubting the possibility....dunno.


Craig
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 02:19pm 22 Oct 2022
Copy link to clipboard 
Print this post

The PIO would be ideal for 3-phase commutation, it's all state machine stuff and we already have lots of PWMs.  



Craig
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 07:58pm 22 Oct 2022
Copy link to clipboard 
Print this post

The PIO should be capable enough to read the quadrature encoders. The bottleneck is in the communication from PIO to MMbasic.
But now I have proven the MMBasic PIO EXEC works I am pretty sure we can do this.

The system would have to work like this:

The PIO would decode the quadrature encoders to a 32 bit number in the ISR (input shift register).

The control loop in MMBasic would run on a fixed frequency (SETTICK) and the interrupt would execute a PUSH instruction in the PIO forcing it to push the ISR into the FIFO. The MMBasic program reads the fifo, calculates the speed and current position, performs the PID and sets PWM accordingly.

So yes, it can be done with the current knowledge I have.

Multiple motors would require multiple PIO state machines, running the identical code.

The complexity is in time syncronizing of the MMBasic PID control algorythms. Not so important for independent axis, but more so for dependent axis (like running a car in a straight line).
Edited 2022-10-23 05:58 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 09:21pm 22 Oct 2022
Copy link to clipboard 
Print this post

  Volhout said  
The complexity is in time syncronizing of the MMBasic PID control algorythms. Not so important for independent axis, but more so for dependent axis (like running a car in a straight line).


Not a big deal. Should be able to handle 4 PIDs comfortably with a SETTICK 5 and then every 10ms, run the trajectory planner. Not much computation at all.  





Craig
Edited 2022-10-23 07:21 by Tinine
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025