Saturday, October 25, 2014

How to select Microcontroller ?

Architecture (8 bits v/s 16 – 32 bits) :

8 bit µC are generally used by hobbyist, college students and for DIY projects. 8 bits µC belongs to 8085 like families but PIC and AVR are more famous makes. However for complex applications like DSP, image processing, RTOS and floating point arithmetic operations 16 / 32 bit µCs are preferred. To begin with one should get familiar with 8 bit µCs before moving to 16 or 32 bit architecture.

Programming language :

Available choice of the programing language is one of the most important aspect of selecting µC. Embedded C and Assembly language are the two popular options. Embedded C is more efficient, flexible and easy way write your code. Embedded C allows us to use your C skills with embedded programming. When the code size efficiency, time accuracy and processing speed does not matters much embedded C is perfect choice. Many Embedded C cross compilers are available, Keil µVision IDE is famous among all.

I/O ports, peripherals and memory :

Large verity of the ordering options are available with all the manufacturers ranging from 8 pin (e.g. ATtiny85) to 64 pin µCs. Generally speaking 4 IO ports (or 32 I/O lines) and integrated ADC, Timers, UART, PWM, JTAG are common features.

In memory options manufactures support FLASH memory from 1 Kbyte to 128Kbyte, EEPROM memory from 512 bytes to 4Kbytes along with SRAM ranging from 1 Kbyte to 4 Kbyte for 8 – bit controllers. For 32 bit larger memory models are available.

Cost :

For learners / hobbyist, it’s more likely that, you will end up in burned or non-functional µC in few initial attempts to program it. If you are rookie, no need to buy expensive once, it’s better to opt for low cost µC. In general 8051’s, ATmega AVR and PICs are few low cost options available.

Availability :

It’s always better to select µC which will be available for long time and available easily, but there is no rule of thumb for this. You can check our electronics shops nearby for this and make optimum choice. Having said this, 8051’s should be available all around same is the case for AVRs and PICs.

Online support:

It’s advised to select µC which has excellent only “Fan following”. It’ll make your life easy, if you’re stuck at some point. Getting the programming tricks, tool chains and hardware assembly online will allow you to complete your task quickly and more ease. These days AVRs and PICs have huge fan following and good online support available.

Packaging :

Hobbyist, college students and for DIY projects DIP packaging is most suitable one – easy to install – easy to replace. One can opt for SMD components to make circuit board compact but this option is valid only for professionals. 

Programmer boards:

Last but not least, a programming board. To make µC work one must program it (send hex file to µC). Wide choice of the programing boars are available now. Programming boards facilitate transfer of hex file from PC to µC. Generally speaking, USB based programming board is an optimum choice. Bunch of USB based programming boards are available for AVR and PICs, but for 8051 it’s bit difficult to find such board.


Sunday, January 5, 2014

Tutorial 5: Serial Port Communication with ATmega series

Serial communication between PC and uC.

Application :
This can be used to input parameters/constants/dynamic values to micro-controller via serial port of PC.

Requirements and components:
We need few basic parts to start with serial communication (Hardware & software requirements)
  1. DB 9 connector (known as serial connector)
  2. MAX 232 IC
  3. Development board.
  4. Some wires and Pin connectors.
  5. PC with serial port.(COM port)
  6. Hyper-terminal or Putty (Serial supported software)
Verify the PC for COM port:

Before we begin the serial communication we need to verify that PC has COM port working on it.
Please follow the steps given below to verify the COM port :

  1. Right click on the my computer and select Manage
  2. This will open the Computer management screen, now click on the "Device Manager" left hand side and click in Ports(COM & LPT) on right hand side.
  3. You must see the COM1 listed under Ports(COM & LPT). Refer the screen shot below.

Fig 1 : COM1 port available under Ports(COM & LPT)

Connecting RS232 to microcontroller:

Do the connections as shown in the diagram below for connecting uC with MAX 232.

Prepare Serial cable:

We need  to prepare a serial cable to connect the PC with the MAX 232 PCB. Make a cable as shown in diagram :

Program for serial communication :

OK !!!
It't time to write the program in CodeVisionAVR.

Start the CodeVisionAVR and run the CodeWizardAVR.
(For more details on CodeVisionAVR pleas refer this tutorial)

Step 1 : Select ATmega16 and set the clock to correct value.

Step 2 : Select the USART tab in CodeWizard,
Check the "Receiver" and "Transmitter" check boxes.
Select "Baud Rate" to 9600
Select "Communication Parameters" to "8 Data, 1 Stop, No Parity"
Select "Mode" as "Asynchronous".

Step 3 : Generate, Save and Exit.
Now generate save and exit the CodeWizard.
Note : This will ask you to save 3 files. All three file must have same name CodeVision will select the file extension automatically.
Here is the example of 3 file in this pgrogram.
  1. Serial_Communication.c
  2. Serial_Communication.cwp
  3. Serial_Communication.prj
