Digital Code Lock

Will be uploaded very soon...

DTMF based device switching

Will be uploaded very soon..

DTMF based robot controll

Will be uploaded soon..

Monday, January 21, 2013

About Microcontrollers

What is microcontroller..?

        Microcontroller is a small size miniature computer that we find in all kind of gizmos. There are two words one is microprocessors and other one is microcontroller. 

Microprocessor:

          In microprocessor there is only CPU which includes ALU for perform arithmetic and logic operations, some registers for data storage and control unit which control over all operation of chip. It needs to interface with some external peripherals like RAM, ROM, Timer etc to be functional it.


Microcontroller:

          In microcontroller all this required peripherals like RAM, ROM, Timer etc are integrated in single unit. All you need is to connect crystal, and power supply with chip to be functional it.


Manufacturer of Microcontroller:

          There are so many company which manufactures microcontrollers. They are available in 8-bit, 16-bit and 32-bit. Some of manufactures are listed below...

ARM
Intel
Atmel
NXP
Texas
Dallas
Toshiba

Types of CPU:

      Today, lots of microcontrollers are available with different types of CPU. Most popular CPUs for microcontroller are 8051, AVR and PIC. Some of microcontrollers have inbuilt analog to digital and digital to analog converter in a single unit.

     We must need to program microcontrollers as per our requirement. For programming purpose of microcontrollers many softwares are available like keil, Mikroc, SDCC, Bascom etc.

Application of Microcontrollers:

      Microcontrollers can be used in automobile industry, control and automation, robotics, Home appliances, industrial appliances, electronics gadgets, communication equipment and count is continue...

8051 architecture and features

8051 is also known as a MCS-51 which is developed by Intel in 1980. It has 8-bit CPU, memory, timers, counters, interrupt controller and serial I/O are highly integrated on single chip. It is a 40-pin IC. It has 4 byte input-output port, EEPROM of 4KB and RAM of 128 bytes. Pin diagram and architecture of 8051 is shown below.




Memory Space:

There are five memory spaces in 8051 which are...

1) Program memory
2) Internal data memory
3) External data memory
4) Special function registers
5) Bit memory

Program memory space is addressed by the 16-bit program counter register which holds the address of memory location from where instruction code is need to be fetched. It can also be addressed by the 16-bit DPTR (data pointer register) using few instruction. It primarily stores instruction code, constant data, constant tables and string.

Internal memory space stores all the variables and data structure which is directly operated by the program. It is functionally the most important data memory space. It contains four bank of general purpose registers and program counter.

External data memory space contains those data which can't fits on the chip. It addressed by the DPTR register. It can also be accessed by the first two general purpose register R0 and R1. This memory space is only accessed by the indirect addressing mode.

Special function registers space contains on chip peripheral I/O registers as well as some special registers which must be programmed to control and perform particular task. This SFRs can only be accessed by direct addressing mode.

Bit memory space is used for storing flags and bit variable. There is some specific instruction by which bit memory space can be accessible. It can also be addressed by direct addressing mode. This memory space is mostly used with decision making process.

Features of 8051:

1) 8-bit Arithmetic and logic unit
2) 8-bit data and 16-bit data address bus.
3) Capability of address 64kb memory location
4) 128bytes on chip RAM i.e data memory
5) 4kb on chip ROM i.e program memory
6) Four 8-bit input/output port
7) Serial port (UART)
8) Two level interrupt priorities
9) Two 16-bit Timers/Counters

Disadvantage of 8051:

1) Limited on chip program and data memory 4kb and 128bytes respectively
2) No watchdog timer
3) It does not support ISP i.e in system programming

To over come this problems some company manufactures wide variety of chip which has 80c51 CPU as a heart (or i would say mind). For best chip which has 80c51 CPU click here...

Please share this with your friend...

P89v51XX- extended feature controller with 8051 CPU

Before some day i posted about 8051 CPU and as you all know it has many disadvantages. Currently lots different chips are available in the market which has 8051 as a CPU. All these chips have different features and characteristics.

Main problem with 80c51 is it does not support ISP and IAP, It has limited size of on chip ROM and RAM. So what will you do if the size of your machine code is more than 4Kb and it requires more RAM to process on data. One Possible solution is you can interface external memory but this required one more external chip and you have to reserve some pins for interfacing or for communication with with memory chip.

