Sie sind auf Seite 1von 57

1.

INTRODUCTION TO AN EMBEDDED SYSTEM An Embedded System employs a combination of hardware & software (a computational engine) to perform a specific function; is part of a larger system that may not be a computer works in a reactive and time-constrained environment. Software is used for providing features and flexibility. Hardware is used for performance & sometimes security. An embedded system is a special purpose system in which the computer is completely encapsulated by the device it controls. Unlike a general purpose computer, such as a PC, an embedded system performs predefined tasks usually with very specific tasks design engineers can optimize it reducing the size and cost of the product. Embedded systems are often mass produced, so the cost savings may be multiplied by million of items.The core of any embedded system is formed by one or several microprocessor or micro controller programmed to perform a small number of tasks. Microcontroller are widely used in Embedded System products. An Embedded product uses the microprocessor(or microcontroller) to do one task & one task only. A printer is an example of Embedded system since the processor inside it perform one task only namely getting the data and printing it. Contrast this with Pentium based PC. A PC can be used for any no. of applications such as word processor, print server, bank teller terminal, video game player, network server or internet terminal. Software for variety of applications can be loaded and run. Of course the reason a PC can perform multiple task is that it has RAM memory and an operating system that loads the application software into RAM & lets the CPU run it. In and Embedded system there is only one application software that is typically burn into ROM. One of the most critical needs of the embedded system is to decrease power consumptions and space. This can be achieved by integrating more functions into the CPU chips. All the embedded processors have low power consumptions in additions to some forms of I/O,Serial Com port & ROM all on a single chip. In higher performance Embedded system the trend is to integrate more & more function on the CPU chip & let the designer decide which feature he/she wants to use.

Page | 1

EXAMPLES OF EMBEDDED SYSTEM:-

o Automated tiller machines (ATMS). o Avionic, such as inertial guidance systems, flight control hardware / software and letter integrated system in aircraft and missile. o Cellular telephones and telephonic switches. o Computer network equipment, including routers timeservers and firewalls o Computer printers, Copiers. o Disk drives (floppy disk drive and hard disk drive) o Engine controllers and antilock brake controllers for automobiles. o Home automation products like thermostat, air conditioners sprinkles and security monitoring system. o House hold appliances including microwave ovens, washing machines, TV sets DVD players/recorders. o Medical equipment. o Measurement equipment such as digital storage oscilloscopes, logic analyzers and spectrum analyzers. o Multimedia appliances: internet radio receivers, TV set top boxes. o Personal digital assistants (PDAs), i.e., small hand held computer with P1M5 and other applications. o Programmable logic controllers (PLCs) for industrial automation and monitoring. o Stationary video game controllers. o Wearable computers.

Page | 2

2. LIST OF COMPONENTS USED

Printed Circuit Board


Microcontroller AT89S52

LCD IN4007 diodes(4) Step down transformer(12-0 V) LEDs(2) 7805 Voltage Regulator Crystal Oscillator - 11.0592MHz.

Capacitor - 33 uF (2), 10 uf (2), 1000 uf (1).

Resistor -470 ohm(6) ,10 kohm(2)

ON/OFF Switch.

Transistor- BC369 PNP.

Optocoupler 4N35(4)

RELAYS(4) Ribbon Wire. 1738 TSOP Remote Soldering Material ( soldering iron,wire& stand) Cutter Cardboard

Page | 3

3. TOOLS REQUIRED

KEIL MICROVISION3.0(COMPILER) PCB WIZARD SOFTWARE WINDOWS 7 SUPPLY DIGITAL CAMERA

Page | 4

4. PCB designing
A printed circuit board, or pcb is used to mechanically support and electrically connect electronics componints using conductive paths ,tracks or signal traces etched from copper sheets laminated onto a non-conductive substrate. It is also referred to as printed wiring board (PWB) or etched wiring board. Printed circuit boards are used in virtually all but the simplest commercially produced electronic devices. A PCB populated with electronic components is called a printed circuit assembly (PCA), printed circuit board assembly or PCB Assembly (PCBA).

Fig2.1.PCB Layout

Page | 5

5 REGULATED POWER SUPPLY Power supplies are designed to convert high voltage AC mains to a suitable low voltage supply for electronic circuits and other devices. A power supply can be broken down into a series of blocks, each of which performs a particular function. For example a 5V regulated supply:

Fig3.1.Block Diagram of Regulated Power Supply

Fig3.2.Power supply Each of the blocks has its own function as described below 1. Transformer steps down high voltage AC mains to low voltage AC. 2. Rectifier converts AC to DC, but the DC output is varying. 3. Smoothing smoothes the DC from varying greatly to a small ripple. 4. Regulator eliminates ripple by setting DC output to a fixed voltage. 5.1 TRANSFORMER
Page | 6

Transformers convert AC electricity from one voltage to another with little loss of power. Transformers work only with AC and this is one of the reasons why mains electricity is AC. The two types of transformers Step-up transformers increase voltage, Step-down transformers reduce voltage.

Page | 7

Most power supplies use a step-down transformer to reduce

the dangerously high

mains

