Sunteți pe pagina 1din 45

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER-1 INTRODUCTION

1 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

INTRODUCTION
In this project an attempt has been made to observe consumption of Electrical energy by means of an energy meter and the data is sent to a computer. Energy meter is generally of the electro-dynamic type. An electronic type of energy meter is used. The calculation circuit is a PCB which calculates the power consumption of each appliance which is connected, explicitly. CALCULATION CIRCUIT would be installed at the back of switch boxes. Two transformers a voltage and a current transformer each samples current and voltage is used to deliver voltage and current to calculate energy consumed in KWH. The circuit can handle up to 20A current. The meter converts energy consumed to pulses of resolution 6.4 Imp/Wh. The pulses converted are then transmitted to modulator and communicated via a non-linear channel to the demodulator circuit. At demodulator circuit, connected to personal computer, signal is demodulated and using a microcontroller sent to personal computer via LPT. A VB6 program reads port and saves the received data to an .dat file. A power supply unit delivers the power required by the I Cs at demodulator circuit. Power supply unit consists of a transformer and 78XX series voltage regulators for regulated supply at +5V. Demodulation Circuit would be at back side of PC and DATA COLLECTION SOFTWARE in PC. Altogether the energy consumption at switches will be recorded on PC.

2 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER-2 BLOCK DIAGRAM

3 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

In this chapter the idea and conceptual block diagram will be demonstrated to provide clear understandings of the project.

2.1 CONCEPT
CALCULATION CIRCUIT is installed at the back side of switch boxes, and DATA COLLECTION SOFTWARE at PC. The calculation circuit is a PCB which will calculate the energy consumed by each appliance which is connected. The calculation circuit is in parallel with every switch and is to be assembled behind switch box.

Figure 2.1: Conceptual Diagram

4 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

2.2 BLOCK DIAGRAM


The transmission media to be used is selected as telephone cable because it is economical and has minimum loss. Demodulator is connected to PC with less than 3ft D25 connector cable. The Block diagram is shown in Figure 2.2.

Figure 2.2: Block Diagram

5 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

2.2.1 Calculation Circuit


Two transformers a voltage and a current transformer each samples current and voltage is used to deliver voltage and current to calculate energy consumed in KWh. The circuit can handle up to 20A current. The meter converts energy consumed to pulses of resolution 6.4 Imp/Wh. The pulses converted are then transmitted to modulator and communicated via a non-linear channel to the demodulator circuit.

2.2.2 Transmission Media


The transmission media to be used is selected as telephone cable because it is economical and has minimum loss over distance.

2.2.3 Demodulator Circuit


At demodulator circuit (connected to PC), first ASK is demodulated to get the same analog signal at the output of watt meter. Using 89C4051 the analog signal is converted and interfaced to parallel port of PC.

2.2.4 Computer
A simple PC is used with Windows Platform installed with Pratham v7.1, a VB6 program to control and receive data from parallel port of computer. Demodulator is connected to PC with less than 3ft D25 connector cable. Pratham v7.1, program reads port automatically and saves the received data to an .ini file.

2.2.5 Power Supply unit (PSU)


Power Supply Unit consists of a Transformer (15-0-15), 7815, 7805 and 7915 voltage regulators. It provides required power for the I Cs.

6 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER-3 WORKING

7 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

In this chapter the circuit diagrams will be explained for all of the constituent circuits. First is calculation circuit.

3.1 CALCULATION CIRCUIT


The circuit diagram of calculation circuit is shown in Figure 3.1.

Figure 3.1: Calculation Circuit A potential and a current transformer is used to sample current and a microcontroller based energy kit CD2299 is used to convert energy usage into pulses of resolution 6.4Im/Wh. An electro mechanical interface shows the traditional readings. An analog MUX converts pulses into ASK. The ASK is then transmitted to demodulator circuit that is remote to the calculation

8 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

circuit. An oscillator using LM353 creates sine wave at frequency 43.3 KHz. This sine wave is used as carrier for ASK message signal. Due to most of the transmission lines are non linear the ASK is best suited for non synchronous modulation. However the error in ASK generation and detection results in change of pulse width but the relevant change in pulse width does not affect the outcome. The frequency of pulse is too small, in order of few hertz hence, practically the outcome of project merely depends upon the number of pulses which on the later circuit will be counted after demodulation inside microcontroller programmed to perform interfacing with computer. Error in modulation scheme is hence avoided by using microcontroller based counter.