Step 4 : Write program statements:

CodeAWizard will create the large program as per our settings. 

Add "delay.h" header file just below "stdio.h" header file.
#include <delay.h>

Now scroll down and search for the line "// Place your code here"
Add following 2 line after "// Place your code here".

printf("Welcome to AVR\n\r");

1st line will send the "Welcome to  AVR" on terminal.
2nd line just adds delay between to printf cmds.

Step 5 : Built the program to generate the .HEX file.
Press "Ctrl + F9" to built the program, this will bring the following screen.
check for the errors and warnings, correct the error if there is any.

In this program there are no errors and warnings.
Click "OK".
This will create the .HEX file at ""C:\Program Files\cvavr2\bin\exe" (Default path)

Step 6 : Burn the program to microcontroller.
Use PonyProg to burn the .Hex file to uC.
(Refer this tutorial for more details on PonyProg)

Step 7 : Now connect the cable to PC serial port and to uC board.
Enjoy !!!

Saturday, October 1, 2011

Tutorial 4 : Connecting External Crystal Oscillator to Atmega (Atmel AVR) series. [Lower FUSE BITs settings for Atmel AVR]

Name : Connecting the crystal oscillator to Atmega (Atmel AVR) series.

Application :
  • This tutorial will illustrate how to connect external crystal oscillator to Atmega16/32, physically and logically.
  • It also explains the concept of fuse bits and how to configure Lower Fuse Bits setting.
Requirements and components :
  • All components required to make the development board (click here)
  • Parallel port programmer (click here)
  • Software : PonyProg2000 (click here)
  • Atmega16 data-sheet.
    (Data-sheet of Mega AVR : Need to refer for Fuse Bits)
Connecting crystal with Atmel AVR is two phase process.
In phase one, we connect the crystal oscillator physically
In phase two, we connect it logically to micro-controller.
(This is done by changing Lower Fuse Bits)

Connecting crystal to megaAVR (Physical connection) :
Following diagram shows how to connect the crystal oscillator to Atmega (Atmel AVR) series.
Note : All connections are shown in this tutorial (click here)

Kindly refer data-sheet of AVR your using, page number 2 will give you all idea about pin configuration.
All MegaAVR data-sheets (click here)

Selecting the values of C1 & C2 :  
Values of capacitors C1 and C2 will change, based on the crystal value
Following table shows the recommended for capacitors C1and C2.

(Available under System Clock and Clock Options header in all MegaAVR data-sheets)
e.g 1.> Crystal oscillator frequency = 11.0592 MHz=>22pF
e.g 2.> Crystal oscillator frequency = 16.0000 MHz=>22pF

Fuse bits :

Fuse bits define the mode of operation for MegaAVR.
Changing the fuse bits changes the internal configuration of micro-controller .
To able to connect the crystal logically, we must change the lower fuse bits.

Note :
Changing fuse bits is like doing open hart surgery on micro-controller.
Any wrong configuration of fuse bits will result in the dead MegaAVR.

Lower Fuse byte :
Lower fuse byte deals with Brown-out Detector, start-up time & Clock source.
In short lower fuse byte is for clock source configuration.
Here is the bit configuration of Lower fuse byte.

Following table shows the description of above bits.
Now default Lower fuse is 

Reading Fuse bits with PonyProg : 
  • Start PonyProg2000
  • Connect the parallel port programmer to parallel port at PC and development board.(Turn on the power of development board)
  • Complete the interface setup, calibration and device selection.
    (For tutorial click here)
  • In menu bar click on Command and then click on Security and configuration bits(Command > security and configuration bits)

  • This reads fuse bits from micro-controller, and displays it in new window.
  • Now above window shows the default fuse bit status.
    Fuse bits marked in red are Lower fuse bits.
  • For PonyProg Check = 0 and Un-check = 1
  • To read the fuse bits again click on read button
Calculating the Lower Fuse bits for 16MHz :
Following table shows the CKSEL3..0 (read as CKSEL 3 down to 0) for device clocking options .

Following table shows the value specific settings for fuse bits 

Note :  CKSEL0 bit is configured for start up time we'll keep it as it is 
(Do not change the CKSEL0 bit)

Hence as above two table shows bit configuration for 16MHz will be
  • CKSEL3 => 1 => Un-check in Ponyprog
  • CKSEL2 => 1 => Un-check in Ponyprog
  • CKSEL1 => 1 => Un-check in Ponyprog
  • CKSEL0 => 1 => Un-check in Ponyprog (By default it is Un-check)  
  • CKOPT  => 0 => Checked in Ponyprog
There for new Lower fuse bit configuration for 16MHz crystal is

