Anda di halaman 1dari 113

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

INDEX
CONTENTS
Abbreviations
1. 2. 3. 4. 5. 6. 7. List of figures Abstract Introduction Block Diagram Schematic diagram Schematic Description(specifications of hardware

components used) Hardware Components o o o o o 8. 9. Microcontroller Power supply Key pad driver lcd display etc

Circuit Description(working principle) Software components Embedded C KEIL procedure description

10. 11. 12. 13.

Conclusion (or) Synopsis Future Aspects Bibliography Appendix

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

ABREVATIONS:

Microcontroller:

Symbo Name l
ACC B PSW SP DPTR DPL DPH P0 P1 P2 P3 IP IE TMOD TCON T2CON Accumulator B register Program status word Stack pointer Data pointer 2 bytes Low byte High byte Port0 Port1 Port2 Port3 Interrupt priority control Interrupt enable control Timer/counter mode control Timer/counter control Timer/counter 2 control
2

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

T2MOD TH0 TL0 TH1 TL1 TH2 TL2 SCON SBUF PCON

Timer/counter mode2 control Timer/counter 0high byte Timer/counter 0 low byte Timer/counter 1 high byte Timer/counter 1 low byte Timer/counter 2 high byte Timer/counter 2 low byte Serial control Serial data buffer Power control

INTRODUCTION
In this project, we will discuss the implementation of a basic watthour meter using microcontroller. In the process, microcontroller measures
DEPT: ECE, S.B.I.T, KMM 3

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

and displays the kWh, presented in a clear digital format and also the respective payment details on an LCD. All metered data is securely stored as it is updated in a nonvolatile memory (EEPROM). The design discussed here gives an automatic buzzer and a red Led will glow indicating that the amount has to be paid for that particular month. We design in such a way that the system provides a grace period of 10 days. As soon as the payment is cleared, we give an interrupt externally using a switch to indicate that the payment has been made. Then the previous amount will be cleared and it will start afresh. If the person neglects to pay the amount, the incoming power supply must be tripped. For that purpose we are going to place a relay circuit. The deployment of electronic energy meters has gained a great deal of momentum over the past several years. This is due to their two main advantages over the traditional electromechanical designs: improved accuracy and an expanded set of features. Current microcontroller technology allows designers to build meters that are competitive in price with traditional devices, while maintaining the required accuracy of 1% for domestic applications. Microcontrollers also allow the easy incorporation of added features, such as rms voltage and current and peak demand metering, as local electric utility companies desire to implement them.

BLOCK DIAGRAM:

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Power supply

LCD Display

Led 1 Switch Led 2

EEPROM

Energy Meter Micro controller

BUZZER

RELAY

HOME

HARDWARE COMPONENTS Micro controller


5

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Power supply Lcd display Energy meter EEPROM Relay Buzzer Led

COMPONENTS USED IN OUR PROJECT:


.MICROCONTROLLER 89C51
3.1.1.INTRODUCTION:

3.1

A Micro controller consists of a powerful CPU tightly coupled with memory RAM, ROM or EPROM), various I / O features such as Serial ports, Parallel Ports, Timer/Counters, Interrupt Controller, Data Acquisition interfacesonto a single Silicon Chip.
It does not mean that any micro controller should have all the above said features on chip, Depending on the need and area of application for which it is designed, The ON-CHIP features present in it may or may not include all the individual section said above.

Any microcomputer system requires memory to store a sequence of instructions making up a program, parallel port or serial port for communicating with an external system, timer / counter for control purposes like generating time delays,
DEPT: ECE, S.B.I.T, KMM 6

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Baud rate for the serial port, apart from the controlling unit called the Central Processing Unit.

Advantages of microcontrollers:

1. If a system is developed with a microprocessor, the designer has to go for external memory such as RAM, ROM or EPROM and peripherals and hence the size of the PCB will be large enough to hold all the required peripherals. But, the micro controller has got all these peripheral facilities on a single chip so development of a similar system with a micro controller reduces PCB size and cost of the design.

One of the major differences between a micro controller and a microprocessor is that a controller often deals with bits , not bytes as in the real world application, for example switch contacts can only be open or close, indicators should be lit or dark and motors can be either turned on or off and so forth.

COMPARISON

What is the difference between a microprocessor and microcontroller?

By microprocessor is meant the general-purpose microprocessors such as Intels x86 Family(8086,80286,80386,80486,and the Pentium)or Motorolas680x0 family(68000,68010,68020,68030,68040.etc.).These microprocessors contain no RAM, no ROM, and no I/O PORTS on the chip itself. For this reason, they are commonly referred as general-purpose microprocessors.

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

(A)Ge Data bus

CPU
General purpose Micro Processo r RAM ROM I/O PORT TIMER SERIAL COM PORT

Address bus

neral purpose Micro processor System

CPU RAM I/O TIMER

ROM Serial COM PORT

(b) Microcontroller

A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add RAM, ROM, I/O PORTS, and TIMERS externally to make them functional. Although the addition of external RAM, ROM and I/O PORTS makes these systems bulkier and much 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 not the case with microcontrollers.
DEPT: ECE, S.B.I.T, KMM 8

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

A microcontroller has a CPU (a microprocessor) in addition to a fixed amount of RAM, ROM, I/OPORTS, and a timer all on a single chip. In other words, the processor, RAM, ROM, I/OPORTS, and timer are all embedded together on one chip; therefore, the designer cant add any external memory, I/O, or timer to it. The fixed amount of on-chip ROM, RAM, and number of I/O PORTS in microcontrollers makes 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 an 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 operation to read signal and turn on and off certain bits. For these reason some call these processors IBP (itty-bitty processors).

In 1981,Intel corporation introduced an 8 bit microcontroller called the 8051.This microcontroller had 128 bytes of RAM,4K bytes of was also referred to as a system on a chip. on-chip ROM, two timers, one serial port, and 4 ports(each 8-bits wide)all on single chip. At that time it

The 8051 is an 8-bit processor, meaning that the CPU can work on only 8-bits of data at a time. Data larger than 8-bits has to be broken into 8-bit pieces to be processed by the CPU. The 8051 can have a maximum of 64K bytes of ROM; many manufacturers have put only 4Kbytes on chip.

A Micro controller consists of a powerful CPU tightly coupled with memory, various I/O interfaces such as serial port, parallel port timer or counter, interrupt controller, data acquisition interfaces-Analog to Digital converter, Digital to Analog converter, integrated on to a single silicon chip. If a system is developed with a microprocessor, the designer has to go for external memory such as RAM, ROM, EPROM and peripherals. But controller is provided all these facilities on a single chip.
DEPT: ECE, S.B.I.T, KMM 9

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Development of a Micro controller reduces PCB size and cost of design. One of the major differences between a Microprocessor and a Micro controller is that a controller often deals with bits not bytes as in the real world application. Intel has introduced a family of Micro controllers called the MCS-51.

The Major Features:


Compatible with MCS-51 products 4k Bytes of in-system Reprogrammable flash memory Fully static operation: 0HZ to 24MHZ Three level programmable clock 128 * 8 bit timer/counters Six interrupt sources Programmable serial channel Low power idle power-down modes

Why AT 89C51? :

The system requirements and control specifications clearly rule out the use of 16, 32 or 64 bit micro controllers or microprocessors. Systems using these may be earlier to implement due to large number of internal features. They are also faster and more reliable but, the above application is satisfactorily served by 8-bit micro controller. Using an inexpensive 8-bit Microcontroller will doom the 32-bit product failure in any competitive market place.

DEPT: ECE, S.B.I.T, KMM

10

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Coming to the question of why to use AT89C51 of all the 8-bit microcontroller available in the market the main answer would be because it has 4 Kb on chip flash memory which is just sufficient for our application. The on-chip Flash ROM allows the program memory to be reprogrammed in system or by conventional non-volatile memory Programmer. Moreover ATMEL is the leader in flash technology in todays market place and hence using AT 89C51 is the optimal solution.

AT89C51 MICROCONTROLLER ARCHITECTURE

The 89C51 architecture consists of these specific features:

Eight bit CPU with registers A (the accumulator) and B Sixteen-bit program counter (PC) and data pointer (DPTR) Eight- bit stack pointer (PSW) Eight-bit stack pointer (Sp) Internal ROM or EPROM (8751) of 0(8031) to 4K (89C51) Internal RAM of 128 bytes: 1. Four register banks, each containing eight registers 2. Sixteen bytes, which maybe addressed at the bit level 3. Eighty bytes of general- purpose data memory

Thirty two input/output pins arranged as four 8-bit ports:p0-p3 Two 16-bit timer/counters: T0 and T1 Full duplex serial data receiver/transmitter: SBUF Control registers: TCON, TMOD, SCON, PCON, IP, and IE Two external and three internal interrupts sources. Oscillator and clock circuits.

DEPT: ECE, S.B.I.T, KMM

11

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Functional block diagram of micro controller

The 89C51 oscillator and clock:

The heart of the 89C51 circuitry that generates the clock pulses by which all the internal all internal operations are synchronized. Pins XTAL1 and XTAL2 is provided for connecting a resonant network to form an oscillator. Typically a quartz crystal and capacitors are employed. The crystal frequency is the basic internal clock frequency of the microcontroller. The manufacturers make 89C51 designs that run at specific minimum and maximum frequencies typically 1 to 16 MHz.

DEPT: ECE, S.B.I.T, KMM

12

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Oscillator and timing circuit

Types of memory:

The 89C51 have three general types of memory. They are on-chip memory, external Code memory and external Ram. On-Chip memory refers to physically existing memory on the micro controller itself. External code memory is the code memory that resides off chip. This is often in the form of an external EPROM. External RAM is the Ram that resides off chip. This often is in the form of standard static RAM or flash RAM.

a) Code memory Code memory is the memory that holds the actual 89C51 programs that is to be run. This memory is limited to 64K. Code memory may be found on-chip or offDEPT: ECE, S.B.I.T, KMM 13

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

chip. It is possible to have 4K of code memory on-chip and 60K off chip memory simultaneously. If only off-chip memory is available then there can be 64K of off chip ROM. This is controlled by pin provided as EA

b) Internal RAM

The 89C51 have a bank of 128 of internal RAM. The internal RAM is found onchip. So it is the fastest Ram available. And also it is most flexible in terms of reading and writing. Internal Ram is volatile, so when 89C51 is reset, this memory is cleared. 128 bytes of internal memory are subdivided. The first 32 bytes are divided into 4 register banks. Each bank contains 8 registers. Internal RAM also contains 128 bits, which are addressed from 20h to 2Fh. These bits are bit addressed i.e. each individual bit of a byte can be addressed by the user. They are numbered 00h to 7Fh. The user may make use of these variables with commands such as SETB and CLR.

FLASH MEMORY:

Flash memory (sometimes called "flash RAM") is a type of constantly-powered non volatile that can be erased and reprogrammed in units of memory called blocks. It is a variation of electrically erasable programmable read-only memory (EEPROM) which, unlike flash memory, is erased and rewritten at the byte level, which is slower than flash memory updating. Flash memory is often used to hold control code such as the basic input/output system (BIOS) in a personal computer. When BIOS needs to be changed (rewritten), the flash memory can be written to in block (rather than byte) sizes, making it easy to update. On the other hand, flash memory is not useful as random access memory (RAM) because RAM needs to be addressable at the byte (not the block) level.

DEPT: ECE, S.B.I.T, KMM