3.2 DEMODULATOR CIRCUIT


The circuit diagram of demodulation circuit is shown in Figure 3.2.

Figure 3.2: Demodulator Circuit

9 | P a g e N I L O T PA L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

The output of calculation circuit is provided to opto-coupler which provides electric isolation between circuits. The output of opto-coupler is fed to an comparator using uA741 which demodulates ASK. A microcontroller AT89C4051 is used to count pulses and convert the count to hexadecimal. The hexadecimal number represents the energy consumed in resolution of 10 Wh/unit. 74244 buffer is used to interface the output data of microcontroller to computers parallel port using D25 connector. The buffer provides reading of output nibble-wise. i.e. The hexadecimal output is read one nibble at a time by VB program. The program then joins the data and makes byte form nibbles.

3.3 POWER SUPPLY UNIT


The circuit diagram of Power Supply Unit is shown in Figure 5.

Figure 3.3: Power Supply Unit Circuit

10 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Power Supply Unit consists of a Transformer rated 15-0-15, three 78XX series voltage regulators and it provide required power for the circuitry. First a Bridge Rectifier converts AC into DC. The rectified output from bridge rectifier is then regulated and filtered using 78XX series voltage regulators. 7815 produces +15V, 7915 produces -15V and 7805 produces +5V. Altogether the constituents provide a stable and reliable power supply unit for I Cs. Transformer chosen is a 15-0-15, 1 Amp type. For input and output filtering capacitors are used so that the ripple in output can be reduced. All diodes are 1N4001/1N4007.

3.4 SOFTWARE
A simple PC is used with Windows Platf orm installed with Pratham v7.1, a VB6 program to control and receive data from parallel port of computer. Demodulator is connected to PC with less than 3ft D25 connector cable. Pratham, program reads port and saves the received data to a .dat file. Snapshot of the program is depicted in Figure 6.

Figure 3.4 : Main Window (Pratham v7.1)

11 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

The software can work in two modes one is automatic another is manual. The software itself is capable of logging data with date and time. It converts the data received to Watt-Hour and logs it in a file at application directory under name of data.dat. It reads output nibble by nibble and then by using a function joins nibbles to form a complete byte.

12 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER 4 Components and Their Configurations

13 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

4.1 OPERATIONAL AMPLIFIER


4.1.1 LM741 The LM741 series are general purpose operational amplifiers which feature improved performance over industry standards like the LM709. The amplifiers offer many features which make their application nearly fool proof, over load protection on the input and output, no latch up when the common mode range is exceeded as well as freedom from oscillations. The LM741 has their performance guaranteed over a zero degree Celsius to seventy degree Celsius temperature range, instead of minus fifty five degree Celsius to one hundred and twenty five degree Celsius. Pin Diagram:

Figure 4.1: uA741 Pin Detail LM741 is used as same as non inverting summer and for demodulation of PWM and ASK. 4.1.2 LF353 The LF353 is a JFET input operational amplifier with an internally compensated input offset voltage. The JFET input device provides with bandwidth, low input bias currents and offset currents.

14 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Pin Details:

Figure 4.2: LF353 Pin Detail LF353 is used in differential amplifier and sine wave oscillator used in ASK. It has a high slew rate for around 30V/us, that is why it is used in sine wave generation. The circuit diagram for sine wave generator is depicted below if Figure 15. Oscillation Circuit :

Figure 4.3: Oscillation Circuit Diagram We need Vout = +/5 V thus Vcc = +/- 5V. To limit the output we use diodes so that forward current is assumed to be 1mA.

15 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Design: Requirement, Vcc = +/- 15V, Vout = +/- 5V, f = 43.3 KHz Assume, R = 170E , C = 1 / ( 2 * pi * 2.44 * 43.3K) ...Equation 5

Therefore, chosen C = 0.1uF. For Vout = +/- 5V, Assume, Id = 1mA, R1 = 3V / (29 * 1mA) R3 = 2 * Vf / Id = 2 * 0.7V / 1mA, R3 = 1k4 ......Equation 6 ..Equation 7

Therefore, R4 = R2 R3 = 3k6. Diodes used are OA79.

4.2 VOLTAGE REGULATOR (78XX series)


