Motors singing in harmony - Playing Pachelbel's canon from motor controllers!
Technically I did this last Saturday, but I was too lazy to upload the video with my ridiculously slow internet.
Anyway, here it is: the ballbot playing Pachelbel’s canon (AKA Canon in D) with it’s motors by changing the PWM frequency for the motor controllers! Only the first dozen or so bars are played since this is one of my earlier revisions of the program.
And yes, I still don’t have my 18650 battery holders, so I’m using a 4s lipo.
Unfortunately, most of the PWM pins on the Teensy correspond to one FTM timer, and so the PWM frequency of any of the 3 motors needs to be the same at the same time. This explains why no two motors are ever playing at the same time.
|Timer||PWM Pins||Default Frequency|
|FTM0||5, 6, 9, 10, 20, 21, 22, 23||488.28 Hz|
|FTM1||3, 4||488.28 Hz|
|FTM2||25, 32||488.28 Hz|
Eventually I stopped playing with the music at the end of the day, and I did get get two motors playing different notes at the same time by using a separate timer, FrequencyTimer2.
On the software side of things, I used an interrupt that acted as a metronome, except my metronome was ticking at every semiquaver instead of crotchet. I treated the semiquaver as the fundamental unit of time and created 3 large 2D arrays for each of the motors to play (the first element of each row corresponding to the frequency and the second element corresponding to the number of semiquaver beats to be played). You can find all the functions and routines I wrote here.
WARNING: If you try this, your motor controllers can get VERY HOT due to the low frequencies that you need to be operating at. See http://www.phy.mtu.edu/~suits/notefreqs.html. Eventually, one of my motor controllers burned out the day after, though I’m not sure whether this was the reason.