| Posted: 02:40pm 08 Jul 2025 |
|
|
|
Phenix,
It depends on how well the MMBasic code is written. But almost certain, you would not loose any I2C data, since the I2C protocol is byte based. And the byte transfer happens in hardware.
But.
When you are planning to run multiple PID's that are fed from multiple I2C data streams, you may want to lower your expectations about the 1ms rate.
A single...maybe... with very tuned coding.
But multiple... most certainly not. MMBasic is interpreted basic. The PID will run. The I2C communication will run. But there is a lot of "glue coding" that has to happen as well. Convert the I2C bytes to 64 bit numerics (float or integer), convert the output of the PID to a PWM or DAC or whatever.
It all sounds simple (and it is) but for multiple channels it multiplies.
In average a pico can run 50k-100k commands per second. But if you want to run 4 PID's in 1ms, that is 12-25 basic commands per PID.
As an example (lets assume you get 4 bytes encoder position from I2C in array x%)
pos! = x(0) + 256*x(1) + 65536*x(2) + 16777216*x(3) if pos!>2147483647 then inc pos!,-4294967296 Just converting that to a float for PID takes 0.18 ms (positive pos!) or 0.24 ms (make pos! negative)
Maybe this can be done faster and simpler (phil99 will most likely jump on this one) but the essence remains. Multiple PID at 1ms.. not likely.
Volhout
Above timing is taken from a RP2040 running 252MHz, 6.00.02 MMBasic. But maybe there is a solution running the PID on the Quadrature decoder Pico. One PID per decoder should be do-able. Then the I2C output would be the PWM value for the servo. And through I2C you would feed it the new set point (and at startup the PID parameters). Distributed CPU power.. haha.. Edited 2025-07-09 01:17 by Volhout |