Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Submitted for partial fulfillment of award of BACHLOR OF TECHNOLOGY (B.Tech) degree In Electronics &Telecommunication
Prof.GS Bakhshi HOD ET/EC Department
Name of Students:RAVI KANT PANDEY ABHISHEK GUPTA ASHUTOSH PATHAK ASHISH SRIVASTAVA
Name of Guide:
ANUBHAV KUMAR (ET/EC DEPARTMENT)
CERTIFICATE
This is to certify that project report entitled "SNR and BER calculation of OFDM using MATLAb" which is submitted by RAVI KANT PANDEY ,ABHISHEK GUPTA, ASHUTOSH PATHAK and ASHISH SRIVASTAVA in partial fulfillment of the requirement for the award of Bachelor Of Technology (B.Tech) degree in Department of Electronics & Telecommunication from GautamBudh Technical University, Lucknow is a record of candidate's own work carried out by him under my/our supervision. . The project report embodies result of original work and studies carried out by Students himself and the contents of the project report do not form the basis for the award of any other degree to the candidate or to anybody else.
Date:22/04/2013
Name of Guide: Mr. Anubhav Kumar Designation: Asst. Prof. Address:Vishveshwarya Institute of Engineering and technology,Dadri,G.B.Nagar(203207)
TABLE OF CONTENTS
DECLARATION CERTIFICATE... ACKNOWLEDGEMENT.. ABSTRACT LIST OF FIGURES. LIST OF SYMBOLS... LIST OF TABLES CHAPTER 1- INTRODUCTION 1.1 BLOCK DIAGRAM.. 1.2 CIRCUIT DIAGRAM 1.3 WORKING PRINCIPLE CHAPTER 2- POWER SUPPLY OF THE SYSTEM 2.1 POWER SUPLLY 2.1.1 Need of power supply 2.2 DIODE. 2.2.1 Electronic symbols.. 2.3 USE OF DIODES IN RECTIFIERS.. 2.3.1 Rectification.
2.3.2 Full wave rectifier.. 2.3.3 Bridge rectifier 2.4 FILTRATION 2.4.1 Choke input filter.. 2.4.2 Capacitor input filter 2.4.3 Circuit diagram.. 2.5 TRANSFORMER.. 2.5.1 Overview.. 2.5.2 Coupling by mutual induction 2.5.3 Simplified analysis. 2.5.4 Analysis of the ideal transformer 2.5.5 DC voltages and currents 2.5.6 The universal EMF equation.. 2.5.7 Practical considerations.. 2.5.7.1 Classifications.. 2.6 CAPACITORS 2.6.1 Current-voltage relation. 2.6.2 Networks.. 2.6.2.1 For capacitors in parallel.. 2.6.2.2 For capacitors in series 2.7 TRANSISTOR. 2.7.1 NPN Transistors.. 2.7.2 PNP Transistor
2.7.3 The two types are 2.7.3.1 PNP type.. 2.7.3.2 NPN type. 2.7.4 Operation of pnp transistor. 2.8 RESISTERS 2.8.1 Theory of operation.. 2.8.1.1 Ohm's law 2.8.1.2Series and parallel resistors. 2.8.2Power dissipation. CHAPTER 3- IC HARDWARE. 3.1 MICROCONTROLLER IC 3.1.1 A brief introduction to microcontroller 3.1.1.1 Key features of microcontrollers 3.2MICROCONTROLLER(AT89S52) 3.2.1 Features.. 3.2.2 Block Diagram.. 3.2.3 Pin configuration. 3.2.3.1 Pin description. 3.3 OSCILLATOR CHARACTERISTICS. 3.4 THE 8051 REGISTERS 3.4.1 Program counter.
3.4.2 Psw (program status word) register. 3.4.3 Cy, the carry flag.. 3.4.4 Ac, the auxiliary carry flag. 3.4.5 P, the parity flag 3.4.6 Ov, the overflow flag.. 3.5 RAM MEMORY SPACE ALLOCATION IN THE 8051 3.6 REGISTER BANKS IN THE 8051. 3.7 STACK IN THE 8051.. 3.7.1 Pushing onto the stack. 3.7.2 Popping from the stack 3.8 ADDRESSING MODES.. 3.8.1 Direct addressing 3.8.2 Indirect addressing 3.8.3 Register instructions.. 3.8.4 Register-specific instructions. 3.8.5 Immediate constants.. 3.8.6 Indexed addressing 3.9 8051 INSTRUCTION SET.. 3.9.1 Mnemonic.. 3.9.2 Operation CHAPTER 4- SIM300 GSM MODULE 4.1 PRODUCT CONCEPT ..
4.1.1 SIM300 key features at a glance.. 4.2 APPLICATION INTERFACE .. 4.3 SIM300 PIN DESCRIPTION 4.4 OPERATING MODES 4.5 POWER SUPPLY . 4.5.1 Power supply pins on the board-to-board connector . 4.5.2 Minimizing power losses 4.5.3 Monitoring power supply 4.6 POWER UP AND POWER DOWN SCENARIOS 4.6.1 Turn on SIM300 . 4.6.1.1 Turn on SIM300 using the PWRKEY pin (Power on) 4.6.1.2 Turn on SIM300 using the RTC (Alarm mode). 4.6.2 Turn off SIM300 . 4.6.2.1 Turn off SIM300 using the PWRKEY pin (Power down) 4.6.2.2 Turn off SIM300 using AT command 4.6.2.3 Under-voltage automatic shutdown 4.6.2.4 Over-temperature automatic shutdown 4.6.3 Restart SIM300 us.ing the PWRKEY pin
4.7. POWER SAVING .. 4.7.1 Minimum functionality mode .. 4.7.2 Sleep mode (Slow Clocking mode) .. 4.7.3 Wake up SIM300 from SLEEP mode . CHAPTER 5- RELAYS AND DISPLAY UNIT... 5.1. RELAYS. 5.1.1 Choosing a relay.. 5.1.1.1 Physical size and pin arrangement.. 5.1.1.2Coil voltage.. 5.1.1.3 Coil resistance. 5.1.1.4 Switch ratings (voltage and current).. 5.1.1.5 Switch contact arrangement (SPDT, DPDT etc) 5.2 LCD INTERFACING.. 5.2.1 The bit descriptions for the different commands are 5.2.2 Moving LCD cursor CHAPTER 6- SOFTWARE AND PROGRAMMING. 6.1 SOFTWARE.. 6.1.1. Keil. 6.1.1.1Features 6.2. PROGRAMMING CHAPTER 7- APPLICATIONS AND CONCLUSION
APPENDIX 1 REFERENCES
ACKNOWLEDGEMENT
It gives us great sense of pleasure to present the report of B.Tech. undertaken during B.Tech. final year. We owe special debt of gratitude to Mr. Anubhav Kumar Department of Electronics& Telecommunication, VGI for his constant support and guidance throughout the course of our work. His sincerity, thoroughness and perseverance have been a constant source of inspiration for us. It is only his cognizant efforts that our endeavors have been light of the day. We also take the opportunity to acknowledge the contribution of Prof. G.S. Bakshi, Head of Department of "Electronics & Telecommunication", VGI for his full support and assistance during the development of the project. We also do not like miss the opportunity to acknowledge the contribution of the faculty members of the department for their kind assistance and cooperation during the development of our project. Last but not least, we acknowledge our friends for their contribution in the completion of the project.
LIST OF FIGURES
Figure 1.1 Block Diagram of the system Figure 1.2 Circuit Diagram of the alert device Figure 2.1 Typical diode package in same alignment diode symbol. Figure 2.2 Symbols of diode... Figure 2.3 Circuit diagram of power supply... Figure 2.4 A historical Stanley transformer Figure 2.5 A practical step down transformer showing magnetizing flux in the core Figure 2.6 Different capacitor.. Figure 2.7 Specific design for Transistor. Figure 2.8 Symbol of PNP transistor Figure 2.9 Symbol of NPN transistor.. Figure 2.10 Working of PNP transistor Figure 2.11 Resistor with wire leads for through hole mounting. Figure3.1 Blok diagram AT89S52 microcontroller Figure 3.2 Pin configuration of AT89S52 Figure 3.3 Oscillator connection Figure 3.4 RAM memory allocation of 8051 Figure 4.1 SIM300 GSM module Figure 4.2 VBAT input Figure 4.3 VBAT ripple wave at maximum power transmit phase Figure 4.4 Timing of turn on system Figure 4.5 Timing of turn off system Figure 4.6 Timing of restart system Figure 5.1 Circuit symbol for relay Figure 5.2 Relay coil Figure5.3 Moving LCD cursor
LIST OF TABLES
Table 2.1 Standard symbols Table 3.1 Resistor banks in 8051 Table 4.1 SIM300 key features Table 4.2 Coding scheme and maximum net data rate over air interface Table 4.3 Board to board connector pin description Table 4.4 Overview of operating modes Table 4.5 AT commands used in alarm mode Table 5.1 Pin description of LCD Table 5.2 The different instruction available for use with the 44780 Table 5.3 Layout of LCD
ABSTRACT
Orthogonal Frequency Division Multiplexing (OFDM) is a bandwidth efficient signalling scheme for wide band digital communications. A general problem found in high speed co mmunication is Inter-Symbol Interference (ISI). ISI occurs when a transmission interferes with itself and the receiver cannot decode the transmission correctly. Orthogonal frequency division multiplex (OFDM) modulation is being used more and more in telecommunica tion, wired and wireless. DVB and DAB already use this modulation technique and ADSL is based on it. The advantages of this modulation are the reason for its increasing usage.OFDM can be implemented easily, it is spectrally efficient and can provide high data rates with sufficient robustness to channel imperfections . The purpose of this paper is to use a Matlab simulation of OFDM to analyse the Bit Ratio (BER) of a transmission varies when Signal to Noise Ratio (S/N Ratio) and Multipropagation effects are changed on transmission channel. Our project is based on this technology and MATLAB software is used. MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematical software package, which is used extensively in both academia and industry. It is an interactive program for numerical computation and data visualization, which along with its programming capabilities provides a very useful tool for almost all areas of science and engineering.
CHAPTER 1 INTRODUCTION
1.1BLOCK DIAGRAM
be viewed as using many slowly modulated narrowband signals rather than one rapidly modulatedwideband signal. The low symbol rate makes the use of a guard interval between symbols affordable, making it possible to eliminate intersymbol interference (ISI) and utilize echoes and time-spreading (on analogue TV these are visible as ghosting and blurring, respectively) to achieve a diversity gain, i.e. a signal-to-noise ratio improvement. This mechanism also facilitates the design of single frequency networks (SFNs), where several adjacent transmitters send the same signal simultaneously at the same frequency, as the signals from multiple distant transmitters may be combined constructively, rather than interfering as would typically occur in a traditional single-carrier system.
the useful symbol duration (the receiver side window size), and k is a positive integer, typically equal to 1. Therefore, with Nsub-carriers, the total passband bandwidth will be B Nf (Hz). The orthogonality also allows high spectral efficiency, with a total symbol rate near the Nyquist rate for the equivalent baseband signal (i.e. near half the Nyquist rate for the double-side band physical passband signal). Almost the whole available frequency band can be utilized. OFDM generally has a nearly 'white' spectrum, giving it benign electromagnetic interference properties with respect to other co-channel users. A simple example: A useful symbol duration TU = 1 ms would require a sub-carrier spacing of (or an integer multiple of that) for orthogonality. N = 1,000 sub-carriers
would result in a total passband bandwidth of Nf = 1 MHz. For this symbol time, the required bandwidth in theory according to Nyquist is N/2TU = 0.5 MHz (i.e., half of the achieved bandwidth required by our scheme). If a guard interval is applied (see below), Nyquist bandwidth requirement would be even lower. The FFT would result in N = 1,000 samples per symbol. If no guard interval was applied, this would result in a base band
complex valued signal with a sample rate of 1 MHz, which would require a baseband bandwidth of 0.5 MHz according to Nyquist. However, the passband RF signal is produced by multiplying the baseband signal with a carrier waveform (i.e., double-sideband quadrature amplitude-modulation) resulting in a passband bandwidth of 1 MHz. A single-side band (SSB) or vestigial sideband (VSB) modulation scheme would achieve almost half that bandwidth for the same symbol rate (i.e., twice as high spectral efficiency for the same symbol alphabet length). It is however more sensitive to multipath interference. OFDM requires very accurate frequency synchronization between the receiver and the transmitter; with frequency deviation the sub-carriers will no longer be orthogonal, causing inter-carrier interference (ICI) (i.e., cross-talk between the sub-carriers). Frequency offsets are typically caused by mismatched transmitter and receiver oscillators, or by Doppler shift due to movement. While Doppler shift alone may be compensated for by the receiver, the situation is worsened when combined with multipath, as reflections will appear at various frequency offsets, which is much harder to correct. This effect typically worsens as speed increases, and is an important factor limiting the use of OFDM in high-speed vehicles. Several techniques for ICI suppression are suggested, but they may increase the receiver complexity.
2.2 Advantages
High spectral efficiency as compared to other double sideband modulation schemes, spread spectrum, etc.
Can easily adapt to severe channel conditions without complex time-domain equalization.
Robust against narrow-band co-channel interference. Robust against intersymbol interference (ISI) and fading caused by multipath propagation.
Efficient implementation using Fast Fourier Transform (FFT). Low sensitivity to time synchronization errors. Tuned sub-channel receiver filters are not required (unlike conventional FDM). Facilitates single frequency networks (SFNs); i.e., transmitter macrodiversity.
2.3Disadvantages
Sensitive to Doppler shift. Sensitive to frequency synchronization problems. High peak-to-average-power ratio (PAPR), requiring linear transmitter circuitry, which suffers from poor power efficiency.
Loss of efficiency caused by cyclic prefix/guard interval. The double sideband modulation of each sub-carrier causes lower spectral
efficiency and higher transmitter power requirements for equivalent coverage as compared to VSB modulation.
2.6.1 Transmitter
An OFDM carrier signal is the sum of a number of orthogonal sub-carriers, with baseband data on each sub-carrier being independently modulated commonly using some type of quadrature amplitude modulation (QAM) or phase-shift keying (PSK). This composite baseband signal is typically used to modulate a main RF carrier. is a serial stream of binary digits. By inverse multiplexing, these are first demultiplexed into parallel streams, and each one mapped to a (possibly complex) symbol stream using
some modulation constellation (QAM,PSK, etc.). Note that the constellations may be different, so some streams may carry a higher bit-rate than others. An inverse FFT is computed on each set of symbols, giving a set of complex time-domain samples. These samples are then quadrature-mixed to passband in the standard way. The real and imaginary components are first converted to the analogue domain using digital-toanalogue converters (DACs); the analogue signals are then used to
modulate cosine and sine waves at the carrier frequency, then summed to give the transmission signal,
2.6.2 Receiver
The receiver picks up the signal , which is then quadrature-mixed down to baseband using , so
cosine and sine waves at the carrier frequency. This also creates signals centered on
low-pass filters are used to reject these. The baseband signals are then sampled and digitised using analog-to-digital converters (ADCs), and a forward FFT is used to convert back to the frequency domain. This returns parallel streams, each of which is converted to a binary stream using an ,
appropriate symbol detector. These streams are then re-combined into a serial stream, which is an estimate of the original binary stream at the transmitter as shown in figure 2.2
where
is the OFDM
where
To avoid intersymbol interference in multipath fading channels, a guard interval of length is inserted prior to the OFDM block. During this interval, a cyclic prefix is transmitted such that the signal in the interval OFDM signal with cyclic prefix is thus: equals the signal in the interval . The
The low-pass signal above can be either real or complex-valued. Real-valued low-pass equivalent signals are typically transmitted at basebandwireline applications such as DSL use this approach. For wireless applications, the low-pass signal is typically complex-valued; in which case, the transmitted signal is up-converted to a carrier frequency transmitted signal can be represented as: . In general, the
2.8 Usage
OFDM is used in Digital Audio Broadcasting (DAB), Digital television DVBLAN IEEE T/T2 (terrestrial), DVB-H (handheld), DMB-T/H, DVB-C2 (cable), 802.11a, ADSL (G.DMT/ITU G.992.1), Mobile phone 4G. Wireless
useful information to false or irrelevant data in a conversation or exchange. For example, in online discussion forums and other online communities, off-topic posts and spam are regarded as "noise" that interferes with the "signal" of appropriate discussion.
3.1 Definition
Signal-to-noise ratio is defined as the power ratio between a signal (meaningful information) and the background noise (unwanted signal):
where P is average power. Both signal and noise power must be measured at the same or equivalent points in a system, and within the same system bandwidth. If the signal and the noise are measured across the sameimpedance, then the SNR can be obtained by calculating the square of the amplitude ratio:
where A is root mean square (RMS) amplitude (for example, RMS voltage). Because many signals have a very wide dynamic range, SNRs are often expressed using
The concepts of signal-to-noise ratio and dynamic range are closely related. Dynamic range measures the ratio between the strongest un-distorted signal on a channel and the minimum discernable signal, which for most purposes is the noise level. SNR measures the ratio between an arbitrary signal level (not necessarily the most powerful signal possible) and noise. Measuring signal-to-noise ratios requires the selection of a representative orreference signal. In audio engineering, the reference signal is usually a sine wave at a standardized nominal or alignment level, such as 1 kHz at +4 dBu (1.228 VRMS). SNR is usually taken to indicate an average signal-to-noise ratio, as it is possible that (near) instantaneous signal-to-noise ratios will be considerably different. The concept can be understood as normalizing the noise level to 1 (0 dB) and measuring how far the signal 'stands out'.
so that
usually we don't include that resistance term while measuring power or energy of a signal. This usually causes some confusions among readers but the resistance term is not significant for operations performed in signal processing. Most of cases the power of a signal would be
where 'A' is the amplitude of the ac signal. In some places people just use
where W is the bandwidth and ka is modulation index Output signal-to-noise ratio (of AM receiver) is given by
Fig 2.3 Recording of the noise of athermogravimetric analysis device All real measurements are disturbed by noise. This includes electronic noise, but can also include external events that affect the measured phenomenon wind, vibrations, gravitational attraction of the moon, variations of temperature, variations of humidity, etc., depending on what is measured and of the sensitivity of the device. It is often possible to reduce the noise by controlling the environment. Otherwise, when the characteristics of the noise are known and are different from the signals, it is possible to filter it or to process the signal. For example, it is sometimes possible to use a lock-in amplifier to modulate and confine the signal within a very narrow bandwidth and then filter the detected signal to the narrow band where it resides, thereby eliminating most of the broadband noise. When the signal is constant or periodic and the noise is random, it is possible to enhance the SNR by averaging the measurement. In this case the noise goes down as the square root of the number of averaged samples.
to noise, interference, distortion or bit synchronization errors. The bit error rate or bit error ratio (BER) is the number of bit errors divided by the total number of transferred bits during a studied time interval. BER is a unitless performance measure, often expressed as a percentage. The bit error probability pe is the expectation value of the BER. The BER can be considered as an approximate estimate of the bit error probability. This estimate is accurate for a long time interval and a high number of bit errors. Example: As an example, assume this transmitted bit sequence: 0 1 1 0 0 0 1 0 1 1, and the following received bit sequence: 0 0 1 0 1 0 1 0 0 1, The number of bit errors (the underlined bits) is in this case 3. The BER is 3 incorrect bits divided by 10 transferred bits, resulting in a BER of 0.3 or 30%.
The transmission BER is the number of detected bits that are incorrect before error correction, divided by the total number of transferred bits (including redundant error codes). The information BER, approximately equal to the decoding error probability, is the number of decoded bits that remain incorrect after the error correction, divided by the total number of decoded bits (the useful information). Normally the transmission BER is larger than the information BER. The information BER is affected by the strength of the forward error correction code.
Binary symmetric channel (used in analysis of decoding error probability in case of non-bursty bit errors on the transmission channel)
A worst case scenario is a completely random channel, where noise totally dominates over the useful signal. This results in a transmission BER of 50% (provided that a Bernoulli binary data source and a binary symmetrical channel are assumed, see below).
Fig 2.3 Bit-error rate curves for BPSK, QPSK, 8-PSK and 16-PSK, AWGN channel.
In a noisy channel, the BER is often expressed as a function of the normalized carrier-tonoise ratio measure denoted Eb/N0, (energy per bit to noise power spectral density ratio), or Es/N0 (energy per modulation symbol to noise spectral density). For example, in the case of QPSK modulation and AWGN channel, the BER as function of the Eb/N0 is given by: .
People usually plot the BER curves to describe the functionality of a digital communication system. In optical communication, BER(dB) vs. Received Power(dBm) is usually used; while in wireless communication, BER(dB) vs. SNR(dB) is used. Measuring the bit error ratio helps people choose the appropriate forward error correction codes. Since most such codes correct only bit-flips, but not bit-insertions or bitdeletions, the Hamming distance metric is the appropriate way to measure the number of bit errors. Many FEC coders also continuously measure the current BER. A more general way of measuring the number of bit errors is the Levenshtein distance. The Levenshtein distance measurement is more appropriate for measuring raw channel performance before frame synchronization, and when using error correction codes designed to correct bit-insertions and bit-deletions, such as Marker Codes and Watermark Codes.
Table 4.2 Coding schemes and maximum net data rates over air interface
VRTC
I/O
VDD_EXT
GND
Module will automatically go into SLEEP mode if DTR is set to high level and there is no on air or audio activity is required and no hardware interrupt (such as GPIO interrupt or data on serial port). In this case, the current consumption of module will reduce to the minimal level. During sleep mode, the module can still receive paging
For the VBAT input, a local bypass capacitor is recommended. A capacitor (about 100F, low ESR) is recommended. Multi-layer ceramic chip (MLCC) capacitors can provide the best combination of low ESR and small size but may not be cost effective. A lower cost choice may be a 100 F tantalum capacitor (low ESR) with a small (1 F to 10F) ceramic in parallel, which is illustrated as following figure. And the capacitors should put as closer as possible to the SIM300 VBAT pins. The following figure is the recommended circuit.
Fig. 4.2 VBAT input The following figure is the VBAT voltage ripple wave at the maximum power transmit phase, the test condition is VBAT=4.0V, VBAT maximum output current =2A, CA=100 F tantalum capacitor (ESR=0.7) and CB=4.7F.
Fig. 4.3 VBAT ripple wave at the maximum power transmit phase
way to reduce the voltage drops. You should also take the resistance of the power supply lines on the host board or of battery pack into account.
Note: Only enter AT command through serial port after SIM300 is power on and Unsolicited Result Code RDY is received from serial port.
When power on procedure complete, SIM300 will send out following result code to indicate the module is ready to operate: RDY
4.6.2.1 Turn off SIM300 using the PWRKEY pin (Power down)
You can turn off the SIM300 by driving the PWRKEY to a low level voltage for period time. The power down scenarios illustrate as following Figure. This procedure will let the module to log off from the network and allow the software to enter into a secure state and save data before completely disconnect the power supply. Before the completion of the switching off procedure the module will send out result code: POWER DOWN After this moment, no any AT commands can be executed. Module enters the POWER DOWN mode, only the RTC is still active. POWER DOWN can also be indicated by VDD_EXT pin, which is a low level voltage in this mode.
If SIM300 has been set to minimum functionality by AT+CFUN=0, then the RF function and SIM card function will be closed, in this case, the serial ports is still accessible, but all AT commands need RF function or SIM card function will not accessible. If SIM300 has disable all RF function by AT+CFUN=4, then RF function will be closed, the serial ports is still active in this case but all AT commands need RF function will not accessible.
When SIM300 is in minimum functionality or has been disable all RF functionality by AT+CFUN=4, it can return to full functionality by AT+CFUN=1.
If DTR Pin is pull down to a low level,this signal will wake up SIM300 from power saving mode. The serial port will be active after DTR change to low level about 20ms. Receive a voice or data call from network to wake up SIM300; Receive a SMS from network to wake up SIM300 RTC alarm expired to wake up SIM300;
Fig.5.1 Circuit symbol for a relay 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 this current and a transistor is usually used to amplify the small IC current to the larger value required for the relay coil. The maximum output current for the popular 555 timer IC is 200mA so these devices can supply relay coils directly without amplification. Relays are usually SPDT or DPDT but they can have many more sets of switch contacts, for example relays with 4 sets of changeover contacts are readily available. For further information about switch contacts and the terms used to describe them please see the page on switches. Most relays are designed for PCB mounting but you can solder wires directly to the pins providing you take care to avoid melting the plastic case of the relay. The supplier's catalogue should show you the relay's connections. The coil will be obvious and it may be connected either way round. 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.
The animated picture shows a working relay with its coil and switch contacts. You can see a lever on the left being attracted by magnetism when the coil is switched on. This lever moves the switch contacts. There is one set of contacts (SPDT) in the foreground and another behind them, making the relay DPDT.
The relay's switch connections are usually labeled COM, NC and NO:
COM = Common, always connect to this; it is 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. Connect to COM and NO if you want the switched circuit to be on when the relay coil is on. Connect to COM and NC if you want the switched circuit to be on when the relay coil is off.
5.1.1.2Coil 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.
5.1.1.3Coil 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:
The purpose of this page is to give a brief tutorial on how to interface with Hitatchi 44780 based LCDs. I have tried to provide the all the data necessary for successfully adding LCDs to your application. The most common connector used for the 44780 based LCDs is 14 pins in a row, with pin centers 0.100" apart. The pins are wired as: Table 5.1 Pin Description of LCD
Pins 1 2 3 4 5 6 7 - 14 Description Ground Vcc Contrast Voltage "R/S" _Instruction/Register Select "R/W" _Read/Write LCD Registers "E" Clock Data I/O Pins
As you would probably guess from this description, the interface is a parallel bus, allowing simple and fast reading/writing of data to and from the LCD. This waveform will write an ASCII Byte out to the LCD's screen. The ASCII code to be displayed is eight bits long and is sent to the LCD either four or eight bits at a time. If four bit mode is used, two "nibbles" of data (Sent high four bits and then low four bits with an "E" Clock pulse with each nibble) are sent to make up a full eight bit transfer. The "E" Clock is used to initiate the data transfer within the LCD. Sending parallel data as either four or eight bits are the two primary modes of operation. While there are secondary considerations and modes, deciding how to send the data to the LCD is most critical decision to be made for an LCD interface application.
Eight bit mode is best used when speed is required in an application and at least ten I/O pins are available. Four bit mode requires a minimum of six bits. To wire a microcontroller to an LCD in four bit mode, just the top four bits (DB4-7) are written to. The "R/S" bit is used to select whether data or an instruction is being transferred between the microcontroller and the LCD. If the Bit is set, then the byte at the current LCD "Cursor" Position can be read or written. When the Bit is reset, either an instruction is being sent to the LCD or the execution status of the last instruction is read back. Table 5.2The different instructions available for use with the 44780
R/S R/W D7 D6 D5 D4 D3 D2 D1 D0 Instruction/Description 4 0 0 0 0 0 0 0 0 0 1 5 0 0 0 0 0 0 0 0 1 0 14 13 12 11 10 9 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 8 0 1 7 1 * Pins Clear Display Return Cursor and LCD to Home Position Set Cursor Move Direction
ID S
SC RL * *
DL N F
A A
A A A A Move Cursor into CGRAM A A A A Move Cursor to Display * * * * Poll the "Busy Flag" Write a Character to the Display at the Current Cursor Position Read the Character on the Display at the Current Cursor Position
A A A * *
BF *
D D D D
D D D D
D D D D
D D D D
Enable Display/Cursor D - Turn Display On(1)/Off(0) C - Turn Cursor On(1)/Off(0) B - Cursor Blink On(1)/Off(0)
Set Interface Length DL - Set Data Interface Length 8(1)/4(0) N - Number of Display Lines 1(0)/2(1) F - Character Font 5x10(1)/5x7(0)
Poll the "Busy Flag" BF - This bit is set while the LCD is processing
Move Cursor to CGRAM/Display A - Address Read/Write ASCII to the Display D - Data Reading Data back is best used in applications which required data to be moved back and forth on the LCD (such as in applications which scroll data between lines). The "Busy Flag" can be polled to determine when the last instruction that has been sent has completed processing. In most applications, I just tie the "R/W" line to ground because I don't read anything back. This simplifies the application because when data is read back, the microcontroller I/O pins have to be alternated between input and output modes.
For most applications, there really is no reason to read from the LCD. I usually tie "R/W" to ground and just wait the maximum amount of time for each instruction (4.1 msecs for clearing the display or moving the cursor/display to the "home position", 160 secs for all other commands). As well as making my application software simpler, it also frees up a microcontroller pin for other uses. Different LCDs execute instructions at different rates and to avoid problems later on (such as if the LCD is changed to a slower unit), I recommend just using the maximum delays given above. In terms of options, I have never seen a 5x10 LCD display. This means that the "F" bit in the "Set Interface Instruction" should always be reset (equal to "0"). Before you can send commands or data to the LCD module, the Module must be initialized. For eight bit mode, this is done using the following series of operations:
1. Wait more than 15 msecs after power is applied. 2. Write 0x030 to LCD and wait 5 msecs for the instruction to complete 3. Write 0x030 to LCD and wait 160 secs for instruction to complete 4. Write 0x030 AGAIN to LCD and wait 160 secs or Poll the Busy Flag 5. Set the Operating Characteristics of the LCD
o o o o o
Write "Set Interface Length" Write 0x010 to turn off the Display Write 0x001 to Clear the Display Write "Set Cursor Move Direction" Setting Cursor Behavior Bits Write "Enable Display/Cursor" & enable Display and Optional Cursor
In describing how the LCD should be initialized in four bit mode, I will specify writing to the LCD in terms of nibbles. This is because initially, just single nibbles are sent (and not two, which make up a byte and a full instruction). As I mentioned above, when a byte is sent, the high nibble is sent before the low nibble and the "E" pin is toggled each time four bits is sent to the LCD. To initialize in four bit mode:
1. Wait more than 15 msecs after power is applied. 2. Write 0x03 to LCD and wait 5 msecs for the instruction to complete 3. Write 0x03 to LCD and wait 160 secs for instruction to complete 4. Write 0x03 AGAIN to LCD and wait 160 secs (or poll the Busy Flag) 5. Set the Operating Characteristics of the LCD
o o o o o o
Write 0x02 to the LCD to Enable Four Bit Mode Write "Set Interface Length" Write 0x01/0x00 to turn off the Display Write 0x00/0x01 to Clear the Display Write "Set Cursor Move Direction" Setting Cursor Behavior Bits Write "Enable Display/Cursor" & enable Display and Optional Cursor
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 "R/S" 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") along with the "R/L" bit in the "Move Cursor/Shift Display" command for characters to be written from left to right (as with a "Teletype" video display). One area of confusion is how to move to different locations on the display and, as a follow on, how to move to different lines on an LCD display. The following table shows how different LCD displays that use a single 44780 can be set up with the addresses for specific character locations. The LCDs listed are the most popular arrangements available and the "Layout" is given as number of columns by number of lines: Table 5.3 Layout of LCDs
LCD Layout 8x1 Top Left Ninth Character Character 0 N/A Second Line N/A Third Line N/A Fourth Line N/A Comments Single 44780/No Support Chip Single 44780/No Support Chip 44780 with Support Chip. This is quite rare Single 44780/No Support Chip 44780 with Support Chip
16x1
0x040
N/A
N/A
N/A
16x1
N/A
N/A
N/A
8x2 10x2
0 0
N/A 8
0x040 0x040
N/A N/A
N/A N/A
0 0 0 0 0 0 0 0 U/N
8 8 8 8 8 8 8 8 U/N
44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip 44780 with Support Chip Two 44780 with Support Chips.
Normally, the LCD is wired as two 40x2 displays. The actual connector is normally sixteen bits wide with all the fourteen connections of the 44780 in common, except for the "E" (Strobe) pins. The "E" strobes are used to address between the areas of the display used by the two devices. The actual pin outs and character addresses for this type of display can vary between manufacturers and display part numbers. Note that when using any kind of multiple 44780 LCD display, you should probably only display one 44780's Cursor at a time. Cursors for the 44780 can be turned on as a simple underscore at any time using the "Enable Display/Cursor" LCD instruction and setting the "C" bit. I don't recommend using the "B" ("Block Mode") bit as this causes a flashing full character square to be displayed and it really isn't that attractive. The LCD can be thought of as a "Teletype" display because in normal operation, after a character has been sent to the LCD, the internal "Cursor" is moved one character to the right. The "Clear Display" and "Return Cursor and LCD to Home Position" instructions are used to reset the Cursor's position to the top right character on the display. To move the Cursor, the "Move Cursor to Display" instruction is used. For this instruction, bit 7 of the instruction byte is set with the remaining seven bits used as the address of the character on the LCD the cursor is to move to. These seven bits provide 128 addresses, which matches the maximum number of LCD character addresses available. The table above should be used to determine the address of a character offset on a particular line of an LCD display. The Character Set available in the 44780 is basically ASCII. I say "basically" because some characters do not follow the ASCII convention fully (probably the most significant difference is 0x05B or "\" is not available). The ASCII Control Characters (0x008 to 0x01F) do not respond as control characters and may display funny (Japanese) characters.
6.1.1. Keil
The Keil C51 C Compiler for the 8051 microcontroller is the most popular 8051 C compiler in the world. It provides more features than any other 8051 C compiler available today.The C51 Compiler allows you to write 8051 microcontroller applications in C that have the efficiency and speed of assembly language. Language extensions in the C51 Compiler give you full access to all resources of the 8051. C51 translates C source files into a relocatable object module. When the DEBUG control is used, the object file contains full symbolic information for debugging with the Vision3 Debugger or an in-circuit emulator. In addition to the object file, the C51 Compiler generates a listing file which optionally may include symbol table and cross-reference information.
6.1.1.1Features
Nine basic data types, including 32-bit IEEE floating-point Flexible variable allocation with bit, data, bdata, idata, xdata, and pdata memory types Interrupt functions may be written in C Full use of the 8051 register banks Complete symbol and type information for source-level debugging Use of AJMP and ACALL instructions Bit-addressable data objects Built-in interface for the RTX51 real-time operating system Support for dual data pointers on Atmel, AMD, Cypress, Dallas Semiconductor, Infineon, Philips, and Transcend microcontrollers
Support for the Philips 8xC750, 8xC751, and 8xC752 limited instruction sets Support for the Infineon 80C517 arithmetic unit
6.2. PROGRAMMING
#include"reg51.h" #include"string.h" sbit sbit RS=P1^0; EN=P1^1;
#define LCDDATA P2 sbit key1 =P3^7; sbit key2 =P3^6; sbit key3 =P3^5; sbit key4 =P3^4; sbitmain_line =P1^2; sbitbackup_line =P1^3; voidsend_bits(int,unsigned char),display(int),lcdinit(); voiddisplayline(char*,int),delay(unsigned int t); unsigned char buffer[50],validkeyno=0,digit=0; unsigned char mode=0,phno[11]={0,0,0,0,0,0,0,0,0,0}; unsigned char phno1[11 ]={8,7,6,5,6,0,0,5,1,1}; unsigned char cursor_pos=0,set_phno=0,i; bit key1done=0,key2done=0,key3done=0; bit key4done=0,message_main=0; bitmessage_backup=0,message_main_line=0; voidkeysense(),keyserve(int),systeminit(); voidgsm_module_init(),putc(int i);
voidsend_ser_com(unsigned char *ptr ); void main() { systeminit(); while(1) { keysense(); if(main_line==0) { if(message_main==1) { message_main=0; message_main_line=1; } } if(message_main_line==1) { message_main_line=0; send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno[i]+48); putc('"');putc(13); strcpy(buffer, "MACHINE'S ARE NOW AGAIN WORKING ON MAIN'S "); send_ser_com(buffer); send_ser_com("at+cmgs="); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000);
putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno1[i]+48); putc('"');putc(13); strcpy(buffer, "YOUR UNIT IS NOW AGAIN WORKING ON MAIN'S "); send_ser_com(buffer);
} if(backup_line==0)message_backup=0; if(main_line==1 &&message_main==0 &&backup_line==0) { if(main_line==1 &&message_main==0 &&backup_line==0) { message_main=1; send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno[i]+48); putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "MACHINE'S ARE WORKING ON BACKUP POWER "); send_ser_com(buffer); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno1[i]+48);
putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "YOUR UNIT IS WORKING ON BACKUP POWER "); } } if(main_line==1 &&message_backup==0 &&backup_line==1) { if(main_line==1 &&message_backup==0 &&backup_line==1) { message_backup=1; send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno[i]+48); putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "WARNING! NO POWER BACKUP.SHUT DOWN "); send_ser_com(buffer); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);delay(60000); send_ser_com("at+cmgs="); putc('"');putc('+');putc('9');putc('1'); for(i=0;i<10;i++)putc(phno1[i]+48); putc('"');putc(13);delay(50000);delay(50000); strcpy(buffer, "WARNING! YOUR UNIT IS NOT WORKING "); send_ser_com(buffer); send_ser_com(buffer);
} } } } voidsysteminit() { P0=0XFF;P1=0XFF;P2=0XFF;P3=0XFF; TMOD=0x20;TH1=0xfd;SCON=0x50; TR1=1;lcdinit();delay(60000); gsm_module_init(); } voidputc(int i) { } voidserialisr() interrupt 4 using 1 { if(TI) TI=0; if(RI) RI = 0; } voidsend_ser_com(unsigned char *ptr ) { while(*ptr) { } } SBUF=*ptr;ptr++;delay(10000); SBUF=i;delay(10000);
voidgsm_module_init() { displayline(" PLEASE WAIT ",1); displayline(" Initializing ",2); send_ser_com("at\r");delay(50000);delay(50000); send_ser_com("ate1\r");delay(5000);delay(50000); send_ser_com("at+cmgf=1\r");delay(5000);delay(50000); for(i=0;i<10;i++) { send_ser_com("at+cmgd="); SBUF=i+48;delay(50000); } displayline("**** WELCOME ***",1); displayline(" V.I.E.T GP-14 ",2); } voidkeysense(void) { if(key1 == 0) { delay(1000); if(key1 == 0) keyserve(1); } else { if(key2 == 0) { delay(1000); if(key2 == 0)
if(++cursor_pos>=10)cursor_pos=0; send_bits(0,cursor_pos+192); }break; case 3:if(key3done==0 && mode==1)//phone no enterd { key3done=1; displayline("**** WELCOME ***",1); displayline(" V.I.E.T GP-14 ",2); }break; case 4:if(!key4done) { key4done=1;mode=1;cursor_pos=0; displayline("SET PHONE NO----",1); for(i=0;i<10;i++) send_bits(1,phno[i]+48); }break;
} } voiddisplayline(char* ptr,int line) { if(line==0); else if(line==1)send_bits(0,0x80); else if(line==2)send_bits(0,0xc0); elsesend_bits(0,line); send_bits(1,*ptr),ptr++; } voidsend_bits(inti,unsigned char com) { LCDDATA = com; RS=i;EN=1;delay(10);EN=0; delay(100); } void delay(unsigned int t) { } voidlcdinit() { send_bits(0,0x38);delay(400); send_bits(0,0x0c);delay(100); send_bits(0,0x01); } for(;t>0;t--);
APPENDIX 1 ABBREVIATIONS
AbbreviationFull form
IR LCD Liquid crystal display AC Alternating current DC Direct current Infrared
IC Integrated circuit MHz VVolts INT Vss GND Integer Virtual ground Ground Mega hertz
VDD Positive power supply CLK Clock ACK Acknowledgement LED Light emitting diode RAM Random access memory I/O Input/output
COST ANALYSIS
REFERENCES
www.atmel.com/images/doc1919.pdf www.keil.com/dd/chip/3411.html www.keil.com/uvision/ en.wikipedia.org/wiki/Capacitor en.wikipedia.org/wiki/Resistor www.usbr.gov/pmts/client_service/recent/studytransformers.pdf www.autoshop101.com/forms/hweb2.pdf www.physics.unlv.edu/~bill/PHYS483/relay.pdf www.tentuts.com/2012/.../lcd-interfacing-with-8051-in-assembly.html probots.co.in/Manuals/SIM300.pdf en.wikipedia.org/wiki/Diode www.technologystudent.com/elec1/transis1.htm