ROCKIT2010-03-28

8 Bit Synth: The Microcontroller: Part 2

In the first microcontroller post, I discussed the reasons why I chose the Atmel AVR 164PA.  Now, I'd like to delve into this microcontrollers feature set.  The 164PA, as the name of the project implies, is an 8 bit microcontroller.  What does that mean?  Well, it means that the bus width, that is the length of a unit of data inside the micro is 8 bits, or 1 byte.  This is a fundamental limitation.  It doesn't mean that we can't deal with data larger than that, but that this microcontroller really isn't designed for it. As a rule, when working with an 8 bit microcontroller, unless you're prepared to deal with the consequences in terms of clock cycles, we should try to avoid doing 16 or 32 bit math.  Some higher bit depth math is inevitable, but we should a least feel a little bit guilty when we do it.  Aside from this fact, the 164PA is like many other microcontrollers, 32-bit, 16-bit, and of course 8-bit.  It can perform mathematical calculations and has various ways to interact with the world outside. Follow the jump for more discussion of micro features.

The 164PA is capable of running up to 20MHz and can perform 20million operations per second and is designed to get through 1 instruction per cycle.  It comes with an internal oscillator capable of 8MHz.  That's not great.  It'd be great if the oscillator could do the full 20MHz, but we'll have to use and external crystal.  It's just as well, because most internal oscillators have a fairly large tolerance range.  I've seen some microcontollers with a lousy 4MHz clock with a 20% tolerance.  In our case, I'll provide a crystal with a low ppm at either 18.432MHz or 20MHz.  We need all the clock cycles we can get and the tolerance will have to be tight to get good on key frequencies out.

We've got 16k of RAM, or program space. 1k of SRAM for variables and use by the micro when it's running.  And 512 bytes of EEPROM which we'll use to store and recall patches.  I haven't determined exactly how many are going to fit, but we'll need one byte for every pot.  Buttons may be able to share a byte.  We'll see.

One nice feature that you don't always see is a hardware multiplier.  The 164PA can multiply to 8 bit numbers in two clock cycles.  That's pretty good.  Usually, multiplication is a series of shifts and additions which can take some serious time.  Getting it done in two clock cycles makes including multiplication in your code less of a worry.  I haven't completely determined yet, but division appears to take a relatively short amount of time as well.

The 164PA has two 8 bit timers and one 16 bit timer.  We'll be using these to generate the synth's sample timing and the timing of things like the LFO and envelope generators.  Three timers is probably bare minimum, although it's probably typical for cheap microcontrollers.  Some will have only one and others will have six.  You can't ever have too many, but constraints make us clever.

We've got 8 channels of 10 bit Analog-to-Digital converters. This isn't enough for sixteen knobs without some kind of multiplexing. As of this writing, I use two 8-to-2 multiplexers to read the pots.

Finally, we have a bunch of hardware communication interfaces.  There are SPI, I2C, and a pair of UARTs.  What these are in particular, I'll get into in later posts, but we'll be using two of three to get the job done.

Aside from that, there are some power saving features which we won't need unless we wanted to make it battery powered or something.  That's the most of it.  Check back for the next part in the series when I discuss configuring the microcontroller.