14

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Flash memory gets its name because the microchip is organized so that a section of memory cells are erased in a single action or "flash." The erasure is caused by Fowler-Nordheim tunneling in which electrons pierce through a thin dielectric material to remove an electronic charge from a floating gate associated with each memory cell. Intel offers a form of flash memory that holds two bits (rather than one) in each memory cell, thus doubling the capacity of memory without a corresponding increase in price.

Flash memory is used in digital cellular phones, digital cameras, LAN switches, PC Cards for notebook computers, digital set-up boxes, embedded controllers, and other devices.

Memory Types

DEPT: ECE, S.B.I.T, KMM

15

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Memory Type FLASH

Features Low-cost, high-density, high-speed architecture; reliability low power; high

ROM Read-Only Memory

Mature, high-density, reliable, low cost; required, time-consuming suitable for mask high

DEPT: ECE, S.B.I.T, KMM

16

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

production with stable code SRAM Static Random-Access Memory Highest density speed, memory; high-power, limited low-

density

drives up cost EPROM Electrically Only Memory EEPROM or E2 Programmable High-density Read- exposed erasure Electrically density High-density, low-cost, high-speed, high-power byte-erasable; higher cost, lower lowest to memory; ultraviolet must light be for

Electrically Erasable Programmable reliability, Read-Only Memory DRAM Dynamic Random Access Memory

Technical Overview of Flash Memory

Flash memory is a nonvolatile memory using NOR technology, which allows the user to electrically program and erase information. Intel Flash memory uses memory cells similar to an EPROM, but with a much thinner, precisely grown oxide between the floating gate and the source (see Figure 2). Flash programming occurs when electrons are placed on the floating gate. The charge is stored on the floating gate, with the oxide layer allowing the cell to be electrically erased through the source. Intel Flash memory is an extremely reliable nonvolatile memory architecture.

DEPT: ECE, S.B.I.T, KMM

17

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Pin diagram of AT89C51

Pin Description:

VCC: Supply voltage.

GND: Ground.

DEPT: ECE, S.B.I.T, KMM

18

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Port 0:

Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance inputs. Port 0 may also be configured to be the multiplexed low order address/data bus during accesses to external program and data memory. In this mode P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming, and outputs the code bytes during program verification. External pull-ups are required during program verification.
Port 1:

Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. Port 1 also receives the low-order address bytes during Flash programming and verification.
Port 2:

Port 2 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memories that use 16-bit addresses (MOVX @DPTR). In this application, it uses strong internal pull-ups when emitting 1s. During accesses to external data memories that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the highDEPT: ECE, S.B.I.T, KMM 19

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

order address bits and some control signals during Flash programming and verification.

Port 3: Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. Port 3 also serves the functions of various special features of the AT89C51 as listed below: Port 3 also receives some control signals for Flash programming and verification

Tab 6.2.1 Port pins and their alternate functions

RST: Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device.

DEPT: ECE, S.B.I.T, KMM

20

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

ALE/PROG:

Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation ALE is emitted at a constant rate of 1/6the oscillator frequency, and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external Data Memory.
If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.

PSEN:

Program Store Enable is the read strobe to external program memory. When the AT89C51 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory.

EA/VPP: External Access Enable (EA) must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset.

DEPT: ECE, S.B.I.T, KMM

21

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming, for parts that require 12-volt VPP.

XTAL1:

Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
XTAL2: Out put from the inverting oscillator amplifier. 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 Figs 6.2.3. 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 6.2.4.There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.

Oscillator Connections
DEPT: ECE, S.B.I.T, KMM

External Clock Drive Configuration


22

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Notes:
1. Under steady state (non-transient) conditions, IOL must be externally limited as follows: Maximum IOL per port pin: 10 mA Maximum IOL per 8-bit port: Port 0: 26 mA Ports 1, 2, 3: 15 mA Maximum total IOL for all output pins: 71 mA If IOL exceeds the test condition, VOL may exceed the related

specification. Pins are not guaranteed to sink current greater than the listed test conditions. 2. Minimum VCC for Power-down is 2V.

Types of memory:

The 8051 have three general types of memory. They are on-chip memory, external Code memory and external Ram. On-Chip memory refers to physically existing memory on the micro controller itself. External code memory is the code memory that resides off chip. This is often in the form of an external EPROM. External RAM is the Ram that resides off chip. This often is in the form of standard static RAM or flash RAM. c) Code memory Code memory is the memory that holds the actual 8051 programs that is to be run. This memory is limited to 64K. Code memory may be found on-chip or off-chip. It is possible to have 4K of code memory on-chip and 60K off chip memory simultaneously. If only off-chip memory is available then there can be 64K of off chip ROM. This is controlled by pin provided as EA
DEPT: ECE, S.B.I.T, KMM 23

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

b) Internal RAM The 8051 have a bank of 128 bytes of internal RAM. The internal RAM is found on-chip. So it is the fastest Ram available. And also it is most flexible in terms of reading and writing. Internal Ram is volatile, so when 8051 is reset, this memory is cleared. 128 bytes of internal memory are subdivided. The first 32 bytes are divided into 4 register banks. Each bank contains 8 registers. Internal RAM also contains 128 bits, which are addressed from 20h to 2Fh. These bits are bit addressed i.e. each individual bit of a byte can be addressed by the user. They are numbered 00h to 7Fh. The user may make use of these variables with commands such as SETB and CLR.

Special Function registered memory:

Special function registers are the areas of memory that control specific functionality of the 8051 micro controller.

a) Accumulator (0E0h) As its name suggests, it is used to accumulate the results of large no of instructions. It can hold 8 bit values.

B) B register (0F0h) The B register is very similar to accumulator. It may hold 8-bit value. The b register is only used by MUL AB and DIV AB instructions. In MUL AB the higher byte of the product gets stored in B register. In div AB the quotient gets stored in B with the remainder in A.

c) Stack pointer (81h)


DEPT: ECE, S.B.I.T, KMM 24

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

The stack pointer holds 8-bit value. This is used to indicate where the next value to be removed from the stack should be taken from. When a value is to be pushed onto the stack, the 8051 first store the value of SP and then store the value at the resulting memory location. When a value is to be popped from the stack, the 8051 returns the value from the memory location indicated by SP and then decrements the value of SP.

d) Data pointer The SFRs DPL and DPH work together work together to represent a 16-bit value called the data pointer. The data pointer is used in operations regarding external RAM and some instructions code memory. It is a 16-bit SFR and also an addressable SFR.

e) Program counter The program counter is a 16 bit register, which contains the 2 byte address, which tells the 8051 where the next instruction to execute to be found in memory. When the 8051 is initialized PC starts at 0000h. And is incremented each time an instruction is executes. It is not addressable SFR.

f) PCON (power control, 87h) The power control SFR is used to control the 8051s power control modes. Certain operation modes of the 8051 allow the 8051 to go into a type of sleep mode which consume much lee power.

DEPT: ECE, S.B.I.T, KMM

25

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

g) TCON (timer control, 88h) The timer control SFR is used to configure and modify the way in which the 8051s two timers operate. This SFR controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are located in TCON SFR. These bits are used to configure the way in which the external interrupt flags are activated, which are set when an external interrupt occurs.

h) TMOD (Timer Mode, 89h) The timer mode SFR is used to configure the mode of operation of each of the two timers. Using this SFR your program may configure each timer to be a 16-bit timer, or 13 bit timer, 8-bit auto reload timer, or two separate timers. Additionally you may configure the timers to only count when an external pin is activated or to count events that are indicated on an external pin.

i) TO (Timer 0 low/high, address 8A/8C h) These two SFRs taken together represent timer 0. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is configurable is how and when they increment in value.
DEPT: ECE, S.B.I.T, KMM 26

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

j) T1 (Timer 1 Low/High, address 8B/ 8D h) These two SFRs, taken together, represent timer 1. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is Configurable is how and when they increment in value.

k) P0 (Port 0, address 90h, bit addressable) This is port 0 latch. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P0.0, bit 7 is pin p0.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level.

l) P1 (port 1, address 90h, bit addressable) This is port latch1. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level m) P2 (port 2, address 0A0h, bit addressable) : This is a port latch2. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level.

DEPT: ECE, S.B.I.T, KMM

27

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

n) P3(port 3,address B0h, bit addressable)

This is a port latch3. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level

o) IE (interrupt enable, 0A8h): The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7 bits of the SFR are used to enable/disable the specific interrupts, where the MSB bit is used to enable or disable all the interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit.

p) IP (Interrupt Priority, 0B8h) The interrupt priority SFR is used to specify the relative priority of each interrupt. On 8051, an interrupt maybe either low or high priority. An interrupt may interrupt interrupts. For e.g., if we configure all interrupts as low priority other than serial interrupt. The serial interrupt always interrupts the system, even if another interrupt is currently executing. However, if a serial interrupt is executing no other interrupt will be able to interrupt the serial interrupt routine since the serial interrupt routine has the highest priority.

q) PSW (Program Status Word, 0D0h) The program Status Word is used to store a number of important bits that are set and cleared by 8051 instructions. The PSW SFR contains the carry
DEPT: ECE, S.B.I.T, KMM 28

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

flag, the auxiliary carry flag, the parity flag and the overflow flag. Additionally, it also contains the register bank select flags, which are used to select, which of the R register banks currently in use.

r) SBUF (Serial Buffer, 99h) SBUF is used to hold data in serial communication. It is physically two registers. One is writing only and is used to hold data to be transmitted out of 8051 via TXD. The other is read only and holds received data from external sources via RXD. Both mutually exclusive registers use address 99h. I/O ports: One major feature of a microcontroller is the versatility built into the input/output (I/O) circuits that connect the 8051 to the outside world. The main constraint that limits numerous functions is the number of pins available in the 8051 circuit. The DIP had 40 pins and the success of the design depends on the flexibility incorporated into use of these pins. For this reason, 24 of the pins may each used for one of the two entirely different functions which depend, first, on what is physically connected to it and, then, on what software programs are used to program the pins.

PORT 0 Port 0 pins may serve as inputs, outputs, or, when used together, as a bi directional low-order address and data bus for external memory. To configure a pin as input, 1 must be written into the corresponding port 0 latch by the program. When used for interfacing with the external memory, the lower byte of address is first sent via PORT0, latched using Address latch enable (ALE)
DEPT: ECE, S.B.I.T, KMM 29

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

pulse and then the bus is turned around to become the data bus for external memory. PORT 1 Port 1 is exclusively used for input/output operations. PORT 1 pins have no dual function. When a pin is to be configured as input, 1 is to be written into the corresponding Port 1 latch. PORT 2 Port 2 maybe used as an input/output port. It may also be used to supply a high order address byte in conjunction with Port 0 low-order byte to address external memory. Port 2 pins are momentarily changed by the address control signals when supplying the high byte a 16-bit address. Port 2 latches remain stable when external memory is addressed, as they do not have to be turned around (set to 1) for data input as in the case for Port 0. PORT 3 Port 3 may be used to input /output port. The input and output functions can be programmed under the control of the P3 latches or under the control of various special function registers. Unlike Port 0 and Port 2, which can have external addressing functions and change all eight-port b se, each pin of port 3 maybe individually programmed to be used as I/O or as one of the alternate functions. The Port 3 alternate uses are:

Pin

Alternate Use SFR

P3.0 - RXD P3.1 - TXD


DEPT: ECE, S.B.I.T, KMM

Serial data input Serial data output


30

SBUF SBUF

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

P3.2 - INTO 0 TCON.1 P3.3 - INTO 1 TCON.3 P3.4 - T0 TMOD P3.5 T1 TMOD P3.6 - WR P3.7 - RD