The LM 7805 series of three positive regulators are available in the TO -220 package and with several fixed output voltages making them useful in a wide range of applications. Each type employs internal circuit limiting, thermal shut down and safe operating area protection, making it essentially in destructible. If adequate heat sinking is provided, they can deliver over one ampere output current. Although the design is primarily as fixed voltage regulator, this device can be used with external components to obtain adjustable voltages and currents. The LM7915 series of three terminal regulators is available with fixed output voltages of -5 volt, -8 volt, -12 volt and -15 volt. This device needs only one external component a compensation capacitor at the output. The LM7915 series is packed in the TO-220 power package and is capable of supplying 1.5 ampere of output current. This regulator employs internal current limiting safe area protection and thermal shut down for protection against virtually all over load conditions.

16 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Pin Diagram:

Figure 4.4: 78XX Voltage Regulators

4.3 BUFFERS (74LS244)


Three state outputs drive bus lines or buffer memory address resistors, PNP inputs reduce DC loading, hysteresis at inputs improves noise margin. This octal buffers and line drivers are designed specifically to improve both the performance and density of three state memory, address driver, clock drivers and bus oriented receivers and transmitters. The designer has a choice of selected combinations of inverting and non-inverting outputs, symmetrical G inputs, and complementary G and G^ inputs. These devices feature high fan out, improved fan in and 400mV noise margin. The pin detail of 74244 buffer is depicted in Figure 20.

17 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Schematic Diagram:

Figure 4.4: 74LS244 Pin Detail

4.4 TRANSFORMER
A transformer is a static or stationary device which transfers electrical power from one circuit to another without change of frequency. The principle of working of transformer is mutual induction between two circuits linked by a common magnetic flux. It consists of two separate coils placed on a laminated core. These coils are electrically separated and magnetically linked through a path of low reluctance. The two coils possesses high mutual inductance. If any one of the two coils called primary is connected to a source of alternating voltage, and alternating flux with the same frequency of as that of supply voltages will set up in the wave. Most of alternating flux will be linked with the other coil called secondary and have mutually induced EMF is produced in it. According to the faradays law of electromagnetic induction, if the secondary circuit is closed with a load, impedance then a current flows through it. Hence electrical power is transferred from primary to secondary without change of frequency. In an ideal transformer, the induced voltage in secondary

18 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

winding (Vs) is in proportion to the primary voltage (Vp), and is given by the ratio of the number of turns in the secondary (Ns) to the number of turns in the primary (Np) as follows:

Vs/Vp=Ns/Np

Figure 21 : Figure 4.5: Transformer Winding Based on voltage transformation ratio or turns ratio, a transformer may be Step-up transformer for which number of turns on secondary is greater than number of turns on primary and in Step-down transformer, the number of turns on secondary is less than that of primary.

19 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER 5 MICROCONTROLLER AND PROGRAMMING

20 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

5.1 MICROCONTROLLER (AT89C4051)


The AT89C4051 is a low-voltage, high-performance CMOS 8-bit microcontroller with 4K bytes of Flash programmable and erasable read-only memory. This device is made using Atmels high-density nonvolatile memory technology and is compatible with the industrystandard MCS-51 instruction set. By combining a versa-tile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C4051 is a powerful microcontroller which provides a highlyflexible and cost-effective solution to many embedded control applications. The AT89C4051 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 15 I/O lines, two 16-bit timer/counters, a five-vector, two-level interrupt architecture, a full duplex serial port, a precision analog comparator, on-chip oscillator and clock circuitry. In addition, the AT89C4051 is designed with static logic for operation down to zero frequency and supports two software-selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The powerdown mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset. RESTRICTION ON CERTAIN INSTRUCTIONS The AT89C4051 is an economical and cost-effective member of Atmels growing family of micro-controllers. It contains 4K bytes of Flash program memory. It is fully compatible with the MCS-51 architecture, and can be programmed using the MCS-51 instruction set. However, there are a few considerations one must keep in mind when utilizing certain instructions to program this device. All the instructions related to jumping or branching should be restricted such that the destination address falls within the physical program memory space of the device, which is 4K for the AT89C4051. This should be the responsibility of the software programmer. For example, LJMP 0FE0H would be a valid instruction for the AT89C4051 (with 4K of memory), whereas LJMP 1000H would not . LCALL, LJMP, ACALL, AJMP, SJMP, JMP @A+DPTR. These unconditional branching instructions will execute correctly as long as the program keeps the destination branching address within the physical boundaries of the program memory size (locations 00H to FFFH for the 89C4051). Violating the physical space limits may cause unknown program behavior.