voltage to a safer low voltage. The input coil is called the primary and the output coil is called the secondary. There is no electrical connection between the two coils,instead yjey are linked by an alternaying magnetic field created in soft-iron core of the transformer. The two lines in the middle of the circuit symbol represent the core. Transformers waste very little power so the power out is (almost) equal to the power in. Note that as voltage is stepped down current is stepped up. The ratio of the number of turns on each coil, called the turn ratio, determines the ratio of the voltages. A step-down transformer haslarge number of turns on its primary (input) coil which is connected to the high voltage mains supply, and a small number of turns on its secondary (output) coil to give a low output voltage.

Turns Ratio =

And

Power Out = Power In Vs Is = Vp Ip

Where

Vp = primary (input) voltage Np = number of turns on primary coil Ip = primary (input) current Ns = number of turns on secondary coil
Page | 8

Is = secondary (output) currenVs = secondary (output) voltage

Page | 9

5.2 Bridge Rectifier A bridge rectifier can be made using four individual diodes, but it is also available in special packages containing the four diodes required.It is called a full-wave rectifier because it uses all AC wave (both positive and negative sections). 1.4V is used up in the bridge rectifier because each diode uses 0.7V when conducting and there are always two diodes conducting, as shown in the diagram below. Bridge rectifiers are rated by the maximum current they can pass and the maximum reverse voltage they can withstand (this must be at least three times the supply RMS voltage so the rectifier can withstand the peak voltages). In this alternate pairs of diodes conduct, changing over the connections so the alternating directions of AC are converted to the one direction of DC.

Fig3.3.Output Full-wave varying DC

5.3 SMOOTHING Smoothing is performed by a large value electrolytic capacitor connected across the DC supply to act as a reservoir, supplying current to the output when the varying DC voltagevarying DC voltage from the rectifier is falling. The diagram shows the unsmoothed varying DC (dotted line) and the smoothed DC (solid line). The capacitor charges quickly near the peak of the varying DC, and then discharges as it supplies current to the output.

Fig3.4.Smoothing circuit and waveform Note that smoothing significantly increases the average DC voltage to almost the peak value (1.4 RMS value). For example 6V RMS AC is rectified to full wave DC of about 4.6V RMS (1.4V is lost in the bridge rectifier), with smoothing this increases to almost the peak value giving 1.4 4.6 = 6.4V smooth DC. Smoothing is not perfect due to the capacitor voltage falling a little as it discharges, giving a small ripple voltage.For many circuits a ripple which is 10% of the supply voltage is satisfactory and the equation below gives the required value for the smoothing capacitor. A larger capacitor will give fewer ripples. The capacitor value must be doubled when smoothing half-wave DC. Smoothing capacitor for 10% ripple, C = 5 Io / Vs f Where C = smoothing capacitance in farads (F) Io = output current from the supply in amps (A) Vs = supply voltage in volts (V), this is the peak value of the unsmoothed DC f = frequency of the AC supply in hertz (Hz)

5.4 REGULATOR

Fig3.5.Regulator Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or variable output voltages. They are also rated by the maximum current they can pass. Negative voltage regulators are available, mainly for use in dual supplies. Most regulators include some automatic protection from excessive current (overload protection') and overheating (thermal protection'). Many of the fixed voltage regulator ICs has 3 leads and look like power transistors, such as the 7805 +5V 1A regulator shown on the right. They include a hole for attaching a heat sink if necessary.

5.5 Working of Power Supply

Transformer

Fig3.6.Transformer and its Waveform The low voltage AC output is suitable for lamps, heaters and special AC motors. It is not suitable for electronic circuits unless they include a rectifier and a smoothing capacitor.

Transformer + Rectifier

Fig3.7.Transformer with rectifier and their waveform

The varying DC output it is not suitable for electronic circuits unless they include a smoothing capacitor.

Transformer + Rectifier + Smoothing

Fig3.8.Transformer with rectifier and smoothing and their waveform

The smooth DC output has a small ripple. It is suitable for most electronic circuits.

Transformer + Rectifier + Smoothing + Regulator

Fig3.9.Transformer with rectifier ,smoothing and regulator circuit with their waveform

The regulated DC output is very smooth with no ripple. It is suitable for all electronic circuits.

6. MICROCONTROLLER 8051/52
In our day to day life the role of micro-controllers has been immense. They are used in a variety of applications ranging from home appliances, FAX machines, Video games, Camera, Exercise equipment, Cellular phones musical Instruments to Computers, engine control, aeronautics, security systems and the list goes on. 6.1 Microcontroller versus Microprocessors What is the difference between a microprocessor and microcontroller? The microprocessors (such as 8086, 80286, 68000 etc.) contain no RAM, no ROM and no I/O ports on the chip itself. For this reason they are referred as general- purpose microprocessors. A system designer using general- purpose microprocessor must add external RAM, ROM, I/O ports and timers to make them functional. Although the addition of external RAM, ROM, and I/O ports make the system bulkier and much more expensive, they have the advantage of versatility such that the designer can decide on the amount of RAM, ROM and I/o ports needed to fit the task at hand. This is the not the case with microcontrollers. A microcontroller has a CPU (a microprocessor) in addition to the fixed amount of RAM, ROM, I/O ports, and timers are all embedded together on the chip: therefore, the designer cannot add any external memory, I/O, or timer to it. The fixed amount of on chip RAM, ROM, and number of I/O ports in microcontrollers make them ideal for many applications in which cost and space are critical. In many applications, for example a TV remote control, there is no need for the computing power of a 486 or even a 8086 microprocessor. In many applications, the space it takes, the power it consumes, and the price per unit are much more critical considerations than the computing power. These applications most often require some I/O operations to read signals and certainbits. It into the microcontrollers. is interesting to know turn on that some and off

