The Great Microcontroller Showdown '10

12/28/10 | by Jfkfhhfj | Categories: Informative, Tips

Micro’s come in many shapes and sizes nowadays, what was once very simple and specialized comes in all sorts of packages with all sorts of peripherals and features. Over the year I’ve put together a healthy collection of many different platforms and devices and I’d like to share my experiences with all of them. I do not claim to be an expert of all the controller lines below, I work mostly with PIC and have a good amount of experience with AVR,I also work mostly in assembly and do little high level programming. However, I still have done plenty of research and I hope I can offer advice that helps.

The way i'm going to do this review is go over several important categories when choosing a controller, generally I see this as most important to least, however some things are interchangeable depending on the target audience and device.

What type of support do outside communities offer/how good are manufacture documents
Programmers (including emulation)
How easy is it to get your code on your chip and to make sure it works.
How easy is it to write your code.
Languages (including assembly and high level)
What the hell are you writing.
How big of a loan will you have to take to finish your death bot of doom.

General architectural things will be discussed throughout the review as well in non particular order. (I.e. I will be going on rants and diversions)

With all that said, let the games begin!

Microchip PIC

The first series i will be going over is my favorite. Microcontroller’s Pic architecture is very intuitive and great for hobbyists. It’s a very minimalistic approach to microcontrollers. Everything about a PIC is simplistic, the assembly, the programing, and the IDE. There is very little which is a hassle to do. For beginners, I always recommend PICs since i feel they’re the easiest chip to get started with. The PIC comes in many different varieties including the PIC10, PIC12, PIC16, PIC18,PIC24, PIC32 and DSPpic. The most commonly used lines are the PIC16, mid end 8 bit processor and their flagship PIC18 high end series microprocessor.

Microchip has always been about the hobbyists, they offer great support and they have tons of great documentation. I personally feel their data sheets are some of the best. Always well organized and very well written. They always supply good code examples in both c and assembly so you spend less time trying to interpret what they’re saying and more time programming.

By far the PICKIT is the best programmer available. It will program all of microchip’s products without hassle, has on board power source, its USB and very portable. Also the pickit supports debug features.


There is something really nice about MPLAB, it’s a small download, and it works, very well. It’s a very bare bones ide, but it gets the job done extremely well. Everything is intuitive and whether you’re managing a huge project or writing a small assembly code. MPLAB just works. Simulation is a breeze as well; MPSIM works great and has everything you could ask for. The biggest gripe with MPLAB is that it is rather old and some ancient features will come back to haunt you. For a while if you weren't building in a project file path lengths had to be kept under a certain number of characters, this wasn't fixed until recently.

Microchip’s assembly is very minimalistic, on most lines it doesn’t support fancy indirect calling, or software controllable stacks or sometimes even branch instructions(PIC16 has no branch), but for what it’s worth, Microchip’s assembly once again just works. It’s very intuitive as far as assembly goes. Although most people hate the idea of a working register I feel it defiantly simplifies things since we can address all SRAM with it. (no specialized move instructions). Interrupts are simple since there’s only one or two vectors. Indirect referencing is done via a INDF register and a FSR register (one hold the memory address, other holds the contents). Higher level series such as the PIC18’s have indirect referencing to program memory through table instructions but they can be cumbersome. The biggest downsides to PICs are the segmented memory banks. Although on the PIC18’s this isn’t much of an issue when you write small programs,on larger projects it can be a real pain in the butt.
Again I’ve done little programming with C, but microchip offers a limited C compiler for most of their micro lines. As far from what I’ve seen, it works and it’s C, what more could you ask for?

Microchip is great when it comes to cost, if you’re a student they offer a hefty discount on their programmers and will send you free chips through their sample programs. Otherwise prices are pretty standard.

Links: - Microchip's Home Page - MPLAB download link - Sample device page - Link to sample program - Pickit 3 programmer


AVR is an industry standard microcontroller and regarded as one of the best. If you want simply the most powerful microcontroller in terms of functionality, AVR is for you.

Atmel’s support is second to none; if you can manage their website you will find documentation on everything. These guys have some of the technically best datasheets out there. With that said, technically best isn’t always the best. Their datasheets can be a chore to read through at times, but you defiantly get the full picture. Also unlike microchip whom include all their supplementary data in their device datasheet, things like instruction set summaries are supplement documentation and you usually have to hunt them down. (That’s what Google is for). AVR also has generally pretty large communities behind them (*cough* AVRfreaks *cough*) As well, they’re the go to micro in industry and university.

