Hello,
currently I try to use a stepper motor on a raspberry pi with raspbian os.
The programm I write in Lazarus (of course:-)
As hardware driver I use a Adafruit stepper card, which contains a PWM driver for each motor connector, the PWM driver is accessed via I2C. I have trouble with lost steps and wonder if correct positioning is even possible in such a configuration. The first problem is that the change between pin-high and pin-low for each motor output is quite time consuming, even theoretically I can't even reach a speed of two revolutions per second (snails are faster...):
2 byte per channel for the on-time and 2 for the off-time = 4byte;
4byte * 4 channels = 16byte per step;
1 byte register address for each data byte: = 32byte per step;
8bit per byte = 256 bit per step;
I2C-frequency 100000kb div 256 = 390 steps per second
Motor with 200 steps per revolution -> 1,95 revolutions per second
And these are idealized values as most of the time the outputs are in an intermediate state (always 2 outputs have to change in the same moment), which takes much reliability. Normally there should be delays in between each change. Increased I2C datarates resulted in transmission errors.
Now there is a further problem, the above calculation doesn't consider that the processing task may be interrupted by the OS.
And here comes my question:
Is it possible to temporary prevent to OS from interrupting the programm flow? So that at least both pins are switched directly one after another and don't stay in the intermediate pin state for too long?
Is it possible, if the hardware access is done in a seperate thread, that the thread is assigned to its own core on the raspi and thus may not be interrupted by the OS? the GUI, of course still has to work when the driver is busy.
In my tests (but with blocked gui) I nearly came to the 2 revolutions per second, so could be that this is no actual problem, but it doesn't seem like a robust design.
Thanks!
Regards