microcontrollers manufactures have gone as far as integrating an ADC and other peripherals

6.2 A brief history of 8051 Family

In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. This microcontroller had 128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one serial port, and four ports (8-bit) all on a single chip. The 8051 is an 8- bit processor, meaning the the CPU can work on only 8 bit . The 8051 has a total of four I/O ports, each 8- bit wide. Although 8051 can have a maximum of 64K bytes of on-chip ROM, many manufacturers put only 4K bytes on the chip. The 8051 became widely popular after Intel allowed other manufacturers to make any flavor of the 8051 they please with the condition that they remain code compatible with the 8051. This has led to many versions of the 8051 with different speeds and amount of on-chip ROM marketed by more than half a dozen manufacturers. It is important to know that although there are different flavors of the 8051, they are all compatible with the original 8051 as far as the instructions are concerned. This means that if you write your program for one, it will run on any one of them regardless of the manufacturer. The major 8051 manufacturers are Intel, Atmel, Dallas Semiconductors, Philips Corporation, Infineon. 6.3 8051 microcontroller The 8051 is the original member of the 8051 family. Intel refers to it as MCS-51. Other members of the 8051 family There are two other members in the 8051 family of microcontrollers. They are the 8052 and the 8031.

AT89C51 from ATMEL Corporation: This popular 8051 chip has on-chip ROM in the form of flash memory. This is ideal for fast development since flash memory can be erased in seconds compared to twenty minutes or more needed for the earlier versions of the 8051. To use the AT89C51 to develop a microcontrollerbased system requires a ROM burner that supports flash memory: However, a ROM eraser is not needed. Notice that in flash memory you must erase the entire contents of ROM in order to program it again. The PROM burner does this erasing of flash itself and this is why a separate burner is not needed. To eliminate the need for a PROM burner Atmel is working on a version of the AT89C51 that can be programmed by the serial COM port of the PC.

Fig3.10. Atmel Microcontroller AT89C51 Hardware features 40 pin IC 4 Kbytes of Flash 128 Bytes of RAM 32 I/O lines Two16-Bit Timer/Counters Two-Level Interrupt Architecture Full Duplex Serial Port On Chip Oscillator and Clock Circuitry Software features

Bit Manipulations Single Instruction Manipulation Separate Program And Data Memory 4 Bank Of Temporary Registers Direct, Indirect, Register and Relative Addressing.

In addition, the AT89C51 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Power down Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset. The Atmel Flash devices are ideal for developing, since they can be reprogrammed easy and fast. If we need more code space for our application, particularly for developing 89Cxx projects with C language. Atmel offers a broad range of microcontrollers based on the 8051 architecture, with on-chip Flash program memory.

Fig3.11.Internal Architecture of AT89C51

6.4 Pin description The 89C51 have a total of 40 pins that are dedicated for various functions such as I/O, RD, WR, address and interrupts. Out of 40 pins, a total of 32 pins are set aside for the four ports P0, P1, P2, and P3, where each port takes 8 pins. The rest of the

pins are designated as Vcc, GND, XTAL1, XTAL, RST, EA, and PSEN. All these pins except PSEN and ALE are used by all members of the 8051 and 8031 families. In other words, they must be connected in order for the system to work, regardless of whether the microcontroller is of the 8051 or the 8031 family. The other two pins, PSEN and ALE are used mainly in 8031 based systems.

Fig3.12.MC 8051

Vcc

Pin 40 provides supply voltage to the chip. The voltage source is +5V.

GND Pin 20 is the ground.

Oscillator Characteristics

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figure. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure.

Fig3.13.OscillatorConnections It must be noted that there are various speeds of the 8051 family. Speed refers to the maximum oscillator frequency connected to the XTAL. For example, a 12 sMHz chip must be connected to a crystal with 12 MHz frequency or less. Likewise, a 20 MHz microcontroller requires a crystal frequency of no more than 20 MHZ. When the 8051 is connected to a crystal oscillator and is powered up, we can observe the frequency on the XTAL2 pin using oscilloscope. RST Pin 9 is the reset pin. It is an input and is active high (normally low). Upon applying a high

pulse to this pin, the microcontroller will reset and terminate all activities. This is often referred to as a power on reset. Activating a power-on reset will cause all values in the registers to be lost. Notice that the value of Program Counter is 0000 upon reset, forcing the CPU to fetch the first code from ROM memory location 0000. This means that we must place the first line of source code in ROM location 0000 that is where the CPU wakes up and expects to find the first instruction. In order to RESET input to be effective, it must have a minimum duration of 2 machine cycles. In other words, the high pulse must be high for a minimum of 2 machine cycles before it is allowed to go low.

EA All the 8051 family members come with on-chip ROM to store programs. In such cases, the EA pin is connected to the Vcc. For family members such as 8031 and 8032 in which there is no on-chip ROM, code is stored on an external ROM and is fetched by the 8031/32. Therefore for the 8031 the EA pin must be connected to ground to indicate that the code is stored externally. EA, which stands for external access, is pin number 31 in the DIP packages. It is input pin and must be connected to either Vcc or GND. In other words, it cannot be left unconnected. PSEN This is an output pin. PSEN stands for program store enable. It is the read strobe to external program memory. When the microcontroller is executing from external memory, PSEN is activated twice each machine cycle. ALE ALE (Address latch enable) is an output pin and is active high. When connecting a microcontroller to external memory, port 0 provides both address and data. In other words the microcontroller multiplexes address and data through port 0 to save pins. The ALE pin is used for de-multiplexing

