Tuesday, March 31, 2009

PIC programming for dummies!

I thought I should make a short list of some of the sources I found useful after delving into to mysterious world of microcontrollers for the first time. I have experience with programming in general, but I don't think that is required, although maybe helpful. As a matter of fact, I think assembly programming and microcontrollers could be a good introduction to programming in general, because of its relatively simple language consisting only of a few commands (about 35 on a PIC microcontroller) and the direct link it has to its hardware. The direct link to the hardware is very important in this matter, since what you actually are programming is a small piece of hardware that can only do one very simple thing, namely sending out either 0 volt or 5 volt to a given number of pins. And since this is basically what a regular PC is doing too, albeit in a way so complex and fast that it is very easy to forget this fact, working with a microcontroller forces you to think about it. The thing that makes the microcontroller useful, though, is that it too is extremely fast! It is relatively slow compared to full fledged computer systems of course, running at speeds of 3GHz or faster, as opposed to a typical microcontroller running at a lousy 4MHz (making the PC about 750 faster than the microcontroller). On the other hand, a microcontroller usually only does one, or maybe a couple, tasks at the time, while a PC easily handles hundreds of tasks. Still, 4MHz for a microcontroller means a clock frequenzy of 4,000,000 beats per second. Every instruction on the controller requires 4 pulses from the clock (a very few requires 8) making it capable of doing something at a speed of 1,000,000 times per second, a number that makes it extremely suitable for a lot of tasks that requires repeated output of electric signals at a high speed.

Following is a list of tutorials, books, hardware vendors, and maybe some links to sites with some inspirational projects to start out with.

First and foremost, you will need to pick which brand of microcontrollers you want to try out. I went for Microchip's PIC microcontrollers. It looks to me that another major brand of microcontrollers would be the ATMega product line from Atmel. I do not know much of them, so I will concentrate on the PIC from Microchip. Then, there's the jungle of books out there, all of them claiming to be the best book for anyone who wants to learn about microcontrollers. Clearly, they can't all be the best, which is exactly my experience as well. I'll list up the books I have bought, with my very personal evaluation of each.

One of the great advantages of using PIC's from Microlab (and again, I don't know if this is also the case with other brands) is that they deliver a free IDE (called MPLab) for programming, debugging and uploading files to the microcontroller. It can be downloaded from their website, or, if you buy the pickit2 programmer, it also comes with a CD. You will need a programmer (hardware to get your software/program from your computer over to the microcontroller) and I strongly suggest going with the PICkit2 starterkit as it includes all you need to get started, is cheap, and handles a lot of different microcontrollers. It took me a while to figure out that not only do we have different brands of microcontrollers, but we also have a huge range of different types of microcontrollers, varying in ways like number of pins, amount of memory, speed, and other things like special functions etc. Allthough, they all more or less function in the same way, and by choosing the pickit2, you will be using a mid-range type of controller that works well for learning.

Here goes:

Hardware:
PicKit2 (this is starter kit, with a programmer, software IDE, and a microcontroller on a protoboard included)

Other hardware is a long list (that I will leave unspecified since others have done that job already) that never ends and includes sensors, motors, lights, tools etc

Books/tutorials:
http://www.gooligum.com (this is a _really_ good one, plus it is free, so don't miss it)

16F690 Datasheet (This is the data 'sheet' for the microcontroller that comes with the PICkit2 starterkit, and is another very good source of information. It is several hundred pages long, but it is easy to find specific and useful information.)

Easy microcontrol'n (despite the name of the book; this is a very useful and good introducton to PIC progamming; highly recommended)

Those three sources will take you a long way, especially in terms of understanding the assembly language (not the least -- why to use assembly, and not C or PBASIC or similar) but also in terms of actually get you starting on incorporating hardware, starting with lighting up LED's and seven segment displays etc. Not too complex, but very useful to get one going.

Also, the PICkit2 starter kit comes with a very good tutorial that demonstrates various aspects of the microcontroller and MPLab IDE in a very instructive and easy to follow way.

There are other books and sources that should be useful too (Physical Computing, Making Things Talk) but these three are very specific on the PIC programming part, so I will strongly suggest starting with them.

As for vendors: Jameco, Microchip, Futurlec, Adafruit, and Digikey are all good sources to hardware.

No comments:

Post a Comment