External interrupt 0 External interrupt 1 External Timer 0 input External timer 1 input External memory write pulse External memory read pulse -

TIMERS

On-chip

timing/counting

facility

has

proved

the

capabilities

of

the

microcontroller for implementing the real time application. These includes pulse counting, frequency measurement, pulse width measurement, baud rate generation, etc,. Having sufficient number of timer/counters may be a need in a certain design application. The 8051 has two timers/counters. They can be used either as timers to generate a time delay or as counters to count events happening outside the microcontroller. Let discuss how these timers are used to generate time delays and we will also discuss how they are been used as event counters.

PROGRAMMING 8051 TIMERS

DEPT: ECE, S.B.I.T, KMM

31

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

The 8051 has timers: Timer 0 and Timer1.they can be used either as timers or as event counters. Let us first discuss about the timers registers and how to program the timers to generate time delays.

BASIC RIGISTERS OF THE TIMER

Both Timer 0 and Timer 1 are 16 bits wide. Since the 8051 has an 8-bit architecture, each 16-bit timer is accessed as two separate registers of low byte and high byte.

TIMER 0 REGISTERS

The 16-bit register of Timer 0 is accessed as low byte and high byte. the low byte register is called TL0(Timer 0 low byte)and the high byte register is referred to as TH0(Timer 0 high byte).These register can be accessed like any other register, such as A,B,R0,R1,R2,etc.for example, the instruction MOV other register. TL0, #4Fmoves the value 4FH into TL0,the low byte of Timer 0.These registers can also be read like any

D15 D14 D0

D13

D12

D11

D10

D9

D8

D7

D6

D5

D4

D3

D2

DEPT: ECE, S.B.I.T, KMM

32

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

TH0 TIMER 1 REGISTERS

TL0

Timer 1 is also 16-bit register is split into two bytes, referred to as TL1 (Timer 1 low byte) and TH1(Timer 1 high byte).these registers are accessible n the same way as the register of Timer 0.

TMOD (timer mode) REGISTER

Both timers 0 and 1 use the same register, called TMOD, to set the various timer operation modes. TMOD is an 8-bit register in which the lower 4 bits are set aside for Timer 0 and the upper 4 bits for Timer 1.in each case; the lower 2 bits are used to set the timer mode and the upper 2 bits to specify the operation.

MODES:

M1, M0:
DEPT: ECE, S.B.I.T, KMM 33

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

M0 and M1 are used to select the timer mode. There are three modes: 0, 1, 2.Mode 0 is a 13-bit timer, mode 1 is a 16-bit timer, and mode 2 is an 8-bit timer. We will concentrate on modes 1 and 2 since they are the ones used most widely. we will soon describe the characteristics of these modes, after describing the reset of the TMOD register.

GATE only

Gate control when set. The timer/counter is enabled

while the INTx pin is high and the TRx control pin is. set. When cleared, the timer is enabled. C/T Timer or counter selected cleared for timer operation (Input from internal system clock).set for counter operation (input TX input pin). M1 M0 Mode bit 1 Mode bit 0

M1 0

M0 0

MODE 0
34

Operating Mode 13-bit timer mode

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

8-bit timer/counter THx with TLx as 5-bit prescaler. 0 1 1 16-bit timer mode 16-bit timer/counters THx with TLx are cascaded; there is no prescaler 1 0 2 8-bit auto reload 8-bit auto reload timer/counter;THx Holds a value that is to be reloaded into TLx each time it overflows. 1 1 3 Split timer mode.

TMOD Register

C/T (clock/timer):

This bit in the TMOD register is used to decide whether the timer is used as a delay generator or an event counter. If C/T=0, it is used as a timer for time delay generation. The clock source for the time delay is the crystal frequency of the 8051.this section is concerned with this choice. The timers use as an event counter is discussed in the next section.

DEPT: ECE, S.B.I.T, KMM

35

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

EX: Find the values of TMOD to operate as timers in the following modes. (a) Mode 1 Timer 1 (b) Mode 2 Timer 0.Mode 2 Timer 1 (c) Mode 0 Timer 1

Solution:

(a)TMOD is 00010000 = 10H The gate control bit and C/T bit are made 0, and the unused timer(Timer 0 bit is also 0) (b) TMOD is 01010010=52H (c) TMOD is 00000000H = 00H

Note: 8051 Timers use 1/12 of XTAL frequency, regardless of machine cycle time.

Clock source for timer

As you know, every timer needs a clock pulse to tick. What is the source of the clock pulse for the 8051 timers? If C/T=0, the crystal frequency attached to the 8051 is the source of the clock for the timer. This means that the size of the crystal frequency attached to the 8051 also decides the speed at which the 8051 timer ticks. The frequency for the timer is always 1/12th the frequency of the crystal attached to the 8051. Although various 8051-based systems have an XTAL frequency of 10MHz,we will concentrate on the XTAL frequency of 11.0592MHz.the reason behind such an odd
DEPT: ECE, S.B.I.T, KMM 36

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

number has to do with the baud rate for serial communication of the 8051.XTAL =11.0592MHz allows the 8051 system to communicate with the IBM PC with no errors.

Gate

The other bit of the TMOD register id the GATE bit. Notice in the TMOD register in the below example figure that both Timers 0 and 1 have the GATE bit. What is its purpose? Every timer has a means of starting and stopping. Some timers do this by software, some by hardware, and some have both software and hardware controls. the timers in the 8051 have is achieved by the instructions SETB TR1 and CLR TR1 for Timer 1,and SETB TR0 and CLR TR0 for Timer0.the SETB instruction starts it, and it is stopped by the CLR instruction. These instructions start and stop the timers as long as GATE =0 in the TMOD register. The hardware way of starting and stopping the timer by an external source GATE =0, meaning that no external hardware is needed to start and stop the timers. in using software to start and stop the timer where GATE=0,all we need are the instructions SETB TRx and CLR TRx.

Now that we have this basic understanding of the role of the TMOD register, we will look at the timers modes and how they are programmed to create a time delay. Because modes 1 and 2 are so widely used, we describe each of them in detail.

EX: How are timers 0 and 1 started and stopped by instruction?

Solution:
DEPT: ECE, S.B.I.T, KMM 37

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

The timers are started by using instructions to set timer start bits TR0 and TR1,which are called timer run control bits. They can be cleared by clearing these bits. When a timer counts to its maximum value, it sets a flag TF0 or TF1.at this point, it is necessary to know more about the bits TF and TR for timers 0 and 1.while TMOD controls the timer modes, another register called the TCON controls the timer/counter operations. The lower four bits of TCON cater to interrupt functions, but the upper four bits are for timer operations. The details of the TCON register are shown below.

MSB

LSB

TF1 IT0

TR1

TF0

TR0

IE1

IT1

IE0

BIT

SYMBOL

FUNCTION

TCON.7 TCON.6 TCON.5 TCON.4

TF1 TR1 TF0 TR0

Timer 1 overflows flag Timer 1 run control bit Timer 0 overflows flag Timer 0 run control bit

Some assemblers dont allow the use of TF0, TR0, etc.in programs, but instead need the use of these as bits of TON. For example, TF1 is TCON.7 and TR1 is TCON.6.

Mode 1 programming
DEPT: ECE, S.B.I.T, KMM 38

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

The following are the characteristic and operations of mode 1:

1. it is a 16-bit timer: therefore, it allows values of 0000 to FFFFH to be loaded into the timers registers TL and TH. 2. After TH and TL are loaded with 16-bit initial value, the timer must be started. This is done by SETB TR0 for Timer 0 and SET TR1 for Timer1. 3. After the timer is started, it starts to count up. it counts up until it reaches its limit of FFFFH. When it rolls over from FFFFH to 0000, it sets high a flag bit called TF (timer flag).this timer flag can be monitored. When this timer flag is raised, one option would be to stop the timer with the instructions CLR TR0 or CLR TR1 for Timer 0 and Timer 1, respectively.again, it must be noted that each timer has its own timer flag: TF0 for Timer 0, and TF1 for Timer 1. 4. After the timer reaches its limit its limit and rolls over, in order to repeat the process the registers TH and TL must be reloaded with the original value and TF must be reset to 0

XTAL oscillat or .

/12 _ C/T =0 TR

TH

TL

TF

TF goes high

overflow When FFFF0 flag

DEPT: ECE, S.B.I.T, KMM

39

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Steps to program in mode 1

1. Load the TMOD value register indicating which timer (Timer 0 or Timer 1) is to be used and which timer mode (0 or 1) is selected. 2. Load register TL and TH with initial count values. 3. Start the timer. 4. Keep monitoring the timer flag (TF) with the JNB TFx, target instruction to see if it is raised. Get out of the loop when TF becomes high. 5. Stop the timer. 6. Clear the TF flag for the next round 7. Go back to Step 2 to load TH and TL again.
DEPT: ECE, S.B.I.T, KMM 40

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

EX: In the following program, we are creating a square wave of 50% duty cycle (with equal portion high and low) on the P1.5 bit. Timer 0 is used to generate the time delay. Analyze the program.

Solution:

MOV HERE: MOV MOV CPL ACALL SJMP

TMOD, # 01 TL0, #0F2H TH0, #0FFH P1.5 DELAY HERE

; Timer 0, mode 1 (16 bit mode) ; TL0 =F2H, the low byte ; TH0 =FFH, the High byte ;toggle P1.5

; load TH , TL again

; ------------ delay using Timer 0

DELAY: SETB AGAIN: JNB TR0 TF0, AGAIN ; start Timer 0 ; monitor Timer 0 flag until ; It rolls over CLR CLR RET
DEPT: ECE, S.B.I.T, KMM 41

TR0 TF0

; stop Timer 0 ; clear Timer 0 flag

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Finding values to be loaded into the timer

Assuming that we know the amount of timer delay we need, the question is how to find the values needed for the TH, TL registers. To calculate the values to be loaded into the TL and TH registers.

1. Divide the desired time delay by 1.085s. 2. Perform 65536-n, where n is the decimal value we got in step 1. 3. Convert the result of step 2 to hex, where yyxx is the initial hex value to be loaded into the timers registers. 4. Set TL=xx and TH=yy.

Generating a large time delay

Size of the time delay depends on two factors; (a) the crystal frequency and (b) the timers 16-bit register in mode 1.both of these factors are beyond the control of the 8051 programmer. We saw earlier that the largest time delay is achieved by making both TH and TL zero. what if that is not enough? See the below example.

Ex: Assuming XTAL = 2MHz,write a program to generate a pulse train 2 seconds period on pin P2.4.USse Timer 1 in mode 1.

Solution:
DEPT: ECE, S.B.I.T, KMM 42

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

MOV REPT: MOV CPL BACK: MOV MOV SETB AGAIN: JNB CLR CLR DJNZ SJMP

TMOD, #10H R0, #28 P2.4 TL1, #00H TH1, #00H TR1 TF1, AGAIN TR1 TF1 R0, BACK REPT

; Timer 1, mode 1 ; counter for multiple delays ; complement P2.4 ; load count value in TL1 ; load count value in th1 ; start timer ; stay until timer roller over ; stop timer ; clear timer flag ; if R0 is not zero, reload timer ; repeat for continuous pulse generation

Calculation = 28x 35.75ms =1001 ms.

Mode 0

Mode 0 is exactly like mode 1 except that it is a 13-bit timer instead of 16-bit.the 13bit counter can hold values between 0000 to 1FFFH in TH-TL. Therefore, when the timer reaches its maximum of 1FFH, it rolls over to 0000, and TF is raised.