the address and data by connecting to the G pin of the 74LS373 chip. I/O port pins and their functions The four ports P0, P1, P2, and P3 each use 8 pins, making them 8-bit ports. All the ports upon RESET are configured as output, ready to be used as output ports. To use any of these as input port, it must be programmed.

Port 0 Port 0 occupies a total of 8 pins (pins 32 to 39). It can be used for input or output. To use the pins of port 0 as both input and output ports, each pin must be connected externally to a 10K-ohm pull-up resistor. This is due to fact that port 0 is an open drain, unlike P1, P2 and P3. With external pull-up resistors connected upon reset, port 0 is configured as output port. In order to make port 0 an input port, the port must be programmed by writing 1 to all the bits of it. Port 0 is also designated as AD0-AD7, allowing it to be used for both data and address. When connecting a microcontroller to an external memory, port 0 provides both address and data. The microcontroller multiplexes address and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE=0, it provides data D0- D7, but when ALE=1 it has address A0-A7. Therefore, ALE is used for de- multiplexing address and data with the help of latch 74LS373. Port 1 Port 1 occupies a total of 8 pins (pins 1 to 8). It can be used as input or output. In contrast to port 0, this port does not require pull-up resistors since it has already pull-up resistors internally. Upon reset, port 1 is configures as an output port. Similar to port 0, port 1 can be used as an input port by writing 1 to all its bits. Port 2 Port 2 occupies a total of 8 pins (pins 21 to 28). It can be used as input or output. Just like P1,

port 2 does not need any pull-up resistors since it has pull-up resistors internally. Upon reset port 2 is configured as output port. To make port 2 as input port, it must be programmed as such by writing 1s to it. Port 3 Port 3 occupies a total of 8 pins (pins 10 to 17). It can be used as input or output. P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although port 3 is configured as output port upon reset, this is not the way it is most commonly used. Port 3 has an additional function of providing some extremely important signals such as interrupts. Some of the alternate functions of P3 are listed below: P3.0 P3.2 RXD (Serial input) P3.1 TXD (Serial output) INT0 (External interrupt 0) P3.3 INT1 (External interrupt 1) P3.4 T0 (Timer 0 external input) P3.5 T1 (Timer 1 external input) P3.6 WR (External memory write strobe) P3.7 RD (External memory read strobe)

6.5 Memory Space Allocation Internal ROM The 89C51 has 4K bytes of on-chip ROM. This 4K bytes ROM memory has memory addresses of 0000 to 0FFFh. Program addresses higher than 0FFFh, which exceed the internal ROM capacity, will cause the microcontroller to automatically fetch code bytes from external memory. Code bytes can also be fetched exclusively from an external memory, addresses 0000h to FFFFh, by connecting the external access pin to ground. The program counter doesnt care where the code is: the circuit designer decides whether the code is found totally in internal ROM, totally in external ROM or in a combination of internal and external ROM.

Internal RAM The 128 bytes of RAM inside the 8051 are assigned addresses 00 to 7Fh. These 128 bytes can be divided into three different groups as follows: 1. A total of 32 bytes from locations 00 to 1Fh are set aside for register banks and the stack. 2. A total of 16 bytes from locations 20h to 2Fh are set aside for bit addressable read/write memory and instructions. A total of 80 bytes from locations 30h to 7Fh are used for read and write storage, or what is normally called a scratch pad. These 80 locations of RAM are widely used for the purpose of storing data and parameters by 8051 programmers.

7. LIQUID CRYSTAL DISPLAY


Liquid crystal displays (LCD) are widely used in recent years as compares to LEDs. This is due to the declining prices of LCD, the ability to display numbers, characters and graphics, incorporation of a refreshing controller into the LCD, their by relieving the CPU of the task of refreshing the LCD and also the ease of programming for characters and graphics. HD 44780 based LCDs are most commonly used. The LCD, which is used as a display in the system, is LMB162A. The main features of this LCD are: 16 X 2 display, intelligent LCD, used for alphanumeric characters & based on ASCII codes. This LCD contains 16 pins, in which 8 pins are used as 8-bit data I/O, which are extended ASCII. Three pins are used as control lines these are Read/Write pin, Enable pin and Register select pin. Two pins are used for Backlight and LCD voltage, another two pins are for Backlight & LCD ground and one pin is used for contrast change. Table3.3.LCD pin description Pin 1 2 3 4 Symbol VSS VCC VEE RS I/O I Description Ground +5V power supply Power supply to control contrast RS=0 to select command register, RS=1 to select data register. R/W=0 for write, R/W=1 for read Enable The 8 bit data bus

5 6 7

R/W E DB0

I I/O I/O

8 9 10 11 12 13 14

DB1 DB2 DB3 DB4 DB5 DB6 DB7

I/O I/O I/O I/O I/O I/O I/O

The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus The 8 bit data bus