Writing Fuse bits with PonyProg :
  • To un-check a bit click on the check box in front of particular bit.
  • To implement change in Ponyprog un-check the CKSEL3..1 (read as CKSEL 3 down to 1) and check the CKOPT as shown in fig below.

  • To write fuse bits click on Write button.
  • This will perform write operation.
This is how to configure and change the fuse bits using PonyProg.

Note :
It my previous experience that any wrong configuration of fuse bits may result in to dead MegaAVR.

Before writing the fuse bits verify the configuration at least twice.

Disclaimer :
All the data or information written above is from data-sheets and other reference documents.
My intention is to share my knowledge and experience with others.
Information or data above is not my innovation at all, its just a collection that works perfectly.

Friday, September 16, 2011

Tutorial 3 : Getting started with PonyProg.

Name : Getting started with PonyProg (parallel and serial port programmer)

: How to configure the PonyProg to make it work with parallel port programmer.( illustrated in tutorial 1.)

Requirements and components :
  1. x86 based PC with suitable o/s  (I use windows XP SP 3)
  2. Software : PonyProg 2000 (Free to download Click here)
    (As I use windows XP SP 3, so I used to download suitable version)
  3. Refer this tutorial to generate .hex file which is to be burned in uC.
Installing the  PonyProg2000 :
  • Download the suitable version click here .
  • PonyProg2000 setup file.
  •  Double click on the setup.exe
    (This will open the installation wizard)
  • Click next .
    (This will open the licenses agreement window, accept the licenses and click next)
  • Select installation directory, by default it is C:\Program Files\PonyProg2000.
    (To change the installation directory click on Browse option)
    Click Next .
  • Click Next : This will create the start menu shortcut .
  • Click on the Install to install PonyProg2000
  • This will install the PonyProg2000 on your system.
    Un-check  the View README.TXT check box.
    Then Click on the Finish .

This will complete the installation on your system.

Configuring PonyProg2000 :
  • Now right click on My Computer .
    Then click on Manage
  • This  will start Computer Management wizard
    In the console tree (on left hand side) click on Device Manager

  • Now expand Port (COM & LPT ) menu.
    Note down the Printer Port.
    Here, I'm having LPT1. 
We need all this stuff for configuring the PonyProg2000
  • Turn on your speakers to enjoy special sound effect !!
    Click on start -> All Programs -> PonyProg -> PonyProg2000

    (This will start the PonyProg2000)

  • Now click on OK.
  • This will open a pop-up window asking you to run the calibration
  • Click on OK.
  • This will open one more pop-up saying "Initial setup is require".
  • Click on OK.
    (Now PonyProg2000 is ready for configuration.)
 Above fig shows the default view of PonyProg2000
STEP 1: Interface setup...
In menu bar click on the Setup and then click on the Interface Setup.. 
This will open up the I/O Port Setup window.
STEP 2 :
Click on Parallel (radio button) to select the Parallel programming mode.
From drop-down menu below Parallel (radio button)
select the Avr ISP I/O .
Then click on LPT1 (radio button).
(as shown below)
Now click on OK, to complete the I/O Port Setup
NOTE : Do not disturb the other settings .

STEP 3 : Calibration
In menu bar click on Setup and then click on Calibration .
This will open the window asking for your conformation.
Note : Remove all the connection from LPT1 (if there are any)
Click on Yes button.
This will calibrate the bus timing.

Another pop-up window will come up saying that, Calibration OK.
Click on OK.
Now we are done with initial setup !!!
It's time to select the Micro-controller.......

