You are on page 1of 75

Introduction

1. Introduction:
Multi-parameter measurement and control system using PIC microcontroller is an interesting proposition. This project aids in the measurement and control of various Global Parameters and a serial interface to the PC. The features of the system are: 1. It allows us to view all the parameter readings simultaneously on the screen. The Graph drawn on the screen keeps on tracking the changes on the parameter. 2. 3. 4. It allows us to maintain a data-base of the The control application may vary among simple It allows us to control the parameters using relay changes encountered in the parameter. on/off operation. circuitry when they exceed their specified limits. The main building block of this project is the PIC microcontroller. For the microcontroller to communicate with the PC we use a RS232 cable which is ideal for serial communication. We use relays which are basically electro-magnetic switches to switch the load on/off whenever a control signal is passed by the microcontroller. We are using MICROSOFT VISUAL BASIC as a front end and C program as a back end for this project.

1.1 Block Diagram:

CPU

Serial Port

RS232 Interface

Voice Output

Microcontroller Board

Signal Conditioning Board

AC Voltage AC Current DC Voltage

Relay Drivers

DC Current Temperature

Relays for Control Outputs

Water Level Light Intensity Figure 1

Power Supply

2. Power Supply: 2.1Single Power Supply:


L 1 D 1 1 V M I N GND 7 8 V 0 O 5 2 / T U T R 2 + 4 C B 3 R I D G E 1 R 3 1 C 2 C 3 L E D 2 O

1 2 3 0 4 V

15 A C 8

Figure 2

Specifications: D1, D2, D3, D4: IN4007 diodes Rectifier: LM7805 C1: 2200F/10V C2: 104 C3: 10F/10V R1, R2: 330/W Any invention of latest technology cannot be activated without the source of power. So in this fast moving world we deliberately need a proper power source which will be apt for a particular requirement. All the electronic components starting from diode to Intel ICs only work with a DC supply ranging from 5v to 12. We are utilizing for the same, the cheapest and commonly available energy source of 230v-50Hz and stepping down, rectifying, filtering and regulating the voltage.
5

2.1.1 Transformer:
A bridge rectifier coupled with a step down transformer is used for our design. The voltage rating of transformer used is 0-12V and the current rating is 500mA. When AC voltage of 230V is applied across the primary winding an output AC voltage of 12V is obtained. One alteration of input causes the top of the transformer to be positive and the bottom negative. The next alteration will temporarily cause the reverse.

2.1.2 Rectifier:
In the power supply unit, rectification is normally achieved using a solid state diode. Diode has the property that will let the electron flow easily in one direction at proper biasing condition. A commonly used circuit for supplying large amounts of DC power is the bridge rectifier. A bridge rectifier of four diodes (4*IN4007) are used to achieve full wave rectification. Two diodes will conduct during the negative cycle and the other two will conduct during the positive half cycle. The DC voltage appearing across the output terminals of the bridge rectifier will be somewhat less than 90% of the applied rms value. Normally one alteration of the input voltage will reverse the polarities. Opposite ends of the transformer will therefore always be 180 deg out of phase with each other. For a positive cycle, two diodes are connected to the positive voltage at the top winding and only one diode conducts. At the same time one of the other two diodes conducts for the negative voltage that is applied from the bottom winding due to the forward bias for that diode. In this circuit due to positive half cycleD1 & D2 will conduct to give 10.8v pulsating DC. The DC
6

output has a ripple frequency of 100Hz. Since each altercation produces a resulting output pulse, frequency = 2*50 Hz. The output obtained is not a pure DC and therefore filtration has to be done.

2.1.3 Filtering Unit:


Filter circuit which is usually a capacitor acts as a surge arrester always follows the rectifier unit. This capacitor is also called as a decoupling capacitor or a bypassing capacitor, is used not only to short the ripple with frequency of 120Hz to ground but also to leave the frequency of the DC to appear at the output. A load resistor R1 is connected so that a reference to the ground is maintained. C1R1 is for bypassing ripples. C2R2 is used as a low pass filter, i.e. it passes only low frequency signals and bypasses high frequency signals.

2.1.4 Regulators:
The voltage regulators play an important role in any power supply unit. The primary purpose of a regulator is to aid the rectifier and filter circuit in providing a constant DC voltage to the device. Power supplies without regulators have an inherent problem of changing DC voltage values due to variations in the load or due to fluctuations in the AC line voltage. With a regulator connected to the DC output, the voltage can be maintained within a close tolerant region of the desired output. IC 7805 regulator is used in this project for providing a DC voltage of +5V.

2.1.5 Specifications:
Resistors R1 and R2 maintain line load regulation. At the secondary side of the transformer, Applied voltage = 12V Conducting drop across the diodes = 2*0.6 = 1.2V Without capacitor: V avg = (12-1.2) V = 10.8V pulsating DC Frequency = 100Hz With capacitor: V=V avg *1.414(form factor) = 15.51V Frequency = o Hz With 7805 voltage regulator: V0= +05V

2.2 Dual Power Supply:


L M
1 C D 1 2 3 0 230V AC V 4 T 15 D 8 C D 2 3 2 GND 2 1 C 4 C 6 R 2 R 4 3 D 6 4 2 1 I N GND

7 8 1 2
O U 3 T R C 3 C 5 D 5 1 R 3

A C

I N

L M
Figure 3

7 9 1 2