21 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CJNE, DJNZ, JB, JNB, JC, JNC, JBC, JZ, JNZ. With these conditional branching instructions the same rule above applies. Again, violating the memory boundaries may cause erratic execution. For applications involving interrupts, the normal interrupt service routine address locations of the 80C51 family architecture have been preserved. POWER-DOWN MODE In the power-down mode the oscillator is stopped and the instruction that invokes powerdown is the last instruction executed. The on-chip RAM and Special Function Registers retain their values until the power-down mode is terminated. The only exit from power-down is a hardware reset. Reset redefines the SFRs but does not change the on-chip RAM. The reset should not be activated before VCC is restored to its normal operating level and must be held active long enough to allow the oscillator to restart and stabilize. Pin Diagram:

Figure 5.1: AT89C4051Pin Detail

22 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

5.2 PROGRAM
The program for microcontroller is written in C. The reg51.h header file is included for embedded C for Atmel series microcontroller operations. At P3.4 the pulses are detected and counter is initialized to count up to 64. Then at 65th pulse P1 is incremented. AT80C4051 is 20 pin I C with only two ports P1 and P3. An interrupt service routine is used as subroutine for incrementing P1. CODE: #include<reg51.h> unsigned char i=0; void incrii() interrupt 1 { i++ ; } void main () { P1=00; T0=1; TMOD=0x06; TF0=0; TL0=-64; IE=0x82; TH0=-64; i=0; TR0=1;

while(1) { P1=i; } }

23 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

In this program T0 is set as up counter to count 64. P3.4 is chosen to receive pulses from demodulator output. After receiving 64 pulses P1 i.e. port 1 is incremented by 1. An interrupt service routine is called for incrementing P1. Using an ISR makes it possible for microcontroller to work in multitasking mode The objective of counting 64 is to change the resolution to 10WH. Later the transmitted data is received at parallel port and converted to KWh.

24 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER 6 Modulation and Demodulation

25 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

ASK (Amplitude Shift Keying)


Amplitude-shift keying (ASK) is a form of modulation that represents digital data as variations in the amplitude of a carrier wave. The amplitude of an analog carrier signal varies in accordance with the bit stream (modulating signal), keeping frequency and phase constant. The level of amplitude can be used to represents binary logic 0s and 1s. We can think of a carrier signal as an ON or OFF switch. In the modulated signal, logic 0 is represented by the absence of a carrier, thus giving OFF/ON keying operation and hence the name given. Like AM, ASK is also linear and sensitive to atmospheric noise, distortions, propagation conditions on different routes in PSTN, etc. Both ASK modulation and demodulation processes are relatively inexpensive. The ASK technique is also commonly used to transmit digital data over optical fiber. For LED transmitters, binary 1 is represented by a short pulse of light and binary 0 by the absence of light. Laser transmitters normally have a fixed bias current that causes the device to emit a low light level. This low level represents binary 0, while a higher-amplitude light wave represents binary 1.

6.1 MODULATION
CD4051 is used to generate ASK. CD4051 is analog MUX. Select lines is connected so that S2 at pin 11 and S1 at pin10 is connected to ground. S0 at pin 9 is connected to output of PWM. The signal when high gives output of sine wave of 43.3 KHz at pin as I1 at pin is fed with output of LF353 oscillator. The circuit diagram of ASK generation is shown in Figure 23. CIRCUIT DIAGRAM:

Figure 6.1: ASK Generation

26 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

6.2 Demodulation
Demodulation is done using uA741 in comparator mode. The output swings between +/-15V for +/- Vsat. The output of comparator gives back the PWM. The circuit diagram of demodulator is shown in Figure 23. CIRCUIT DIAGRAM:

Figure 6.2: ASK Demodulation using Comparator

27 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER 7 APPLICATION AND SCOPE

28 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

7.1 APPLICATION

The project can be used in large malls and commercial building where monitoring is impossible by inspection.

In large area of installation we can easily set it up by use of amplification circuit on lines.

Safe house monitoring. Warehouse energy monitoring.

7.2 SPECIAL FEATURE


It is affordable because software to be used can be made on any platform suiting any operating system. A personal computer can be designed in such a way that with minimum configuration it can handle the system in unique. Project itself can be enhanced in such a way that it administers the complete switching in applied area. Low power consumption and easy to maintain and repair. Once the information is received at computer, it can be transmitted over a long distance via internet and can be administered remotely by executives of company.

7.3 SCOPE FOR FUTURE WORK


