Wednesday, August 25, 2010

3ph HD: I'm serious about this MIDI thing,

While I've been waiting for the circuit boards for the 3ph HD, I could have been porting every piece of code I've ever written for microcontrollers over to the STM32F103. At least, all the things I would need to make a functioning motor controller: clocks and timers, PWM output, digital I/O, ADC, UART communication, interrupt handlers. All of that. It's a known unknown. In other words, I know what I have to do and I just haven't spent the time scouring the 1,072-page reference manual for all the right register and bit names to make that stuff work.

The "clock tree". Page 84/1072.

After I wade through the fundamentals, I'll also have to port over the actual motor control algorithm. It will be indistinguishable from the controller currently implemented on the 3ph Duo, a modified version of something called a synchronous current regulator. If you're really really interested, I updated my documentation of the control scheme to include some fun new graphs.

Oh, I get it now.

Enough of that.

Instead, I've been working on the unknown unknown: how to encode the three tracks of music to be played on the three phases of the motor? I settled quickly on MIDI, for two reasons. One: It efficiently encodes the type of audio I want to play, namely three tracks of music. No vocals. No intermediate frequencies. Just what you can find on the keys of a piano. I'm not saying you can't send pure audio to the motor (just use it like a speaker), but my goal is to replicate 8-bit video game music, which is a simpler format. Which brings me to the second reason for using MIDI: Tons and tons of 8-bit music libraries.

And yes, I have picked out the first test song. I've pretty much had the first song picked out since before I started the project. It's known only as "Track 1" and is from Top Gear for the SNES. (Trivia: The first video game I ever owned. It came way before the car show.) It's also got one of the best 8-bit soundtracks ever. If you don't believe me, ask Muse.

Time for another VB GUI, to piss off my programmer friends.


I must admit, I enjoyed writing a MIDI file parser. It's nice when you write code that won't cause things to blow up or fall over if it doesn't work. If it doesn't parse correctly you just...try again. Is this what I passed up by not pursuing my early career ambitions as a programmer? Risk/danger free debugging? Anyway, I know it's right now because the length of time of the parsed data is the length of the song, and I can see from the note visualization that it's at least got the general melodic form of "Track 1".

MIDI is actually pretty easy to parse, if you don't care about anything other than notes. Every event has a delta-time stamp. By incrementing an absolute time counter while stepping through the file, every note can be assigned an absolute time stamp. This is what I will send to the controller: [Timestamp, Note]. Since the controller can't store a full song in RAM, there will be three streams of this and some yet-to-be-determined buffering routine, but that's essentially the plan. There are "note on" and "note off" commands, but I'll lump everything into one packet format and send an inaudible frequency like 20kHz as the "off" note.

Now I should get back to the motor controller part...

2 comments:

  1. Google took me to this old post. That is one sweet project! Well conceived, and well done!

    ReplyDelete