DEPT: ECE, S.B.I.T, KMM

43

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Mode 2 programming

The following are the characteristics and operations of mode 2. 1. It is 8-bit timer; therefore, it allows only values if 00 to FFH to be loaded into the timers register TH. 2. After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL. Then the timer must be started. This is done by the instruction SETB TR0 for Timer 0 and SETB TR1 for Timer 1.this is just like mode 1. 3. After the timer is started, it started, it start to count up by incrementing the TL register. It counts up until it reaches its limit of FFH. When it rolls over from FFH to 00, it sets high the TF (timer flag).if we are using Timer 0, TF0 goes high; if we are using Timer 1, and TF1 is raised. Overfl ow
DEPT: ECE, S.B.I.T, KMM 44

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

flag

XTAL Oscillato r /12

TL

TF

TH TR TF goes high when FF---0

4. When the TL registers rolls from FFH to 0 and TF is set to 1, TL is reloaded automatically with the original value kept by the TH register. To repeat the process, we must simply clear TF and let it go without any need by the programmer to reload the original value. This makes mode 2 an auto-reload, in contrast with mode 1 in which the programmer has to reload TH and TL.

DEPT: ECE, S.B.I.T, KMM

45

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

It must be emphasized that mode 2 is an 8-bit timer. However, it has an autoreloading capability. In auto-reload TH is loaded with the initial count and a copy of it is given to TL. This reloading leaves TH unchanged, still holding a copy of the original value. This mode has many applications, including setting the baud rate in serial communication.

Steps to program in mode 2

To generate a time delay using the timers mode 2 take the following steps.

1. Load the TMOD value register indicting which timer (Timer 0 or Timer 1) is to be used, and select the timer mode(mode 2).
DEPT: ECE, S.B.I.T, KMM 46

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

2. Load the TH registers with the initial count value. 3. start the timer 4. Keep monitoring the timer flag (TF) with the JNB TFx, target instruction to see whether it is raised. get out of the loop when TF goes high. 5. clear the TF flag 6. Go back to step 4, since mode 2 is auto-reload.

SERIAL COMMUNICATION: Computers can transfer data in two ways: parallel and serial. In parallel data transfers, often 8 or more lines (wire conductors) are used to transfer data to a device that is only a few feet away. Examples of parallel transfers ae printers and hard disks; each uses cables with many wire strips. Although in such cases a lot of data can be transferred in a short amount of time by using many wires in parallel, the distance cannot be great. To transfer to a device located many meters away, the serial method is used. In serial communication, the data is sent one bit at a time, in contrast to parallel communication, in which the data is sent a byte or more at a time. Serial communication of the 8051 is the topic of this chapter. The 8051 has serial communication capability built into it, there by making possible fast data transfer using only a few wires. If data is to be transferred on the telephone line, it must be converted from 0s and 1s to audio tones, which are sinusoidal-shaped signals. performed by a peripheral device called a modem, modulator/demodulator. Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block of data at a time, while the asynchronous method transfers a single byte at a time. In data transmission if the data can be transmitted and received, it is a duplex transmission. This is in contrast to simplex transmissions such as with printers, in which the computer only sends data. Duplex transmissions can be half or full duplex,
DEPT: ECE, S.B.I.T, KMM 47

This conversion is which stands for

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

depending on whether or not the data transfer can be simultaneous.

If data is

transmitted one way at a time, it is referred to as half duplex. If the data can go both ways at the same time, it is full duplex. Of course, full duplex requires two wire conductors for the data lines, one for transmission and one for reception, in order to transfer and receiv e data simultaneously. Asynchronous serial communication and data framing The data coming in at the receiving end of the data line in a serial data transfer is all 0s and 1s; it is difficult to make sense of the data unless the sender and receiver agree on a set of rules, a protocol, on how the data is packed, how many bits constitute a character, and when the data begins and ends. Start and stop bits Asynchronous serial data communication is widely used for character-oriented transmissions, while block-oriented data transfers use the synchronous method. In the asynchronous method, each character is placed between start and stop bits. This is called framing. In the data framing for asynchronous communications, the data, such as ASCII characters, are packed between a start bit and a stop bit. The start bit is always one bit, but the stop bit can be one or two bits. The start bit is always a 0 (low) and the stop bit (s) is 1 (high). Data transfer rate The rate of data transfer in serial data communication is stated in bps (bits per second). Another widely used terminology for bps is baud rate. However, the baud and bps rates are not necessarily equal. This is due to the fact that baud rate is the modem terminology and is defined as the number of signal changes per second. In modems a single change of signal, sometimes transfers several bits of data. As far as the conductor wire is concerned, the baud rate and bps are the same, and for this reason we use the bps and baud interchangeably. The data transfer rate of given computer system depends on communication ports incorporated into that system. For example, the early IBMPC/XT could transfer data at the rate of 100 to 9600 bps. In recent years, however, Pentium based PCS

DEPT: ECE, S.B.I.T, KMM

48

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

transfer data at rates as high as 56K bps. It must be noted that in asynchronous serial data communication, the baud rate is generally limited to 100,000bps. RS232 Standards To allow compatibility among data communication equipment made by various manufacturers, an interfacing standard called RS232 was set by the Electronics Industries Association (EIA) in 1960. In 1963 it was modified and called RS232A. RS232B AND RS232C were issued in 1965 and 1969, respectively. Today, RS232 is the most widely used serial I/O interfacing standard. This standard is used in PCs and numerous types of equipment. However, since the standard was set long before the advert of the TTL logic family, its input and output voltage levels are not TTL compatible. In RS232, a 1 is represented by -3 to -25V, while a 0 bit is +3 to +25V, making -3 to +3 undefined. For this reason, to connect any RS232 to a microcontroller system we must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa. MAX232 IC chips are commonly referred to as line drivers. RS232 pins RS232 cable, commonly referred to as the DB-25 connector. In labeling, DB25P refers to the plug connector (male) and DB-25S is for the socket connector(female). Since not all the pins are used in PC cables, IBM introduced the DB-9 Version of the serial I/O standard, which uses 9 pins only, as shown in table. DB-9 pin connector

12345 6789
(Out of computer and exposed end of cable)

Pin Functions:

Pin Description 1 Data carrier


DEPT: ECE, S.B.I.T, KMM

detect
49

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

2 3 4

(DCD) Received data (RXD) Transmitted data (TXD) Data terminal

ready(DTR) 5 Signal ground (GND) 6 Data set ready (DSR) 7 Request to send (RTS) 8 Clear to send (CTS) 9 Ring indicator (RI) Note: DCD, DSR, RTS and CTS are active low pins. The method used by RS-232 for communication allows for a simple connection of three lines: Tx, Rx, and Ground. The three essential signals for 2 way RS232
Communications are these: TXD: carries data from DTE to the DCE. RXD: carries data from DCE to the DTE SG: signal ground

8051 connection to RS232


The RS232 standard is not TTL compatible; therefore, it requires a line driver such as the MAX232 chip to convert RS232 voltage levels to TTL levels, and vice versa. The interfacing of 8051 with RS232 connectors via the MAX232 chip is the main topic. The 8051 has two pins that are used specifically for transferring and receiving data serially. These two pins are called TXD and RXD and a part of the port 3 group (P3.0 and P3.1). pin 11 of the 8051 is assigned to TXD and pin 10 is designated as RXD. These pins are TTL compatible; therefore, they require a line driver to make them RS232 compatible. One such line driver is the MAX232 chip. MAX232 converts from RS232 voltage levels to TTL voltage levels, and vice versa. One advantage of the MAX232 chip is that it uses a +5V power source which,
DEPT: ECE, S.B.I.T, KMM 50

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

is the same as the source voltage for the 8051. In the other words, with a single +5V power supply we can power both the 8051 and MAX232, with no need for the power supplies that are common in many older systems. The MAX232 has two sets of line drivers for transferring and receiving data. The line drivers used for TXD are called T1 and T2, while the line drivers for RXD are designated as R1 and R2. In many applications only one of each is used.

TXD

RXD TXD

2 3 5

Embedded Controller

RXD GND

MAX 232

Baud rate in the 8051 The 8051 transfers and receives data serially at many different baud rates. The baud rate in the 8051 is programmable. The is done with the help of Timer1. The 8051 divides the crystal frequency by 12 to get the machine cycle frequency. In the case of XTAL=11.0592MHZ, the machine cycle frequency is 921.6 KHz (11.0592MHz/12=921.6KHz). the 8051s serial communication UART circuitry divides the machine cycle frequency of 921.6khz divided by 32 once more before it is used by Timer 1 to set the Baud rate. Therefore, 921.6 kHz divided by 32 gives 28,800 Hz. This is the number well use to find the Timer 1 value to set baud rate. Baud rate TH1(Decimal ) 9600 4800 2400 -3 -6 -12 TH1(Hex ) FD FA F4
51

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

1200

-24

E8

NOTE: XTAL=11...592MHz SBUF register SBUF is an 8-bit register used solely for serial communication in the 8051. for a byte of data to be transferred via the TXD line, it must be placed in the SBUF register. Similarly, SBUF holds the byte of data when it is received by the 8051s RXD line. SBUF can be accessed like any other register in the 8051. Look at the following the examples of how this register is accessed.
MOV MOV MOV SBUF, #D SBUF, A A, SBUF ; load SBUF=44h, ASCII for D ; copy accumulator into SBUF ; copy SBUF into accumulator

The moment a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TXD pin. Similarly, when the bits are received serially via RXD, the 8051 defames it by eliminating the stop and start bits, making a byte out of the data received, and then placing it in the SBUF.

SCON (serial control) register The SCON register is an 8-bit register used to program the start bit, stop bit, and data bits of data framing, among other things. The following describes various bits of the SCON register.

SM0

SM1

SM2

REN

TB8

RB8

TI

RI
52

DEPT: ECE, S.B.I.T, KMM

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

SM0 SM1 SM2 REN TB8 RB8 TI

SCON.7 SCON.6 SCON.5 SCON.4 SCON.3 SCON.2 SCON.1

Serial port mode specifier Serial port mode specifier Used for multiprocessor communication. (make it 0.) Set/cleared by software to enable/disable reception Not widely used Not widely used Transmit interrupt flag. Set by hardware at the beginning Of the stop bit in mode 1. Must be cleared by software.

RI software.

SCON.0

Receive interrupt flag. Set by hardware halfway through the stop bit time mode 1. Must be cleared by

Note: Make SM2, TB8, and RB8=0.

SM0, SM1
SM0 and SM1 are D7 and D6 of the SCON register, respectively. These two bits determine the framing of data by specifying the number of bits per character and the start and stop bits. They take the following combinations.

SM0 0

SM1 FUNCTION 0 Serial Mode 0

DEPT: ECE, S.B.I.T, KMM

53

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

0 1 1

1 0 1

Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit Serial Mode 2 Serial Mode 3

Of the 4 serial modes, only mode 1 is of interest to us. In the SCON register, when serial mode 1 is chosen, the data framing is 8 bits, 1 stop bit, and 1 start bit, which makes it compatible with the COM port of IBM/compatible PCs. the 8051. More importantly, serial mode 1 allows the baud rate to be variable and is set by Timer 1 of In serial mode 1, for each character a total of 10 bits are transferred, where the first bit is the start bit, followed by 8 bits of data, and finally 1 stop bit.

MODE 0