So how you feel if you get more memory space on a single chip...??? Here i am going to talk about P89v51xx family. There are main three chips are available in this family...

1) P89v51RB2
2) P89v51RC2
3) P89v51RD2

Memory Space:

Chip
Size of ROM
(kB)
Size of RAM
(kB)
Range of frequency
(MHz)
P89v51RB2
16
1
Up to 40MHz
P89v51RC2
32
1
Up to 40MHz
P89v51RD2
64
1
Up to 40MHz

Pin diagram and architecture:


Mode of Operation:

P89v51 family supports two mode of operation in first mode i.e X1, chip is operates in simple 80c51 clock  rate which is 12 clocks per machine cycle. and in second mode i.e X2, chip is operates in 6 clocks per machine cycle.

Features of P89v51XX:

1) CPU: 80c51
2) Power supply: 5V
3) Operating frequency: up to 40MHz
4) Three high current ports (16mA)
5) Three 16-bit timers and counter
6) Eight interrupt sources with four priority level
7) Two DPTR register
8) Support ISP and IAP
9) Brownout detection
10) Watchdog timer

This chip can be programmed by using "Flash Magic tool" which is easy and freeware to use. Click here for how to program P89v51XX using Flash Magic...

Download Datasheet  

Brown Out in Controller

There are so many circuits inside the chip. All these different circuits require different voltage levels. So when the supply voltage fall down from the minimum voltage level due to electrical noise or any other reason performance of these circuits goes out of control.


So chip has in built reset functionality to get overcome from this problem. This brown out usually occurs when supply gets turns off. So when supply voltage fall below the minimum required voltage level then there is automatically chip get restarted.

Please share this with your friend...

Understanding Intel Hex file

Intel hex file is a file which contains binary data values to program micro-controllers, EEPROMs,  and other chips. Compiler converts source code into machine code and outputs it into hex file. This hex file then burned into chip using burner for make chip functional.

Typical look of hex file is...


Now each line has six different meaningful parts and these parts are...

1) Starting Code
2) Byte Count
3) Memory Address
4) Record Type
5) Data
6) Checksum


1) Start Code: It is a single character an ASCII code of colon(":"). Every line of hex file is starts with colon. It indicates the new line in hex file.

2) Byte Count: It consist of two hex character and it represents the length of data bytes in the record.

3) Memory Address: It consist of 4-digit memory location that represent the starting address of subsequent data in the record. Data starts storing from this memory location and its increments after storing of each data byte.

4) Record type: It consists of two hex digits. There are six types of records. This field has only five possible values which are from 00 to 05.

=> 00 = Data record; which contains data and 16-bit address.

=> 01 = End of file records; every hex file must be end with end of file record type for that record type field must contains "01". End of file records always has following format.


=> 02 = Extended segment address records; it is also known as HEX86. Extended segment record must have two data bytes. Absolute 32-bit address is generated using addition of extended segment address's data field and data record's address field.

=> 04 = Start segment address record; this is for 80x86 processors. it specifies the initial contents of code segment and instruction pointer. Here 1st two values (bytes) of data field are for code segment and other two are for instruction pointer.

=> 05 = Start linear address records; This is for 80386 and higher CPU. Contents of data field that is of 32-bit are loaded into the EIP register.

5) Data Field: This field contents data byte and address as well. Content of record field differentiate whether it is data or an address.

6) Checksum: This is two hex digits appears at the end of each line. For calculating this number 1st add every hex number of line not include ":" and checksum field it self then perform 2's compliment of least significant byte.

Please share this with your friend...

Generating Hex file using Keil

Earlier i posted about Intel hex file and different components in it. And now here i am posting about how to generate hex file using Keil software. Keil is the all in one simulator which is most popular in embedded lovers as well as in industry. By using keil you can develop your source code in both the languages that is assembly language and C language but the hex file is common for both.

So first make sure that there is no error in your source code and if there is any then make it solve. Now just follow the below steps use screenshot if you find any difficulty.

Step-1: In menu bar navigate to Project >> Options to target and click on it or in project workspace window right click on Target1 >> Options for target and new window appears on your desktop.



Steps-2: In Options for Target window go to Target tab and enter the value of your crustal frequency in Xtal field. Make sure that you enter this in MHz.



Steps-3: Now go to Output tab and just tick mark the Create HEX file check box and hit ok.


Now just rebuild your target and you are done. your hex file is generated in the same folder in which your project file is located.

