Sunday 9 February 2014

Building your own Micro controller board!

Building your micro-controller is the first step in learning of micro-controllers. In this post i'm going to guide you as to how to build your own Atmega8 micro-controller board, if you're using any other uc belonging to atmel's mega family(ex: atmega16, atmega32, atmega328p etc.) the steps remain the  same.

Why its better to do your own board? Why not just buy one?
The answer for this question is simple, It totally depends on the time you have to do the project on your mind. If you are in a hurry and the deadline for your project is in a week or two, Then its better to buy a ready made board.! but if you are just doing something as your hobby and just trying something it would be better to make your own board, and another advantage would be you can make your board for your applications.

Components needed to make a atmega8 board..

One Atmega8, 4 or 8MHZ crystal(Optional), 22pf capacitors - 2(If using external crystal), LM7805
0.33uf capacitor - 1, 0.1uf electrolytic capacitor -2, LED( color is of your wish :) ) - 1, 330 ohm resistor - 1
0.1uf ceramic capacitor - 1, 4.7k resistor - 1, 10k resistor - 1, around 2 - 3 strips of male berg strips, 1n4148 diode - 1, 1n4007 diode - 1, 4700uf electrolytic capacitor -1, FRC 10pin connector - 1, Power jack or PTR Terminal Blocks or PTR connector (2pin) - 1, Button switch - 1,  some single stand wires, soldering iron, soldering flux, soldering lead and finally one PCB.

Crucial circuits for the board to work!

There are totally three important and simple circuits for a micro-controller board to work properly.

First one is the power supply circuit.
The power supply circuit should contain very less amount of ripples for the uc to work properly. As the datasheet of atmega8 specifies the input voltage to atmega8 should not be more than 5.5V, hence if you have a power source of greater than 5V you need to use a voltage regulator, and the common voltage regulator used is LM7805 which is a 5V regulator which needs two capacitors at input and output, the values are taken from datasheet which is 0.33uf at input and 0.1uf at output. these two capacitors are normally neglected easily! but they are very important when load on the regulator is more. A 4700uf capacitor is added in parallel to the 5V line to remove any spikes when running motors from the same board. 

Second crucial circuit is the Reset circuitry.
Reset circuit is used to re-initialize all the ports, registers and set the program counter to zero(i.e uc goes to the beginning of your program). For AVR family reset is active low(i.e when reset pin is at zero voltage the uc resets).The reset circuit would look like this..




The third crucial circuit is the programming circuit!
Programming of atmega8 is done through ISP(In-System Programming).. If you use a PC then serial port can be used for programming, for which the best software would be PonyProg.! 
Circuit for programming is provided by olimex.As shown..

If you're using laptop then you would have to buy USB-ASP Programmer.! if you want to try USART-USB converter for programming, PLEASE DON'T.. Pony prog takes more than 20min to program using the converter. USB-ASP is a better option.. connect the pins of frc connector to pins of micro-controller as shown in schematic. 
Here are pictures of my Atmega8 programmer




Building the board!

 First take a PCB which would look something like this.

 









TIP:- Try to get a pcb with bottom side already tinned.. this would help a lot while soldering.! :)






First solder LM7805 and PTR connector. with capacitors in parallel, as per 7805 datasheet its 0.33uf and 0.1uf. I've brought the positive voltage from ptr connector to regulator through a 1n4007 diode..
this is just for the sake of reverse voltage protection. 1000uf or 4700uf caps can be put in parallel with output. If your board is just using some low power ic's then 1000uf would do the job.. but if you have motor loads running from your board then i would recommend 4700uf.



Now going to the soldering of atmega8 first solder ic base(use ic bases with DIP ic's) .And also try to add berg strips in parallel with atmega8 on both sides. Now solder the power supply connections(i.e 5v to pin7 and gnd to pin8 and pin22) and you're done with power supply part. Solder  bypass cap( 0.1uf elctrolytic) across vcc and gnd near all the ic's in your board.! solder the reset circuit shown above, as near as possible to the micro-controller. you can see the picture o full board at the end.

Now at the edge of your board solder the FRC-10Pin connector for programming and connect the pins to the spi pins(MOSI,MISO,SCK) and reset pin of the micro-controller by default atmega8 runs on 1MHz internal oscillator, you can use that instead of a external oscillator for most of your applications until and unless it is very time specific such as serial communication. its is highly recommended that you use external oscillator while trying serial communication. and also its simple to add the external oscillator,  just solder the pins of oscillator one each to XTAL1 and XTAL2 pins of atmega, and those two pins are grounded through two 22pf capacitors. as shown

now your micro-controller board is officially ready for programming. Now just write a code for blinking led on as of the pins to test the board. I use AtmelStudio6 for writing code for atmel micro-controllers. Its your choice! :)
After writing the code use Ponyprog software to transfer the .hex file to uc if you're using serialport programmer or if you use USB-ASP use the software provided with the USB-ASP hardware.

If the LED blinks at the port pin you've coded for, your board is good.!! :)
Now you can just add components to your board needed for your application, take for example.

if you're using motors then add a L293D. Need a external ADC? Internal ADC is slow for you then add a MCP3204(Its a ADC working on SPI protocol), Port pins are not enough for you? Add a PCF8574 ( Its a I2C I/O Expander)..

And Finally here are some pics of one of my board..







Thank you!