In mode 0, the data are transferred through the RXD pin, while clock pulses appear on the TXD pin. The bout rate is fixed at 1/12 the quartz oscillator frequency. On transmit, the least significant bit (LSB bit) is being sent/received first. (received). TRANSMIT Data transmission in form of pulse train automatically starts on the pin RXD at the moment the data has been written to the SBUF register.In fact, this process starts after any instruction being performed on this register. Upon all 8 bits have been sent, the bit TI in the SCON register is automatically set.

DEPT: ECE, S.B.I.T, KMM

54

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

RECEIVE Starts data receiving through the pin RXD once two necessary conditions are met: bit REN=1 and RI=0 (both bits reside in the SCON register). Upon 8 bits have been received, the bit RI (register SCON) is automatically set, which indicates that one byte is received.

Since, there are no START and STOP bits or any other bit except data from the SBUF register, this mode is mainly used on shorter distance where the noise level is minimal and where operating rate is important. A typical example for this is I/O port extension by adding cheap IC circuit ( shift registers 74HC595, 74HC597 and similar).
Mode 1

DEPT: ECE, S.B.I.T, KMM

55

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

In Mode1 10 bits are transmitted through TXD or received through RXD in the following manner: a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1) last. The START bit is not registered in this pulse train. Its purpose is to start data receiving mechanism. On receive the STOP bit is automatically written to the RB8 bit in the SCON register. TRANSMIT A sequence for data transmission via serial communication is automatically started upon the data has been written to the SBUF register. End of 1 byte transmission is indicated by setting the TI bit in the SCON register.

DEPT: ECE, S.B.I.T, KMM

56

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

RECEIVE Receiving starts as soon as the START bit (logic zero (0)) appears on the pin RXD. The condition is that bit REN=1and bit RI=0. Both of them are stored in the SCON register. The RI bit is automatically set upon receiving has been completed.

The Baud rate in this mode is determined by the timer 1 overflow time.

MODE 2

SM2 SM2 is the D5 bit of the SCON register. This bit enables the multiprocessing capability of the 8051. For our applications, we will make SM2=0 since we are not using the 8051 in a multi processor environment. REN The REN (receive enable) bit is D4 of the SCON register. The REN bit is also referred to as SCON.4 since SCON is a bit-addressable register. When the REN bit is high, it allows the 8051 to receive data on the RXD pin of the 8051. As a result if we want the 8051 to both transfer and receive data, REN must be set to 1. By making REN=0, the receiver is disabled. Making REN=1 or REN=0 can be achieved by the
DEPT: ECE, S.B.I.T, KMM 57

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

instructions SETB SCON.4 and CLR SCON.4, respectively.

Notice that these

instructions use the bit-addressable features of the register SCON. This bit can be used to block any serial data reception and is an extremely important in the SCON register. TB8 TB8 (transfer bit 8) is bit D3 of SCON. It is used for serial modes 2 and 3. we make TB8=0 since it is not used in our applications. RB8 RB8 (receive bit 8) is bit D2 of the SCON register. In serial mode 1, this bit gets a copy of the stop bit when an 8-bit data is received. This is (as is the case for TB8) is rarely used anymore. In all our applications we will make RB8=0. Like TB8, the RB8 bit is also used in serial modes 2 and 3.

DEPT: ECE, S.B.I.T, KMM

58

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

TRANSMIT
TI (transmit interrupt) is bit D1 of the SCON register. This is an extremely

important flag bit in the SCON register. When the 8051 finishes the transfer of the 8bit character, it raises the TI flag to indicate that it is ready to transfer another byte. The TI bit is raised at the beginning of the stop bit.

RECEIVE
RI (receive interrupt) is the D0 of the SCON register. This is another extremely important flag bit in the SCON register. When the 8051 receives data serially via RXD, it gets rid of the start and stop bits and places the byte in the SBUF register. Then it raises the RI flag bit to indicate that a byte has been received and should be picked up before it is lost. RI is raised halfway through the stop bit.

DEPT: ECE, S.B.I.T, KMM

59

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Mode 3

Mode 3 is the same as Mode 2 except the baud rate. In Mode 3 is variable and can be selected.

BAUD RATE CALCULATION:

Internal

timer stages are as fallows

XClk

Divided by 12

Divided by 32

Divided by X Baud Rate UART

Divided by X box can be replaced with T1 timer so that by changing the value of timer we can obtain the required baud rate.

Let XClk Baud Rate

= =

11.0592 Mhz (XClk / 12 / 16 / 2 / X )

For attaining 9600 baud Rate, X can be calculated as =


DEPT: ECE, S.B.I.T, KMM

11.0592 x 106 / 12 / 16 / 2 / 9600


60

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

So set the 2s Complement of 3 in Timer 1 so that we can achieve 9600 baud rates.

Note: Assuming 8-bit Auto reload mode and 8-bit variable baud rate modes. Doubling the baud rate in the 8051: There are two ways to increase the baud rate to data transfer in the 8051. 1. Use a higher- frequency crystal. 2. Change a bit in the PCON register, shown below.

SMOD

--

--

--

GF1

GF0

PD

IDL

Option1 is not feasible in many situations since the system crystal is fixed. More Importantly, it is not feasible because the new crystal may not be compatible with the IBM PC serial COM ports baud rate. Therefore, we will explore option2. there is a software way to double the baud rate of the 8051 while the crystal frequency is fixed. This is done with the register called PCON (power control). The PCON register is an 8bit register. Of the 8 bits, some are unused, and some are used for the power control capability of the 8051. The bit that is used for the serial communication is D7, the SMOD (serial mode) bit. When the 8051 is powered up, D7 (SMOD) of this PCON register is zero. We can set it to high by software and thereby double the baud rate. The following sequence of instructions must be used to set high D7 of PCON, since it is not a bit-addressable register:
MOV A, PCON ; place a copy a of PCON in ACC SETB ACC.7 ; make D7=1

MOV PCON, A ; changing any other bits

DEPT: ECE, S.B.I.T, KMM

61

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

To see how the baud rate is double with this method, we show the role of the SMOD bit (D7 bit of the PCON register), which can be 0 or 1. we discuss each case.

Baud rates for SMOD =0 When SMOD=0, the 8051 divides 1/12 of the crystal frequency by 32 and uses that frequency for Timer 1 to set the baud rate. In the case of XTAL=11.0592MHZ we have:
Machine cycle freq.=11.0592 MHz/12 = 921.6KHz And 921.6 KHz/32 = 28,800 Hz since SMOD=0

This is the frequency used by Timer 1 to set the baud rate. This has been the basis of all the examples so far since it is the default when the 8051 is powered up. The baud rate for SMOD=0 was listed in above table. Baud rates for SMOD = 1 With the fixed crystal frequency, we can double the baud rate by making SMOD=1. When the SMOD bit (D7 of the PCON register) is set to 1, 1/12 of XTAL is divided by 16 (instead of 32) and that is the frequency used by Timer 1 to set the baud rate. In the case of XTAL=11.0592 MHz, we have:
Machine cycle freq. = 11.0592 MHz / 12 = 921.6 KHz And 921.6 KHz / 16 = 57,600 Hz since SMOD = 1

This is the frequency used by Timer 1 to set the baud rate. Table: Baud Rate comparison for SMOD = 0 and SMOD = 1

DEPT: ECE, S.B.I.T, KMM

62

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

TH1 (Decimal) -3 -6 -12 -24

(Hex ) FD FA F4 E8

SMOD = SMOD = 0 9,600 4,800 2,400 1,200 1 19,200 9,600 4,800 2,400

Note: XTAL=11.0592 MHz. Table: shows that the values loaded into TH1 are the same for both cases; however, the baud rates are doubled when SMOD=1.

INTERRUPTS: Interrupts are hardware signals that are used to determine conditions that exist in external and internal circuits. Any interrupt can cause the 8051 to perform a hardware call to an interrupt handling subroutine that is located at a predetermined absolute address in the program memory. Five interrupts are provided in the 8051. Three of these are generated automatically by the internal operations: Timer flag 0, Timer Flag 1, and the serial port interrupt (RI or TI) Two interrupts are triggered by external signals provided by the circuitry that is connected to the pins INTO 0 and INTO1. The interrupts maybe enable or disabled, given priority or otherwise controlled by altering the bits in the Interrupt Enabled (IE) register, Interrupt Priority (IP) register, and the Timer Control (TCON) register. . These interrupts are mask able i.e. they can be disabled. Reset is a non maskable interrupt which has the highest priority. It is generated when a high is applied to the reset pin. Upon reset, the registers are loaded with the default values.

DEPT: ECE, S.B.I.T, KMM

63

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Each interrupt source causes the program to do store the address in PC onto the stack and causes a hardware call to one of the dedicated addresses in the program memory. The appropriate memory locations for each for each interrupt are as follows: Interrupt RESET IE0 (External interrupt 0) TF0 (Timer 0 interrupt) IE1 (External interrupt 1) TF1 (Timer 1 interrupt) SERIAL Address 0000 0003 000B 0013 001B 0023

Functions of micro controller in main unit are 1. 2. 3. 4. 5. Sends appropriate commands to ADC to start conversion, Collects the output of ADC for every 10 sec and stores in buffer, Sends command to the modem for dialing the base every 80 sec, Sends data in a serial manner to MODEM, After data gets transmitted sends command for disconnection.

6. Sends appropriate information to the display unit as per status of the communication medium.

DEPT: ECE, S.B.I.T, KMM

64

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Power supply

The power supplies are designed to convert high voltage AC mains electricity to a suitable low voltage supply for electronics circuits and other devices. A power supply can by broken down into a series of blocks, each of which performs a particular function. A d.c power supply which maintains the output voltage constant irrespective of a.c mains fluctuations or load variations is known as Regulated D.C Power Supply
DEPT: ECE, S.B.I.T, KMM 65

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

For example a 5V regulated power supply system as shown below:

Transformer: A transformer is an electrical device which is used to convert electrical power from one

Electrical circuit to another without change in frequency.

DEPT: ECE, S.B.I.T, KMM

66

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

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. Step-up transformers increase in output voltage, step-down transformers decrease in output voltage. 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 they are linked by an alternating magnetic field created in the 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 turns ratio, determines the ratio of the voltages. A step-down transformer has a large 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.

An Electrical Transformer

Turns ratio = Vp/ VS = Np/NS

Power Out= Power In

DEPT: ECE, S.B.I.T, KMM

67

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

VS X IS=VP X IP Vp = primary (input) voltage Np = number of turns on primary coil Ip = primary (input) current

RECTIFIER:

A circuit which is used to convert a.c to dc is known as RECTIFIER. The process of conversion a.c to d.c is called rectification

TYPES OF RECTIFIERS:

Half wave Rectifier Full wave rectifier 1. Centre tap full wave rectifier. 2. Bridge type full bridge rectifier.

Comparison of rectifier circuits:

Type of Rectifier Parameter Number of diodes 1 PIV of diodes


DEPT: ECE, S.B.I.T, KMM 68

Half wave Bridge

Full wave

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

2Vm Vm Vm

D.C output voltage

Vm/

2Vm/

2Vm/

Vdc,at no-load

0.318Vm

0.636Vm

0.636Vm

Ripple factor Ripple frequency Rectification efficiency Transformer Utilization Factor(TUF) RMS voltage Vrms

1.21

0.482

0.482

2f

2f

0.406

0.812

0.812

0.287

0.693

0.812

Vm/2

Vm/2

Vm/2

Full-wave Rectifier: From the above comparison we came to know that full wave bridge rectifier as more advantages than the other two rectifiers. So, in our project we are using full wave bridge rectifier circuit.

