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 !!!