The LCD discuss in this section has the most common connector used for the Hitachi 44780 based LCD is 14 pins in a row and modes of operation and how to program and interface with microcontroller is describes in this section. VCC, VSS, VEE The voltage VCC and VSS provided by +5V and ground respectively while VEE is used for controlling LCD contrast. Variable voltage between Ground and Vcc is used
1

to specify the contrast (or "darkness") of the characters on the LCD screen.

RS (register select) There are two important registers inside the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, then allowing to user to send a command such as clear display, cursor at home etc.. If RS=1, the data register is selected, allowing the user to send data to be displayed on the LCD.

R/W (read/write)

The R/W (read/write) input allowing the user to write information from it. R/W=1, when it read and R/W=0, when it writing. EN (enable) The enable pin is used by the LCD to latch information presented to its data pins. When data is supplied to data pins, a high power, a high-to-low pulse must be applied to this pin in order to for the LCD to latch in the data presented at the data pins. D0-D7 (data lines) The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCDs internal registers. To displays the letters and numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS =1. There are also command codes that can be sent to clear the display or force the cursor to the home position or blink the cursor. We also use RS =0 to check the busy flag bit to see if the LCD is ready to receive the information. The busy flag is D7 and can be read when R/W =1 and RS =0, as follows: if R/W =1 and RS =0, when D7 =1(busy flag =1), the LCD is busy taking care of internal operation and will not accept any information, when D7=0 the LCD is ready to receive new information

7.2 Interfacing of micro controller with LCD display In most applications, the "R/W" line is grounded. This simplifies the application because when data is read back, the microcontroller I/O pins have to be alternated between input and output modes. In this case, "R/W" to ground and just wait the maximum amount of time for each instruction (4.1ms for clearing the display or moving the cursor/display to the "home position", 160s for all other commands) and also the application software is simpler, it also frees up a microcontroller pin for other uses. Different LCD execute instructions at different rates and to avoid problems later on (such as if the LCD is changed to a slower unit). Before sending commands or data to the LCD module, the Module must be initialized. Once the initialization is complete, the LCD can be written to with data or instructions as required. Each character to display is written like the control bytes, except that the "RS" line is set. During initialization, by setting the "S/C" bit during the "Move Cursor/Shift Display" command, after each character is sent to the LCD, the cursor built into the LCD will increment to the next position (either right or left). Normally, the "S/C" bit is set (equal to "1") Table 3.4.LCD Command Code

Commands and Instruction set

Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. The internal operation of the LCD is determined by signals sent from the MCU. Sending Commands to LCD To send commands we simply need to select the command register. Everything is same as we have done in the initialization routine. But we will summarize the common steps and put them in a single subroutine. Following are the steps: 1. Move data to LCD port 2. Select command register 3. Select write operation 4. Send enable signal 5. Wait for LCD to process the command

Fig 3.14.LCD INTERFACING WITH MICROCONTROLLER

Fig3.15.ircuit diagram of LCD interfacing

8. Relay Driver using Optocoupler (Auto Electro Switching)


Relay is an electrically operated switch. Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil current can be on or off so relays have two switch positions and most have double throw (changeover) switch contacts as shown in the diagram.

Fig3.16.Relay Driver The relay's switch connections are usually labelled COM, NC and NO: COM = Common, always connect to the moving part of the switch. NC = Normally Closed, COM is connected to this when the relay coil is off. NO = Normally Open, COM is connected to this when the relay coil is on. Relays allow one circuit to switch a second circuit which can be completely separate from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. There is no electrical connection inside the relay between the two circuits; the link is magnetic and mechanical.

Fig3.17.Relay Devices The coil of a relay passes a relatively large current, typically 30mA for a 12V relay, but it can be as much as 100mA for relays designed to operate from lower voltages. Most ICs (chips) cannot provide

32 | P a g e

this current and a transistor is usually used to amplify the small IC current to the larger value required for the relay coil.

33 | P a g e

8.1 Pole and Throw Since relays are switches, the terminology applied to switches is also applied to relays. A relay will switch one or more poles, each of whose contacts can be thrown by energizing the coil in one of three ways: Normally-open (NO) contacts connect the circuit when the relay is activated; the circuit is disconnected when the relay is inactive. It is also called a Form A contact or make contact. Normally-closed (NC) contacts disconnect the circuit when the relay is activated; the circuit is connected when the relay is inactive. It is also called a Form B contact or break contact. Change-over (CO), or double-throw (DT), contacts control two circuits: one normally-open contact and one normally-closed contact with a common terminal. It is also called a Form C contact or transfer contact (break before make). If this type of contact utilizes make before break functionality, then it is called a Form D contact. The following designations are commonly encountered: SPST Single Pole Single Throw. These have two terminals which can be connected or disconnected. Including two for the coil, such a relay has four terminals in total. It is ambiguous whether the pole is normally open or normally closed. The terminology SPNO and SPNC is sometimes used to resolve the ambiguity. SPDT Single Pole Double Throw. A common terminal connects to either of two others. Including two for the coil, such a relay has five terminals in total.

Fig3.18.Designations

34 | P a g e