Specifications: D1, D2, D3, D4: IN4007 diodes Rectifier: LM7812, LM7912 C1, C2: 2200F/25V C3, C4: 10F/25V C5, C6: 104F

2.2.1 Transformer:
A full wave rectifier coupled with a center-tapped transformer is used for our design. When AC is applied to the primary winding of the power transformer it can either be stepped down or up depending on the value of DC needed. In our circuit the transformer of 230v/15-0-15v is used to perform the step down operation where a 230V AC appears as 15V AC across the secondary winding. One alteration of input causes the top of the transformer

to be positive and the bottom negative. The next alteration will temporarily cause the reverse. The current rating of the transformer used in our project is 2A. Apart from stepping down AC voltages, it gives isolation between the power source and power supply circuitries.

2.2.2 Rectifier:
Here, we use bridge rectifier with four diodes (4*In4007). The current ratings of the diode should be twice the maximum load current that will be drawn.

2.2.3 Filter Capacitor:


The purpose of filter capacitor is to smooth out the ripple in the rectified AC voltage. The residual amount of ripple is determined by the value of filter capacitor: the larger the smaller the ripple. 2200F is the suitable value for all the voltages generated using this kit. The other consideration in choosing the correct capacitor is its voltage rating. The working voltage of capacitor has to be greater than peak output voltage of rectifier.

2.2.4 Regulators:
With a regulator connected to the DC output, the voltage can be maintained within a close tolerant region of the desired output. IC7812 and 7912 is used in this project for providing +12v and 12v DC supply.

10

2.2.5 Specifications:
Resistors R1 and R2 maintain line load regulation. At the secondary side of the transformer, Applied voltage = 15v Conducting drop across the diodes = 2*0.6 = 1.2v Without capacitor: Vavg = (15-1.2) v = 13.8c pulsating DC Frequency = 100Hz With capacitor: V=Vavg *1.414(fiormfactor) = 19.51v Frequency = oHz With 7812 voltage regulator: V0= +12v With 7912 voltage regulator: V0= -12v

11

Microcontrolle r

12

3. Microcontroller:
The microcontroller is a complete microprocessor system built on a single integrated circuit. Microcontrollers were developed with the purpose to build a complete microprocessor system that substantially reduces the cost of building simple products. Microcontrollers are named as they perform control functions. The microcontroller is very commonly used in variety of intelligent products. For example, most personal computer keyboards are implemented with the microcontroller. It replaces scanning, matrix decoding and serial transmission circuits. Many low-cost products such as toys, microwave ovens, VCRs, and industrial products are based on microcontroller. From microwaves to automatic braking system, they are around us making our lives more comfortable and safer. Unlike our desktop computer, microcontrollers interact with other machines rather than humans. A microcontroller may be used to measure the temperature of our toast at breakfast and when the temperature reaches a pre-determined value, the toaster could be turned off. Embedded systems have become a part of our life. Using this small device we have developed a microcontroller based system development kit. We can program the EPROM according to the application needed. Once it is programmed it can be used as a dedicated system for that application. The user cannot access the program memory
13

once the code has been written in the ROM. We can attach other accessories through the I/O slots provided in the kit. The programs for testing the design and performance of the kit also have been included.

3.1 Features of PIC16F877:


The core Features and Peripherals are discussed below.

3.1.1 Core Features:


High performance RISC CPU Only 35 single word instructions to learn All single cycle instructions except for program branches which are two cycle Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data Memory (RAM) Interrupt capability (up to 14 sources) Direct, indirect and relative addressing modes Power-on Reset (POR) Power-up Timer (PWRT) and Oscillator Start-up Timer (OST) Processor read/write access to program memory Wide operating voltage range: 2.0V to 5.5V Low-power consumption: - < 0.6 mA typical @ 3V, 4 MHz - < 1 A typical standby current

3.1.2 Peripheral Features:


Timer0: 8-bit timer/counter with 8-bit prescaler

14

Timer1: 16-bit timer/counter with prescaler, can be incremented during SLEEP Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler 10-bit multi-channel Analog-to-Digital converter Synchronous Serial Port (SSP) with SPI (Master mode) and IC (Master/Slave) Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin only)

3.2 Device Overview:


This document contains device specific information. The PIC16F877/874 devices come in 40-pin packages. The PIC16F877 Block diagram is:

15

Figure 4

16

3.3 Memory Organization:


There are three memory blocks in each of the PIC16F87X MCUs. The Program Memory and Data Memory have separate buses so that concurrent access can occur and is detailed in this section.

3.3.1 Program Memory Organization:


The PIC16F87X devices have a 13-bit program counter capable of addressing an 8K x 14 program memory space. The PIC16F877/876 devices have 8K x 14 words of FLASH program memory. Accessing a location above the physically implemented address will cause a wraparound. The RESET vector is at 0000h and the interrupt vector is at 0004h.

Figure 5 17

3.3.2 Data Memory Organization:


The data memory is partitioned into multiple banks which contain the General Purpose Registers and the Special Function Registers. Bits RP1 (STATUS<6>) and RP0 (STATUS<5>) are the bank select bits. Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved for the Special Function Registers. Above the Special Function Registers are General Purpose Registers, implemented as static RAM. All implemented banks contain Special Function Registers. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.
RP1:RP0 00 01 10 11 Bank 0 1 2 3

Table 1

3.3.3 Special Function Registers:


The Special Function Registers are registers used by the CPU and peripheral modules for controlling the desired operation of the device. These registers are implemented as static RAM.