STEP 4 : Device selection
In menu bar click on device button, this will open a drop down menu.
Move the mouse pointer to AVR micro, this will open a drop down list of the AVR micro-controllers those can be programmed using PonyProg2000
Select the appropriate one by clicking on the option,
(Here I'm selecting ATmega16)

STEP 5 :
Once we change the device to ATmega16 one can notice the two changes
1.  In navigation tool bar you will find AVR micro and Atmega16 on left hand side.
2.  status bar will also display the same settings.(at bottom)

STEP 6 : Loading the .hex file in PonyProg2000
To find how to locate the .hex file after successful compilation (using CodeVisionAVR) refer this tutorial (click here)
(path will be ##/cvavr2>Bin>Exe)
Now we can locate the Hello_embedded.hex file.
To load file ->
1.  In menu bar click on the File and select Open Device File ... option

2.  This will open the "Open device content file" window.
3.  Change the "File of type" option to .hex (as shown below)
4.  Navigate to proper folder in order to find the .hex file using look in drop-down menu.
5.  Now select the  Hello_embedded.hex and then click open button
6. This will load the Hello_embedded.hex in PonyProg2000 (see fig bellow)

STEP 6 : Programming the micro-controller
(some people also refer it is as Burning uC or writing uC

1.  Connect the Parallel port programmer to Parallel port (PC) and programming pins of development board (micro-controller).
2.  In menu bar click on the command and then click on Write All option.

3.  PonyProg will ask for your permission .
4.  Click on the Yes button.
5.  Now PonyProg will write and verify the code, it will take 1-2 minutes
6.  After the successful write operation PonyProg says "Write successful".
Click OK button to complete the procedure.
7.  Now carefully remove the parallel port programmer from micro-controller board, and press Reset button on development board.

Enjoy Output.

Note :
This is how normal operation of PonyProg takes place.
Remove the programmer from development board to see output.
Your queries and suggestions are always welcome.

Saturday, January 8, 2011

Tutorial 2: Making a development board for ATmega series.

Name: Making a development board for ATmega series.
Application: This is small development board & can be used with ATmega 16/32/64/644 etc.

Requirements and components:
There are 5 baric parts of the development board –
1.       µC holding circuit.
·         General purpose PCB
[If you’re not good with soldering then this can be implemented with two bread board]
·         40 pin IC holder
2.       Power supply circuit.
·         Small sliding switch (with three terminals)
·         Diode 1N4004
·         Electrolytic capacitors -100µF/25V, 10µF/25V
·         IC 7805(or 78L05)
·         Heat sink for 7805(with screw)
3.       Programming pins.
·         This is discussed letter.
4.       Reset circuit.
·         Resistor- 1.2KΩ
·         Electrolytic capacitor- 1uF/10V
·         Micro press button switch(D1/D2 press button switch with two legs)
5.       Crystal circuit.
·         Ceramic capacitors – 22pF
·         Crystal – 16MHz
[Note: Atmel Corporation ships ATmega AVR ICs with internal RC oscillator @ 8MHz. Hence, if you buy a new brand IC from stores then you don’t need to implement crystal assembly. But if you chance the “Fuse bit setting” (just mark the word here!!! we will see this in detail) then you need crystal assembly]
6.       Other
·         Male and female burg strips
·         Wires and soldering accessories.

Following diagram shows the connection set up for ATmega16/32
If you see in the diagram all the above parts of circuit are implemented. SV1 and SV2 are the female (or can be male) connectors connected to the port C and port D of IC. One can also connect same connections to the Port A and Port B. But, I recommend that you leave port A as it is. (i.e. don’t connect anything to port A, because this port is used for internal ADC of MegaAVRs.)

One must take care of few things as-
·         Solder the IC base only don’t solder the IC directly to PCB.
·         Watch the position of VCC and GND pins as well as soldered tracks.
·         One can solder the crystal directly but it is good to have female burg at crystal, so that you can change the crystal whenever you need to do so.
Basic connections for development board

One pint to be noted here is that, when you mastered the skills of soldering you can start developing more complex circuit on general purpose PCB. And once u got all things correct on general purpose then you can start develop your own PCB module. But still I recommend the general purpose is better than to have a PCB module as you can modify the circuit on general purpose PCB.
Here are the some of the boards developed by me -

Cost and availability of components:

You can just figure out the components required from above mentioned list and the diagram. Cost of all the components is very less as compared to Atmega ICs.
·         Cost of all components except IC = Rs. 100/- [INR]
·         Cost of IC[ATmega 16/32] = Rs. 250/- [INR]
Note: All components will be available @

20, Kalpana Building, 1st Floor, 357,
Lamington Road, Opp. Police Station,
Mumbai-400 007 (INDIA)
Component Division
Tel.: (022) 2386 3549 / 2382 3550
Kit Division
Tel.: (022) 2387 9562
Fax: (022) 2382 3552

Tutorial 1: Parallel port programmer for Atmel MegAVR series.

Application: This programmer can be used with ATmega series. (E.g. ATmega16/32/8/48/88/168.)

Requirements and components:

·         PC with windows xp & parallel port (DB-25 port)
·         Software Ponyrog2000
·         [Note Download any version of PonyProg2000 for Windows 9x/ME/NT/2000/XP distribution]
·         DB-25 male connector and its case
·         FRC cable [Flexible Ribbon Cable] -- with more than 5 strands.
·         Soldering iron & soldering wire.
·         Burg housing connectors (both male & female)

DB-25(parallel port) Pin out

Burg housing connectors (male and female)

Connections for Parallel port programmer

Parallel port pins
µC pins
connectivity table for programmer

Cost and availability of components:
Part name
Quantity required
Cost (for each unit)[in INR]
DB-25 male connector
DB-25 plastic case
FRC cable
1 meter
Burg housing connectors
(both male and female)
(set of 40 pins)

Note: All components will be available @

20, Kalpana Building, 1st Floor, 357,
Lamington Road, Opp. Police Station,
Mumbai-400 007 (INDIA)
Component Division
Tel.: (022) 2386 3549 / 2382 3550
Kit Division
Tel.: (022) 2387 9562
Fax: (022) 2382 3552

Note: Above programmer works perfect with ATmega 8/16/32/44/88/168.