DEPT: ECE, S.B.I.T, KMM

69

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Bridge Rectifier: A bridge rectifier makes use of four diodes in a bridge arrangement to achieve full-wave rectification. This is a widely used configuration, both with individual diodes wired as shown and with single component bridges where the diode bridge is wired internally. A bridge rectifier makes use of four diodes in a bridge arrangement as shown in fig(a) to achieve full-wave rectification. This is a widely used configuration, both with individual diodes wired as shown and with single component bridges where the diode bridge is wired internally.

Fig(A) Operation: During positive half cycle of secondary, the diodes D2 and D3 are in forward biased while D1 and D4 are in reverse biased as shown in the fig(b). The current flow direction is shown in the fig (b) with dotted arrows.

DEPT: ECE, S.B.I.T, KMM

70

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Fig(B)

During negative half cycle of secondary voltage, the diodes D1 and D4 are in forward biased while D2 and D3 are in reverse biased as shown in the fig(c). The current flow direction is shown in the fig (c) with dotted arrows.

Fig(C) Filter:

A Filter is a device which removes the a.c component of rectifier output

DEPT: ECE, S.B.I.T, KMM

71

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

but allows the d.c component to reach the load

Capacitor Filter: We have seen that the ripple content in the rectified output of half wave rectifier is 121% or that of full-wave or bridge rectifier or bridge rectifier is 48% such high percentages of ripples is not acceptable for most of the applications. Ripples can be removed by one of the following methods of filtering.

(a) A capacitor, in parallel to the load, provides an easier by pass for the ripples voltage though it due to low impedance. At ripple frequency and leave the d.c.to appears the load.

(b) An inductor, in series with the load, prevents the passage of the ripple current (due to high impedance at ripple frequency) while allowing the d.c (due to low resistance to d.c)

(c) Various combinations of capacitor and inductor, such as L-section filter section filter, multiple section filter etc. which make use of both the properties mentioned in (a) and (b) above. Two cases of capacitor filter, one applied on half wave rectifier and another with full wave rectifier. Filtering 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 voltage from the rectifier is falling. The capacitor charges quickly near the peak of the varying DC, and then discharges as it supplies current to
DEPT: ECE, S.B.I.T, KMM 72

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

the output. Filtering significantly increases the average DC voltage to almost the peak value (1.4 RMS value). To calculate the value of capacitor(C), C = *3*f*r*Rl Where, f = supply frequency, r = ripple factor, Rl = load resistance Note: In our circuit we are using 1000F. Hence large value of capacitor is placed to reduce ripples and to improve the DC component.

Regulator:

Voltage regulator ICs is available with fixed (typically 5, 12 and 15V) or variable output voltages. The maximum current they can pass also rates them. 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 have 3 leads and look like power transistors, such as the 7805 +5V 1A regulator shown on the right. The LM7805 is simple to use. You simply connect the positive lead of your unregulated DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect the negative lead to the Common pin and then when you turn on the power, you get a 5 volt supply from the output pin.

DEPT: ECE, S.B.I.T, KMM

73

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Fig 6.1.6 A Three Terminal Voltage Regulator 78XX: The Bay Linear LM78XX is integrated linear positive regulator with three terminals. The LM78XX offer several fixed output voltages making them useful in wide range of applications. When used as a zener diode/resistor combination replacement, the LM78XX usually results in an effective output impedance improvement of two orders of magnitude, lower quiescent current. The LM78XX is available in the TO-252, TO-220 & TO-263packages, Features: Output Current of 1.5A Output Voltage Tolerance of 5% Internal thermal overload protection Internal Short-Circuit Limited No External Component Output Voltage 5.0V, 6V, 8V, 9V, 10V,12V, 15V, 18V, 24V Offer in plastic TO-252, TO-220 & TO-263 Direct Replacement for LM78XX circuit description:
DEPT: ECE, S.B.I.T, KMM 74

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

The MC3032 is an optoisolator TRIAC driver. The 180-ohm resistor sets the current for the LED emitter in the optoisolator. Change the value of this resistor - if necessary - to get reasonable current (e.g., 15 mA). Note that you cannot test this circuit without a load. The TRIAC will not switch unless connected to an AC voltage source, so you can't test it for simple switching w/o applying AC and a load. Note the 500V rating on

the .01 cap. Controlling relay with ttl logic

Energy Meter:An

electric meter or energy meter is a device that

measures the amount of electrical energy supplied to or produced by a residence, business or machine. The most common type is more properly known as a kilowatt hour meter or a joule meter. When used in electricity retailing, the Utilities record the values measured by these meters to generate an invoice for the electricity. They may also record other variables including the time when the electricity was used.

Prepayment Meters:
The standard business model of electricity retailing involves the electricity company billing the customer for the amount of energy used in the previous month or quarter. In some countries, if the retailer believes that the customer may not pay the bill, a prepayment meter may be installed. This requires the
DEPT: ECE, S.B.I.T, KMM 75

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

customer to make advance payment before electricity can be used. If the available credit is exhausted then the supply of electricity is cut off by a relay.

Interfacing of relay:
The circuit diagram for interfacing relay to a 8051 microcontroller is shown below

Relays allow us to control the high power circuits or instruments using low power circuits and voltage levels such as output of microcontrollers. Interfacing relays to 8051 or any other microcontroller is just simple as controlling a LED. A relay consists of a coil which is driven by low power circuits such as microcontrollers in order to control high power ac circuits through output switches. Normally there are two types of switches in a relay, they are Normally Open (NO) and Normally Closed (NC) contacts. NO contacts are open when relay is not activated where as the NC contacts are closed, when relay is activated by supplying power to the input coil, the NO contacts are now closed and the NC contacts are open.
DEPT: ECE, S.B.I.T, KMM 76

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Interfacing of LED:
The first thing usually done while learning any microcontroller or embedded system is blinking an LED. The circuit below shows the circuit for Interfacing an LED.

WORKING PRINCIPLE: A scheme of Electricity billing system called ?PREPAID ENERGY METER WITH TARIFF INDICATOR? can facilitate in improved cash flow management in energy utilities and can reduces problem associated with billing consumer living in isolated area and reduces deployment of manpower for taking meter readings. Every consumer can buy a memory card (is nothing but an EEPROM IC) with a password stored inside it using a MC program. The memory card is available at various ranges (ie. Rs 50, Rs 100, Rs 200 etc?).In our project we have given the name for memory card as smart card. When the consumer insert a smart card into the card reader which is connected in ?prepaid energy meter with tariff indicator?kit.Then the card reader will read the stored information and delete the information from the EEPROM IC(smart card) using the MC program. So that the smart card cannot be reused by others. Suppose if a consumer buy a card for Rs.50/- he / she can insert this amount through the card reader so that prepaid energy meter with tariff indicator kit will be activated. According to the power consumption the amount will be reduced. When the amount is over, the relay will automatically shutdown the whole system. In our project we also have a provision to give an alarm sound to consumer before the whole amount is reduced.

BUZZER: An electric signaling device, such as a doorbell, that makes a buzzing


sound.
DEPT: ECE, S.B.I.T, KMM 77

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

An audible warning device indicating it is time to do something. A buzzer or beeper is a signalling device, usually electronic, typically used in automobiles, household appliances such as a microwave oven, or game shows. It most commonly consists of a number of switches or sensors connected to a control unit that determines if and which button was pushed or a preset time has lapsed, and usually illuminates a light on the appropriate button or control panel, and sounds a warning in the form of a continuous or intermittent buzzing or beeping sound. Initially this device was based on an electromechanical system which was identical to an electric bell without the metal gong (which makes the ringing noise). Often these units were anchored to a wall or ceiling and used the ceiling or wall as a sounding board. Another implementation with some AC-connected devices was to implement a circuit to make the AC current into a noise loud enough to drive a loudspeaker and hook this circuit up to a cheap 8-ohm speaker. Nowadays, it is more popular to use a ceramic-based piezoelectric sounder which makes a high-pitched tone. Usually these were hooked up to "driver" circuits which varied the pitch of the sound or pulsed the sound on and off. In game shows it is also known as a "lockout system," because when one person signals ("buzzes in"), all others are locked out from signalling.Several game shows have large buzzer buttons which are identified as "plungers". The buzzer is also used to signal wrong answers and when time expires on many game shows, such as Wheel of Fortune, Family Feud and The Price is Right. The word "buzzer" comes from the rasping noise that buzzers made when they were electromechanical devices, operated from stepped-down AC line voltage at 50 or 60 cycles. Other sounds commonly used to indicate that a button has been pressed are a ring or a beep. What is the energy for a buzzer?

Electrical sound .

Electronic Switch
DEPT: ECE, S.B.I.T, KMM 78

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

An electronic device in which one or more input signals can be routed to one or more outputs by the application of the appropriate electrical control signals. The term is most often applied when analog signals are involved, but the terminology is occasionally used when digital signals are involved. Conceptually, an electronic switch can be visualized as a group of one or more mechanical electrical switches (such as light switches used in commercial wiring or toggle switches used in many electronic control panels) in which, instead of mechanically opening or closing the contacts, the physical opening and closing is achieved by applying appropriate electrical control signals to separate terminals on the switch in much the same way that a relay performs. The electronic switch does not contain mechanical contacts but semiconductor devices such as bipolar junction transistors or field-effect transistors. The basic electronic switch is depicted in illus. a. A and B are the terminals of the switch. When a control signal is applied to VC, the switch closes. When the electronic switch is closed, a small residual resistance Rs remains between the terminals as depicted in the simple model of illus. b. The value of this resistance is termed the on resistance. In most applications the nonzero on resistance does not prove problematic, but the user needs to be aware of this limitation. The electronic switch is typically bidirectional in the sense that the terminals A and B are interchangeable. See also Electric switch; Relay; Transistor.

Electronic switches can be very small, allowing a large number of these devices to be placed in a small area they can be very fast, with on and off response times which are orders of magnitude faster than can be achieved with mechanical counterparts; and they are considerably more reliable over a large number of cycles than their mechanical counterparts. (electronics) Vacuum tube, crystal diodes, or transistors used as an on and off switching device

EEPROM:
EEPROM (electrically erasable programmable read-only memory) is usermodifiable read-only memory (ROM) that can be erased and reprogrammed (written to) repeatedly through the application of higher than normal electrical voltage. Unlike EPROM chips, EEPROMs do not need to be removed from the
DEPT: ECE, S.B.I.T, KMM 79

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

computer to be modified. However, an EEPROM chip has to be erased and reprogrammed in its entirety, not selectively. It also has a limited life - that is, the number of times it can be reprogrammed is limited to tens or hundreds of thousands of times. In an EEPROM that is frequently reprogrammed while the computer is in use, the life of the EEPROM can be an important design consideration. A special form of EEPROM is flash memory, which uses normal PC voltages for erasure and reprogramming.

DEPT: ECE, S.B.I.T, KMM

80

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

SOFTWARE Vision3 Vision3 is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components: A project manager. A make facility. Tool configuration. Editor. A powerful debugger. \C251\Examples, \C166\Examples, and

To help you get started, several example programs (located in the \C51\Examples, \ARM\...\Examples) are provided.
HELLO is a simple program that prints the string "Hello World" using the

Serial Interface. Building an Application in Vision2 To build (compile, assemble, and link) an application in Vision2, you must:
1. Select Project - (for example, 166\EXAMPLES\HELLO\HELLO.UV2).

2. Select Project - Rebuild all target files or Build target. Vision2 compiles, assembles, and links the files in your project.