The project in total can send the power consumption of a switch to computer and hence the power consumption can be remotely monitored. The transmission media to be used is telephone cable and it could transmit data over a large distance without significant loss, economically. It can be further translated into a circuit which administers the power and every household in remote areas. It can be used for automatic lighting system when the beholders of house or

29 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

company are not home. A website supporting java platform can be part of centralized power monitoring system. Such as Gmail when password is entered it will let to decide which switch to close/open and when?. So a simple idea can be turned into industry.

30 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CHAPTER 8 RESULT AND CONCLUSION

31 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

CONCLUSION

In this project work an attempt has been made and succeeded in monitoring power consumption remotely via telephone cable. The PC can be designed in such a way that with minimum configuration it can handle the system only.

RESULT

Rating of Complex Load (Watt)

Observed Reading on PC

Conversion Constant

Time (sec)

Energy Measured

Time (sec)

(Watt-Hour)

1000

10

2000

10

Table 1: Result

32 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

BIBLIOGRAPHY
References: David A Bell, Op-Amps and Linear I Cs, Fourth Edition, 2006, Prentice Hall India, New Delhi. K Sam Shamugham, Digital and Analog Communication, Fourth Edition, 2006, John Wiley and Sons, New York. Jan Axelson, Parallel Port Complete, First Edition, Lakeview Research, Madison (USA).

33 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Appendix I SOFTWARE

34 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

a. Pratham v7.0
Pratham v7.0 is installed on PC with windows operating system. This software is made in VB 6. It can be used on any port and baud rate. This software uses an active x control in VB6. It is for mere illustration and test of the circuit. The user friendly and more compatible version can be made using C. The software is so simple that it can be made free source. Further it can be used to put a switch on and off thus, creating a powerful tool. The same can be used to communicate data over the internet.

b. Code
FRMMAIN.FRM

Option Explicit Const Start% = 8 Const HighNibbleSelect% = &H10 Dim DataIn%(0 To 7) Dim ChannelNumber% Dim LowNibble% Dim HighNibble%

Private Sub cmdReadPorts_Click() Dim EOC% For ChannelNumber = 0 To 7 'Select the channel. DataPortWrite BaseAddress, ChannelNumber

35 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

'Pulse Start to begin a conversion. DataPortWrite BaseAddress, ChannelNumber + Start DataPortWrite BaseAddress, ChannelNumber 'Wait for EOC Do DoEvents LowNibble = StatusPortRead(BaseAddress) EOC = BitRead(LowNibble, 6) Loop Until EOC = 1 'Read the byte in 2 nibbles. DataPortWrite BaseAddress, ChannelNumber + HighNibbleSelect HighNibble = StatusPortRead(BaseAddress) DataIn(ChannelNumber) = MakeByteFromNibbles() Next ChannelNumber DisplayResult End Sub

Private Sub DisplayResult() For ChannelNumber = 0 To 7 lblADC(ChannelNumber).Caption = Hex$(DataIn(ChannelNumber)) & "h" Next ChannelNumber End Sub

Private Sub Form_Load() StartUp

36 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

End Sub

Private Sub Form_Unload(Cancel%) ShutDown End Sub

Private Function MakeByteFromNibbles%() Dim S0%, S1%, S2%, S3%, S4%, S5%, S6%, S7% S0 = (LowNibble And 8) \ 8 S1 = (LowNibble And &H10) \ 8 S2 = (LowNibble And &H20) \ 8 S3 = (LowNibble And &H80) \ &H10 S4 = (HighNibble And 8) * 2 S5 = (HighNibble And &H10) * 2 S6 = (HighNibble And &H20) * 2 S7 = HighNibble And &H80 MakeByteFromNibbles = S0 + S1 + S2 + S3 + S4 + S5 + S6 + S7 End Function

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single) End Sub

Private Sub mnuPort_Click(Index%) frmSelectPort.Show End Sub

37 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Frmnewportaddress.frm

Option Explicit

Private Sub cmdCancel_Click() frmNewPortAddress.Hide End Sub

Private Sub cmdOK_Click() Dim NewPortAddress% Dim IndexOfNewPort% Dim Character$ Dim ValidEntry% ValidEntry = True IndexOfNewPort = 3 'Read the port address entered by the user. 'If the address is within the accepted range, hide this form, 'enable the port's option button, and display the address. 'If the address is out of range, display a message. 'If the text box is empty, disable the port's option button. Select Case txtAddressOfNonStandardPort.Text Case "" NewPortAddress = 0 Port(IndexOfNewPort).Address = 0