DPST Double Pole Single Throw. These have two pairs of terminals. Equivalent to two SPST switches or relays actuated by a single coil. Including two for the coil, such a relay has six terminals in total. The poles may be Form A or Form B (or one of each). DPDT Double Pole Double Throw. These have two rows of change-over terminals. Equivalent to two SPDT switches or relays actuated by a single coil. Such a relay has eight terminals, including the coil. The "S" or "D" may be replaced with a number, indicating multiple switches connected to a single actuator. For example 4PDT indicates a four pole double throw relay (with 14 terminals) 8.2 Choosing a relay You need to consider several features when choosing a relay: 1. Physical size and pin arrangement If you are choosing a relay for an existing PCB you will need to ensure that its dimensions and pin arrangement are suitable. You should find this information in the supplier's catalogue. 2. Coil voltage The relay's coil voltage rating and resistance must suit the circuit powering the relay coil. Many relays have a coil rated for a 12V supply but 5V and 24V relays are also readily available. Some relays operate perfectly well with a supply voltage which is a little lower than their rated value. 3. Coil resistance The circuit must be able to supply the current required by the relay coil. You can use Ohm's law to calculate the current:

35 | P a g e

RELAY COIL CURRENT= SUPPLY VOLTAGE / COIL RESISTANCE

For example: A 12V supply relay with a coil resistance of 400 passes a current of 30mA. This is OK for a 555 timer IC (maximum output current 200mA), but it is too much for most ICs and they will require a transistor to amplify the current. 4. Switch ratings (voltage and current) The relay's switch contacts must be suitable for the circuit they are to control. You will need to check the voltage and current ratings. Note that the voltage rating is usually higher for AC, for example: "5A at 24V DC or 125V AC". 5. Switch contact arrangement (SPDT, DPDT etc) Most relays are SPDT or DPDT which are often described as "single pole changeover" (SPCO) or "double pole changeover" (DPCO).

Protection diodes for relays Relay coils produce brief high voltage 'spikes' when they are switched off and this can destroy transistors and ICs in the circuit. To prevent damage you must connect a protection diode across the relay coil. Current flowing through a relay coil creates a magnetic field which collapses suddenly when the current is switched off. The sudden collapse of the magnetic field induces a brief high voltage across the relay coil which is very likely to damage transistors and ICs. The protection diode allows the induced voltage to drive a brief current through the coil (and diode) so the magnetic field dies away quickly rather than instantly. This prevents the induced voltage becoming high enough to cause damage to transistors and ICs

36 | P a g e

. Fig3.19.Protection Diodes

8.3 Relay and transistor comparison as switch Like relays, transistors can be used as an electrically operated switch. For switching small DC currents (< 1A) at low voltage they are usually a better choice than a relay. However, transistors cannot switch AC (such as mains electricity) and in simple circuits they are not usually a good choice for switching large currents (> 5A). In these cases a relay will be needed, but note that a low power transistor may still be needed to switch the current for the relay's coil. The main advantages and disadvantages of relays are listed below: Advantages of relays: Relays can switch AC and DC, transistors can only switch DC. Relays can switch higher voltages than standard transistors. Relays are often a better choice for switching large currents (> 5A). Relays can switch many contacts at once. Disadvantages of relays: Relays are bulkier than transistors for switching small currents. Relays cannot switch rapidly (except reed relays), transistors can switch many times per second. Relays use more power due to the current flowing through their coil. Relays require more current than many ICs can provide, so a low power transistor may be needed to switch the current for the relay's coil.
37 | P a g e

8.4 Relay Driver For its interfacing with microcontrollers or other low current digital ICs, a power or current amplifier circuit is required, known as relay driver circuits. Mainly two such driver circuits i.e. ULN2003 and transistor/optocouplers are often used. An Auto Electro Switching/Relay Driver circuit comprises of an optocoupler which will isolate the controller from the outer spikes or fluctuations or from the external hardware and at the same time it drives a power transistor i.e. make it on when a signal from the controller pin is applied to it. Optocoupler actually comprises of a diode and a phototransistor. It comes in a DIP IC package. Thus signal from the MCU is given to the LED part or the driving part. When LED begins to glow then the phototransistor acts as on switch or short circuit. This output is given to power transistor, which will amplify the current of the signal and then can be used to drive a relay. The I/P signal is connected to the Relays common terminal and the O/P can be taken from the relays NO terminal. When relay is ON then NO is connected to the common terminal of the relay.

Fig3.20.Block diagram of Relay driver Optocoupler It has one IR LED and a photo- transistor. One pin of the LED is connected to the MCU to get a signal
38 | P a g e

(0 or 1) and the pin is given ground. When the signal from the MCU is 0, then LED emits light. This light will turn on the NPN transistor. Emitter of the transistor is grounded. Collector is connected to the PNP transistor whose emitter is connected to Vcc and collector to the relay. The purpose of using the optocouplers is to pass the supply from the PC/MCU to the appliances & is for isolation of the port of the PC/MCU from an external hardware. The voltage signal from the PC/MCU is being converted into light by the LED and then further converted into voltage by the phototransistor. This ensures that there is no physical connection between the PC and the appliances. The signal from the PC/MCU is coupled only through light so that if in any case the external hardware ( in this case :appliances) produces an error voltage it will not be passed over to the port of the PC/MCU and will not damage the internal circuitry of the PC/MCU.

Fig3.21.Optocoupler (4N35) Pin Diagram Table3.5Pin description Pin no. Function

1 2 3 4 5 6

Anode Cathode NC Emitter Collector Base