Creating Your Own Application in Vision2 To create a new project in Vision2, you must:
DEPT: ECE, S.B.I.T, KMM 81

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

1. Select Project - New Project. 2. Select a directory and enter the name of the project file. 3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device Database. 4. Create source files to add to the project. 5. Select Project - Targets, Groups, Files, Add/Files, select Source Group1, and add the source files to the project.
6. Select Project - Options and set the tool options. Note when you select

the target device from the Device Database all special options are set automatically. You typically only need to configure the memory map of your target hardware. Default memory model settings are optimal for most applications. 7. Select Project - Rebuild all target files or Build target. Debugging an Application in Vision2 To debug an application created using Vision2, you must: 1. Select Debug - Start/Stop Debug Session.
2. Use the Step toolbar buttons to single-step through your program. You

may enter G, main in the Output Window to execute to the main C function.
3. Open the Serial Window using the Serial #1 button on the toolbar.

Debug your program using standard options like Step, Go, Break, and so on. Starting Vision2 and creating a Project Vision2 is a standard Windows application and started by clicking on the program icon. To create a new project file select from the Vision2 menu Project New Project. This opens a standard Windows dialog that asks you for the new project file name. We suggest that you use a separate folder for each project. You can simply use the icon Create New Folder in this dialog to get a new empty folder.
DEPT: ECE, S.B.I.T, KMM 82

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Then select this folder and enter the file name for the new project, i.e. Project1. Vision2 creates a new project file with the name PROJECT1.UV2 which contains a default target and file group name. You can see these names in the Project

Window Files. Now use from the menu Project Select Device for Target and select a CPU for your project. The Select Device dialog box shows the Vision2 device database. Just select the microcontroller you use. We are using for our examples the Philips 80C51RD+ CPU. This selection sets necessary tool options for the 80C51RD+ device and simplifies in this way the tool Configuration

Building Projects and Creating a HEX Files Typical, the tool settings under Options Target are all you need to start a new application. You may translate all source files and line the application with a click on the Build Target toolbar icon. When you build an application with syntax errors, Vision2 will display errors and warning messages in the Output Window Build page. A double click on a message line opens the source file on the correct location in a Vision2 editor window. Once you have successfully generated your application you can start debugging.

DEPT: ECE, S.B.I.T, KMM

83

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

After you have tested your application, it is required to create an Intel HEX file to download the software into an EPROM programmer or simulator. Vision2 creates HEX files with each build process when Create HEX files under Options for Target Output is enabled. You may start your PROM programming utility after the make process when you specify the program under the option Run User Program #1.

CPU Simulation Vision2 simulates up to 16 Mbytes of memory from which areas can be mapped for read, write, or code execution access. The Vision2 simulator traps and reports illegal memory accesses being done. In addition to memory mapping, the simulator also provides support for the integrated peripherals of the various 8051 derivatives. The on-chip peripherals of the CPU you have selected are configured from the Device Database selection You have made when you create your project target. Refer to page 58 for more Information about selecting a device. You may select and display the on-chip peripheral components using the Debug menu. You can also change the aspects of each peripheral using the controls in the dialog boxes.

Start Debugging You start the debug mode of Vision2 with the Debug Start/Stop Debug Session command. Depending on the Options for Target Debug Configuration, Vision2 will load the application program and run the startup code Vision2 saves the editor screen layout and restores the screen layout of
DEPT: ECE, S.B.I.T, KMM 84

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

the last debug session. If the program execution stops, Vision2 opens an editor window with the source text or shows CPU instructions in the disassembly window. The next executable statement is marked with a yellow arrow. During debugging, most editor features are still available.

For example, you can use the find command or correct program errors. Program source text of your application is shown in the same windows. The Vision2 debug mode differs from the edit mode in the following aspects: _ The Debug Menu and Debug Commands described on page 28 are Available. The additional debug windows are discussed in the following. _ The project structure or tool parameters cannot be modified. All build Commands are disabled. Disassembly Window The Disassembly window shows your target program as mixed source and assembly program or just assembly code. A trace history of previously executed instructions may be displayed with Debug View Trace Records. To enable the trace history, set Debug Enable/Disable Trace Recording. If you select the Disassembly Window as the active window all program step commands work on CPU instruction level rather than program source lines. You can select a text line and set or modify code breakpoints using toolbar buttons or the context menu commands. You may use the dialog Debug Inline Assembly to modify the CPU instructions. That allows you to correct mistakes or to make temporary changes to the target program you are debugging.

SOURCE CODE
DEPT: ECE, S.B.I.T, KMM 85

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

1. 2.

Click on the Keil uVision Icon on Desktop The following fig will appear

3. 4.

Click on the Project menu from the title bar Then Click on New Project

DEPT: ECE, S.B.I.T, KMM

86

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

5.

Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\

6. 7. 8.

Then Click on save button above. Select the component for u r project. i.e. Atmel Click on the + Symbol beside of Atmel

DEPT: ECE, S.B.I.T, KMM

87

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

9.

Select AT89C51 as shown below

10. Then Click on OK 11. The Following fig will appear

DEPT: ECE, S.B.I.T, KMM

88

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

12. Then Click either YES or NOmostly NO 13. Now your project is ready to USE 14. Now double click on the Target1, you would get another option
Source group 1 as shown in next page.

15. Click on the file option from menu bar and select new

DEPT: ECE, S.B.I.T, KMM

89

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

16. The next screen will be as shown in next page, and just maximize it
by double clicking on its blue boarder.

17. Now start writing program in either in C or ASM 18. For a program written in Assembly, then save it with extension .
asm and for C based program save it with extension .C

DEPT: ECE, S.B.I.T, KMM

90

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

19. Now right click on Source group 1 and click on Add files to Group
Source

DEPT: ECE, S.B.I.T, KMM

91

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

20. Now you will get another window, on which by default C files will
appear.

21. Now select as per your file extension given while saving the file 22. Click only one time on option ADD 23. Now Press function key F7 to compile. Any error will appear if so
happen.

DEPT: ECE, S.B.I.T, KMM

92

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

24. If the file contains no error, then press Control+F5 simultaneously. 25. The new window is as follows

26. Then Click OK

DEPT: ECE, S.B.I.T, KMM

93

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

27. Now Click on the Peripherals from menu bar, and check your required
port as shown in fig below

28. Drag the port a side and click in the program file.

29. Now keep Pressing function key F11 slowly and observe. 30. You are running your program successfully
DEPT: ECE, S.B.I.T, KMM 94

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

CONCLUSION

FUTURE ENHANCEMENT

DEPT: ECE, S.B.I.T, KMM

95

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

BIBILOGRAPHY
The 8051 Micro controller and Embedded -Muhammad Ali Mazidi Janice Gillispie Mazidi The 8051 Micro controller Architecture, Programming & Applications -Kenneth J.Ayala Fundamentals Of Micro processors and Micro computers Systems

DEPT: ECE, S.B.I.T, KMM

96

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

-B.Ram Micro processor Architecture, Programming & Applications -Ramesh S. Gaonkar Electronic Components -D.V. Prasad

DEPT: ECE, S.B.I.T, KMM

97

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

CHAPTER 1: INTRODUCTION
1.1Introduction:

1.2 Project Overview:


An embedded system is a combination of software and hardware to perform a dedicated task. Some of the main devices used in embedded products are Microprocessors and Microcontrollers. Microprocessors are commonly referred
DEPT: ECE, S.B.I.T, KMM 98

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

to as general purpose processors as they simply accept the inputs, process it and give the output. In contrast, a microcontroller not only accepts the data as inputs but also manipulates it, interfaces the data with various devices, controls the data and thus finally gives the result. The Advanced Digital Energy Meter with Rejuvenate and Alert System Using 8051 Microcontroller is an exclusive project that the purpose of the project is to provide an automation system which gives a record of current usage of power and also the payment details of the digital energy meter.

1.3 Thesis Overview:


The thesis explains the implementation of The Advanced Digital Energy Meter with Rejuvenate and Alert System Using 8051 Microcontroller. The organization of the thesis is explained here with:

Chapter 1 Presents introduction to the overall thesis and the overview of


the project. In the project overview a brief introduction of The Advanced Digital Energy Meter with Rejuvenate and Alert System and its applications are discussed.

Chapter 2

Presents the topic embedded systems. It explains the about

what is embedded systems, need for embedded systems, explanation of it along with its applications.

Chapter 3

Presents the hardware description. It deals with the block

diagram of the project and explains the purpose of each block. In the same chapter the explanation of microcontrollers, power supplies, Energy Meter, LCD Display.

Chapter 4
DEPT: ECE, S.B.I.T, KMM

Presents the software description. It explains the


99

implementation of the project using Keil IDE software.

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Chapter 5

Presents the project description of the energy meter module

interfacing to microcontroller.

Chapter 6
the project.

Presents the advantages, disadvantages and applications of

Chapter 7
project.

Presents the results, conclusion and future scope of the

CHAPTER 2: EMBEDDED SYSTEMS

2.1 Embedded Systems:


An embedded system is a computer system designed to perform one or a few dedicated functions often with real-time computing constraints. It is
DEPT: ECE, S.B.I.T, KMM 100

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today. Embedded systems are controlled by one or more main processing cores that are typically either microcontrollers or digital signal processors (DSP). The key characteristic, however, is being dedicated to handle a particular task, which may require very powerful processors. For example, air traffic control systems may usefully be viewed as embedded, even though they involve mainframe computers and dedicated regional and national networks between airports and radar sites. (Each radar probably includes one or more embedded systems of its own.) Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are massproduced, benefiting from economies of scale. Physically embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power plants. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure.

In general, "embedded system" is not a strictly definable term, as most systems have some element of extensibility or programmability. For example, handheld computers share some elements with embedded systems such as the operating systems and microprocessors which power them, but they allow different applications to be loaded and peripherals to be connected. Moreover, even systems which don't expose programmability as a primary feature generally need to support software updates. On a continuum from "general
DEPT: ECE, S.B.I.T, KMM 101

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

purpose" to "embedded", large application systems will have subcomponents at most points even if the system as a whole is "designed to perform one or a few dedicated functions", and is thus appropriate to call "embedded". A modern example of embedded system is shown in fig: 2.1.

Fig 2.1:A modern example of embedded system Labeled parts include microprocessor (4), RAM (6), flash memory

(7).Embedded systems programming is not like normal PC programming. In many ways, programming for an embedded system is like programming PC 15 years ago. The hardware for the system is usually chosen to make the device as cheap as possible. Spending an extra dollar a unit in order to make things easier to program can cost millions. Hiring a programmer for an extra month is cheap in comparison. This means the programmer must make do with slow processors and low memory, while at the same time battling a need for efficiency not seen in most PC applications. Below is a list of issues specific to the embedded field. 2.1.1 History:

DEPT: ECE, S.B.I.T, KMM

102

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

In the earliest years of computers in the 193040s, computers were sometimes dedicated to a single task, but were far too large and expensive for most kinds of tasks performed by embedded computers of today. Over time however, the concept of programmable controllers evolved from traditional electromechanical sequencers, via solid state devices, to the use of computer technology. One of the first recognizably modern embedded systems was the Apollo Guidance Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. At the project's inception, the Apollo guidance computer was considered the riskiest item in the Apollo project as it employed the then newly developed monolithic integrated circuits to reduce the size and weight. An early mass-produced embedded system was the Autonetics D-17 guidance computer for the Minuteman missile, released in 1961. It was built from transistor logic and had a hard disk for main memory. When the Minuteman II went into production in 1966, the D-17 was replaced with a new computer that was the first high-volume use of integrated circuits. 2.1.2 Tools: Embedded development makes up a small fraction of total

