Playing soundfile and driving stepper motors at the same time?

Status
Not open for further replies.
Hi there, I am working on a project where I want to synchronize triggering playback of sound-files with the movements of two stepper motors.

Things are working but when playing back a sound-file, the steppers will run slower and with a different tone. I assume its the interrupts from the sd card that is causing this?


So the question: is it feasible to run two stepper motors and playback a sound-file at the same time?
There is also some other audio synthesis being done but that has no effect on the behavior of the steppers.

Teensy 4
Audio shield.
Accelstepper
Trinamic TMC5160 Stepper driver being run in step mode. (Has to be initialized over spi)

Thank you for any advice!
 
Thank you for your reply.

Unfortunately this library is not yet out for Teensy 4 although luni64 say they are working on it. As it is now it will not compile for Teensy 4.

Any other suggestions as to what may cause this and a possible path towards a solution?

Thank you!
 
Accelstepper relies on calling some function (run()??) as often as possible. If other software blocks too long run()? may not be called often enough which slows down Accelstepper. You can try to call it via an intervalTimer instead of calling it in loop.
 
Accelstepper relies on calling some function (run()??) as often as possible. If other software blocks too long run()? may not be called often enough which slows down Accelstepper. You can try to call it via an intervalTimer instead of calling it in loop.

Alternatively, it's possible to use DMA to read from the SD card, which might help.
 
Hi all, putting the two run() functions(for two steppers) inside a function and calling it from an intervalTimer seems to have helped the issue.

I have tested it quite a bit now and it seems to be able to operate all the other functions and synthesis this program does as well with the interrupt running. The only thing I have noticed is that if I play two soundfiles at the same time I seem to run into a bottleneck with the serial communication from my computer, I must then slow the rate of messages. This is only used for testing (using osc encoded messages over SlipSerial) so it doesnt matter for the final project.

Thank you so much for your help and suggestions!

Luni, I must say the performance your library seems to have is enticing, hope to see it for Teensy 4:)

Thank you again!
 
Status
Not open for further replies.
Back
Top