The 4N35 optoisolators consist of a gallium arsenide infrared emitting diode driving a silicon phototransistor in a 6-pin dual in-line package. There is no electrical connection between the two, just a
39 | P a g e

beam of light. The light emitter is nearly always an LED. The light sensitive device may be a photodiode, phototransistor, or more esoteric devices such as thyristors, triacs etc. To carry a signal across the isolation barrier, optocouplers are operated in linear mode. Pin Description of 4N35 The IC package may also be called an IC or a chip. It is important to note that each type of optocoupler may use different pin assignments. For carrying a linear signal across isolation barrier there are two types of optocouplers. Both types use an infrared light emitting diode (LED) to generate and send a light signal across an isolation barrier. The difference is in the detection method. Some optocouplers use a phototransistor detector while others use a photodiode detector which drives the base of a transistor. The phototransistor detector uses the transistors collector base junction to detect the light signal. This necessitates that the base area be relatively large compared to a standard transistor. The result is a large collector to base capacitance which slows the collector rise time and limits the effective frequency response of the device. In addition the amplified photocurrent flows in the collector base junction and modulates the response of the transistor to the photons. This causes the transistor to behave in a non-linear manner. Typical phototransistor gains range from 100 to 1000. The photodiode/transistor detector combination on the other hand uses a diode to detect the photons and convert them to a current to drive the transistor base. The transistor no longer has a large base area. The response of this pair is not affected by amplified photocurrent and the photodiode capacitance does not impair speed. Optocoupler Operation Optocouplers are good devices for conveying analog information across a power supply isolation barrier, they operate over a wide temperature range and are often safety agency approved they do, however, have many unique operating considerations. Optocouplers are current input and current output devices. The input LED is excited by changes in drive current and maintains a relatively constant forward voltage. The output is a current which is proportional to the input current. The output current can easily be converted to a voltage through a pull-up or load resistor.

Applications AC mains detection


40 | P a g e

Reed relay driving Switch mode power supply feedback Telephone ring detection Logic ground isolation Logic coupling with high frequency noise rejection.

Features Interfaces with common logic families Input-output coupling capacitance < 0.5 pF Industry Standard Dual-in line 6-pin package 5300 VRMS isolation test voltage Lead-free component

Transistor A transistor is a semiconductor device used to amplify and switch electronic signals and power. It is composed of a semiconductor material with at least three terminals for connection to an external circuit. A voltage or current applied to one pair of the transistor's terminals changes the current flowing through another pair of terminals. Because the controlled (output) power can be higher than the controlling (input) power, a transistor can amplify a signal.

Transistor as a Current Amplifier


41 | P a g e

A PNP transistor can be used as a current amplifier for driving the relay. Since approx 500-1000mA current can be passed from emitter to collector in PNP transistor with a little base current (approx 12mA).

Fig3.22.Transistor as a current amplifier Here a circuit shows interfacing of relay with PNP transistor. Here Vin signal is given to transistor from microcontroller or other low current digital devices. By using this driver circuit a relay can be derived from microcontroller, but has a drawback i.e. whenever the relay gets off a back spike is generated in the base of transistor which can harm the controller or other digital devices. This problem can be solved by using an optocoupler between controller and transistor's base as shown:

42 | P a g e

Fig3.23.Use of Optocoupler in current amplifier In this circuit the MCU is connected to transistor through optocoupler, means there is an optical connected between microcontroller and transistor not any physical connection, so the spike generated by the transistor wouldn't be reach controller, so by using this circuit we've isolated the controller from Power transistor. The PNP Power transistor used here is BC369. Power Transistor (BC 369) High current gain High collector current Low collector-emitter saturation voltage Complementary type: BC 368 (NPN)

Fig3.24.Power Transistor BC369 Terminal 1: Emitter Terminal 2: Collector Terminal3: Base


43 | P a g e

9. TSOP 1738
The TSOP 17XX series are miniaturized receivers for infrared remote control systems. PIN diode and preamplifier are assembled on lead frame, the epoxy package is designed as IR filter. The demodulated output signal can directly be decoded by a microprocessor. TSOP 17XX is the standard IR remote control receiver series, supporting all major transmission codes. Here XX refers to the frequency of the infrared carrier signal on which the code is modulated, which is 38 KHz in our case. It has three pins .GND and Vcc are connected to the power supply with VCC as 5V and Vout which becomes 0V, or GND when the demodulated bit received is high i.e. 5V and vice versa.

Fig3.25.TSOP 1738 Features

44 | P a g e

_ Photo detector and preamplifier in one package _ Internal filter for PCM frequency _ TTL and CMOS compatibility _ Output active low _ Low power consumption _ High immunity against ambient light _ Continuous data transmission possible (up to 2400 bps) _ Suitable burst length .10 cycles/burst _Available for carrier frequencies of 27 kHz up to 62 kHz _ No external components necessary _Output microcomputer-compatible _High sensitivity for large transmitting range (120 ft/ 35 m) _Maximum interference safety against optical and electrical disturbances _High quality level ISO 9001 _Automated large-volume production

Typical applications TV sets Video recorders Sat receivers DVD (Digital Versatile Disk) Slide projectors
45 | P a g e

Hi-fi components

Fig3.26.RC5 Code transmission

12 CIRCUIT DIAGRAMS

46 | P a g e

Fig4.4.Microcontroller with relay driver

47 | P a g e