programming. There's also a large number of embedded architectures, unlike the PC world where 1 instruction set rules, and the UNIX world where there's only 3 or 4 major ones. This means that the tools are more expensive. It also means that they're lowering featured, and less developed. On a major embedded project, at some point you will almost always find a compiler bug of some sort. Debugging tools are another issue. Since you can't always run general programs on your embedded processor, you can't always run a debugger on it. This makes fixing your program difficult. Special hardware such as JTAG ports can overcome this issue in part. However, if you stop on a breakpoint when your system is controlling real world hardware (such as a motor), permanent equipment damage can occur. As a result, people doing embedded
DEPT: ECE, S.B.I.T, KMM 103

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

programming quickly become masters at using serial IO channels and error message style debugging. 2.1.3 Resources: To save costs, embedded systems frequently have the cheapest processors that can do the job. This means your programs need to be written as efficiently as possible. When dealing with large data sets, issues like memory cache misses that never matter in PC programming can hurt you. Luckily, this won't happen too often- use reasonably efficient algorithms to start, and optimize only when necessary. Of course, normal profilers won't work well, due to the same reason debuggers don't work well. Memory is also an issue. For the same cost savings reasons, embedded systems usually have the least memory they can get away with. That means their algorithms must be memory efficient (unlike in PC programs, you will frequently sacrifice processor time for memory, rather than the reverse). It also means you can't afford to leak memory. Embedded applications generally use deterministic memory techniques and avoid the default "new" and "malloc" functions, so that leaks can be found and eliminated more easily. Other resources programmers expect may not even exist. For example, most embedded processors do not have hardware FPUs (Floating-Point Processing Unit). These resources either need to be emulated in software, or avoided altogether.

2.1.4 Real Time Issues: Embedded systems frequently control hardware, and must be able to respond to them in real time. Failure to do so could cause inaccuracy in measurements, or even damage hardware such as motors. This is made even more difficult by the lack of resources available. Almost all embedded systems need to be able to prioritize some tasks over others, and to be able to put
DEPT: ECE, S.B.I.T, KMM 104

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

off/skip low priority tasks such as UI in favor of high priority tasks like hardware control. 2.2 Need For Embedded Systems: The uses of embedded systems are virtually limitless, because every day new products are introduced to the market that utilizes embedded computers in novel ways. In recent years, hardware such as microprocessors, microcontrollers, and FPGA chips have become much cheaper. So when implementing a new form of control, it's wiser to just buy the generic chip and write your own custom software for it. Producing a custom-made chip to handle a particular task or set of tasks costs far more time and money. Many embedded computers even come with extensive libraries, so that "writing your own software" becomes a very trivial task indeed. From an implementation viewpoint, there is a major difference between a computer and an embedded system. Embedded systems are often required to provide Real-Time response. The main elements that make embedded systems unique are its reliability and ease in debugging. 2.2.1 Debugging: Embedded debugging may be performed at different levels, depending on the facilities available. From simplest to most sophisticate they can be roughly grouped into the following areas: Interactive resident debugging, using the simple shell provided by the embedded operating system (e.g. Forth and Basic) External debugging using logging or serial port output to trace operation using either a monitor in flash or using a debug server like the Remedy Debugger which even works for heterogeneous multi core systems. An in-circuit debugger (ICD), a hardware device that connects to the microprocessor via a JTAG or Nexus interface. This allows the operation
DEPT: ECE, S.B.I.T, KMM 105

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

of the microprocessor to be controlled externally, but is typically restricted to specific debugging capabilities in the processor. An in-circuit emulator replaces the microprocessor with a simulated equivalent, providing full control over all aspects of the microprocessor.
A complete emulator provides a simulation of all aspects of the

hardware, allowing all of it to be controlled and modified and allowing debugging on a normal PC. Unless restricted to external debugging, the programmer can typically load and run software through the tools, view the code running in the processor, and start or stop its operation. The view of the code may be as assembly code or source-code. Because an embedded system is often composed of a wide variety of elements, the debugging strategy may vary. For instance, debugging a software (and microprocessor) centric embedded system is different from debugging an embedded system where most of the processing is performed by peripherals (DSP, FPGA, co-processor). An increasing number of embedded systems today use more than one single processor core. A common problem with multi-core development is the proper synchronization of software execution. In such a case, the embedded system design may wish to check the data traffic on the busses between the processor cores, which requires very low-level debugging, at signal/bus level, with a logic analyzer, for instance.

2.2.2 Reliability: Embedded systems often reside in machines that are expected to run continuously for years without errors and in some cases recover by them if an error occurs. Therefore the software is usually developed and tested more

DEPT: ECE, S.B.I.T, KMM

106

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

carefully than that for personal computers, and unreliable mechanical moving parts such as disk drives, switches or buttons are avoided. Specific reliability issues may include: The system cannot safely be shut down for repair, or it is too inaccessible to repair. Examples include space systems, undersea cables, navigational beacons, bore-hole systems, and automobiles.
The system must be kept running for safety reasons. "Limp modes" are

less tolerable. Often backup is selected by an operator. Examples include aircraft navigation, reactor control systems, safety-critical chemical factory controls, train signals, engines on single-engine aircraft. The system will lose large amounts of money when shut down: Telephone switches, factory controls, bridge and elevator controls, funds transfer and market making, automated sales and service. A variety of techniques are used, sometimes in combination, to recover from errorsboth software bugs such as memory leaks, and also soft errors in the hardware: Watchdog timer that resets the computer unless the software periodically notifies the watchdog Subsystems with redundant spares that can be switched over to software "limp modes" that provide partial function Designing with a Trusted Computing Base (TCB) architecture[6] ensures a highly secure & reliable system environment An Embedded Hypervisor is able to provide secure encapsulation for any subsystem component, so that a compromised software component cannot interfere with other subsystems, or privilegedlevel system software. This encapsulation keeps faults from propagating from one subsystem to another, improving reliability.
DEPT: ECE, S.B.I.T, KMM 107

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

This may also allow a subsystem to be automatically shut down and restarted on fault detection. Immunity Aware Programming

2.3 Explanation of Embedded Systems:


2.3.1 Software Architecture: There are several different types of software architecture in common use. Simple Control Loop: In this design, the software simply has a loop. The loop calls subroutines, each of which manages a part of the hardware or software. Interrupt Controlled System: Some embedded systems are predominantly interrupting controlled. This means that tasks performed by the system are triggered by different kinds of events. An interrupt could be generated for example by a timer in a predefined frequency, or by a serial port controller receiving a byte. These kinds of systems are used if event handlers need low latency and the event handlers are short and simple. Usually these kinds of systems run a simple task in a main loop also, but this task is not very sensitive to unexpected delays. Sometimes the interrupt handler will add longer tasks to a queue structure. Later, after the interrupt handler has finished, these tasks are executed by the main loop. This method brings the system close to a multitasking kernel with discrete processes.

Cooperative Multitasking:
DEPT: ECE, S.B.I.T, KMM 108

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

A non-preemptive multitasking system is very similar to the simple control loop scheme, except that the loop is hidden in an API. The programmer defines a series of tasks, and each task gets its own environment to run in. When a task is idle, it calls an idle routine, usually called pause, wait, yield, nop (stands for no operation), etc.The advantages and disadvantages are very similar to the control loop, except that adding new software is easier, by simply writing a new task, or adding to the queue-interpreter. Primitive Multitasking: In this type of system, a low-level piece of code switches between tasks or threads based on a timer (connected to an interrupt). This is the level at which the system is generally considered to have an "operating system" kernel. Depending on how much functionality is required, it introduces more or less of the complexities of managing multiple tasks running conceptually in parallel. As any code can potentially damage the data of another task (except in larger systems using an MMU) programs must be carefully designed and tested, and access to shared data must be controlled by some synchronization strategy, such as message queues, semaphores or a non-blocking synchronization scheme. Because of these complexities, it is common for organizations to buy a real-time operating system, allowing the application programmers to concentrate on device functionality rather than operating system services, at least for large systems; smaller systems often cannot afford the overhead associated with a generic real time system, due to limitations regarding memory size, performance, and/or battery life.

Microkernels And Exokernels


DEPT: ECE, S.B.I.T, KMM 109

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

A microkernel is a logical step up from a real-time OS. The usual arrangement is that the operating system kernel allocates memory and switches the CPU to different threads of execution. User mode processes implement major functions such as file systems, network interfaces, etc. In general, microkernels succeed when the task switching and intertask communication is fast, and fail when they are slow. Exokernels communicate efficiently by normal subroutine calls. The hardware and all the software in the system are available to, and extensible by application programmers. into three categories: 2.3.2 Stand Alone Embedded System: These systems takes the input in the form of electrical signals from transducers or commands from human beings such as pressing of a button etc.., process them and produces desired output. This entire process of taking input, processing it and giving output is done in standalone mode. Such embedded systems comes under stand alone embedded systems Eg: microwave oven, air conditioner etc... 2.3.3 Real-time embedded systems: Embedded systems which are used to perform a specific task or operation in a specific time period those systems are called as real-time embedded systems. There are two types of real-time embedded systems. Hard Real-time embedded systems: These embedded systems follow an absolute dead line time period i.e.., if the tasking is not done in a particular time period then there is a cause of damage to the entire equipment. Eg: consider a system in which we have to open a valve within 30 milliseconds. If this valve is not opened in 30 ms this may cause damage to
DEPT: ECE, S.B.I.T, KMM 110

Based on

performance, functionality, requirement the embedded systems are divided

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

the entire equipment. So in such cases we use embedded systems for doing automatic operations. Soft Real Time embedded systems: Eg: Consider a TV remote control system, if the remote control takes a few milliseconds delay it will not cause damage either to the TV or to the remote control. These systems which will not cause damage when they are not operated at considerable time period those systems comes under soft realtime embedded systems. 2.3.4 Network communication embedded systems: A wide range network interfacing communication is provided by using embedded systems. Eg: Consider a web camera that is connected to the computer with internet can be used to spread communication like sending pictures, images, videos etc.., to another computer with internet connection throughout anywhere in the world. Consider a web camera that is connected at the door lock. Whenever a person comes near the door, it captures the image of a person and sends to the desktop of your computer which is connected to internet. This gives an alerting message with image on to the desktop of your computer, and then you can open the door lock just by clicking the mouse. Fig: 2.2 show the network communications in embedded systems.

DEPT: ECE, S.B.I.T, KMM

111

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

Fig 2.2: Network communication embedded systems

2.3.5 Different types of processing units: The central processing unit (c.p.u) can be any one of the following microprocessor, microcontroller, digital signal processing.
Among these Microcontroller is of low cost processor and one of the

main advantage of microcontrollers is, the components such as memory, serial communication interfaces, analog to digital converters etc.., all these are built on a single chip. The numbers of external components that are connected to it are very less according to the application. Microprocessors are more powerful than microcontrollers. They are used in major applications with a number of tasking requirements. But the microprocessor requires many external components like memory, serial communication, hard disk, input output ports etc.., so the power consumption is also very high when compared to microcontrollers. Digital signal processing is used mainly for the applications that particularly involved with processing of signals
DEPT: ECE, S.B.I.T, KMM 112

THE ADVANCED DIGITAL ENERGY METER WITH REJUVENATE AND ALERT SYSTEM

DEPT: ECE, S.B.I.T, KMM

113

Anda mungkin juga menyukai