Sunday, December 19, 2010

MIDI Scooter...

It was only a matter of time...

I merged my MIDI-playing code with my scooter-driving code and put them both on the new, rad-hardened 3ph v3.1 controller. A brief summary of what exactly is going on here:
  1. Laptop program parses a MIDI file and I choose three tracks that look interesting.
  2. XBee radio streams MIDI data wirelessly to the motor controller.
  3. Motor controller uses the frequency of the MIDI note as the PWM frequency.
  4. Each phase corresponds to one MIDI track. Three phases can play three tracks simultaneously.
For kicks, here's the code for both ends of the system.

Because the PWM frequency is independent of the motor speed, this all happens more-or-less in the background while the regular motor control algorithm runs in the foreground. Meaning, I can ride the scooter around at low speeds without noticing any difference in performance. At high speeds, when the note frequencies get close to the commutation frequencies, bad things would happen.

The real motivation for this was to demonstrate just how much extra processing power there is to be squandered in this motor control setup. The MIDI routine now dominates both the processor usage and the data bandwidth. The motor controller itself, which is full field-oriented sinusoidal control, runs in the leftover gaps, and is still fast enough to execute a 1kHz current/torque controller. Yay 32-bit processors.


  1. I can see this being a saftey feature--electric scooters are considered by some to be 'dangerous' as they are silent...

    I don't see what the problem is--pedestrians are silent too--but SOME people do...

    I would so rock out to Bohemian Rhapsody on my electric scooter.

  2. Nice video!

    But I didn't get it how it actually works. You're using the tone freqency as a pwm signal and you say this is independent of the motor speed?

    Please check my blog to see what my point is.

  3. I guess the easiest way for me to think about it is as follows:

    Each of the three motor phases is driven by a PWM voltage signal, which flips from 0V to 33V, normally at 15.6kHz. The average voltage over one switching period is the duty cycle multiplied by 33V. So, with a 50% duty cycle, the average voltage is 16.5V.

    To control the motor, the average voltage is varied sinusoidally. The frequency of this sinusoidal signal IS proportional to the motor speed. But this frequency is much lower than the actual switching frequency of the transistors. For example, if the motor is spinning at 500rpm and has 14 poles, the commutation frequency is just 58Hz.

    The sound is produced not by the commutation frequency, but rather by the transistor switching frequency. I use notes in the range of 500-8000Hz instead of the 15.6kHz "silent" PWM. Since each of the three phases has a separate PWM frequency, it can play three notes simultaneously.

    And yes, the sound is being produced by the motor itself. The small vibrations created by the current ripple in the phase coils can be easily heard, just like the high-pitched whine of a cordless drill motor with a cheap speed controller.

  4. Hey, the link to the code is broken. If you still have the code could you fix the link?