Tuesday, August 18, 2009

Getting Started with Microcontrollers

A microcontroller is an integrated chip. They contains a CPU, RAM, ROM, I/O ports, and timers like a standard computer, but because they are designed to execute only a single specific task to control a single system, they are much smaller and simplified so that they can include all the functions required on a single chip. Note that there are lots of verities of µcontrollers and in this article my emphasis is on ‘PIC µcontroller.
A microcontroller differs from a microprocessor, which is a general-purpose chip that is used to create a multi-function computer or device and requires multiple chips to handle various tasks. A microcontroller is meant to be more self-contained and independent, and functions as a tiny, dedicated computer.
Microcontrollers need software to perform specific tasks. So, you need a ‘Programmer’, it is the hardware needed to put the software inside the µcontroller. Programming the µcontroller is also known as "burning" the µcontroller.
This is a simple and easy-to-build PIC JDM programmer. It works using the power from the RS-232 Serial port. The serial cable should not be longer than 3 feet.
click on image to zoom
Then you need the ‘Software’ to use with the computer and transfer the code to the PIC. Let’s start with the serial port.

Below figure shows the pin assignments for the four DB-9 serial RS-232 port connectors. These connectors are used to connect serial devices such as modems.


At now this information is enough for the beginner. Now move towards the JDM Programmer.

This name comes from the name of ‘Jens Dyekjar Madsen’ who devised this first. There are lots of JDM Programmers available but the above programmer is for only PIC16X628a and PIC16X84a µcontrollers.

In the schematic the capacitor is of 100µF/16v value. And zener diode is of 5.1v. The R2 (3K3) resistor and LED is optional, you may omit these. Make sure about the right connection of Programmer and the DB-9 serial RS-232 computer port.

After doing these things you need software to ‘burn’ the µcontrollers. I do recommend ‘PICPgm Programmer’ and ‘Pony Prog, as they are easy to use and free to download.

PICPgm Programmer Automatically detects the Programmer and µcontrollers, no settings is required. Just connect your programmer to serial port, browse the 'hex' file code and click on ‘Programm PIC’ icon.


Where as in Pony Prong first click on ‘Setup’ and then select ‘Interface Setup’.

A new window will open; select ‘serial’ and ‘JDM API’ from drop down list. Also check on that ‘COM’ option on which your programmer is connected, in my case it is ‘COM1’.


After this again click in ‘Setup’ and select ‘Calibration’. A message window will appear, just click ‘yes’.


Now select you µcontroller from drop down list.


Another important detail when using and programming microcontrollers is the configuration word or also known as ‘FUSES’.

A fuse indicates the configuration for the PIC regarding the timers, watchdog, code protection and oscillator.

For fuse settings click on ‘Command’ and then select ‘Security and Configuration bit’.
A new window will appear with a lot of check boxes.
Do not panic, normally the hex code contains these configuration. If it is not so, then check in the ‘asm’ file for these settings and you will find something like this:
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _LVP_OFF

Configure it according to your asm file. Some explanation is given below:
  • CP: if checked all memory is code protected
  • PWRTE: if checked power-up timer is enabled
  • WDTE: if checked watchdog timer is disabled
  • FOSC1,FOSC0: oscillator selection bits
FOSC1
FOSC0
Status
not checked
not checked
RC resistor/capacitor oscillator
not checked
checked
HS high speed crystal/resonator oscillator
checked
not checked
XT crystal/resonator oscillator
checked
checked
LP low power oscillator


After this browse your hex code from ‘file’ menu then from ‘Command’ menu select ‘Write All’. A status window will open and show you the writing progress.

That is it. Enjoy playing with µcontrollers.

No comments:

Post a Comment