38 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Port(IndexOfNewPort).PortType = "" Port(IndexOfNewPort).Enabled = False frmSelectPort.optPortName(0).Value = True frmNewPortAddress.Hide UpdateLabels Case Else NewPortAddress = CInt(Val("&h" & txtAddressOfNonStandardPort.Text)) If NewPortAddress > 0 And NewPortAddress < &H800 Then Port(IndexOfNewPort).Address = NewPortAddress Port(IndexOfNewPort).Enabled = True frmSelectPort.optPortName(IndexOfNewPort).Value = True frmNewPortAddress.Hide UpdateLabels Else MsgBox "The port address must be between 0 and 7FFF. Leave the address blank if there is no port." End If End Select End Sub

Private Sub Form_Load() Left = (Screen.Width - Width) / 2 Top = (Screen.Height - Height) / 2 End Sub

39 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Frmselectport.frm

Option Explicit

Private Sub cboEcpMode_Click(Index As Integer) SetEcpMode (cboEcpMode(Index).ListIndex) End Sub

Private Sub cmdAddPort_Click() 'Display a text box to enable user to add a port 'at a nonstandard address. frmNewPortAddress.Show End Sub

Private Sub cmdFindPorts_Click() 'Test the port at each of the standard addresses, 'and at the non-standard address, if the user has entered one. Dim Index% Dim PortExists% Dim Count% Index = 0 'First, test address 3BCh Port(Index).Address = &H3BC PortExists = TestPort(Index) 'If there is a port at 3BCh, increment the index.

40 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

If Not (Port(Index).Address) = 0 Then Index = Index + 1 End If 'Test address 378h Port(Index).Address = &H378 PortExists = TestPort(Index) 'If the port exists, increment the index. If Not (Port(Index).Address) = 0 Then Index = Index + 1 End If 'Test address 278h Port(Index).Address = &H278 PortExists = TestPort(Index) 'Disable option buttons of unused LPT ports For Count = Index + 1 To 2 optPortName(Count).Enabled = False Port(Count).Enabled = False Next Count If Not (Port(3).Address = 0) Then PortExists = TestPort(Index) Else optPortName(3).Enabled = False End If End Sub

41 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Private Sub cmdOK_Click() frmSelectPort.Hide End Sub

Private Sub cmdTestPort_Click() Dim PortExists% Dim Index% 'Get the address of the selected port Index = -1 Do Index = Index + 1 Loop Until optPortName(Index).Value = True PortExists = TestPort(Index) Select Case PortExists Case True MsgBox "Passed: Port " + Hex$(BaseAddress) + "h is " + Port(Index).PortType + ".", 0, "Test Result:" Case False MsgBox "Failed port test. ", 0, "Test Result:" End Select

End Sub

Private Sub Form_Load() Dim Index% Left = (Screen.Width - Width) / 2

42 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Top = (Screen.Height - Height) / 2 'Load the combo boxes with the ECP modes. For Index = 0 To 3 cboEcpMode(Index).AddItem "SPP (original)" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "bidirectional" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "Fast Centronics" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "ECP" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "EPP" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "reserved" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "reserved" Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "test"

43 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Next Index For Index = 0 To 3 cboEcpMode(Index).AddItem "configuration" Next Index 'Enable the option buttons for existing ports. For Index = 0 To 3 optPortName(Index).Enabled = Port(Index).Enabled Next Index UpdateLabels End Sub Private Sub optPortName_Click(Index As Integer) 'Store the address and index of the selected port. Dim Count% BaseAddress = Port(Index).Address IndexOfSelectedPort = Index EcpDataPortAddress = BaseAddress + &H400 EcrAddress = BaseAddress + &H402 For Count = 0 To 3 cboEcpMode(Count).Enabled = False Next Count cboEcpMode(Index).Enabled = True End Sub The code above is only VB6 code for Pratham v7.0. The required dlls can be found on windows website. There are three forms in application as depicted before. Modules can be added to fulfill the port logic control using microprocessor of PC itself.

44 | P a g e N I L O T P A L M R I N A L

CENTRALIZED POWER MONITORING SYSTEM

Thanks to,

Texas Instruments and National semiconductors for online support. Watt-hour meter is original idea from National Data Handbook, Prentice Hall USA, 1993. Google Images. Department of Electrical and Electronics Engineering, SIT, Tumkur.

45 | P a g e N I L O T P A L M R I N A L

S-ar putea să vă placă și