*bangs head on desk* the most frustrating aspect of any AVR chip is programming the damn thing.
There is no one programmer from ATMEL that will program all their chips. Some use ISP some use JTAG some use god knows what. The best thing to do usually is grab a JTAG programmer off of ebay and stick to an ATMEGA series chip. Most AVR microcontrollers support several programming options, this is nice however can bit a bit confusing at time (see above :P). The most common interface is ISP which is your standard In-Circuit Serial Programming.AVRs also support JTAG and other high voltage serial/parallel programming algorithms.(check out the data sheets) You can buy the 40$ AVR Mkii ISP and be able to program most if not all of their stuff. Programming through ISP can be a nightmare especially if you set the wrong fuses and brick your chip (very easy to do). Also ISP is very finicky with the programming speed and sometimes doesn’t work. I’ve even had issues with JTAG. Many times if the proper power up sequence isn’t followed the chip will refuse to talk to the programmer. This is by far the worst experience with AVRs but once you figure out the kinks of whatever setup you have, it’s usually smooth sailing (until you F$*#K up the fuses).


AVR study hands down is one of the sexiest worksuites available for a micro. It’s just sooo shiny. And then it crashes. But really, AVR Studio is a great IDE and it’s the complete opposite of MPAB IDE. It’s a bit of a PIA to download and update (requires registration and multiple service packs) but it’s a fully featured modern IDE. One of the biggest problems with MPLAB is how ancient it feels and looks, with AVR Studio this is not an issue. As an IDE it does everything you could want it to do, everything is intuitive and when emulating there are just some really nice features that blow any other IDE out of the water. It’s a great IDE, just wish they would iron out some of the bugs.

AVR assembly is both its greatest strength and weakness. In terms of sheer power, the AVR assembler is unmatched and the language is almost flawless. However, there is a steep learning curve associated with AVR and it’s assembly language. This mostly has to do with how it’s memory is arranged and mapped.

AVR memory:
Like all processors we have our CPU, Ram and Rom. In an AVR our program memory is 16 bit long and that constitutes our word length, this program Rom is accessible through our Z pointer. (and our LPM and SPM instructions). We can use program memory to both store instructions as well as ROM lookup tables. By using the .db(Define byte) and .dw(Define Word) we can load Rom with values at assemble time. This is mostly due to the power of the AVR assembler and ability of the Z pointer to indirectly reference program memory. This is an extremely useful feature.
Now the AVR RAM is a bit peculiar. The SRAM is mapped linearly and broken up into sub blocks. We have a General Purpose Register (r0,r31), I/O space (Our IO ports and Special function Registers) and our Data SRAM (everything else). Data SRAM is where we hold our system variables and where the stack pointer resides. Another really powerful aspect is that with AVRs we can use our PUSH and POP instructions to load the stack with system variables as well as control program flow.
However there is a downside to this implementation. Depending what sub block we are addressing, determines which instructions we use. We can generally address any space with our GPRs, however if were loading to IO space we use the in and out instructions, and if we load to data space we use lds and sts. Moving between GPR is done via mov. If you program a lot with AVR, this actually isn’t too bad, and preferred in some cases (prevents data corruption). However, it’s all a gimmick. The memory space is completely linear, there is no reason you can use an out instruction to load to a GPR to data space, it’s the same memory and in some cases you can(play around with it its fun)! The only thing preventing you most of the time is the assembler itself. Because of all these different instructions to do the same thing it can get rather confusing (SBIS, SBRS). For beginners, I do not prefer AVR assembly and I think at times it can be really counter intuitive.
With a PIC, the memory space is linear. Although we have a working register W0, there is only one Mov instruction (From and To W.) which addresses all RAM.
With that said, AVR assembly is great if you know what you’re doing, it’s extremely powerful especially with things such as software stack and its indirect referencing system, but for novices it can bit a bit much.
C, is a completely different story. One way which AVR blows microchip out of the water is through its C compiler and general C support. Out of the box AVR studio works with C and uses a GCC compiler so for those Linux guys they’re covered as well. This is where Microchip could learn from ATMEL.


Here is another gripe I have with AVR’s. And it mostly goes back to programmers. There really is no one programmer that does it all, and because of this the costs associated with developing with AVR chips can be quite high. If you use the ATtiny line, you need an ISP programmer if you use ATmega you need a JTAG programmer and if you use anything else, well good luck. Although programmers can be chopped together easily, it’s nice to be able to buy something from the company that you know works (Instead of relying on Chinese clones). Also ATMEL’s sample program is almost nonexistent, you gotta buy all the chips you use, So no love for students.

With that aside, the costs aren’t tremendous, you can get an ISP programmer for around 40$, and the chips themselves are never more than a few dollars. However I wish ATMEL made more of an initiative to make things a little bit friendlier.

Links: - Main website - AVR ISP Mkii programmer (for ATtiny Chips) - Sample product page List of all their products and features.

*This concludes the part of the article of the chips I actually know a bit about, please only use the following for reference*

TI Launchpad MSP430

This is TI’s attempt at getting back into the minds of hobbyists. This line is meant to be cheap affordable and no frills. The actual processor is built around a simple but powerful assembly language and has very barebones peripherals. TI released an evaluation kit for the MSP430 called the Lanuchpad which main feature is that it only costs 4.30$ and includes theoretically everything you need to get started.

There seems to be a good amount of support documentation floating around, and TI does a decent job of providing a good amount of documentation. Ti is really trying to make a push into the hobbyist market and offers a wiki for their launchpad product.

Programming depends on the device but for the value line, programming seems to be done via a serial interface. The launchpad evaluation board has a programmer and emulator onboard, so that should be all you need to get going. It will also program other MSP430 devices and not just the value line.


TI provides a link to IAR embedded workbench, which works, most of the time. It’s a decent toolsuite, but doesn’t hold a candle to dedicated suites such as MPLAB or AVR studio. (and it just crashed on me... $*$#@!!!)

I haven’t had much time to play with the assembly, but from what I see, it truly looks very “modern.” We have a very small instruction set, but we also have some really powerful assembler directives that allow control of the stack and the ability to easily create ROM tables. It’s the best of both worlds. It’s a really nice step in the right direction with a nice core.

4.30$, its cheap and for that it’s worth it in parts alone, if you can get an IDE to work with it, it’s a great chip which has a lot of potential.

Links: - Launchpad Wiki - Buy it - Datasheet for value line chip

Parallax Propeller

This is quite possibly one of the most interesting processors I’ve ever come across. Parallax builds its processors around “Cogs” or miniature processor cores. Each processor has its own peripherals, shares IO and has access to main memory in a round robin fashion. A typical propeller has 8 cogs which can run at an impressive 20 MIPS, giving you a total of 160MIPS per chip. I’ve found that this chip is defiantly nice and very impressive especially coming from such a small company like Parallax, but I still have a hard time seeing exactly what its really good at. It seems the processor is much geared mostly towards game development (each core has its own video genorator).
There are also a few quirks you should be aware of. First off, there is no rom, so all programs are run off of the ram. Unless you have external EEPROM, every time you reset the chip your program is lost. Part of the startup routine includes looking for external EEPROM and automatically loading its contents into RAM. Another quirk is all the IO is shared via each processor core, not only that, IO control is OR’d with each COG, so things can get pretty messy. Really, you have to check out the documentation for this chip because it is very interesting.

Parallax is a very small company but their effort is the same as any other large companies. Their datasheet’s are pretty informative and they have just the same documentation you come to expect. Their website is pretty informative and easy to navigate and it’s a breeze getting everything you need to get up and going. However i've yet to find any real support online like there is for the other processor cores mentioned.

Programming of a propeller is done via serial and you can use any USB to serial adapter to do this. The one provided on their website is incredibly cheap and nice and compact. Because of the onboard bootloader, things are pretty no frills here.


You can download the free Propellor Tool from Parralax’s website. This is a super simple IDE, again no frills, just what you need to get things working. The best thing about Propellor Tool is the sheer amount of reference code that comes with the IDE. You’ll have plenty of examples for both the SPIN language and assembly. Once you can figure out what you’ll use your chip for, you’ll have no lack of reference code to tear apart.

The assembly is pretty standard and does everything you expect it to do however programming for a multicore chip is rather, interesting. Essentially each cog has its own RAM to store its program, while the main system RAM holds your main program. Using a SPIN command you can enable a new processor and you set the origin address of the assembly you would like it to load. On startup, the cog will take that code from the main memory and dump it into its ram. This usually takes a little while but allows each cog to independently run its own code.
If you don’t feel like dealing with that, you can use the high level SPIN language which is a combination of C, BASIC and some really interesting preprocessor directives. I haven’t used it much but you can do some really powerful stuff pretty easily. One of the interesting things is this processor support direct driving of a composite video signal and has instructions to generate text to any NTSC TV set. Pretty cool stuff for a little micro.

The propeller is defiantly an expensive chip, but you’ll only need one and the chip is pretty much all you need to get going. If you want to grab a chip “programmer” and eeprom from parallax it’ll run you about 20$ shipped, which isn’t bad at all. So it’s an expensive chip, but that’s only because of the sheer amount of stuff you get in that little hunk of silicon.
Links: - Parallax main site. - General Information for the propeller,ProductName - Buy a Propellor here - Programmer here - Datasheet here


Ardunino is a hit with the hobbyist community. Combine open source, with tons of support, tons of code, high level language and a super simple interface and Arduino is what you get. Arduino Is essentially a bootlaoder for the popular ATmega series of chips made by ATMEL. Arduino is nothing more than a wrap for AVR chips and a philosophy, provide the support and the hackers will come.
However, there is a dark side to Arduino, with the simplicity a high level language offers, it also brings forth hacktronics and some pretty shoddy engineering. If you’re someone with little electronics experience and you want something cool to play with, Arduino is for you. If you’re an EE who wants to learn microcontrollers I recommend Arduino AFTER you learn a more substantial core. Then you can use Arduino as a powerful development tool and not as a crippling toy. (Seriously what did you expect from someone who prefers assembly over C?)

Go on any major hobbyist website/hacker community and if you can’t find support for Ardunio you’re doing something wrong. Unlike the corporate driven datasheets and reference documents you will find hacker guides and tons of support from people who just love to hack. The Arduino website is chock full of information as well. This is the beauty of open source, the wealth of information.

Arduino is programmed via USB and usually when you get your Ardunio board it has a USB header on it which is all you need to upload your compiled programs.


Arduino’s main IDE is a simple .jar program which is cross platform and extremely minimalistic. You write your sketches and compile them onto your Arduino and off you go. Nothing more is needed. Support for outside compilers is plentiful aswell. No matter what platform you run, you can program with Arduino.

Arduino is prized for it’s C like language which is incredibly high level and very powerful. Open source libraries add everything from sound generation to image processing and everything between. Find your library, learn some simple commands and that’s all you need to get going with Arduino. If you actually care what’s going on, good luck(:P).

A typical Arduino board will go for around 20$. Part of the Arduino philosophy is the idea of shields. Stack-able modules which connect to your main Arduino board and add features such as sensors and other peripherals. Shields can range from cheap to expensive depending on the functionality. Arduino is very affordable for anyone to jump right in and build some pretty impressive electronics.

Links: - Main website - Programmer - Arduino Uno, latest board


The holy grail of microcporcessors. These processors are in everything from your Iphone to your toaster. However you’ll never find an ARM chip. ARM simply licenses its processor core for companies to modify at their leisure. At its heart ARM is a general purpose RISC processor.

The first part of developing with ARM is finding a vendor and figuring out what support they offer. ARM platforms can range from elaborate to very simple and can be an evaluation kit or just a dip chip. Typically ARM processors interface through JTAG or serial and you upload binaries into the Rom.


Programming is typically done through JTAG or serial and varies from manufacturer to manufacturer (Hint, find one which works first)

Varies from manufacture to manufacture, however anything that generates ARM binaries can be used (usually).

Typically c is used when programming with ARM however an extensive assembly language is usually provided, I’ve yet to find an appropriate assembler.

Developing with ARM can be a costly experience or it can be dirt cheap, it just depends on how much time you’re willing to spend banging your head against your desk and wondering why you can’t get the damn chip to work. Unfortunately, if you’re working with ARM you’re already provided with everything you need from whomever you’re working for. If you’re trying to work with ARM you have a lot of research ahead of you.
Links: - main ARM website - Platform based around ARM Cortex m3 processor - Best source of information about ARM - Really cheap ARM eval board.

Have fun..

So which is the best?

Honestly, there is no best, nor is there a worst. The best thing sometimes is just to pick a chip and just start working with it. What you should do is rather than pick the “best” or “easiest” chip, pick what works for you best. Also instead of learning what a chip CAN do, learn what a chip CAN’T do, because often times this is what will limit you the most. Understand a chip’s limitations so that when you come across them you know how to deal with them. In either case, happy programming!

I hope this article helped to shed light onto the subject of different processor brands out there. I know my knowledge isn’t complete so I hope anyone who would like to shed light on the caveats I skimmed over to do so. I will gladly add more processors to this list as I come across them and I look forward to updating the sections I glanced over. Even with these faults I hope this serves as a nice intro guide into the world of different processors.

Any questions comments or concerns, email me at


Super Cap Solar Bot Pt1: Ideas and Power

11/28/10 | by Jfkfhhfj | Categories: Projects

It's been a while since i posted a project but i think its about time we make use of the tools we have.

I've always wanted to make a simple bot and it should be no surprise that i'm in the solar boat club, so i figured i would combine the two.

I have a small 5W panel in my lab; its too small to directly power any significant equipment and too small to let set on a desk and do nothing.

Usually panels like these are used to passively charge lead acid/whatever batteries. They provide around 12V and usually more than enough current to charge a decently sized battery in a few hours.

However, i wanted to do something different, i wanted to use the panel to power a small robot that had a backup power source. If i made the systems efficient, i wouldn't need that much power to make it move about.

The obvious choice for a backup power source is a battery, although this is true, batteries get a little pesky because you need charge controllers for them. I could design one, but they're not the most thrilling things in the world to build and design.

A better alternative is a capacitor bank. If i stick to my rule of only using minimal power to get about, a capacitor bank makes sense (especially considering how easy they are to charge)

The biggest problem with capacitor banks are the less than spectacular energy density they offer. Energy density is how much energy a medium stores per unit volume. A battery will give you much more energy per unit volume than a capacitor, thus for equal amounts of energy, you need a larger bank (significantly larger). Enter the super-capacitor

Super Caps:
Super-capacitors offer much superior energy density compared to an electrolytic capacitor. The capacitors I am using for this project are 5.5V 1Farad capacitors from: Which you can find here:

Props to for sourcing such cheap and powerful capacitors.

Lets compare the energy densities of our capacitors:

We recall that energy stored in a capacitor is given by the following formula:

We can see that the super-cap has a 100 fold increase in energy density over the electrolytic cap.

How does it do it?
Super-caps are really a hybrid between a traditional capacitor (Separation of plates) and a chemical battery. The key is with super-caps, to use nano-scale barriers to separate our charge, increasing surface area. We also use the space for the dielectric to hold charge (where the icky chemical part comes in). These two things combined help increase our energy density. There is one downside, super-caps sacrifice the ability to store large voltages (because of the nano-sized gaps), have increased leakage currents, and take longer to charge than conventional capacitors. However the ability to store much more energy is worth it.

So why super caps again?
Even at 100 joules per cubic centimeter, a typical alkaline battery dwarfs it at 1100 joules per cubic centimeter. However, the ease of charge and use of a super capacitor bank makes them very attractive. Also another thing to note. Capacitors deliver instantaneous current at rates much higher than a battery. Although a capacitor has lower energy density, the power density is much greater for a capacitor, it can discharge its entire energy contents in a fraction of a second while batteries take seconds to discharge completely. (This of an explosion versus a slow burning match)

The Goods
Each super-cap holds 12 Joules of energy at 5 volts. A typical AA holds about 1kj of energy. So to match the capacity of a AA battery i'd need on the order of 100 super-caps. (Not on my budget) Luckily, we don't need 1kj of energy for our robot, we only need enough energy to move the robot (not far).

For this bot we have 30 super-caps:

They came packed in a tray very well via first class mail. My order got here in a few business days (not bad for free shipping)

Just like electrolytic capacitors, super-caps are polarized. a word of caution with these however. Because of how thin the are, the manufacturer didn't leave enough of the marking band on to show the polarity of the caps (and the leads are equal length). However, it should be noticed that the side with the dimple is + and the flat side is -. Thus in my picture above, the capacitor is facing with the + terminal upwards.

The Pack

For this project we are putting our 30 1Farad capacitors in parallel for a 30F pack, this yields us 375 joules. A little more than 1/3 of a AA battery. Still quite a capacitor pack.

In this bank i have the capacitors in an alternating pattern to put them all in parallel like so:


Once you hook all the + together and all the - together, the pack is in parallel.

The backside of the proto-board looks like this: (to give you an idea of how i wired it)

The Idea:
Although 5V isn't a huge system voltage, its convenient for our micro's and motors. at 5v our motors are self-current limiting. They don't draw as much power at 5V as they do at say 12V, this is nice for current limiting. The biggest reason is that these caps are rated at 5V and i'd prefer one large parallel pack rather than a combination of series and parallel.

So, our source of energy is our solar panel:

Solar panels provide power by converting photons into electrons (kinda) Each panel has a few ratings. The open circuit voltage (Voltage between bare terminals) the Short circuit current (Current through a short) and the maximum power point.

For maximum power you want to keep the load of the solar panel at this voltage current point. Since i don't have money for a maximum power point system ill do one better, a switching power supply. Although not a MPPT system, with my switching power supply i can adjust the load on the capacitor bank to adjust the load on the panels, thus with some math and some good logic i can easily implement a sudo-MPPT system using a cheap little switching power supply chip.

I will be using the LM2674 buck converter IC to convert the panel voltage(anywhere from 0 to 18V) into 5V. The advantage of a switching power supply is that it works for a wide range of input voltages and is very efficient.

(Thanks to nat semi for the samples!)

So that covers the power system, i'll be using a 5 watt panel to charge a 30F capacitor bank via a switching power supply.

The logic:

For the logic on this project i will be using a PIC18F. What model i don't know, but what i would like to do:

-Analog input for sensors (LDRs, color sensors etc)
-Serial In/Out for radio/infra red communications
-PWM out for motor drive

A potential candidate is the PIC18F26J50 i recently sampled a few and after checking them out i'll make my decision.

I also might be introducing the use of C to program. For robots C is ideal because we have to use complex data structures but we don't care how long it takes to process them.

Whats next?

I have to begin fabricating the robot's chassis and i will begin testing the power systems. I have to implement a charge controller on the Cap pack and begin designing the mechanics. So stay tuned!

Also any feedback is appreciated!


A new beginning

04/30/10 | by Jfkfhhfj | Categories: Code

Recently I've had the wonderful opportunity to TA ESE 123 at Stony Brook University with Professor David Westerfeld. Over the past semester I've been working in the student lab, helping with their assignments and lab tasks. For the second half of the class however, the students were to build a digital clock combined with a USB charger. The project took advantage of AVR mirocontrollers for the digital clock part of the design. Being a freshman level class, it would be a daunting task to teach not only basic electric theory, but combine that with basic microcontroller theory combined with learning assembly. I decided it would be best to write a handout that went over all the basics of computation theory, microcontrollers as well as completely outline the hardware and software aspects of the digital clock. The resulting document is about 30 pages of insight, knowledge and experience all dedicated to the project this semester of ESE 123. The audience of this document is the beginner and expert alike, I hope that anyone who reads it learns something new.

Attached to this post is the full handout, it introduces a new line of hardware for this blog, the AVR series of microcontrollers. The specific chip used in the project was the ATtiny48 microcontroller. I am also attaching the full commented code.

Get the full writeup here: Write Up
Grab the code here: Code

*Note, the code was written by Professor Westerfeld and cannot be used without his consent.


Introducing the PIC18

12/22/09 | by Jfkfhhfj | Categories: Informative, General

I figured it'd be a good time to move to a more capable microcontroller as the projects on the blog seems to be getting more and more complicated and lets face it, keeping up with our PIC16 and their limitations can get a little annoying when you're moving lots of important data. We need more pins, we need more features on the chip and we need better instructions.

Enter the PIC18 series from microchip.

The PIC18 is the most high end 8-bit microcontroller that microchip offers. It has many advantages over the lower end PIC16s the biggest being a new and improved instruction-set and memory management system.

I suggest you take a look at a datasheet for a PIC, everything in this article will reference:

A new memory system:

The coolest thing with the PIC18s is an Access Bank system. In this system the MCUs RAM is divided up into 16 banks (0-15)> Each bank has however many memory addresses(Depending on PIC, for example the PIC18F1220 has 256 byte banks) and you select which bank you want with the BSR (Bank Select Register). This sounds awfully similar to ram-pages of the PIC16F however its the access bank delimiter in the opcode that makes life so much easier. The access bank is the first 128 Bytes of bank 0 (Our General purpose registers) and the last 128 of bank 15 (Our Special Function registers) by default all operations are done in the access bank (a=0)This allows us to access a good amount of GPR and all of our SFR without ever changing what bank were working in. No more STATUS,RPx calls. However if we want to access ram outside the access bank we have to set the access bank delimiter call in the instruction to 1 and then by default you will be working in whatever bank happens to be set in the BSR.

Software accessible Stack:

I'm not too familiar with this feature, but the PIC18 allows you to control the stack from software, you also have complete control over the stack pointer, this is extremely powerful and not offered on the PIC16

New and improved modules:

The PIC18 series features an 8-bit hardware multiplier. Microchip provides sample code for doing all sorts of fun arithmetic. This is good if you want to crunch numbers but don't want to go into a full DSP. Also some PIC18s feature on chip USB and other goodies.

Priority interrupts:

This is another really cool feature. The PIC18 features two interrupt vectors, one high priority and one low priority. This allows you to have a really complex interrupt scheme allowing really sophisticated user interaction. For every interrupt you can choose what priority it is. An example of this is having a sample system for a sensor have highest priority while the user interface is low priority, that way even if the user is interacting the device to cause an interrupt, you don't interrupt the sample of the sensor if it is time sensitive.


This feature is going to take me the longest to get used to, but the PIC18 features a plethora of new instructions to make our lives easier. One nice and needed one is a MOVFF instruction (move from one register to another) These instructions are meant to speed up your code and make execution much faster. All new instructions follow a similar style to the traditional ones, they just do more for the clock. You can take a look at them on page 193 of the datasheet.

Free C compiler:

Microchip offers a free c-compiler for the PIC18 series for MPLAB, i haven't used it but its free and its a c compiler.

Tons of other stuff i still have to figure out:
I'm working on it :P

The PIC18 series is a really powerful line and there isn't much that they cant do. The first project i will be posting with them is a Digitial Audio Processor, we'll be taking advantage of the priority interrupts to make really fast and efficient code.

Hope to see you soon, happy programming!


The Fundamentals of Digital Audio

12/08/09 | by Jfkfhhfj | Categories: Informative, General

Digital audio is a very powerful thing, we listen to our iPods every day, we stream music from websites using our computers and we work with many algorithms derived from techniques in digital audio. Digital audio has its roots in wave mechanics and is a very fundamental process for modern computation. We will be discussing sound as a wave, some basic properties of waves and how to convert a wave into something which you can store in memory, and techniques to play that wave back. We’ll start with an introduction to sound and how to represent sound as a wave, and a mathematical function.

An introduction to sound:

Sound is a wave, and like all waves it transfers energy through a medium, in this case it is usually air. Whenever something emits a “sound” it compresses air molecules, these compressed air molecules exert a force on uncompressed ones, this starts a chain reaction and sound propagates; this is the essence of a sound wave. For sound to exist you need a medium, be it air, a solid, liquid or plasma. The sound wave will travel through that medium until it dissipates completely and is undetectable. Sound is usually the result of a force or stress on an object, you hit a tuning fork on a table, and it will vibrate at a particular frequency. To better visualize a sound wave mathematically, we will look at strign vibrations.

String Vibrations:

Like a turning fork, a string when plucked vibrates a particular frequency. The frequency at which a string vibrates at is due to its mass, length and tension on that string. The frequency which is most prevalent is called the fundamental frequency, when you play middle c on an instrument the fundamental frequency is 261 Hz. Now if middle c is a set frequency, why does middle c sound different on different instruments? The answer is because the sound from an instrument inst pure, each instrument has a unique harmonic structure which delivers a unique sound. To understand this more let’s look at the math of a wave.

Mathematical representation of a sound wave:

The nice thing about waves, is we can represent them mathematically, the simplest being that of a sine wave. Sine is a natural function which oscillates between crest to crest at a particular frequency. We can represent a pure oscillating sound by the following function.

Where A is the amplitude (sine is a function which oscillates between 1 and -1, multiplying it by A will result in A as the amplitude). The Greek letter omega is the angular frequency which is denoted in radians/second and the Greek letter phi denotes the angular offset (for all cases in this article we can consider it zeros). A “Pure” sound is that which is sinusoidal, we here these all the time on cheap synthesizers, when a sound is sinusoidal, it can be represented by the above formula alone. If a synthesizer were to play middle c, it would produce a sine wave of frequency 261Hz (omega = 640) and what you would notice is that it sounds like the right pitch, but no natural instrument sounds like a pure tone. When an instrument makes a tone, it is usually comprised of its fundamental frequency and higher order oscillations called harmonics. Harmonics are usually either ½(Strings) or ¾(Closed tube) integer multiples of the fundamental frequency of a lesser amplitude. Because of this we can consider and natural tone a superposition of fundamental sine waves and harmonic sine waves. Most tones in nature are comprised of a superposition of sine waves. We can use this fact to break down any complex sound into a series of many simple ones governed by the very simple formula above.

Synthesizer theorem:

Breaking a complex sound into a series of sine waves can be done using a Fourier series. A Fourier series simply is a mathematical series which can break apart any repeating oscillations into a series of simpler sine waves. We use a Fourier transform to translate an arbitrary function into a series of sine functions. For the purpose of this article we’ll use a Fourier series as a concept and we won’t be exploring the math behind it (Maybe one day).

To give a quick example of this we can consult Wikipedia. We all know and love our humble saw tooth wave; If we find the Fourier series of a saw tooth wave we get the following series as a result.

If we take n=1 we get the fundamental frequency of the series:

If we take the first 5 terms we get:

As we take n to infinity, we get a better and better approximation of our function. This is the fundamental way in which analog synthesizers would generate more complicated sounds, they would take several sine wave oscillators which they would combine in ways to reproduce a wave, and they wouldn’t need many because after a while the approximation was good enough to replicate the sound. This is fine and dandy, but in digital circuits we do not use sine waves as our building blocks, instead we use impulses.

The Impulse wave:

An impulse wave is completely different from a sine wave, instead of taking a wave as an infinite series of sine waves; we take the function and evaluate its value at a specific time t. We break the function up into many steps and by taking the value at every step we can reconstruct the wave. In this scenario as step size goes to infinity, we get a better reconstruction of the wave.

In this graph we have 5 impulses (red) that make up the waveform (green). Each impulse exists at time t and has a definite height to it. We break up a wave into specific impulses with definite height, we do this every sample. If the red waveform were 10KHz and we had 5 impulses per period, our sample frequency would be 50KHz. Each sample all we do is record the height of the waveform at that time.

="" alt="" title="" width="400" height="280" />

If we were to reconstruct the wave using our impulses we would get the following:

="" alt="" title="" width="400" height="280" />

As you can see, its not a pretty picture, but if you were to filter the signal, you would get a pretty good reconstruction of the original. To increase reconstruction we increase the sample rate and get more samples of the waveform per period. A wave with 100 samples/wave looks much more accurate than one with 10 samples/wave.

One golden rule is that your sampling frequency should always be above that of your highest recorded sound (Or at least the ones you would like to capture)

Digital Audio:

The heart of digital audio is taking an analog sound signal in the form of voltage over time and doing periodic analog to digital conversions and then storing these results in memory for later use.

Lets go back to our graph with the impulses. Lets say the vertical axis is voltage and the horizontal is time. Every impulse we sample a wave:

IMPULSE # -- VOLTAGE -- A2D(Int)(VDD=5V) -- T(uS)(@50KHz/Sample)
1         --  .1     --  5               -- 20
2         --  .2     --  10              -- 40
3         --  .3     --  15              -- 60
4         --  .4     --  21              -- 80
5         --  .5     --  26              -- 100
6         --  .1     --  5               -- 120
7         --  .2     --  10              -- 140
8         --  .3     --  15              -- 160
9         --  .4     --  21              -- 180
10        --  .5     --  26              -- 200

In all digital audio systems there are two things which determine your bandwidth.
The first is bit-rate which is how many bits you use to convert the signal. A bit-rate of 8-bits can break a signal up into 256 parts, thus a 5V signal has an ideal resolution of (5/256) 19mV(not bad!).

The second is sampling-rate, this is how often you sample a waveform, typical MP3 sample rates are about 44.1KHZ or one sample every 22uS.

The bandwidth of a signal is simply the sample-rate times the bit-rate.

The advantage of a digital system is that 22uS is rather slow, we can do a lot of work between sampling and storing a waveform, and with some good code we can produce high-quality powerful audio systems which are easy and cheap to make.

What now?
So now that we have an introduction to basic properties of sound, what can we do now? In upcoming posts i will be discussing the PIC18 series of micro-controllers, and some sample code to do audio pass-through and eventually storing and playing back a waveform.


Pages: 2 4 5 6

February 2017
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28        

Ads by Google Store!

This blog is dedicated to working with digital circuitry and the use of microcontrollers, small compact computers on a chip. I will be encompassing many techniques to develop projects, tools to use to write and assemble code and i will be sharing any projects i am currently working on. User feedback is a must! I do not know it all, hell im not even that experienced, but without a general place to get all the info needed i find it very hard to get into the world of microcontrollers without pursing a CE degree. So come one come all and enter the world of mystery and creativity!


  XML Feeds

multiblog engine