Important Note: Keil does not provide any path selection option for storing generated hex file. it is automatically store it in the same folder which contains your project file.

Now you can burn this hex file into ROM of micro-controller..

Please share this with your friend...

Introduction to Flash Magic

Before few days i posted about Intel hex file and how to generate hex file using keil simulator. If you dont know about this things then you can go through following links...


Flash Magic is a tool which used to program hex code in EEPROM of micro-controller. it is a freeware tool. It only supports the micro-controller of Philips and NXP. You can burn a hex code into those controller which supports ISP (in system programming) feature. To check whether your micro-controller supports ISP or not take look at its datasheet. So if your device supports ISP then you can easily burn a hex code into EEPROM of your device.

Flash magic supports several chips like ARM Cortex M0, M3, M4, ARM7 and 8051. You can found list of supported devices from HERE

The procedure to program code memory is very easy and needs only five steps to configure Flash magic for better operation. Flash magic use Serial or Ethernet protocol to program the flash of device. Below is the screenshot of flash magic.


Now here i am going to show you how to use this tool and configure it. First of all go to options and then go to advanced options.


then keep following setting in all different tabs of Advanced setting.









After configuring above settings then just go to following 5 steps..

Step-1 Communication:


1) Select your target device
2) Select your com port and if you are using USB to serial converter make sure that you will select proper com port other wise you can not communicate
3) Now select baud rate ideally it should be 9600 (recommended). Avoid higher than 9600 for proper communication
4) Now select your interface if you are using DB-9 then it will be None (ISP)

Step-2 Erase:


Now here tick mark the Erase all Flash option. This is the most crucial thing because wrong selection in this step can be result into lost of boot loader in your chip. Nothing to worry if you lost your boot loader because you can again load it but to load boot loader you must program you chip through universal programmer or any other programmer which is not depend upon boot loader for loading hex code. After loading boot loader you can again able to program your chip using flash magic.

Step-3 Hex file:


This is very simple and you need to set up a path of your Hex file which is to be loaded on chip.

Step-4 Options:



In this always keep Verify after programming option enable by tick mark. You can use another features as well according to your need.

Step-5 Start:


Now you are all set to burn your code memory just click on start but and it will start to load hex code in your chip. You can see the process at the bottom.


Do comment if you found any trouble or problem to understand.

Download

Share this with your friend...

C library for microcontrollers - How to use..??

using C library for 8051
Most embedded systems are currently being developed in C language. The main advantage of programming microcontroller in C language is that we can develop our own embedded library in C and use it anytime. Lots of development tools are available to write source code in embedded C for example keil, mikroC, SDCC etc.

I am gonna upload some of the important embedded C library which you can directly use in your project with little or no modification. I will recommend please go through every tiny part of my library especially the declaration part of pins, ports and variables because this will help you in designing your circuit diagram and developing your algorithm. So before going to this article lets have some clear understanding about C library.

What is C library..??

Every C library contains variables and functions which are responsible perform some process or action defined by users and return some value or data. The major component of library are....

  • Header File (having ".h" extension)
  • Standard C file (having ".c" extension)

1) Header File:  Header file consists variable declaration and the function declaration (prototype) which are being defined in C file. If you want to use your header file in more than one file than variables should be declare by "extern" keyword in header file. Functions can also be declared by "extern" keyword

2) C file: The C file contains the definition of function which are declared in header file and may or may not be return some value to the source file. If function is returning any value then it must be stored in variable which having specific data type i.e. same as data type of return variable at the time of function call.

How to use C library of ThE nIk'S wOrLd NiK's RuLeS..?? 

Here i am only going to discuss about Keil. Download library files from link given at the bottom of this post and unzip it. Now paste both the files i.e. header file and C file in your project directory.

Now in Project Workspace right click on Source Group 1 and then click on Add File to Group 'Source Group 1'

Adding files to source group in keil
Adding ".C" file in Source Group
Now one dialogue box appear in that dialogue box select "C Source File (*.c)" from "Files of Type". So it only shows the file having ".C" extension. Select the file which you want to add and click on "Add" button and then click on "Close" button.

Selecting ".C" file to be add in Source Group
Selecting ".C" file to add in Source Group
Verify the Project Workspace window now showing the file in your source group. Make sure that it must have extension of ".c"

So we are done with our one file i.e. C source file of library. Lets come to adding the header file. It is very simple but make sure that both this file must be available in your current project directory. To add the header file just simply write the following line of code in your main source file (The file having main function).

#include<name_of_header_file.h>

here name_of_header_file must be replaced by the actual file name.

To verify whether the file added accurately and working perfectly click on "Translate Current File" in Build tool. After finishing process header file must be appear under the main source file.

After complete procedure your code should look like similar to below piece of code.
#include<reg51.h> // Standard header file for 8051 family
#include<name_of_header_file.h> // replace "name_of_header_file" with actual file name

// Function Prototyping..No need for the functions of library

// Global variable declaration...

// Pin and Ports declaration...

void main()
{
    // Code statements...

    While(1)   // Repeat forever..
    { 

       // Code statements...

    }

} 

For download library file click here...  and navigate to list of libraries.

If you having any query or doubt feel free to use comment...

Thursday, January 17, 2013

Loading Hex file in 8051

Micro-controller only understands binary language. So we need to install hex code into the ROM of controller chip. There are so many loaders available in the market to flash the ROM of micro-controllers. But they are very costly. As i posted earlier about flash magic and specification of p89v51xx chip. We can program hex file easily into ROM.


So you can download this tool from their and it is completely free. We are going to use DB-9 cable or RS-232 in this tutorial.


How it is work..???

As i mentioned flash magic is only support those device which supports ISP. So such chip has boot loading software in built and it is known as a boot loader. So our main target is to put our victim chip into boot loading mode. This is achieved by resetting chip.

when start button of flash magic is pressed to indicate flashing the ROM, it continuously sends 'U' to controller and when the chip is being reset, it goes into boot load mode and gives the echo to flash magic and hex code is then loaded into ROM.

So there is mainly two ways to put chip in boot loading mode..
    1) Using Reset switch
    2) Without Reset switch

Using Reset switch

Circuit diagram is given below. Using reset switch you can put chip into boot loading mode by using two method, in both the method circuit diagram remains same.


Method-1 :

1) Configure flash magic
2) Power up your circuitry
3) Click on "start" button in flash magic
4) When it ask for "Reset device" press reset switch

Method-2 :

1) Configure flash magic
2) Power up your circuitry
3) Press and hold reset switch
4) Click on "start" button in flash magic
5) When it ask for "Reset device" release reset switch

Without using reset switch

Circuit diagram is given below and the only difference in this is that it does not contain reset switch. So the feature which we gonna use here is brown out detection. Go through below post..




1) Configure Flash magic
2) Click on "start" in flash magic
3) When it asks for "Reset device" power up your circuitry

So its very easy and less time consuming. You can use any method suitable to you. Do comment if you have any doubt or trouble.

Download

Please share this with your friend...

Dual Tone Multiple Frequency - DTMF

DTMF stands for dual tone multiple frequency. DTMF is a term which used in telephone industry. When any key on telephone or mobile phone is pressed one tone is generated and it is audible which is nothing but a DTMF tone. To decode DTMF tone from mobile phone we need MT8870 DTMF decoder IC, 3.5mm male and female connector.


What is DTMF code..??

When any of the key like "1", "2", "*", "#" etc is pressed particular code is transmitted. This code is consist of two frequency among which one is higher frequency and second one is lower frequency. Following table shows the combination of frequency for respected keys.

1 2 3 697 Hz
4 5 6 770 Hz
7 8 9 852 Hz
* 0 # 941 Hz
1209 Hz 1336 Hz 1447 Hz

According to above table "8" is combination of lower frequency of 852 Hz and higher frequency of 1336 Hz and "#" is of lower frequency of 941 Hz and higher frequency of 1447 Hz. So this is all about DTMF code, now let see about how DTMF code are generated, transmitted and Decoded in mobile phone system. Here i am only talk about GSM system.

Transmission of DTMF code in GSM network

In GSM networks so many channels are available but mainly there is only two channels...
    1) Physical Channels
    2) Logical Channels

DTMF code are transmitted in FACCH i.e. fast associated control channel. Complete hierarchy of FACCH  is given below

  • GSM Channels
    • Logical Channels
      • Signalling Channels
        • Dedicated Control Channels
          • Fast Associated Control Channel

FACCH is a bidirectional channel i.e. uplink and downlink. It is used to transmit and receive emergency controlling signal messages. When any data or message need to be transmitted through this channel, it will replace the voice signal to digital signalling data for very short amount of time.