V C C

6 5

P
Q ? 3 P N P C B E 1 2 R E K ? 5 4

2 4 N 3 5

2 2 0 V N
L A Y S P D T

A C 4

D e v i c e

U 3 3 3 3 3 3 3 3 1 2 3 4 5 6 7 8 Y C C C ? R ? A Y P S N T A P R R 1 L 9 8 7 6 5 4 3 2 P P P P P P P P P P P P P P P P

? 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

4 0
. . . . . . . . . . . . . . . . 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 / / / / / / / / A A A A A A A A D P D P DP DP DP DP DP DP 2P 2P P P 0 2 1 2 22 32 42 52 62 72 . . . . . . 2 1 . 0 2/ A 2 . 1 2/ A 3 2 / 2A 4 3 / 2A 5 4 / 2A 6 5 / 2A 7 6 / 2A 8 7 / A 1 1 1 1 1 1 8 9 1 0 1 2 3 4 5 U ? 6 5 4 2 4 N 3 5 K 3 1 U ? 6 5 2 G 4 N 3 5 K 3 U ? ? 5 4 4 R ? Q ? 1 2 R P N P C B E E L A Y S P D T ? P N P C B E R ? Q ? 3 1 2 R 5 4 E K ? 5 4

D e v i c e
L A Y S P D T

/ T / T

1 0 3 . 0 / 1 1X D R - E . X 1 / 1T 2 X D 3 3 . 2 / I1N 3 T O 3 . 3 / I1 N 4 T 1 P 3 . 4 /1 T 5 O P 3 . 5 1/ T6 1 P 3 . 6 / 1W 7 R P 3 . 7 / R D P S E E 2 9 N

D e v i c e

1 9 1 8 X T A L X T A L 9 R S T 3 1 A E T 8 A / V 9 C

1 2 P

A P

3 0 / P R O

5 2

2 0

6 5 4

1 2 R E

D e v i c e
L A Y S P D T

2 4 N 3 5

V o l t a g e 0 - 1 2 V 220V AC
1 + 2 C ? 1 1 T ? 5 4 4 T R A N 8 S F O R M E R U V ? I N V O

R e g u l a t o r
U 3 T

7 8 0 5

T s o p
+

1 7 3 8 R e c . S e c t i o n

O u t p u t 5 V D C
B R I D G E

I O

D L E

1 D

T S D

i t l e

< T i t l e c u o c u n

i z e D o B < D a t e :S

Fig4.5. Microcontroller with TSOP and relay driver

48 | P a g e

13. C CODE FOR PROJECT


#define f40k 1 #define DATA P1 #define RS P35 #define RW P36 #define E P37 #include <lcdrout.h> #define IRDet P32 //IR serial input stream sbit IRLED = P3^3;//LED will blink on valid IR code

#define CH1 #define CH2 #define CH3 #define CH4 #define CH5 #define CH6 #define CH7 #define CH8 #define TRUE 1 #define FALSE 0

P20 P21 P22 P23 P24 P25 P26 P27

unsigned char RC5RxAddress, RC5RxCommand; // Last command received on RC5 bit RC5Avail=FALSE; unsigned char Repeating; // And if the data are new...

49 | P a g e

TR0=TRUE; // Start timer 1 IRLED = 0; IE0=0; // Clear any pending int's

EX0=TRUE; // Prepare for another startbit... void main(void) {

lcd_initialize(); P2=0xff;

ACC=0x83; lcd_cmd(); lcd_display("IR REMOTE ACC=0xC4; lcd_cmd(); lcd_display("Control secdelay(3); ACC=0x80; lcd_cmd(); lcd_display("RECEIVING...... ",12);
50 | P a g e

",12);

",12);

ACC=0xC0; lcd_cmd(); lcd_display("DEVICE CODE EX0 = 1; // Enable EX0 Interrupt EA = 1; // Enable Global Interrupt Flag CH1 = 0; // Initial state, this output is low P2=0xff; while (1) { if(RC5Avail) { RC5Avail = FALSE; // reset the variable for next check switch(RC5RxCommand) { case 0x01: { CH1 = ~CH1; // toggle the output ACC='1'; lcd_datawrite(); } break; case 0x02: { CH2 = ~CH2; ACC='2'; lcd_datawrite();
51 | P a g e

",12);

} break; case 0x03: { CH3 = ~CH3; ACC='3'; lcd_datawrite(); } break; case 0x04: { CH4 = ~CH4; ACC='4'; lcd_datawrite(); } break; case 0x05: { CH5 = ~CH5; ACC='5'; lcd_datawrite(); } break; case 0x06: { CH6 = ~CH6; ACC='6'; lcd_datawrite(); } break; case 0x07:
52 | P a g e

{ CH7 = ~CH7; ACC='7'; lcd_datawrite(); } break; case 0x08: { CH8 = ~CH8; ACC='8'; lcd_datawrite(); } break; } } } } }

53 | P a g e

14. PROJECT PHOTOGRAPH

54 | P a g e

55 | P a g e

. REFERENCES
GOOGLE www.alldatasheets.com

www.datasheets.com

www.electronicsforyou.com

www.projectguidance.com

8051 microcontroller and embedded systems by Ali Mazidi\

WIKIPEDIA

56 | P a g e

57 | P a g e

Das könnte Ihnen auch gefallen