3.4 I/O Ports:


Some pins for these I/O ports are multiplexed with an alternate function for the Peripheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin.

18

3.4.1 PORTA and the TRISA Register:


PORTA is a 6-bit wide, bi-directional port. The corresponding data direction register is TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin). Reading the PORTA register reads the status of the pins, where as writing to it will write to the port latch. All write operations are read-modify-write operations. Therefore, a write to a port implies that the port pins are read; the value is modified and then written to the port data latch. Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI pin. All other PORTA pins have TTL input levels and full CMOS output drivers. Other PORTA pins are multiplexed with analog inputs and analog VREF input. The operation of each pin is selected by clearing/setting the control bits in the ADCON1 register (A/D Control Register1).

3.4.2 PORTB and the TRISB Register


PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISB bit (= 0) will make the corresponding PORTB pin an output (i.e., put the contents of the output latch on the selected pin). Three pins of PORTB are multiplexed with the Low Voltage Programming function: RB3/PGM, RB6/PGC and RB7/PGD. PORTB pins have a weak internal pull-up.

19

A single control bit can turn on all the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak pull-up is automatically turned off when the port pin is configured as an output. The pull-ups are disabled on a Power-on Reset. This interrupt can wake the device from SLEEP. The user, in the Interrupt Service Routine, can clear the interrupt in the following manner: a) any read or write of PORTB. This will end the mismatch condition. b) Clear flag bit RBIF.A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end the mismatch condition and allow flag bit RBIF to be cleared. The interrupt-on-change feature is recommended for wake-up on key depression operation and operations where PORTB is only used for the interrupt-on-change feature. Polling of PORTB is not recommended while using the interrupt-on-change feature. This interrupt-on-mismatch feature, together with software configurable pull-ups on these four pins, allow easy interface to a keypad and make it possible for wake-up on key depression. Refer to the Embedded Control Handbook, Implementing Wake-up on Key Strokes (AN552). RB0/INT is an external interrupt input pin and is configured using the INTEDG bit (OPTION_REG<6>).

3.4.3 PORTC and the TRISC Register:


PORTC is an 8-bit wide, bi-directional port. The corresponding data direction register is TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISC bit (= 0) will make the corresponding PORTC pin an output (i.e., put the contents of the output latch on the selected pin). PORTC is multiplexed with several peripheral functions.

20

When enabling peripheral functions, care should be taken in defining TRIS bits for each PORTC pin. Some peripherals override the TRIS bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit override is in effect while the peripheral is enabled, read-modify write instructions (BSF, BCF, and XORWF) with TRISC as destination, should be avoided. The user should refer to the corresponding peripheral section for the correct TRIS bit settings.

3.4.4 PORTD and TRISD Registers:


PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. PORTD can be configured as an 8-bit wide microprocessor port (parallel slave port) by setting control bit PSPMODE (TRISE<4>). In this mode, the input buffers are TTL.

3.4.5 PORTE and TRISE Register:


PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6, and RE2/CS/AN7) which are individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers. The PORTE pins become the I/O control inputs for the microprocessor port when bit PSPMODE (TRISE<4>) is set. In this mode, the user must make certain that the TRISE<2:0> bits are set, and that the pins are configured as digital inputs. Also ensure that ADCON1 is configured for digital I/O. In this mode, the input buffers are TTL.

21

3.5 Addressable Universal Synchronous Asynchronous Receiver Transmitter (USART):


The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the two serial I/O modules. (USART is also known as a Serial Communications Interface or SCI.) The USART can be configured as a full duplex asynchronous system that can communicate with peripheral devices such as CRT terminals and personal computers, or it can be configured as a half duplex synchronous system that can communicate with peripheral devices such as A/D or D/A integrated circuits, serial EEPROMs etc. The USART can be configured in the following modes: Asynchronous (full duplex) Synchronous - Master (half duplex) Synchronous - Slave (half duplex) Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous Receiver Transmitter. The USART module also has a multi-processor communication capability using 9-bit address detection.

3.6 Analog-to-Digital Converter (A/D) Module:


The Analog-to-Digital (A/D) Converter module has eight inputs for PIC16F877. The A/D conversion of the analog input signal results in a corresponding 10-bit digital number. The A/D converter has a unique feature of being able to operate while the device is in SLEEP mode. To

22

operate in SLEEP, the A/D clock must be derived from the A/Ds internal RC oscillator. The A/D module has four registers. These registers are: A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) A/D Control Register0 (ADCON0) A/D Control Register1 (ADCON1) The ADCON0 register, shown in Register 11-1, controls the operation of the A/D module. The ADCON1 register, shown in Register 112, configures the functions of the port pins. The port pins can be configured as analog inputs (RA3 can also be the voltage reference), or as digital I/O. Additional information on using the A/D module can be found in the PICmicro Mid-Range MCU Family Reference Manual (DS33023). ADCON0 Register (Address: 1Fh)
R/W-0 R/W-0 ADSC1 ADSC0 bit7 R/W-0 CHS2 R/W-0 CHS1 R/W-0 CHS0 R/W-0 GO/De U-0 R/W-0 ADON bit0

Table 2

bit 7-6 ADCS1:ADCS0: A/D Conversion Clock Select bits 00 = FOSC/2 01 = FOSC/8 10 = FOSC/32 11 = FRC (clock derived from the internal A/D module RC oscillator) bit 5-3 CHS2:CHS0: Analog Channel Select bits 000 = channel 0, (RA0/AN0) 001 = channel 1, (RA1/AN1) 010 = channel 2, (RA2/AN2) 011 = channel 3, (RA3/AN3) 100 = channel 4, (RA5/AN4)

23

101 = channel 5, (RE0/AN5) (1) 110 = channel 6, (RE1/AN6) (1) 111 = channel 7, (RE2/AN7) (1) bit 2 GO/DONE: A/D Conversion Status bit If ADON = 1: 1 = A/D conversion in progress (setting this bit starts the A/D conversion) 0 = A/D conversion not in progress (this bit is automatically cleared by hardware when the A/D conversion is complete) bit 1 Unimplemented: Read as '0' bit 0 ADON: A/D On bit 1 = A/D converter module is operating 0 = A/D converter module is shut-off and consumes no operating current ADCON1 Register (Address 9Fh)
U-0 ADFM bit7 U-0 R/W-0 U-0 R/W-0 PCFG3 Table 3 R/W-0 PCFG2 R/W-0 PCFG1 R/W-0 PCFG0 bit0

bit 7 ADFM: A/D Result Format Select bit 1 = Right justified. 6 Most Significant bits of ADRESH are read as 0. 0 = Left justified. 6 Least Significant bits of ADRESL are read as 0. bit 6-4 Unimplemented: Read as '0' bit 3-0 PCFG3:PCFG0: A/D Port Configuration Control bits

24

3.7 Instruction Set Summary:


Each PIC16F87X instruction is a 14-bit word, divided into an OPCODE which specifies the instruction type and one or more operands which further specify the operation of the instruction. The PIC16F87X instruction set summary in byte-oriented, bit-oriented, and literal and control operations. For byte-oriented instructions, f represents a file register designator and d represents a destination designator. The file register designator specifies which file register is to be used by the instruction. The destination designator specifies where the result of the operation is to be placed. If d is zero, the result is placed in the W register. If d is one, the result is placed in the file register specified in the instruction. For bit-oriented instructions, b represents a bit field designator which selects the number of the bit affected by the operation, while f represents the address of the file in which the bit is located. For literal and control operations, k represents an eight or eleven bit constant or literal value. All instructions are executed within one single instruction cycle, unless a conditional test is true or the program counter is changed as a result of an instruction. In this case, the execution takes two instruction cycles with the second cycle executed as a NOP. One instruction cycle consists of four oscillator periods. Thus, for an oscillator frequency of 4 MHz, the normal instruction execution time is 1 s. If a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 s.

25

Byte-oriented Register Operations

Bit-Oriented Register Operations

Literal and Control Operations

Table 4

26

3.8 Pin Description:

Figure 6

The Description of the circuit is given below.

3.8.1 Analog inputs:


Pin no 2 to 10 can be used to connect any analog signals of range 0-5v.

3.8.2 Digital signals:


As mentioned in the circuit the pin outs from the port is taken to a 26 pin FRC connector through which we can connect our Digital level signals 0 or 5 volts.

27

3.8.3 Clock:
The PIC16F877 can be operated in Four Different oscillator modes. The user can program two configuration bits FOSC1 and FOSC0 to select one of these four modes. *LP Low Power crystal *XT crystal / resonator *HS High speed crystal/resonator *RC Resistor capacitor The clock we have used is 10 MHZ which fall under HS category.

3.8.4 MCLR/VPP:
This is master clear input pin to the IC. A logic low signal will generate a reset signal to the microcontroller. So we have tied this pin to VCC for the proper operation of the microcontroller.

3.8.5 TXD and RXD:


TO communicate with the outside world the microcontroller has an inbuilt USART. The O/P and I/P line from the USART is taken and given to a MAX232 IC for having communication with the PC. Since we have used comport for interfacing the microcontroller.

3.8.6 VCC and Ground:


Pin no 32, 11 are tied to VCC and pin no 31, 12 are grounded to provide power supply to the chip.

28

Hardware Description

29

4. Hardware Description: 4.1 RS232:


The most common communication interface for short distance is RS-232. RS-232 defines a serial communication for one device to one computer communication port, with speeds up to 19,200 baud. Typically 7 or 8 bits (on/off) signal are transmitted to represent a character or digit. The 9 pin connector is used. The pin details are given below. RS-232 9- PIN CONNECTOR
TXD- TxD+ COM +5V COM

+12V CTS RxDRxD+

Figure 7

4.2 MAX 232:


The Max 232 is a dual RS-232 receiver / transmitter that meets all EIA RS232C specifications while using only a +5V power supply. It has 2 onboard charge pump voltage converters which generate +10V and 10V power supplies from a single 5V power supply. It has four level translators, two of which are RS232 transmitters that convert TTL\ CMOS input levels into + 9V RS232 outputs. The other two level translators are RS232 receivers that convert RS232 inputs to 5V TTL\CMOS output level.
30

These receivers have a nominal threshold of 1.3V, a typical hysterisis of 0.5V and can operate up to + 30V input. 1. Suitable for all RS232 communications. 2. +12V power supplies required. 3. Voltage quadruples for input voltage up to 5.5V (used in power supply Section of computers, peripherals, and modems). Three main sections of MAX232 are 1. A dual transmitter 2. A dual receiver 3. +5V to + 10V dual charge pump voltage converter.

4.2.1 Power supply section:


The MAX232 power supply section has 2 charge pumps the first uses external capacitors C1 to double the +5V input to +10V with input impedance of approximately 200 . The second charge pump uses external capacitor to invert +10V to 10V with an overall output impedance of 45 . The best circuit uses 22 F capacitors for C1 and C4 but the value is not critical. Normally these capacitors are low cost aluminum electrolyte capacitors or tantalum if size is critical. Increasing the value of C1 and C2 to 47 F will lower the output impedance of +5V to+10V doubles by about 5 and +10V to -10V inverter by about 10 . Increasing the value of C3 and C4 lowers the ripple on the power supplies thereby lowering the 16 KHz ripple on the RS232 output. The value of C1 and C4 can be lowered to 1 F in systems where size is critical at the expense of an

31

additional 20 impedance +10V output and 40 additional impedance at 10V input.

4.2.2 Transmitter section:


Each of the two transmitters is a CMOS inverter powered by + 10V internally generated supply. The input is TTL and CMOS compatible with a logic threshold of about 26% of Vcc. The input if an unused transmitter section can be left unconnected: an internal 400K pull up resistor connected between the transistor input and Vcc will pull the input high forming the unused transistor output low. The open circuit output voltage swing is guaranteed to meet the RS232 specification 5v output swing under the worst of both transmitters driving the 3K Minimum load impedance, the Vcc input at 4.5V and maximum allowable ambient temperature typical voltage with 5K and Vcc= +.9 v The slow rate at output is limited to less than 30V/ s and the powered done output impedance will be a minimum of 300 with +2V applied to the output with Vcc =0V.The outputs are short circuit protected and can be short circuited to ground indefinitely.

4.2.3 Receiver section:


The two receivers fully conform to RS232 specifications. Theyre input impedance is between 3K either with or without 5V power applied and their switching threshold is within the +3V of RS232 specification. To ensure compatibility with either RS232 IIP or TTL\CMOS input. The MAX232 receivers have VIL of 0.8V and VIH of 2.4V the receivers have 0.5V of hysterisis to improve noise rejection.

32

The TTL\CMOS compatible output of receiver will be low whenever the RS232 input is greater than 2.4V. The receiver output will be high when input is floating or driven between +0.8V and 30V.

4.2.4 Electrical characteristics of MAX232:


Vcc = 6v V+ = 12v V- = 12v Input voltage : T1in,T2in : -0.3 to (Vcc+ 0.3v) R1in,R2in : +30v or 30v Output voltage: T1out, T2out : ((V+)+0.3v) to ((V-)+0.3v) R1out, R2out : -0.3V to (Vcc+0.3V) Power dissipation : 375mW Output resistance :300

4.2.5 Pin Diagram:

C1+ V+ C1C2+ C2-

1 2 3 4 5 6 7 8
33

16

Vcc GND T1 out R1 in R1 out

M AM XA
X 2 23 2

15 14 13 12 11 10 9

3 2

VT2 out

T1 in T2 in

R2 in
Figure 8

R2 out

4.3 Relay:
Relays are electromagnetic switches used as protective devices, indicating devices and as transmitting devices. Protective relay protect good component from the effects of the circuit components that have failed. Transmission relay are used in communication systems. Indicating relay may be used to identify a component which has failed. The relay is one of the most widely used components in industrial electronic. In combination with transistors, electron tubes and other circuit elements, this electromagnetic device performs countless tasks. Relays are electro magnetically operated remote controlled switches with one or more sets of contacts. When energized, the relay operates to open or close its contacts or to open some contacts and close others. Contacts which are opened when energized are called Normally Open (NO) or simply open contacts. Contacts which are closed when energized are called Normally Closed (NC) or simply open contacts. Normally open contacts are referred to as a contacts. Normally closed contacts are sometimes referred to as b contacts. There are certain terms associated with relays. The relay is said to pick up when it is energized and trips, and this pick up value is the smallest value of the fluctuating current required to close a contact or open b contact or closing b contact is said to reset or dropout.

34

Relay contact are held in their normal position by either springs or by some gravity-activated mechanism. An adjustment or adjustments are usually provided to set the restraining force to cause the relay to operate within predetermined conditions. Relay operates on one of the two different principles namely electromagnetic attraction or electromagnetic induction. Electromagnetic attraction type relays, which may either be AC or DC actuated, consists of an electromagnet having a core and winding.

4.3.1 Relay Driver:

Figure 9

The current needed to operate the relay coil is more then that can be supplied by most chips (op. amps etc), so a transistor is usually needed to drive the relay coil. A diode is used to short circuit the high voltage back emf induced when current flowing through the coil is suddenly switched off.

35

Here, we use PIC microcontroller that can not supply the required voltage to operate the relay coil. So we use a relay driver.

4.4 Precision Rectifier:


The CT and PT outputs are relatively very low when compared with the primary voltage and current. The outputs of the CTs and PT are sine wave in nature. We must rectify it properly without any loss and there should be provision for amplification. For the above mentioned problems we cannot use a DIODE based rectifiers due to following reasons: 1. Diode based rectifiers require a minimum of 1.4V for its operation. 2. Only 90% efficiency can be achieved . 3. Output can neither be tuned nor amplified. 4. Impedence matching cannot be achieved. To avoid the above problems we go for Op-Amp based full wave precision rectifiers. We use Op-Amp full wave Precision rectifier IC1458 for our application.

4.4.1 CIRCUIT OPERATION:

36

Figure 10

In the rectifier circuit, A1 is an inverting unity gain amplifier. The output from A1 is added to the original input signal in A2 (inverting summing mixed gain amplifier). In this circuit, the diode D2 is always in conducting mode and diode D1 is kept at virtual ground. E in feeds A2 through a 20Kohm resistor and A1 through a 10Kohm resistor. During positive half cycle, the output of an Op-Amp A1 is 5V because it is an inverting unity gain amplifier and hence the diode D2 is forward biased. Since it is a continuously conducting diode there is no potential drop in the diode. So we get 5V at the output E2. Since the OpAmp A2 is an inverting summing mixed gain amplifier the output voltage will be E3 = - (20/10)*(-5) + (10/10)*(-5) = +10 5 = +5V During negative half cycle of input voltage E in, there is no output from Op-Amp A1 due to rectification (i.e.) the output of the Op-Amp A1 is +5V and the output of the diode D1 is 5V. The voltage from A1 gets cancelled with the voltage from D1. So diode D2 remains open for the negative half cycle. The output from the Op-Amp A2 is +5V. Thus we get a constant pulsating DC for both the half cycles. This voltage is passed through a buffer amplifier with provision of filtering out the ripples. Thus at the output of the buffer circuit we get pure DC of 5V.

4.4.2 Filter Unit:


Filter circuit removes 100Hz signal generated by the precision rectifiers. Here we use powerful integrative filters to minimize charging and

37

discharging times. This provides instantaneous displaying of parameters and zeroing of parameters whenever inputs are switched off. A low pass filter is also used to prevent high frequency noises, which may be generated by motor centers.

Parameter Measurement

38

5. Parameter Measurement: 5.1 DC Voltage Measurement:


The range selected for DC voltage is 0-50v. This voltage is converted to 0-3V using signal conditioning circuit and then given to ADC on add on card. This voltage is usually meant as excitation voltage. The input voltage is reduced to our desired range in two stages. The input voltage is first reduced to a considerable amount using potential divider circuit of resistance 1M ohms and 1K ohms. This passes on to an op amp of gain 2; we require a gain of 60. This is achieved with the help of second stage op-amp whose adjustment ratio is 60. So it is possible to get a gain of 100. For maximum output voltage =50 = (50/1Meg+1K) x 1K = 50mV (Across potential divider CKt) After two stage amplification

39

Output Voltage = 50mv x 2 x 30 = 3V This 3V is given to the ADC of PIC Microcontroller

5.2 DC Current Measurement:


The range selected for DC current measurement is 0-50mA. This mA current signal is converted to 0-3V range. The input DC current is converted to voltage using a shunt resistor R. The voltage at shunt resistor is 500mV. This voltage is converted to 3V by two stage amplifier. The first op-amp is of unity gain. We require a gain of 6. This is achieved with the II stage with adjustment gain extended upto 25. Output voltage at maximum I/P current After two stage Amplification Output Voltage = 500mV x 1 x 6 = 3V This 3v is given to the ADC of PIC Microcontroller = 50mA x 10 = 500mV (Across Rs)

5.3 AC Voltage Measurement:


The range selected for AC voltage measurement is 0-250 V. Most of the electrical appliances work under this range. Maximum Input range of 250V is converted to Ac using isolation potential transformer. This 5V AC is converted to 5V DC by rectification process. Here bridge rectifier is not used. Since it consumes 1.4V rectification above it is only possible, so.

40

5.4 AC Current Measurement:


The range of measurement of Ac current is selected as 0-5A. I/P current 0-5A is converted to 0.5A using a current transformer. This 0.5A AC current is converted to 5v AC using a shunting resistor of 10 ohms and the operation is similar as that of Ac voltage measurement.

5.5 Light Intensity Measurement:


The range for measurement of light intensity is selected as 0-100 Cp. We use light detecting resistor for light intensity measurement in our project. Light detecting resistor is a resistor which is made of material that varies its resistance in accordance to incident light intensity. If the light intensity exceeds the prescribed limit the respective bulb is tripped off using the relay. The diagram for the light detecting circuit is given as below
1 2 V

R 1 3 3 0

h m

D D

1 I O D E Z E N L E D R R

o h m

Figure 11

5.6 Temperature Measurement:


The range for temperature measurement is selected as 0-100C. We use thermistor for temperature measurement in our project. Thermistor is
41

a resistor which is made of material that varies its resistance in accordance to temperature. If the device is heated to a temperature more than the prescribed limit, then the respective bulb is tripped off using the relay. The diagram for the temperature detecting circuit is given as below
5 V

2 K T H

o h m s E R M

I I S

T O

3 3 0

o h m

Figure 12

5.7 Water Level Measurement:

Figure 13

Four open wires will be provided at four different levels. One at ground and other three as indicated in the figure.

42

As the water level raises and reaches each level, conduction occurs through the water and indication will be there as shown above. As the water reaches the final level the given load is tripped off. The tripping of the load is obtained using the relay circuitry.

43

Software Description

6. Software Description:
PC sends data to PC in four formats. They are: 1. Initialization of ports [1 ff ff 80 00]. 2. Read the current port values from microcontroller [2]. 3. Write data to microcontroller [3 ff ff 80 00]. 4. ADC read command [4x]. The following flowchart gives the description about how the PIC microcontroller receives the input from the analog sources and gives the corresponding control functions and signals to the PC for the display of the parameters that have been measured. There are two parts in the program. They are: 1. 2. Interrupt Program Main Program

44

Interrupt Program
START

CHECK USART INT

No
RETURN

Yes

CHECK DATA FREE FROM ERROR Yes

No

RESET CONT.RECIEVE RETURN

IF SYNC_FLAG==0

Yes

IF RCREG=='['

No

RETURN

No
IF RCREG==']' Yes

Yes
FSR=0X30 SET FIRST BIT OF SYNC_FLAG

CLEAR FIRST BIT OF SYNC_FLAG SET FIRST BIT OF Rrdy FLAG

No
CHECK IF RCREG CONTAINS NUMBER OR ALPHABET

Alphabet

Number
RCREG=RCREG AND 0X0F RCEG=RCREG AND 0X0F RCREG=RCREG + 0X09

STORE RCREG TO THE POINTED LOCATION AND INCREMENT POINTER

RETFIE

START

45
INITIALIZE PORT REGISTERS,CONFIGURE ADC AND

Main Program
START

INITIALIZE PORT REGISTERS,CONFIGURE ADC AND USART.CLEAR USED MEMORY LOCATIONS

SEND COMM MESSAGE C No

IF Rrdy flag==1

YES
IF Rbufo ==1

YES

GET DATA FROM NEXT LOC,AND SAVE IT TO TRIS REGISTERS CLEAR Rrdy flag

No

IF Rbufo ==2

YES

READ PORT VALUES CONVERT TO ASCII SENDS IT TO PC. CLEAR Rrdy flag

NO YES
IF Rbufo ==3 GET DATA FROM NEXT LOC AND SAVE IT TO PORT REGISTERS. CLEAR Rrdy flag

NO YES
IF Rbufo ==4 SET ADC FOR CONVERSION.GET RESULTS AFTER CONVERSION TO ASCII. SEND IT TO PC.CLEAR Rrdy flag C

46

According to the measured data, the control signals are again sent to the PC wherever necessary. If the measured value exceeds the threshold value, the load may be switched off.

47

Advantages and Applications

48

7. Advantages and Applications: 7.1Advantages:


The main advantage of this project is, it allows us to view all the parameter readings simultaneously on the screen. The graph drawn on the screen keeps on tracking the changes on the parameter. Also these parameters can be monitored on a remote terminal by specifying the IP address. For this we should have an Internet connection available.

7.2 Application:
This Project can be implemented in any of the process industries where there is a need for simultaneous and fast acquiring of data and control. The devices like motor , heater may be introduced instead of the lamps and may be turned on or tripped off accordingly

49

Suggestions for Improvement

50

8. Suggestions for Improvement:


Like any other project ours is also something novel and is quite creed and primitive. Proper refining is essential to bring up the project to meet professional standards. The following suggestions are offered for this purpose: 1. For industrial purposes recorded voice may be used instead of buzzer, for indicating that supply is low and the process is to be terminated 2. Indication of pre-switching status must be provided for the user. 3. For household usage the circuit implementation must be made simpler and safer. 4. The relays must be made compatible with the devices like motor, heater etc 5. With the help of WAP and Internet the online graph may be viewed on mobile or remote terminal by specifying the IP address. So many suggestions can thus be offered and depending upon the feasibility all stack suggestions may be implemented and the system will one day available in the market commonly

51

Conclusion

52

9. Conclusion:
To conclude we would like to say that we benefited a lot from this project as we learnt the value of team work, co-operation, and coordination besides the concepts of embedded technology. Multi-parameter measurement and control system is necessary in many situations. Using this, you can measure and control various global parameters like current, voltage, light intensity, temperature, etc. these parameters can be measured simultaneously as well as the graphs of the changes in the parameter can be viewed online. You can turn ON or OFF the water pumping motor, heater, garden light, or any other electrical appliance at home which are represented by bulbs in our project kit. The system is particularly suitable for use at industries and homes. It is simple to operate and is user-friendly. In the present world science and technology are at their peak and man has started depending on the intellect of machines rather than on the intellect of human brain, it springs no surprise that we have come to stage when all the processes are being controlled by embedded systems. Controlling of the processes is mostly done using microcontroller, and thus man power required to handle these complicated processes is reduced, and thereby the risks to human in hostile environment. The future seems well inclined towards embedded technology

53

Appendices

54

Appendix-1: Source Code


#include <pic.h> #include "delay.c" short int Rrdy_Flag=0,Sync_Flag=0; int Rbuf[12]; int Ch; short int Ptr=0; char Rchar; char RetAscii(int c); static void interrupt Int(); void Send_Mess(); void main() { ADCON1 = 0x88; ADCON0 = 0x81; TRISA = 0xff; TRISB = 0xff; TRISC = 0xbf; TRISD = 0xff;

55

SPBRG = 64; TXEN = 1; // Enable transmit BRGH = 1; // ; Select high baud rate

SPEN = 1; //Enable Serial Port CREN = 1; // Enable continuous reception RCIF = 0; // Clear RCIF Interrupt Flag RCIE = 1; // Set RCIE Interrupt Enable

PEIE = 1; // Enable peripheral interrupts GIE = 1; // ; Enable global interrupts Send_Mess(); for(;;) {

