Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Playing soundfile and driving stepper motors at the same time?

  1. #1

    Playing soundfile and driving stepper motors at the same time?

    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!

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,979
    Could be something in the code not shown ? - conditional delay() or other?

    @luni has this Stepper driver code that works well on Teensy AFAIK :: github.com/luni64/TeensyStep

    … might offer better results if usable.

  3. #3
    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!

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    811
    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.

  5. #5
    Quote Originally Posted by luni View Post
    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.

  6. #6
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •