Sunday, 22 September 2013

Interfacing SD Card with 8051 (AT89S52) microcontroller



SD card is preferred due to its small size, High memory capacity, non-volatile memory,  Low power consumption and low cost. So this memory product is used in most of the consumer electronic products.
If you want to make a data acquisition system which should store a vast amount of data then SD card is a very good choice. This article describes the interfacing of the SD card with AT89S52 microcontroller.

Interfacing SD card with AT89S52
SD card works at 3.3v TTL logic while the microcontroller works on a logic level of 5v CMOS level standards. so they cannot connected directly. If we connected the sure the SD card will be damaged.
To Solve this problem we need a voltage level converter circuit in between the SD card and the 89s52 microcontroller. We can use SN74LS4245 dedicated level converter chip, which perform the level conversion.
If you need to build a cheap level converter then we can make it with a simple NPN transistor.

Connect the 5V side to the microcontroller and 3.3v side to the SD card. This circuit can only be used for transferring the data from microcontroller to SD card. And for transferring the data from the SD card to microcontroller you can directly connect the pins since the microcontroller 89S52 can read the data at 3.3v logic.
Communication Mode
There are 2 communication protocols for SD card. They are SD mode and SPI mode. SD mode is a standard SD card read-write mode. But it needs an SD card controller interface. But AT89S52 doesn’t have an integrated SD card interface controller. so we go for the next mode which is SPI mode. It just needs an 4 wire for data communication. Also a lot of microcontrollers now in the market have inbuilt SPI interface circuit.
Although the AT89S52 doesn’t have an inbuilt SPI hardware controller we can use a software SPI controller to simulate the SPI bus.
Also AT89s52 has only 256byts of RAM while the sd card read and write blocks need 512byts at a time. So we need an external RAM which should be interfaced with the microcontroller. In this circuit we are using 62256 IC which has an capacity of 32KB.
Software Design
During power on the sd card will be in SD bus mode. Send an reset command CMDO to enter into SPI mode. Sending data to the SD card is done by creating a software SPI bus. Use this following code to transmit data to the SD card.
*********************************************************************************
sbit CS=P1^0;
sbit CLK= P1^1;
sbit DATaI=P1^2;
sbit DATaO=P1^3;
#define SD_Disable() CS=1 //Disable CS
#define SD_Enable() CS=0 //Enable CS

unsigned char SPI_TransferByte(unsigned char val)
{
unsigned char BitCounter;
for(BitCounter=8; BiCounter!=0; BitCounter--)
{ CLK=0;
DATaI=0; // write
if(val&0x80) DATaI=1;
val<<=1;
CLK=1;
if(DATaO)val|=1; // read
}
CLK=0;
return val;
}

Initializing the SD card

unsigned char SD_Init(void)
{ unsigned char retry,temp;
unsigned char i;
for (i=0;i<0x0f;i++)
{ SPI_TransferByte(0xff); //delay
}
SD_Enable(); //Enable Chip select

SPI_TransferByte(SD_RESET); //send a reset command
SPI_TransferByte(0x00);
SPI_TransferByte(0x00);
SPI_TransferByte(0x00);
SPI_TransferByte(0x00);
SPI_TransferByte(0x95);
SPI_TransferByte(0xff);
SPI_TransferByte(0xff);
retry=0;

do{ temp=Write_Command_SD(SD_INIT,0);
//Send the initialization command
retry++;
if(retry==100) //retry 100 times
{SD_Disable(); //disable chip select

return(INIT_CMD1_ERROR);
//If retry fails returns an error number
}
}while(temp!=0);

SD_Disable(); //disable card
return(TRUE); //return success
}

*******************************************************************************

Reading and Writing data Blocks
After the completion of the initialization of SD card we can carry out its read and write operations.
SPI Bus mode supports single block (CMD24) and multi-block (CMD25) write operation. Multi-block operation is to write down starting from the specified location, until the SD card before receiving a stop command CMD12 to stop.
A single block write operation of data block length of only 512 bytes.
For reading the SD card the CMD17 is used and the SD card will reply with 0XFE followed by the 512byte of data and last 2 bytes are CRC verification code.

Interfacing SD Card with 8051 (AT89S52) microcontroller



SD card is preferred due to its small size, High memory capacity, non-volatile memory,  Low power consumption and low cost. So this memory product is used in most of the consumer electronic products.
If you want to make a data acquisition system which should store a vast amount of data then SD card is a very good choice. This article describes the interfacing of the SD card with AT89S52 microcontroller.

Interfacing SD card with AT89S52
SD card works at 3.3v TTL logic while the microcontroller works on a logic level of 5v CMOS level standards. so they cannot connected directly. If we connected the sure the SD card will be damaged.
To Solve this problem we need a voltage level converter circuit in between the SD card and the 89s52 microcontroller. We can use SN74LS4245 dedicated level converter chip, which perform the level conversion.
If you need to build a cheap level converter then we can make it with a simple NPN transistor.

Connect the 5V side to the microcontroller and 3.3v side to the SD card. This circuit can only be used for transferring the data from microcontroller to SD card. And for transferring the data from the SD card to microcontroller you can directly connect the pins since the microcontroller 89S52 can read the data at 3.3v logic.
Communication Mode
There are 2 communication protocols for SD card. They are SD mode and SPI mode. SD mode is a standard SD card read-write mode. But it needs an SD card controller interface. But AT89S52 doesn’t have an integrated SD card interface controller. so we go for the next mode which is SPI mode. It just needs an 4 wire for data communication. Also a lot of microcontrollers now in the market have inbuilt SPI interface circuit.
Although the AT89S52 doesn’t have an inbuilt SPI hardware controller we can use a software SPI controller to simulate the SPI bus.
Also AT89s52 has only 256byts of RAM while the sd card read and write blocks need 512byts at a time. So we need an external RAM which should be interfaced with the microcontroller. In this circuit we are using 62256 IC which has an capacity of 32KB.
Software Design
During power on the sd card will be in SD bus mode. Send an reset command CMDO to enter into SPI mode. Sending data to the SD card is done by creating a software SPI bus. Use this following code to transmit data to the SD card.
*********************************************************************************
sbit CS=P1^0;
sbit CLK= P1^1;
sbit DATaI=P1^2;
sbit DATaO=P1^3;
#define SD_Disable() CS=1 //Disable CS
#define SD_Enable() CS=0 //Enable CS

unsigned char SPI_TransferByte(unsigned char val)
{
unsigned char BitCounter;
for(BitCounter=8; BiCounter!=0; BitCounter--)
{ CLK=0;
DATaI=0; // write
if(val&0x80) DATaI=1;
val<<=1;
CLK=1;
if(DATaO)val|=1; // read
}
CLK=0;
return val;
}

Initializing the SD card

unsigned char SD_Init(void)
{ unsigned char retry,temp;
unsigned char i;
for (i=0;i<0x0f;i++)
{ SPI_TransferByte(0xff); //delay
}
SD_Enable(); //Enable Chip select

SPI_TransferByte(SD_RESET); //send a reset command
SPI_TransferByte(0x00);
SPI_TransferByte(0x00);
SPI_TransferByte(0x00);
SPI_TransferByte(0x00);
SPI_TransferByte(0x95);
SPI_TransferByte(0xff);
SPI_TransferByte(0xff);
retry=0;

do{ temp=Write_Command_SD(SD_INIT,0);
//Send the initialization command
retry++;
if(retry==100) //retry 100 times
{SD_Disable(); //disable chip select

return(INIT_CMD1_ERROR);
//If retry fails returns an error number
}
}while(temp!=0);

SD_Disable(); //disable card
return(TRUE); //return success
}

*******************************************************************************

Reading and Writing data Blocks
After the completion of the initialization of SD card we can carry out its read and write operations.
SPI Bus mode supports single block (CMD24) and multi-block (CMD25) write operation. Multi-block operation is to write down starting from the specified location, until the SD card before receiving a stop command CMD12 to stop.
A single block write operation of data block length of only 512 bytes.
For reading the SD card the CMD17 is used and the SD card will reply with 0XFE followed by the 512byte of data and last 2 bytes are CRC verification code.

Friday, 13 September 2013

How To Test Remote Control

Here is a useful tool to test the working of the Remote handsets used for operating TV, VCD player and other remote operated gadgets. These devices use Infrared rays pulsating at 38 kHz and the sensor used is the TSOP 1738 specially designed to sense the 38 kHz IR rays. The circuit gives beeps when it detects the pulsed IR rays from the remote handset.
About Photo Sensor:

The IR Sensor TSOP 1738 is a sophisticated Photo module with circuitry to sense and amplify the pulsed IR rays. It has a PIN photodiode and a pre amplifier stage enclosed in an epoxy case. It is 3 pin device with an active low output. That is, in the stand by state (without receiving IR rays) its output will be high giving +5 volts. When it senses the IR rays, its output turns low and sinks current. The circuit inside the photo module amplifies the coded pulses of IR rays coming from the IR LED of the handset. The photodiode is the detector of IR rays from which the signals pass into an AGC (Automatic Gain Control) stage and then into a Band pass filter. From there, the signals will be demodulated and send to the output transistor. When the Photodiode senses IR rays, the output transistor sinks current.



Features of TSOP 1738:
1. Demodulated output can be directly decoded by a microprocessor
2. Internal filter for PCM frequency
3. TTL and CMOS compatibility
4. Low power consumption of 5 volt at 5 mA. Above 5V, the device will be destroyed
5. Immunity against ambient light
6. Noise protection
7. Continuous data transmission up to 2400 bps
8. Suitable burst length of 10 cycles per second. Between each 10 to 70 cycles, a time gap of 14 cycles is necessary to reset the module.
9. The module will not respond to continuous IR rays
10. Filament lamp, Fluorescent lamp, Sunlight etc may affect the functioning of the module and may induce false triggering.
Remote Circuit Diagram:
Working of the circuit is simple. Zener diode ZD and the current limiter R1 gives 5 volts regulated power supply for the IR sensor. Normally, the output of the sensor will be high which inhibits the working of PNP transistor T1 and buzzer will be off. When the sensor gets IR rays from the remote, the output of the sensor turns low and triggers T1. It then conducts and buzzer beeps. Resistor R2 keeps the base of T1 high in the standby state and C1 act as a buffer. C2 keeps buzzer on for few seconds even if the IR ray stops. R3 discharges the stored current from C2.

 
Remote Circuit Diagram:
Working of the circuit is simple. Zener diode ZD and the current limiter R1 gives 5 volts regulated power supply for the IR sensor. Normally, the output of the sensor will be high which inhibits the working of PNP transistor T1 and buzzer will be off. When the sensor gets IR rays from the remote, the output of the sensor turns low and triggers T1. It then conducts and buzzer beeps. Resistor R2 keeps the base of T1 high in the standby state and C1 act as a buffer. C2 keeps buzzer on for few seconds even if the IR ray stops. R3 discharges the stored current from C2.

 
In addition to TSOP 1738, other sensors are also available. The following table helps you to identify the pin connection of IR modules.

CALL BELL WITH WELCOME INDICATION

Here is a simple call bell circuit that displays a welcome message when somebody presses the call bell switch momentarily. The alphanumeric display can be fitted near the call bell switch.
The circuit is built around two 555 ICs (IC1 and IC2), seven KLA511 common-anode alphanumeric displays (DIS1 through DIS7) and a few discrete components. For easy understanding, the entire circuit can be divided into two sections: controller and display. The controller section is built around IC1 and IC2, while the display section is built around alphanumeric displays DIS1 through DIS7).

As shown in the circuit, both IC1 and IC2 are wired as monostable multivibrators having time periods of around 5 seconds and 2 minutes, respectively. You can change the time period of IC1 by changing the values of resistor R12 and capacitor C3. Similarly, the time period of IC2 can be changed by changing the values of resistor R2 and capacitor C1. Alphanumeric displays DIS1 through DIS7 are wired such that they show 'WELCOME' when the output of IC2 goes high.

Working of the circuit is simple. First, power-on the circuit using switch S2. LED1 glows to indicate presence of power supply in the circuit. Now if you press call bell switch S1 momentarily, it triggers both the timers (IC1 and IC2) simultaneously. IC1 produces a high output at its pin 3 for about five seconds. transistor T2 conducts and piezobuzzer PZ1 sounds for about five seconds indicating that there is somebody at the door. At the same time, IC2 too produces a high output at its pin 3 for about two minutes. Transistor T1 conducts to enable the alphanumeric displays. The word 'WELCOME' is displayed for about two minutes as DIS1 through DIS7 ground via transistor T1. If switch S1 is pressed again within these two minutes, piezobuzzer PZ1 again sounds for five seconds and the display continues to show 'WELCOME'.
Assemble the complete circuit on a general-purpose PCB and house in a small cabinet with call bell switch S1 and LED1 mounted on the front panel. At the rear side of the cabinet, connect a DC socket for the adaptor. Install the complete unit (along with the display) at the entrance of your house. Connect the 6V battery or 6V adaptor for powering the circuit. Configure switch 2 (used to enable/disable the call bell) in a switch board at a suitable location inside your house. If you don'tuse a battery, connect the power adaptor to the DC socket on the rear of the cabinet. Close switch S2 only when you want to activate the circuit with battery. Otherwise, keep it open when the 6V adaptor is in use.

USB FM Transmitter Circuit for PC and Laptop

Here's a small FM transmitter ciruit for your desktop or laptop to enjoy the movie and music from a distance. This FM transmitter, which is powered by USB, recovers output on your computer or your MP3 player to the relay on the tape FM (frequency 108 MHz). For Assemblying this FM transmitter kit, an electronics hobbyist will have built in about 30 minutes


FM Transmitter Construction
It is not necessary to drill the transmitter PCB. All components will be soldered to the plate with their legs folded.

The two transistors and the LEDs are polarized:
The transistor has a flat side, the LED a foot longer than the other is the anode (A), the other is the cathode (K). The audio cable (minijack) must be transformed from a stereo cable into a cable.


Mono Sound:
Soldering together the white and red cables, leaving aside the yellow cable (mass). The frequency setting will be turning the variable capacitor gently with a screwdriver or thin cardboard but rigid.

 FM Transmitter Parts List
* 1 Ohm resistor 510 (green - brown - brown)
* 100 resistor 1 kOhm (brown - black - yellow)
* 1 MOhm resistors (brown - black - green)
* 1 capacitor 0.1 uF (0.1)
* 1 nF capacitor 47 (0.047)
* 1 capacitor 4.7 pF (479)
* 2 pF capacitors 22 (22)
* 1 variable capacitor 1.5 pF ... 15
* 2 transistor BF 246 (F246A)
* 1 red LED
* 1 audio cable (minijack)


Saturday, 2 February 2013

NON CONTACT TECHOMETER



The aim of the project is to design a contactless speed sensing device (tachometer) for a Brushless DC (BLDC) motor. Traditional tachometers require a physical contact to the shaft of the motor to measure the speed. In certain applications, where it is not feasible to measure the speed for safety and technical reasons, it is possible for a contactless tachometer to take the readings from a certain distance.

This proposed system uses the IR transmitting and receiving technique. This is achieved by receiving IR rays from a reflecting spot on the shaft of the motor. Such arrangements can measure the rate at which the IR rays are getting reflected back. The project uses a microcontroller of 8051 family. A pair of sensors (Transmitter and receiver) is used to develop a pulse for each reflection that sends an interrupt to the microcontroller. The timer of the controller calculates the speed by each pulse received in a particular time interval and displays the same. The microcontroller is interfaced with an LCD to display the speed.

The concept of the contact-less tachometer can be enhanced and implemented in the bikes, cars for speed measurement, avoiding the use of traditional analog speedometer.