if(Rrdy_Flag == 1) { Rrdy_Flag = 0; if(Rbuf[0] == 1) {


56

Rbuf[1] <<= 4; Rbuf[2] |= Rbuf[1]; Rbuf[2] &= 0x10; Rbuf[2] |= 0xef; TRISA = Rbuf[2]; Rbuf[3] <<= 4; Rbuf[4] |= Rbuf[3]; TRISB = Rbuf[4]; Rbuf[5] <<= 4; Rbuf[6] |= Rbuf[5]; Rbuf[6] &= 0xbf; Rbuf[6] |= 0x80; TRISC = Rbuf[6]; Rbuf[7] <<= 4; Rbuf[8] |= Rbuf[7]; TRISD = Rbuf[8]; } if(Rbuf[0] == 2) { while(!TXIF) continue; TXREG = '{'; DelayUs(25);
57

while(!TXIF) continue; Ch = PORTA >> 4; Ch &= 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = PORTA & 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25);

while(!TXIF) continue; Ch = PORTB >> 4; Ch &= 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = PORTB & 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25);
58

while(!TXIF) continue; Ch = PORTC >> 4; Ch &= 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = PORTC & 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = PORTD >> 4; Ch &= 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = PORTD & 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25);

59

while(!TXIF) continue; TXREG = '}'; DelayUs(25);

} if(Rbuf[0] == 3) { Rbuf[1] <<= 4; Rbuf[2] |= Rbuf[1]; PORTA = Rbuf[2]; Rbuf[3] <<= 4; Rbuf[4] |= Rbuf[3]; PORTB = Rbuf[4]; Rbuf[5] <<= 4; Rbuf[6] |= Rbuf[5]; PORTC = Rbuf[6]; Rbuf[7] <<= 4; Rbuf[8] |= Rbuf[7]; PORTD = Rbuf[8]; } if(Rbuf[0] == 4) {

60

Rbuf[1] <<= 3; Rbuf[1] |= 0x81; ADCON0 = Rbuf[1]; DelayUs(25); ADGO = 1; while(ADGO) continue;

while(!TXIF) continue; TXREG = '{'; DelayUs(25); while(!TXIF) continue; Ch = ADRESH >> 4; Ch &= 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = ADRESH & 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25);

61

while(!TXIF) continue; Ch = ADRESL>> 4; Ch &= 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; Ch = ADRESL & 0x0f; Rchar = RetAscii(Ch); TXREG = Rchar; DelayUs(25); while(!TXIF) continue; TXREG = '}'; DelayUs(25); } } } } void Send_Mess()
62

{ while(!TXIF) continue; TXREG = 'P'; DelayUs(25); while(!TXIF) continue; TXREG = 'i'; DelayUs(25); while(!TXIF) continue; TXREG = 'c'; DelayUs(25); while(!TXIF) continue; TXREG = '1'; DelayUs(25); while(!TXIF) continue; TXREG = '6'; DelayUs(25); while(!TXIF) continue; TXREG = 'F'; DelayUs(25); while(!TXIF) continue;
63

TXREG = '8'; DelayUs(25); while(!TXIF) continue; TXREG = '7'; DelayUs(25); while(!TXIF) continue; TXREG = '7'; DelayUs(25); }

static void interrupt Int() { if(RCIF) { RCIF = 0; if(Sync_Flag != 0) { if(RCREG == ']') { Rrdy_Flag = 1; Sync_Flag = 0;
64

} else { if(RCREG >= '0' && RCREG <= '9') { Rbuf[Ptr++] = (RCREG & 0x0f); } if((RCREG >= 'a' && RCREG <= 'f') || (RCREG >= 'A' && RCREG <= 'F')) { Rbuf[Ptr++] = ((RCREG & 0x0f)+0x09); } } } else { if(RCREG == '[') { Sync_Flag = 1; Ptr = 0; } } } }
65

char RetAscii(int c) { switch(c) { case 0: return('0'); break; case 1: return('1'); break; case 2: return('2'); break; case 3: return('3'); break; case 4: return('4'); break; case 5: return('5'); break; case 6: return('6'); break; case 7:
66

return('7'); break; case 8: return('8'); break; case 9: return('9'); break; case 0x0a: return('A'); break; case 0x0b: return('B'); break; case 0x0c: return('C'); break; case 0x0d: return('D'); break; case 0x0e: return('E'); break; case 0x0f: return('F'); break; }
67

Appendix-2: Data Sheets Data Sheet 1: PIC16F877 Pin Details

Table 5

68

Table 6

69

Data Sheet 2: Electrical Characteristics of PIC16F877

70

Data Sheet 3: DC and AC Characteristics of PIC16F877

Figure 14

71

Data Sheet 6: MAX232

Table 7

72

Table 8

73

Table 9

74

References:

BOOKS: JOHN B. PEATMAN : DESIGN WITH MICROCONTROLLERS, MCGRAW HILL, 1988. ROY CHOUDHURY, ET.AL LINEAR INTEGRATED CIRCUITS, NEW AGE INTERNATIONAL, 1998. MILLMAN AND HALKIAS ELECTRONIC DEVICES AND CIRCUITS, MCGRAW HILL. MAGAZINES: ELECTRONICS FOR YOU ELECTOR ELECTRONICS WEBSITES: WWW.MICROCHIP.COM WWW.ELECTRONICSFORYOU.COM WWW.HOWSTUFFWORKS.COM WWW.AMAZON.COM WWW.MIKROELEKTRONIKA.CO.YU

75

You might also like