Real Time Processing
Did you know that MIDI (Musical Interface for Digital Instruments) uses the typical Serial Port on a micro? You can interface and make music using pretty much any microprocessor!
MIDI is just Serial Data at 31250 bits per second (bps). By comparison, USB 2.0 is 480,000,000 bits per second! Still, to this day MIDI is the preferred method of transferring data between digital instruments!
Why? Because it’s cheap and it does the trick.
However because it is only at 31250bits per second! There is only a limited amount of data which can be throughput at any given time.
In music, chords, or groups of notes are commonly played AT THE SAME TIME! Since Serial Data can only transfer one byte at a time, how do we get three notes to be played simultaneously?
Answer: We can’t. We just output the three notes consecutively, and because the time between each note is miniscule (One On note is 3 bytes at 31250bps) 768 microseconds! about 1millisecond apart. This is something you’re not going to notice.
However, 1 millisecond for a microcontroller feels like an eternity. Even for a 40 MIPs/MHz processor, this is 40,000 instructions/calculations that it could do. There’s no need to waste these precious clock cycles!
What’s important in this case is that we use interrupts on the uP.
This is basically telling the uP to do:
- Send this data
- Tell me when you’re done
- (CPU goes at does other important things
By using interrupts, we can create a program that is quick to react to inputs/commands. These do not necessarily have to be human inputs.
There are problems with the above method.
You need RAM, and as much as you can get!
You need RAM or a memory buffer because, we need to queue up all the bytes we need to send. If we didn’t have this queue, we’d need to WAIT in a WHILE loop of some sort until all the data is sent! That means waiting 1 ms for each byte!
An analogy would be, imagine a bucket being filled up with a stream of water, to not lose any water, you need to get water out of it faster than it is going in. The stream can increase/decrease in volume every now and then, so for water not to overflow, you’ll need a big bucket! The bigger the bucket the better right?
So what am I going to do when the bucket gets full? What can one do? (Getting more RAM isn’t really an option!)
This is my objective for the day! I’m going to find a way to make sure no data gets lost and the CPU is still freed up to do what it wants!