Decoding DTMF code

When any DTMF code has been received at mobile phone it can be audible through speaker. So to decode this DTMF code speaker output it self can be used. Output of speaker is connected to IC MT8870 which is DTMF decoder IC. (MT8870 Datasheet) It used widely to decode DTMF code. It gives 4-bit digital output q1, q2, q3, and q4 according to the received key. Following table shows the equivalent digital output for each key.

DTMF code table

Connecting mobile phone with MT8870

Our main aim is to connect mobile phone's speaker output to MT8870 so for achieving this we will use aux cable which has 3.5mm male audio jack at both its end as shown in below image. 3.5mm audio jack is a TRS connector which is Tip Riing Sleeve (ground) as shown in below image. Now we will use 3.5mm female audio jack to get mobile phone's speaker output and connect it with MT8870. Go through following images to get clear understanding..

Aux cable
Aux Audio Cable

 3.5mm jack specification
3.5mm Male Jack Specifications

3.5mm female connector
3.5mm Female Jack

Connection Diagram for MT8870

Circuit diagram for decoding DTMF code using MT8870 is given below. In our requirement MT8870 is configured in single-ended input configuration.

Circuit diagram to decode DTMF code using MT8870

As shown in circuit MT8870 needs crystal oscillator of 3.58MHz (Exactly 3.579545 MHz) and 5v Vcc supply to be functional. Crystal is connect in between pin no 7 and 8. Pin no 8 is connected to Vcc and 9 is connected to ground. Now lets talk about pin description of MT8870 but before that take look at internal structure of MT8870.

Courtesy : Mitel

Pin Description of MT8870:

1 IN+ : This pin is input to the non-inverting terminal of internal op-amp.

2 IN- : This pin is input to the inverting terminal of internal op-amp. Input signal from the mobile is applied to this pin using 3.5mm connector pairs and aux cable.

3 GS : Gain selector, This pin provides feedback to the op-amp circuitry. Feedback resistor of appropriate value is connected between this pin and input signal. Value of resistor decides the gain of amplification. 

4 Vref : Reference Voltage, This is output pin. Op-amp is configured in differential amplifier mode and both the inputs are bias in mid-rail range so for that generally Vcc/2 voltage is apply to non-inverting terminal hence Vref is connected to IN+ i.e. pin no 1.

5 INH : Inhibit, This is active high input pin. If you don't want to decode A,B,C,D then connect this pin to Vcc and if you want to decode them then connect it to ground, internally it is pulled down.

6 PD : Power down, This is also active high input pin. Vcc supply (High) at this pin enables the power down mode and in power down mode oscillator and internal filters stops functioning and IC goes to stand by mode.

10 TOE : Three state output enable, This is active high input pin. +Vcc at this pin will allow output Q1, Q2, Q3 and Q4 to latch data from internal latch circuitry. When this pin is connected to ground output Q1 to Q4 will not latch decoded DTMF code. This pin also pulled up internally.

11 to 14 Q1 to Q4 : four output bits, When TOE is connected to Vcc this will represents the DTMF code as per valid DTMF tone and when TOE is connected to ground this pins are remain in high impedance state.

15 StD : Delayed steering, This is output pin. When DTMF tone received, decoded and latched by the output pins Q1 to Q4 then Std will goes high and when voltage on pin no 17 i.e St/Gt falls below threshold voltage Vtst then Std again fall down to low.

16 ESt : Early steering, This is output pin. If valid DTMF tone is received then this pin goes high and remains high till any loss of signal occurs however Loss of signal make this pin to go logic low.

17 St/Gt : This is dual purpose pin and performed bidirectional operation i.e St - Steering input as input and Gt - Guard time as output. When voltage greater Vtst appears at St, it causes latch to register new output data. GT is used to configure time constant of Est pin.

Filters and Detector Section

This circuitry is varies vendor by vendor. But most of the ICs are used two band pass filters one is for low tone group frequency and another one for high tone group frequency. Mostly anti-aliasing and switched capacitor filters are used. Detector sections generally used digital counting techniques to verify the valid DTMF tone and produce output.

Complete process hierarchy is given in below image.

Process of decoding DTMF code using MT8870 from mobile phone

MT8870 IC don't have good noise immunity at output side so to remove this drawback inverter IC can be used which inverts the DTMF code and gives good noise immunity.


If you having any doubt feel free to do comment...