SIM UNIVERSITY SCHOOL OF SCIENCE AND TECHNOLOGY TRIPLE PHASE SMART ENERGY METER NAME: NEO JAN SON STUDENT ID: K0704384 SUPERVISOR: MR. CHIN CHENG SIONG / DR. YEDROUDJ MOHAMMED A project report submitted to SIM University in fulfillment of the requirements for the degree of Bachelor of Engineering (Electronics) November 2011 ACKNOWLEDGEMENT I would like to thank all the people who have helped me in my final year project. The first person whom I would to thank is my previous supervisor Dr Yedroudj Mohammed who has shown his guidance, personal judgments and support in my first half duration of my project. When he was around in Singapore, he has put his time to spend off his Singapore Polytechnic full lecturing hours just to meet us and guide me to update on my progress status for that precious few times. It was a pity that he has to leave Singapore and went to United Kingdom in the midst of my project due to his work, but overall he was a good supervisor. I would also like to thanks my changing supervisor Mr. Chin Cheng Siong, because he is the one who continues to guide me along for this project. I am really glad to have him as my supervisor and I am lucky that he is very patient to me all the way and gave his useful suggestions and advices to make sure there is improvement in my report. Lastly, I would like to say thank to my family who give encouragement to me and support me throughout my study in UniSIM. 1 ABSTRACT For the last century, electric meters have been the measurement devices not only for the household, but also for industrial areas and the areas in which require electricity is required to be used. Electricity bills are charged according to what the consumer is using. There are many cases whereby consumers have used more than what they have estimated and ended up paying more bills than what they expected to. There is also situations happen when this electric meters which is running in analog form is measuring the power consumption is not accurate, thus this results in the users to get charged more bills than the actual amount. This project is aiming to design a triple phase smart energy meter which is capable to solve the problems which may occur. A triple phase meter can be multi-tasking and check for the tariff rates constantly for three different power loads. This project design is for prototype simulation and it can be further improved in the near future to fabricate into a more compactable size. A smaller size will be convenience for users to bring it outside and perform its necessary power measurements. The prototype is running in digital form whereas traditional electric meter is in an analog form at the start. Digital energy meters will be more accurate in measurements compared to analog meters. The prototype has a „smart‟ characteristic which is why the project name is called “Triple Phase Smart Energy Meter”. The feedback system will be induced in the prototype which helps to regulate the power consumption for the electrical appliances. Thus the feedback system serves the purpose for the smart characteristic of this prototype meter. Microcontroller will be installed in the circuit of the prototype design. Microcontroller serves as the „brain‟ control system of the triple phase meter. Circuit diagram has to be designed with the help of circuit drawing software tools. Circuit diagram will be completed by combining schematic diagram and PCB (printed circuit board) layout to synchronise into Gerber file for which is suitable for fabrication and assembly. The completed triple phase meter will be assigned to measure different appliances (such as fan, light bulbs, laptops etc.) for its reliability and accuracy tests check. Not only that, relays are installed into the circuitry which serves as feedback system function to regulate power consumption. Load (electrical appliances) has to be assign to switch off once it hit a certain power unit or it will cut off the main supply at specific time period which is not in use. In conclusion, triple phase smart energy meters are necessary to replace the existing energy meters. They can be used for multi-functions which are able to measures power in different forms be it in apparent power, RMS (root mean square) or even reactive/active power. These meters ultimately serve as cost saving tool which benefit to all the people. 2 Content Page 1. 2. 3. 4. 5. Title Page Acknowledgement Abstract Content Page Introduction 1.1 Background of Problem 1.2 Project Scope and Objective 1.2.1 Project Scope 1.2.2 Project Objective 1.3 Proposed Approach 1.4 Gantt Chart 1.5 Project Resources 1.5.1 Resources Required 1.6 Skill Review 1.6.1 Target for Progress 1.6.2 Strength and Weakness 1.6.3 Challenge Faced Literature Review 2.1 Background of the Project 2.1.1 Review on Energy Meter 2.1.2 Example of Triple Phase Energy Meter By Maxim 2.1.3 Background of the Project (Triple Phase Energy Meter IC) 2.2 Building Block of Triple Phase Energy Meter 2.2.1 Current Sensing using current transformer (C.T.) 2.2.2 Voltage Sensing using voltage transformer (V.T.) AC Parameter 3.1 Instantaneous Voltage, Current and Power 3.2 RMS Voltage, RMS Current, Apparent Power and Active Power System Hardware Design 4.1 Architecture of ADE7878 IC & PIC16F877A 4.1.1 Pin Configuration of ADE7878 IC 4.1.2 Operation of IC ADE7878 4.1.3 Pin Configuration of PIC16F877A 4.1.4 Operation of IC PIC16F877A 4.2 Design Layout 4.3 Call Sign ( ) functions descriptions 4.4 Problems faced at initial 4.5 Schematic Design of the Triple Phase Energy Meter Circuit 4.6 Parts Listing 4.7 Bread Board Design Prototype 4.8 Things for improvements in future Critical Review and Reflection 0 1 2 3 5 5 5 5 6 7 8 8 8 9 9 11 12 13 13 13 15 17 18 19 20 22 22 23 25 25 36 36 38 39 43 50 55 57 60 67 71 72 3 6. Conclusion 7. Reference 8. Appendix 73 74 75 4 1. INTRODUCTION TO ENERGY METER 1.1 Background of problem The older models of power system grids are gradually going towards phase out in this 21st century. As modern technologies advances with more innovative and faster models, this will be replaced by the introduction of smart grids. Smart grids incorporate its efficiency, reliability and smart systems factors together to meet the demands of today‟s world users. Smart meters as part of the smart grid series technology, brings in the advancement in energy saving consumption, compatibility in terms of size, faster outage detection and environmental savings of resources. It is estimate by the next decade, most of the countries from the world will use smart meters to replace the olden electromechanical meters. Traditional electrical meters such as electromechanical meters are passive meters. They have mechanical problems, technical problems, management problems and some social problems. The mechanical parts inside these meters due to wear and tear over time, will cause errors in the readings and make false information on billing records. On the other hand, as these meters are easier to adjust with fraught work, that means for example, people who would like to pay lesser bills on their electricity may have done some changes in the reading‟s settings, it may not be reliable. Smart energy meters today surpassed all the disadvantages of electromechanical meters. Apart from measuring energy, these energy meters provide parameters such as reactive power and rms which show real-time data useful for balancing electric loads and reducing power outages. They can also help to support the specific period (off peak and peak hour measurement) billing methods in the electricity bills which allow users to tariff their usages etc. Overall, smart energy meters are operated by using the measurement readings voltage and current in instantaneous forms and multiplied them to become electrical power. This power is further integrated against time to produce used energy (eg: joules/kilowatts). 1.2 Project Scope and Objective 1.2.1 Project Scope The project scope is to design a triple phase energy meter which has the function of reading and measurement of power consumption. This design will be the prototype which has the analog base front end and meter design cater for device evaluation. The design has to be low cost and energy efficiency. The main focus is to study and work on retrieving the information to get for this triple 5 phase energy meter. To implement it, it is necessary to understand how the overall ADE7878 energy meter IC work and some of the specifications, block diagrams and data, for example, related triple phase metering IC‟s datasheets, related types of 3-phase energy meter ready-made in the market, and some general terminologies to the components inside the chip (ADE7878) are needed. Terminologies are such as pin configurations, phase error between 3channels, gain error and power supply rejection. A 5V power load (battery form) can be included inside the PCB board power circuit as a replacement for the power supply to the energy meter. This is to prevent the usage of the high voltage of the household electricity from damaging the energy meter. The 5V load is the step down result from the original 220V household power. The below steps are for the project scope guideline: (1) Schematic diagram design (2) PCB layout design (3) Components selection (4) Current transformer sensing input circuit (5) Voltage transformer sensing input circuit (6) Fabrication of PCB board from the PCB layout design (7) Soldering and surface mounting of fabricated PCB board (8) Load testing for fully power connected PCB board 1.2.2 Project Objective The project‟s objective is to create a triple-phase energy meter prototype which functions for energy measurements and consume electricity by the user in three load sources. The circuit has to goes through a few software-based testing in order to make sure the design is appropriate for the purpose and meet the criteria. Below is the list of tasks which is for developing the board: (1) To read through the internal circuitry of the energy meter well before proceed to design for the triple phase meter. (2) To apply the formula P=VI when measuring the power using the energy meter and understand how the meter work with the integration of power against time (3) To familiarise the different chip components functions together well with DSP (4) To do some calibrations with the help of a constant fixed meter and to remove offsets in the active power calculation 6 (5) To read through more examples from real life models to create the power supply design and place this design into the prototype design. 1.3 Proposed Approach It is very important to start with a fresh mind to create the energy meter prototype, there is necessary to study & learn how to read with full understanding of schematic diagrams and also how to engage in the using of suitable PCB design software which was chosen to plot the circuitry. After finishing up the software design, another step is to fabricate the designed PCB layout. To assemble the arranged components either with manual soldering or surface mounting technique is also needed to be considered. Last but not least, it is required to test and check the functionality of the final design. For the design of the triple phase energy meter prototype that consists of an energy meter integrated circuit, voltage transducer, current transducer, electromechanical counter, filter networks and power supply circuit, the understanding of every individual part and components is very important in the initial stage. The triple phase energy meter prototype must be able to act as an analog front end prototype for the development of an energy meter that measure with high accuracy and superior stability in environmental variation. Figure 1 7 Note: this lines mean the initially planned approach was not able to complete due to difficulty faced in the design of PCB and schematic to able to liaise together for fabrication of the actual PCB board for minimal size to present. 1.4 Gantt Chart A Gantt chart [17] is a universal project tool which helps organization or individuals to keep track on projects‟ status and planning. Inside this chart, it displays the starting and finishing time of each sub topics/events within the project‟s content. It also marks the target in terms of duration (days/weeks) for each event and it shows easily whether the schedule is done on time or not. It can be easily identified when the Gantt chart display out the percentage which any events has finished through. Overall, Gantt chart [17] is making the project more schedule‟s oriented and put any event timeframe at a larger point of view. (For the Gantt chart, please refer to page 76 under Appendix section) 1.5 Project resources Resources are the main requirements to execute the most of the tasks within in this project. This is part of the project management terminology. It is important to know the correct resources which a particular project‟s topic/content need to have. If there is enough suitable resources, it will put the project at a halt and slow down the project progress. Below are the listed resources which are required for this project: 1.5.1 Resources required Evaluation Board Documentation ADE7878 Energy Metering IC (pdf file) Polyphase Multifunction Energy ADE7878 Metering IC (pdf file) PIC16F877A microcontroller PBLABIDE Quick Start Guide Schematic and PCB design user guide Designing a power supply circuit 8 1.6 Skill Review 1.6.1 Targets for progress The key points shown below have been identified to improve the project work to meet the dateline schedule project time frame. 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) Literature review Evaluation of project methodology Submit Project Proposal Report Create the schematic diagram Create the PCB design Building the hardware Submit interim report. Testing the hardware Verification of the result Submit final report writing Poster and Powerpoint presentation Project Management Skill In the project, the skill and technique of project management PMJ300 module [13] has been used in order to be in systematical way. The skills from the integration, scope, time, cost, quality, human resources, communications, risk and procurement are the main parts which are needed to be considered to engage with the project target to make the project well organized to reach for the goals in the project. (1) Project Integration The integration skills adopted from this management module helps me to identify, define, combine, unify and coordinate the processes (develop project charter, develop project management plan, direct and manage project execution, monitor & control project work, perform integrated change control and close project). (2) Project Scope The scope covers only the required work. This is to make sure that the work which involves in completing the project does not go out of content. For example, if the project is on triple phase energy meter, the scope should be focusing only on this triple phase energy meter to make sure it is not directed towards any other energy meters. (3) Project Time The time factor is a disciplinary act to ensure the project is completed within the target timeframe. A proper tool such as Gantt chart is tabulate from at the start to schedule the tasks and the sub-events to complete within a specific period of time. Activities need to 9 be defined and set in sequences (to determine which task should come first after then followed by the other one) before a Gantt chart is created. (4) Project Cost The cost management has to take in consideration of the amount of money spent that has spent for in this project. Besides the timing factor, integration of the project activities are needed to considered in order to calculate for the estimated cost of the project. It can be based on the type of components to be used, the way of soldering whether it is surface mounting or manual soldering and the kind of software which is needed for drawing the circuit diagram. Once the specific components, software and soldering method are fixed, budget can be determined. Lastly, the controlling of the cost will be put into place to monitor the status of the project and see whether it is over the determined/estimated cost. (5) Project Quality Quality of work is a show of standard of how good or bad the project is. A good quality project requires good planning to the requirements of what the project needs. Compliance will be shown by documenting the project in a quality way. Quality should be control and maintain at high level requirement to keep the project work perform at its best manner. (6) Project Human Resources Human resources are a completely individual project work assessment. The concern for this project is to engage with sales personnel who sell the components and software needed for the project. In cases of project involving a group of people, a project team needs to be formed. (7) Project Communications In the communicator segment, the important person to keep aware of the project status and on-going progressing result is the project supervisor. The communication between supervisor and project student has to be a two way mode. Supervisor has to keep aware of what the student is doing for the project in order to get full assessment of project‟s grading. (8) Project Risk Risk management involves the processes of conducting risk management planning, identification, analysis, response planning, monitor and control of the project. In this project, there is risk to access on which software to draw the schematic diagram in which may have fewer functions to execute. There is also risk in choosing the wrong microcontroller which does not have the best performance in power measurements. All these need to be identified and tackle to solve these risk problems and possible to reduce the risk factors in each identified risk. (9) Project Procurement 10 Procurement management involves the processes necessary to purchase or acquire products or results from outside such as vendors, shop attendants etc. It also covered in the administering of contract issued by buyers that is acquiring the project from the seller, and administering contractual obligations placed on by contract. Knowledge on schematic and PCB design software It is very important to know how to use the schematic and PCB design software. This is because the vendor has to retrieve the Gerber file which is a converted result from the designed done PCB circuitry inside this software. Test trial run will be further completed with the hardware input and this determines whether the project is successful or not. Target Skills Review This project is targeted with many essential skills required. The most important two key points are: Know how to use the PCB and schematic software and understand the design concept. Books and websites extraction for related and relevant information Many models of meters available in the market are being compared and referred back to come out with the new idea of this design energy meter finally. This information also secures the focus scope of project direction and guides along to achieve my objective for the project. Design concept of a triple phase energy meter prototype and internal circuitry It will boost the improvement to the design of the triple phase energy meter prototype when there is a certain understanding and knowledge of internal circuitry and signal flow diagram. It is necessary to make sure the measurement power from the output is accurate and precise to the given current and voltage source in order to produce the project target results. 1.6.2 Strengths and Weaknesses Nobody is perfect in this world. I certainly have my weakness and my strength to support me throughout this project timeframe. It is certainly a good reminder to point out my weakness points and rectify them. After which, it will become my strength to add onto my advantage for the project. Weakness No experience in PCB design 11 No experience in schematic design No experience in implementing PCB and schematic combine into Gerber file for fabrication Unfamiliar with C-Language programs Strength Understand well in reading and interpreting datasheet Knowledge in electronic fundamental Always keen to learn more Priorities for skill improving Engaging into a suitable software platform to design PCB and schematic layouts and use them efficiently Research more on the various different types of energy meter‟s terminology Comparison and find new ideas to improve the PCB and schematic design Hardware troubleshooting skills Components selection and alteration if any connection faults or circuit failure 1.6.3 Challenges Faced This project requires a certain level in C-Programming which adopt to use to manipulate the microcontroller and the various signals, so it is needed to be even more alert on it to make sure the program written works It is not easy to lookout for suitable vendor whom understand the Gerber file, additionally it is also needed to follow the required specification details There is always the money factor to concern as some of the components purchase and assembly is costly 12 2. LITERATURE REVIEW 2.1 Background of the project An energy meter which is also known as electric meter is a measurement device for energy consumption produced from the household, industrial area, business offices or any electronic driven devices. In the modern world today, billing units are the typical calibration generated by electric meters. The most common in used is kilowatt per hour (kWh). A cycle produced by the electric meters is displayed in terms of periodic readings to get billing cycles and energy. Electronic and electromechanical meters are the two basic types. 2.1.1 Review on Energy meters Electromechanical meters The first ever invented electric meter was by the name of Elihu Thomas in 1888. The invention was produced through an accident encountered. Its creator was tinkering with an arc lamp when he noticed the peculiar way a spring had fallen off of it, as if affected by rotating electric fields. [9] An aluminum disc which spins at a speed equivalent to the speed of power used. The electromechanical induction meter works by counting the aluminum disc‟s revolutions. Hence, the used energy is equivalent to the number of revolutions made by the aluminum disc. Two coils are placed inside the metallic disc. First coil generates a magnetic flux comparatively to the voltage. The second coil generates a magnetic flux comparatively to the current. The combination of the two magnetic flux together with current and voltage produce Foucault current [10] in the metallic disc. The outcome of this effect generates a force comparatively to the product of instantaneous voltage and current. 13 Figure 2: Picture of the first electric meter invented in 1888, cited diagram from [9] Electronic meters Electronic meters are used to measure energy usage and it has an LCD to display the readings of the usage amount. These readings are able to send to remote areas. The function of electronic meters is not just for measuring energy usage. They are measurements for apparent energy power, RMS calculations, fundamental active and reactive power etc. They are also capable to selectively measured power usage to bills on certain time frame. This time frame can be separated into off peak hours which can charge cheaper and peak hours for higher charges to bills. Figure 3: Picture of a polyphase electronic energy meter, cited diagram from [3] 14 2.1.2 Example of triple phase energy meter chip by Maxim Below are the two examples of metering IC models which are available in the market. Comparison of the specification of many metering ICs is needed to find the suitable metering ICs which work the best for the triple phase energy meter for this project. The overall functional diagrams for these two ICs will be discussed to know its specific functions. There are some characteristics such as memory space, programmable based and the numbers of channel inputs which need to be consider so as to get the right microcontroller for the project. 71M6513/71M61513H Chip Figure 4: cited diagram from [11] 71M6513 is an energy measurement IC which can be used to measure power tool IC for industrial, commercial and residential areas. It has an accuracy of 0.5%. The 71M6513 is a high end combination system with System-on-Chip (S.o.C). It has The SoC consists of a converter, serial ports, voltage reference, comparator, real-time clock (RTC), LCD 15 driver, regulator, temperature sensor, oscillator, 5V boost driver and the RAM. The load was connected through the converter port with six analog inputs. There is a 21-bit delta-sigma ADC which converts analog signals to digital form. The voltage reference port works together with the boost driver to maintain a 5V voltage from the load to the IC. The RAM ensures the memory of the IC is enough to store and access the information input to the chip. The temperature sensor regulates the heat sink and cooling system to make sure the IC chip is not over-heated. The comparator‟s function is to regulate for power failure. The flash is a in-system programmable IC to support the IC‟s main system. Overall, this IC offered a range of high (0.1%) to standard (0.5%) accuracy for measurements in residential or commercial usages. This is required with its feature of multiple voltage/current inputs and complex LCD or DIO configurations. . MAXQ3181 Chip Figure 5: cited diagram from [12] The MAXQ3181 is a specific metering IC which support front end collection and calculation of multi-phases voltage and current, active power and energy and many other metering parameters of different phasing load. The MAXQ3181 chip consist of various inputs for voltage bias & reference, three voltage phase inputs, three current phase‟s inputs, one neutral power input, DSP controllers, ADC, SPI with registers (I/O) 16 and buffers (I/O) and CFP CFQ counters with registers (I/O) and buffers (I/O). On the top of the block diagram, the VCOMM acts as a common input platform to liaise the ADC conversion between channel DC offset. The CFP CFQ works as a configurable pulse output to support for energy or RMS voltage or current sensing. Load sense from the ADC which has been converted to digital signals pass through the SPI segments. This is a controller which is also an interdevice bus protocol that provides synchronous, fast, full duplex communication between a chosen master device and one or more slave devices. 2.1.3 Background of the Project (Triple phase energy meter IC) The intention of this project is to come out with a design of a prototype for triple phase energy meter. The function of this prototype is to calculate measured power and energy with high accuracy. The Analog model ADE7878 was earlier on recommended by my previous supervisor to set as a reference to design this prototype. The objective of this prototype design of a triple phase energy meter is to be at a low cost, high precision accuracy in measurement of energy and power. In the initial of this project, ADE7878 was chosen as a reference due to its common features or parameters which can be use for modification to a new design. ADE7878 is a multi-function measurement IC. It has three flexible pulse outputs and serial interfaces. There are three phase current sense inputs, one neutral current sense input, three phase voltage sense inputs and one voltage neutral sense input connecting through a filter network and attenuation circuitry to the ADE7878 IC. The mentioned sensing inputs are the ADC inputs. Inside this IC, it contains waveform sample registers that allow access to all ADC inputs. This IC is therefore required to connect to the assigned microcontroller of LPC2368 through digital isolators which act as a digital signal processor (DSP). Signals from sensing inputs in analog form pass through the IC through the digital isolators to the microcontroller LPC2368 in digital form. The LPC2368 after which undergoes its appropriate digital signals transmission and attenuation to produce signal strength and power reading & values through the pulse outputs (CF1,CF2 and CF3). The ADE7878 integrated circuit has two interrupt request pins IRQ0 and IRQ1. Whenever an interrupt incident happens, these pins trigger signals as indication of its occurrence. The ADE7878 is specially designed to provide low power modes to assure the chip IC is still in functional condition (continuous accumulation of energy/power usage) if encountered sabotage situation. The ADE7878 is available in the 40-Lead LFCSP, Pb-free package. During the second half of the project year (Jan2011-May2011), I have realised I am not able to synchronise the schematic layout design together with my PCB layout. They are many unknowns which caused me to extend my project another half year. I begin to outsource for another microcontroller. 17 I have seen a few models from other metering ICs. I decided to use Microchip PIC16F877A 40pins enhanced flash microcontroller to program my triple phase measurements for power, current and voltage. A major decision was further made to change with the use of RCAD software to build up my schematic design in replace of ExpressPCB and ExpressSchematic software which I used earlier on to build up using ADE7878 metering IC. 2.2 Building Block of triple phase energy meter prototype At the start, ADE7878 was used as a reference to design a new prototype to achieve a better accuracy meter and can be able to sustain in environmental condition and time. This will be evaluated towards at the backend of the measurement. Using a suitable current transformer on the current channel, the evaluation board can then be connected to a test bench or high voltage 240v RMS test circuit. An on board resistor divider network provides the attenuation for the line voltage. Below Figure 6 of a triple phase energy meter building block that I have created. The energy meter will consist of an ADE7878 integrated circuit, a voltage transformer, a current transformer, oscillator display, power supply circuit and the load side. All analog input signals are filter using the on board anti aliasing filters before being presented to the analog input of the ADE7878. The current transformer on the current channel can use either an air core coil, CT or a shunt resistor. Figure 6 18 As mentioned from the background portion, ADE7878 was replaced with PIC16F877A microcontroller. Power supply is connected to the microcontroller PIC16F877A. At the same time MPLABIDE software is also connected to the PIC16F877A. A program source code will be written in C-Language to control all the inputs and outputs of the computation and through the MPLABIDE as a medium to convert all the commands & instructions to the PIC16F877A. PC16F877A will be the brain of the entire triple phase smart energy meter. There will be a load inserted to the microcontroller. In the real world, the load can be any household appliances such as electric fan, laptops, mobile phones etc. Due to the cost and easier to build reasons, a few light bulbs will be used as a simulation to demonstrate the whole process. A relay unit is also connected to the microcontroller. This serves as the cutoff system which regulates and does a time to time check for power consumption from the load. A relay programming is needed to write in the source code to function the feedback call. Lastly a liquid crystal display shows the output value of the power consumed by user. Figure 7 2.2.1 Current Sensing using current transformer (C.T.) A magnetic field is generated when a single wire carries the current. A simple example to represent will be the picture view of a right hand clutch with a loose fist and sticking out the thumb finger. The clutched fingers represent the magnetic lines of flux around the wire (current) and the thumb point to the direction of current flowing in the single wire. This is called the right-hand-rule. AC current can be represented by rotating the wrist so the thumb points one way down the wire, then the opposite direction. Below 19 figure 8 shows the right hand rule together with a schematic symbol for C.T. Figure 8: cited diagram explanation from [6] The current transformer wraps around the single wire (pass the wire through the hole in the transformer) and the magnetic core (toroid/donut shaped metal core) matches up with those magnetic lines of flux, and concentrates them. In the case of small gauge wire, apply the right-hand-rule, current will be produced depending on how many turns the small gauge wire are wrapped around the core. Current transformer can measure current without even making physical contact to the single wire. This is due to the very high voltage the flux is running and it is dangerous. The current which is flowing in the single wire can be accurately measured by choosing the core material that is capable of concentrating the magnetic lines of flux, and also know exactly the number of turns revolve around the core. A measurement tool called the constant multiplier can be used to measure the current values at the specific current transformer. 2.2.2 Voltage Sensing using voltage transformer (V.T.) Figure 9 A voltage transformer converts one voltage to another. Alternating current is the parameter in which transformer work with because there are constantly changes in the 20 direction of the electrical flow. The power which goes through the transformer will be the same from its input and output as energy in theoretically term, it neither get created or get destroyed. In the case of voltage changes, the current will also change to make sure the amount of power compute will be the same. There should be negligence from the loss of power from transformer due to heat loss and perhaps leakage. The voltage transformer is functioning like an electrically-powered generator. It has been arranged to build with no moving parts. It consists of at least two windings or coils. A magnetic field is being generated as current flows through the powered winding, or primary. The magnetic field will slowly spread to become bigger as current flows to the unpowered windings (s), or secondaries. Current flowing in the secondaries area will cause its direction to change, hence causing the reverse direction of magnetic field and electric flow. There is reverse effort in vice versa when current flows back in original direction. Some parts of the transformer will vibrate (also known as hum), which is caused by the change of the magnetic field. The windings has higher current running at low voltages will end up with less turns of wire. On the other hand, having more turns of wire, the windings will be lesser current running at higher voltages. The number of turns in the wire‟s windings is depending on the amount of voltage the transformer is running at. For example, a 5-to-1 step down voltage transformer might take 1200 volts 60 cycles alternating current, and change it to the 240 volts alternating current actually distributed to the households. A possible scenario will be at the primary, there is 800 turns of wire; and at secondary, there is 160 turns of wire. The high-current low-voltage windings have more turns of thinner wire. The thinner wire carries less current although it is running in higher voltage. Likewise for thicker wire, it carries more current. Thicker wires are not often found in high-current low-voltage windings. In most cases, voltage transformers haven silicon steel cores to channel the magnetic field. The voltage transformers are able to perform at its best condition when the magnetic field is concentrated around the wires. The silicon steel cores keep the magnetic field as effectively as possible even in nearby pieces of metal. Power transformers are often performing at very high reliability percentage. In order to maintain the reliability of the transformers, they are immersed with nonconductive oil at high temperatures. This nonconductive oil helps to prevent shorts and cools the transformers. A non-toxic material like fluorinated hydrocarbons are used nowadays in replace of the dangerous chemicals. 21 3. AC PARAMETERS There are a few types of AC parameters to obtain results findings. They are instantaneous, peak, RMS and average. DC has only one parameter. The sub-topic below will therefore goes through some parameters use in the AC circuit to find it‟s current, voltage and power. The trigonometric equations shown later will help to further understand on how to measure an energy meter in a better and accurate way. 3.1 Instantaneous Voltage, Current and Power In a given time domain (t), there are 3values which are the correspondents, they are instantaneous voltage u, current i and power p [16]. At any point of time, a waveform which has been chosen for measurement or analysis has infinity number of instantaneous values with respect to time function and its parameter. As we are concern in time domain, voltage are expressed as u(t) whereas current as i(t). Below is an example which I quote for AC parameters: There is a resistor and a coil connected in series to a sinusoidal voltage with a peak voltage of 5Vpeak , a peak current 2Apeak and a frequency of 100Hz. Given the time taken for the whole cycle to attend stability is 3.8ms. Calculate in terms of time domain function of the overall circuit for its sinusoidal voltage u(t), peak current i(t) and the instantaneous power p(t). Figure 10 u (t ) 5V sin(2ft ) i (t ) 2 A sin(60 2t ) The current waveform was shifted 60° to the corresponding of its voltage waveform. Power = Voltage * Current (by formula) 22 p(t ) u (t ) * i(t ) p(3.8) u (3.8) * i(3.8) [5V sin(2 *100 Hz * 3.8 *10 3 )] * [2 A sin(60 2 * * 3.8 *10 3 )] 4.98W This means in order to run the above mentioned AC circuit at 5Vpeak voltage 2Apeak current frequency 100Hz at 3.8ms, 4.98W of power is used. The instantaneous power can be derived from the multiplication of instantaneous voltage and instantaneous current. 3.2 RMS Current, RMS Voltage, Active and Apparent Power A varying current or voltage has an effective value which can be derived from RMS (root mean square). AC pulse has a similar steady DC (constant) which is comparable to that of RMS. In our daily livelihood example for an iron, if is going to take 100V DC value supply to heat up to an optimum temperature to perform clothes ironing, then similar it will be the same RMS value it will take to reach its performing heating temperature. But when we come to AC value, it will be much less voltage consumed as it takes only 0.7time of RMS/DC supply. Which mean, the iron only take 100*0.7 = 70V to reach its performing temperature. Apparent power [8] is a measurement of AC power. It is being computed by the multiplication of RMS current and RMS voltage. Thus, it is equivalent to RMS power. On the other hand, active power which is equivalent to real power just like transmission to loads like fan, computers, television etc. In the calculation of the active power, it is advisable to minimize the gap of the phase difference between current and voltages. The amount of active power is inversely proportion to the phase difference. The active power [8] gets its measurement energy value from the energy meter over time which is what it usually what has been derived of. By equation: Active Power = Vrms * I rms * cos , cited from [15] whereby = phase difference co s = power factor The apparent power [8] requires a circuit in connection to the actual power supply. It is often mistaken by people that load is involve in the connection. From the above equation, active power correlates to the apparent power and also the power factor. The power factor, cos θ is calculated in between 0 – 1. The function of power factor helps to measure the effective power in a distributed system. A unity power factor (always be 1) 23 [15] is generated when there is no phase difference between the voltage and current values. Unity Factor = 1 ( = 0 , cos = cos 0 = 1 ) ,cited from [15] Under the condition of a unity factor in power, apparent power will be equivalent to active power. This also means under no phase difference conditions, apparent power is the same as active power. The theory derives the efficiency of a power distribution system will decrease when there is a larger power factor. This is a not a good news as more power is used and also more loss in energy. At a given transmission amount of useful power, a high power factor consumes lesser current in comparison to that of a low power factor. A proper way to ensure the power factor is running at an effective rate, the circuit can be suggested with the addition of capacitors and inductors in a passive network. There is loss in real power in this case as the load gets more leakage with the same amount of apparent power. 24 4. SYSTEM HARDWARE DESIGN In this section, will be explaining on how to design a triple phase energy meter circuit using IC ADE7878 as the heart of the meter. The hardware and components used to build a triple phase energy meter prototype will also be covered in detail. The below block diagram shows an overview design of a triple phase energy meter circuit Figure 11 4.1 Architecture of ICs ADE7878 & PIC16F877A Figure 12: cited diagram from [1] 25 Figure 12 shows the functional block diagram of energy metering IC ADE7878. It is a 3-phase electrical energy measurement IC with serial interfaces and three flexible pulse outputs (CF1, CF2 and CF3). It is of high accuracy and using the second order sigma-delta (Σ-Δ) analog-to-digital converters (ADCs), a digital integrator, reference circuitry, and the entire signal processing to perform measurements. The signal processing in the DSP and ADC is executed done in the digital domain within the circuitry. It is available in a 40-lead LFCSP, Pb-free package. Component such as resistors, capacitors, diodes etc are surface mounted on the conductor side of the PCB board. The entire metering IC together with its circuitry is power up by a 5V source. ADE7878 has a total of seven analogue input channels. They are IAN/IAP, IBN/IBP, ICN/ICP, VAN/VAP, VBN/VBP, VCN/VCP and a combine INN/INP/VNN/VNP. Channels IAN/IAP, IBN/IBP and ICN/ICP are used for current sensing. Channels VAN/VAP, VBN/VBP and VCN/VCP are used for voltage sensing. The last channel is a combine neutral port for both current and voltage to ground. The four main operations on chip components used in IC ADE7878 are as follow: (1) Analog inputs (2) Analog to Digital conversion (3) Current Channel ADC (4) Voltage Channel ADC The function of these 4 on chip operations is presented as below: (1) Analog Inputs ADE7878 has a total of seven analog inputs in current and voltage types of channels. There are four pairs of fully differential voltage inputs in the current channels which are IAP with IAN, IBP with IBN, ICP with ICN and INP with INN. The voltage tolerance in terms of differential signaling between this four pairs of voltage input signals is at +/-0.5 V. On top of that, voltage tolerance for the IxP with IxN current input signals in analog form withstand at +/-0.5 V with respect to AGND. A tolerance level of +/-25 mV can be applied on the maximum common-mode signal on the inputs. 26 Figure 13: The graph above shows a schematic view of a pair of current channels (V1 + V2) induce with the maximum common mode voltage and differential input voltage to an amplifier , cited diagram from [2] All analog inputs have a programmable gain amplifier. It comes with a choice of 1,2,4,8 or 16. Inputs (IA, IB and IC) are set at Bit [5:3] (PGA2[2:0] in the gain register. The Figure 14 is a table below shows where the Bit [5:3] is located and its description. Figure 14: cited diagram from [2] There are three single-ended voltage inputs channels; they are VAP, VBP and VCP. The voltage tolerance at maximum rate for these three inputs channels is +/-0.5 V with respect to VN (neutral voltage channel). On top of that, voltage tolerance for the VxP with VxN voltage input signals in analog form withstand at +/-0.5 V with respect to AGND. A tolerance level of +/-25 mV can be applied on the maximum common-mode signal on the inputs 27 Figure 15: The graph above shows a schematic view of a pair of voltage channels (V 1 + Vcm) induce with the maximum common mode voltage and differential input voltage to an amplifier, cited diagram from [2] The figure 16 below shows how the setting of the gain with a start up bit of [8:6](PGA3[2:0] in the gain register table of the top page. Figure 16: cited diagram from [2] (2) Analog to Digital Conversion ADE7878 has seven sigma-delta (Σ-Δ) analog-to-digital converters (ADCs). All ADCs are active when it is in PSM0 mode. The ADCs which are in charge of the current measurements in Phase „A‟, „B‟ and „C‟ will be active when it is in PSM1 mode. Those ADCs which involves in neutral current measurements and phase „A‟, „B‟ and „C‟ voltages measurements are switched off. All ADCs are shut down to reduce power consumption when it is in PSM2 and PSM3 modes. Figure 17: The diagram above shows a first order Σ-Δ ADC (Inside the ADC contains the integrator, latched comparator running in 16bits clock, reference voltage regulator and digital LPF), cited diagram from [2] 28 An Σ-Δ modulator converts the input signal into a continuous serial line of 1s and 0s call upon by the sampling clock. The frequency of the sampling clock is at 1.024 MHz (CLKIN/16bits). The serial data (1s and Os) drives the 1-bit DAC in the feedback loop. DAC output is not included in the input signal. In the condition of a high loop gain, the input signal level is comparable to the average value of the DAC output (bit stream). The data produced from the 1-bit ADC at a single sampling period for any given input value is of no usage. It will only be useful when the results retrieved at many samples are average out. The digital low pass filter which is right after the latched comparator is the tool to do the averaging process for the samples. The digital LPF performs this averaging process which they retrieve from the modulator‟s data (large number of bits), thus it can output 24-bit data which match the input signal level content. There are two methods which the Σ-Δ modulator adopt to achieve high resolution in replace of a 1-bit conversion method. First method is oversampling. This is done by sampling the signal at very high frequency which is many times higher than the original wanted bandwidth. For example, if the wanted bandwidth is 500 Hz to 1 kHz and our ADE7878‟s sampling rate is 1.024 MHz. The quantization noise produce while sampling the signal will be spread evenly and thinly due to the usage of high bandwidth. As a result, quantization noise in the wanted bandwidth will decrease a lot. This can be shown in the below graph. In order to improve the signal-to-noise ratio (SNR) in the wanted bandwidth, the second method is to shape the quantization noise and possible shift to the higher frequency band of the sampling rate frequency. This shaping of the quantization noise has to work together with the oversampling process to get good SNR. Figure 18: cited diagram from [2] 29 Anti-aliasing Filter The previous Figure 18 in the Σ-Δ modulator shows an analog low pass filter (RC). The function of this analog LPF is to act as an anti-aliasing filter. Aliasing happens when frequency components that is higher than half of the sampling frequency to overlap with the lower frequency components. As a result, the higher frequency components roll into the reconstructed signal and cause distortion of the signal. There is mirror image of the frequency components which lies above the sampling frequency (also known as Nyquist frequency – 512 kHz) and reflected below the 512 kHz. This RC filter which is likely a fencing wall helps to attenuate noise near the sampling frequency and reduce distortion in the wanted bandwidth (500Hz – 1 kHz). It is advisable to engage a RC filter with a corner frequency of 5 kHz so that the attenuation will be high enough to support at 1.024MHz of sampling frequency in the current sensors. In order to reduce aliasing effects on current sensors, a RC filter with a 20dB per decade attenuation should be sufficient. In the case of a di/dt sensor such as a Rogowski coil, the coil has s 20dB per decade gain. An easy way to offset this gain problem is to add in an extra RC filter to get a -40dB per decade attenuation. This -40dB attenuation add together the +20dB gain produce the same effect of noise reduction. Figure 19: cited diagram from [2] ADC Transfer Function All ADCs in the ADE7878 under the condition of same input signal level, output the same 24-bit signed code. With a full-scale input signal of 0.5 V and an internal reference of 1.2 V, the ADC output code is nominal at 5,928,256 (0x5A7540). The range of this ADC‟s code is between 0x800000 (-8388608) and 0x7FFFFF (+8388607). This represents the same voltage compare to input signal level of +/-0.707 V. Performance of the ADC is usually more reliable when the input signals are lower than +/-0.5 V. (3) Current Channel ADC The figure 20 below shows the ADC and signal processing path for input IA of the current channels. (IB and IC is same figure as IA) The outputs of the ADC are in a 24bit data-word (stream of 0s and 1s) and are running at a rate of 8kSPS (samples per 30 second) The ADC generates its maximum output code value with the help of its feature of a +/-0.5 V specified full scale analog input signal. The figure below display the differential inputs (IAP and IAN) in pass through a full scale voltage signal to the ADC and to the DSP to produce readings and calculations of signals. The range of the ADC is fluctuate between -5928256 (0xA58AC0) and +5928256 (0x5A7540). The neutral current of the 3-phase system is represented by an input, IN. The input will only be connecting to AGND if the neutral line is not there. The Vin in the current channel signal path is identical to the Vin in the neutral current signal path All these mentioned Vin is available to me on below combined figures. Figure 20: cited diagram from [2] Current Waveform Gain Registers Both the signal path of each phase and neutral current has a multiplier. The running waveform in current level will oscillate in the opposite direction either at positive or negative phase if there is induce of the two‟s complement number to the 24-bit signed current waveform registers (AIGAIN, BIGAIN, CIGAIN and NIGAIN). An example will be the ADC output will be driven up by 50% if 0x400000 is written to the gain registers. Likewise to scale down by 50%, 0xC00000 is written to the gain registers. The equation of Figure 21 below is the mathematical formula to calculate the function of the current waveform gain registers. Current Waveform = Content .of .Current.Gain. Re gister ADCOutput * (1 ) 2 23 Figure 21: cited equation from [2] 31 The calculations for the current rely on the content of the AIGAIN, BIGAIN, CIGAIN or NIGAIN registers. This means, the calculations for corresponding phase apparent, active and reactive energy and current rms will be affected if there are changes to these registers. In other words, the scaling for the waveform sampled per interval will alter depending on the registers‟ content. DSP operates on 28bits. As for ADE7878, it operates on 32-, 16- or 8-bit words on its serial ports. The figure below shows a 32-bit register stream which is used by the 24-bit xIGAIN registers in the least significant bits (LSBs) on the right. It is a standard binary code for the first 4bits with 0s in the left (MSBs). Figure 22: cited diagram from [2] Current Channel HPF A dc offset is stored inside the ADC outputs. This offset is like a nuisance as it creates errors in the calculations of power and rms. High-Pass Filters (HPFs) are placed in the connection of the neutral and phase currents of the phase voltages. These HPFs help to remove all dc offset found on the current channel. By default, all filters are enabled and are used in the DSP. The binary code 0x00000000 is a clear sign for 24-bit HPFDIS register. The filters will be disabled in the case of a nonzero value inserted into the HPFDIS bit stream. The figure 23 below shows the HPFDIS register. It is of similarity to that of current waveform gain registers in 32-bit. The difference is the MSBs with a standard of eight 0s compared to the previous of four 0s. Figure 23: cited diagram from [2] Current Channel Sampling The 24-bit signed registers (IAWV, IBWV, ICWV and INWV) stored the waveform samples of the current channel which is retrieved from the HPF‟s output. These samples are running at 8 kSPS. At this moment, there are no errors in the calculations of power and rms. The availability of IAWV, IBWV, ICWV and INWV registers will determine whether the Bit 17 (DREADY) in the STATUS0 register is set or not. Setting Bit 17 (DREADY) in the MASK0 register enables an interrupt to be set when the DREADY flag is set. The transmission sign will be in 32 bits as the ADE7878 read the IAWV, IBWV, ICWV and INWV signed registers. Below figure 24 is an IxWV bit stream register. 32 Figure 24: cited diagram from [2] Inside the ADE7878, there is a high speed data capture (HSDC) port. This port function to speed up the waveform sample registers for accessing purpose. di/dt CURRENT SENSOR AND DIGITAL INTEGRATOR The di/dt sensor detects changes in the magnetic field created by ac current with the effect of electromotive force (EMF) and changes in magnetic flux density. Below figure 25 shows the flow of the magnetic field direction. Figure 25: cited diagram from [2] The magnitude of the current is running in a direction 90degree to the direction of the flux density of a magnetic field induced by a current. An electromotive force is being generated between the two ends of the conductor loop when there are changes in the magnetic flux density. The di/dt of the current is proportional to the EMF which is a voltage signal. The mutual inductance from the di/dt sensor and the current carrying conductor determines how the voltage output from the di/dt sensor. Power can only be measured after the filtering of the current signal at the presence of di/dt sensor. A build-in integrator is found inside the datapath of each phase and neutral current. This integrator helps to regain the current signal from the di/dt sensor. In the case of powered up and reset to the ADE7878, the digital integrator will be switched off by default. The integrator is triggered on by a Bit 0 (INTEN) inside the CONFIG register. As you can see the below graph with a flat line, it shows a flat gain of magnitude and phase response in the wanted region of frequency bandwidth. This happen when the current induced signal comes inside the magnetic field with a di/dt sensor. There is a disadvantage when using the di/dt sensor. It has a 20dB/dec gain which creates significant high frequency noise attenuation. As mentioned from the previous section under anti-aliasing filter, a RC filter placed after the di/dt sensor 33 should be able to offset this noise by cutting a 20dB/dec to the wanted bandwidth region. This is done when the ADC is sampled. \ Figure 26: The above two graphs show the range of 0Hz – 4 KHz interest of band frequency with di/dt sensor induced, cited diagram from [2] Figure 27: The two graphs above shows the gain and the phase response from the frequency range between 40Hz– 70Hz in a 20dB per decade cycle inside the digital integrator, cited diagram from [2] Note: the integrator has −20 dB/dec attenuation and approximately −90° phase shift The DICOEFF 24-bit signed register is used in the digital integrator algorithm. The code value 0x000000 indicates that the integrator is just turn on or being reset. The register has to start with code 0xFF8000, after which the integrator then can be power up. DICOEFF is not used when the integrator is turned off and can remain at 0x000000 in that case. This DICOEFF 24-bit signed register is structure just like the typical current waveform gain registers. It comes in a 32-bit pattern. The left side in MSBs 34 with four 0s and the rest are the code bits, which practically means it is transmitted same to 0xFFF8000. ADE7878 can be operated together with a conventional current sensor, such as a current transformer (CT) in the case of a disabled digital integrator. (4) VOLTAGE CHANNEL ADC The figure 28 below shows a voltage channel with input VA with its ADC and signal processing chain. There are two differential inputs VA and VN at the start of this voltage channel. The ADC output swings between −5,928,256 (0xA58AC0) and +5,928,256 (0x5A7540). The same voltage channel goes for input VB and VC. The ADC outputs are signed two‟s complement 24-bit words and are available at a rate of 8 Ksps. The ADC is able to reach its maximum code value when the voltage tolerance of the specified full scale analog input signal fluctuates at +/-0.5 V. Figure 28: cited diagram from [2] Voltage Waveform Gain Registers Each phase voltage‟s signal path has a multiplier. A complement two‟s number is written to the 24-bit signed current waveform gain registers (AVGAIN, BVGAIN, CVGAIN and NVGAIN) which toggle and invert the voltage waveform. For example, the output of ADC will increase by 50% if registers are input with code 0x400000. On the other hand, to decrease the ADC output by 50%, write 0xC00000 to the registers. The mathematical formula symbolizes the function for voltage waveform gain registers. Content .of .Voltage .Gain. Re gister ) 2 23 Figure 29: cited equation from [2] Voltage .Waveform ADC.Output * (1 35 The voltage calculations depend on the content of the AVGAIN, BVGAIN, CVGAIN and NVGAIN registers. This means, the calculations for corresponding phase apparent, active and reactive energy and voltage rms will be affected if there are changes to these registers. The scaling of the sampled waveform will change accordingly too. The xVGAIN registers format structure is same as of the current waveform gain registers. They are in the 32-bit format. Again the left side 4MSBs are all 0s follow by the extended sign for the remaining 28bits. Figure 30: cited diagram from [2] 4.1.1 Pin Configuration of IC ADE7878 Figure 31: Pin function description of ADE7878, cited diagram from [1] 4.1.2 Operation of IC ADE7878 The figure 32 shown below is the operation block diagram of the IC ADE7878. The three current sensing analogue inputs (IAP/IAN, IBP/IBN and ICP/ICN) together with the neutral current input are connected each to a programmable gain amplifier (PGA1). The function of this PGA helps to facilitate the easy moving of the transducer interface of all the 4current channels. As for the voltage sensing inputs (VAP, VBP and VCP), 36 this 3 voltage channels together with a shared neutral input (VN) are connected to another programmable gain amplifier (PGA3). At the voltage and current inputs, a CLKIN is connected to it to supervise for input clock frequency, input capacitance and equivalent series resistance. There is also a CLKOUT for manning the output capacitance. There is also a RESET switch to restart a whole new measurement for the inputs. All the seven channels inputs after passing through the PGA go through the ADC to convert its content to digital domain. The Phase „B‟ and phase ‟C‟ voltage and current inputs are therefore go through the series of measurements such as total fundamental, active, reactive and apparent energy calculations. As for phase „A‟, it goes through a phase calibration register (APHCAL). This xPHCAL is a 10-bit register which vary the time advance in the voltage channel signal path. Then it goes through a voltage waveform gain register (AVGAIN). This AVGAIN helps to perform the voltage channel ADC. After which, Phase „A‟ goes through a disabled High Pass Filter (HPFDIS) which allows the dc offset in the current channel. At the current channel of Phase „A‟, it goes through a digital integrator to retrieve the current signal from the di/dt sensor. The current channel is then goes through a current RMS signal processing flow with X2 follow by a low pass filter to a square root. The end result from this signal processing output RMS values which stores to a register call the AIRMS. Reactive power calculation has to pass through a low pass filter with an AVAROS then to an AVARGAIN. AVAROS is a register to compensate offsets in the calculations of total reactive power. AVARGAIN is another register to compensate offsets in the calculations of fundamental reactive power. As for fundamental active power calculation, it goes through an AFWATTOS register then to an AFWGAIN register. AFWATTOS adjust the offset to compute out the actual fundamental active power. AFWGAIN assists in the gain adjust of the fundamental active power. For fundamental reactive power calculation, it goes through an AFVAROS register then to the AFVARGAIN register. AFVAROS adjust the offset for fundamental reactive power computation. AFVARGAIN is for Phase „A‟ fundamental reactive power gain adjust. After all this measurements no matter is from Phase „A‟, „B‟ or „C‟, it goes to the digital frequency converter (DFC). This is somehow to the ending process whereby signal waveforms from the previous current and voltage are now into endpoint readings. Depending on which phase the computation comes from, it will goes through a checksum register (CF1DEN, CF2DEN or CF3DEN). In the Normal Power Mode (PMS0), it is important to sustain at desired value for the configuration registers, checksum register is the one which helps to maintain this value. Phase „A‟, it will be CF1DEN register. After which, the overall readings will be at CF1 output. 37 Figure 32: cited diagram from [2] 4.1.3 Pin Configuration of IC PIC16F877A As mentioned in the project background and project approach, the metering IC was changed from Analog ADE7878 to Microchip PIC16F877A metering IC. Below figure 33 is a functional pin diagram of the 40pin enhanced flash microcontroller of PIC16F877A. 38 Figure 33: Pin description of PIC16F877A at last 3pages Appendix, cited diagram [14] 4.1.4 Operation of IC PIC16F877A The block diagram (Figure 34) below shows the overall functional diagram of PIC16F877A microcontroller. It has five ports output (Port „A‟, Port „B‟, Port „C‟, Port „D‟ and Port „E‟). It has three sets of memory units within its memory organization. They are Flash Program Memory running at maximum 8K * 14words length, data memory (RAM) running at maximum 8bytes * 368 length and EEPROM data memory running at maximum 8bytes * 256 length. There is a Timer0 module inside the PIC16F877A chip. Without the presence of prescaler, Timer0 is increasing at every instruction cycle at timer mode. The increasing of Timer0 will be put to a halt at next two instruction cycles after TMR0 register is written. Timer0 on other hand will also increase either on every rising or fall edge of pin{6} RA4/TOCKI at counter mode. The source edge select bit (TOSE) will be the factor if there rising edge on the instruction cycle. The Timer1 is function as a counter and a timer, running in 16-bit, split into TMR1H 8-bit register and TMR1L 8-bit register. Both registers are readable and writable (RW), ranging from 0000h to FFFFh file address. Timer1 is available in a few modes. There are timer, counter, synchronous counter and asynchronous counter. There is a build-in crystal oscillator circuit in Timer1. There is also an internal reset switch in Timer1 which can be used by a CCP (Capture/Compare/Pulse width modulation) trigger output. 39 There is a Timer2 inside the PIC16F877A chip. It has a prescaler and a postscaler and runs at 8-bit. Inside the CCP unit at its PWM (Pulse Width Modulation) operation, Timer2 can be used as its time base. Timing information within Timer2 can be easily removed by any reset device, which is why it has readable and writable capabilities. The 10-bit A/D is used for a conversion and result computation for both ADRESH and ADRESL registers. It is also function as a justifier in the 16-bit result register whether ADFM (formal select bit) is a high (1) in right justified or low (0) in left justified. The parallel slave port (PSP) is used at the Port „D of the chip. It asynchronously readable and writable by the external world through read enable control input pin, pin[8] RE0/read enable/AN5 and write enable control input pin, pin[9] RE1/write enable/AN6. EEPROM as mentioned above in the first paragraph is one of the three memory blocks in the memory organization of PIC16F877F chip. It is not directly mapped in the register file space. The special function registers (SFRs) is where it indirectly mapped into. There are six different SFRs available in this memory. They are EECON (control registers for memory accesses), EECON2 (write sequence registers), EEDATA (read data memory location), EEDATH, EEADR and EEADRH. There is the CCP (Capture/Compare/Pulse width modulation) unit in this microcontroller. It is running as 16-bit register, comprise of CCP1 and CCP2. CCP1 has a two 8-bit registers (CCPR1L and CCPR1H). CCP1‟s operation is being supervised by the CCP1CON register. A compare match produces the special event trigger and thus reset the Timer1. CCP2 has the two 8-bit registers of CCPR2L (low byte) and CCPR2H (high byte). CCP2‟s operation is being supervised by CCP2CON register. An A/D conversion is able to initiate when the A/D module is enable, this is due to the condition of the compare match producing the special event trigger and reset the Timer1. The synchronous serial port is a control bit which enables or disables the serial port and configures SCK, SDO, SDI and SS enable as serial ports pins or I/O pins. There are two I/O units in this PIC16F877A chip. One of it is USART (Universal Synchronous Asynchronous Receiver Transmitter) which also can be call as SCI (Serial Communications Interface). USART can be configured as synchronous – slave or master clock (half duplex) system which can transmit with peripheral devices such as EEPROM and A/D converters. USART can also be configured as asynchronous (full duplex) systems that can perform transmission with peripheral devices such as keyboards and cashier drawer. Comparator module is also part of PIC16F877A chip. There are two analog comparators inside the module. The RA3 input pin{5} which has connection with RA0 pin{2} are multiplexed together with inputs of comparators. RA4 output pin{6} and 40 RA5 output pin{7} are thus multiplexed with outputs of comparators. One of the examples of the comparators‟ input is the on-chip voltage reference. The voltage reference in the PIC16F877A functions as a generator of a 16-tap resistor ladder network. It provides a fixed voltage reference when the comparators are in mode „110‟. This reference generator will be operated and control by a programmable register. Inside the PIC16F877A chip, there is a program counter running in 13-bit which helps to address the program memory space of 14-bit * 8K word. The 8Level Stack (13-bit) unit helps to assign the bit coding through put for the program counter for computation. The flash program memory (also known as program memory space) has a total of eight levels of stack, a rest vector, an interrupt vector and an on-chip program memory (page 0-3). The entire memory map for the flash program has a file address range from 0000h to 1FFFh. The instruction registers in the chip receives the 14-bit stream data from the flash program memory. The 14-bit data are spilt into two flows, one which goes as a 7-bit direct address to the address multiplexer and the other goes to the instruction decode and control with 8-bit data. The overall PIC16F877A contains an internal circuitry of power up timer, oscillator start up timer, power-on reset, watchdog timer, brown-out reset, in-circuit debugger and low voltage programming. This internal circuitry is connected to the timing generator with an oscillator‟1‟ input clock and an oscillator‟2‟ output clock. The internal circuitry is also been maneuvered by a MCLR (master clear reset input) and VDD, VSS (main power supply). There is a FSR (file select register) which indirectly or directly helps to access the register file. This FSR runs in an 8-bit indirect address multiplexed together with the 7-bit direct address from instruction register to become RAM address data. The RAM (read access memory) data is sent in a 9-bit stream to the RAM file register. The output data from Port „A‟, „B‟, „C‟, „D‟ and „E‟ are sent through a 8-bit data bus to the Program counter and the RAM file register. On the other side, the 8-bit data from the instruction register is multiplexed with the five Ports through put to the ALU (Arithmetic Logic Unit). This ALU performs different logic and arithmetic calculations such as subtraction and division from the combined data from instruction register and five Ports. The output of the ALU‟s calculation is transmitted to the W register. W register is a temporary file register to store the output of the arithmetic computation. After that, it will return the stored output and return back to the ALU. 41 The status register contains the arithmetic status of the ALU, the reset status and the bank select bits for data memory. The other registers, not only from W register, having other instructions command can set the status register as its destination. If the Status register is the destination for an instruction that affects the Z, DC or C bits. Then the write to these three bits is disabled. The device logic will affect whether these bits are set or cleared. Port A has 6pins which are RA0/AN0 {pin2} ,RA1/AN1 {pin3}, RA2/AN2/Vref-/CVref {pin4}, RA3/AN3/Vref+ {pin5}, RA4/TOCKI/C1OUT {pin6} and RA5/AN4/SS/C2OUT {pin7}. Port B has 8pins which are RB0/INT {pin33}, RB1 {pin34}, RB2 {pin35}, RB3/PGM {pin36}, RB4 {pin37}, RB5 {pin38}, RB6/PGC {pin39} and RB7/PGD {pin40}. Port C has 8pins which are RC0/T1OSO/T1CKI {pin15}, RC1/T1OSI/CCP2 {pin16}, RC2/CCP1 {pin17}, RC3/SCK/SCL {pin18}, RC4/SDI/SDA {pin23}, RC5/SDO {pin24}, RC6/TX/CK {pin25} and RC7, RX/DT {pin26}. Port D has 8pins which are RD0/PSP0 {pin19}, RD1/PSP1 {pin20}, RD2/PSP2 {pin21}, RD3/PSP3 {pin22}, RD4/PSP4 {pin27}, RD5/PSP5 {pin28}, RD6/PSP6 {pin29} and RD7/PSP7 {pin30}. Port E has 3pins which are RE0/RD/AN5 {pin8}, RE1/WR/AN6 {pin9} and RE2/CS/AN7 {pin10} The respective naming convention for the pins‟ purpose can be found in the appendix at the last 3pages of the report. 42 Figure 34: cited diagram from [14] 4.2 Design Layout POWER SUPPLY: The power supply is very important section of all electronic devices as all the electronic devices works only in DC. One important aspect of the project is that the power supply should be compact. Most electronic devices need a source of DC power. Power supply unit consists of following units: (1) Step down transformer (2) Rectifier unit 43 (3) Input filter (4) Regulator unit (5) Output filter The circuit is powered by a 12V dc adapter, which is given to LM7805 voltage regulator by means of a forward voltage protection diode and is decoupled by means of a 0.1 μf capacitor. The voltage regulator gives an output of exactly 5V dc supply. The 5V dc supply is given to all the components including the Microcontroller, the serial port, and the IR transmitters and sensors. The AC supply which when fed to the step down transformer is leveled down to 12 volts AC. This is then fed to full wave rectifier which converts it in to 12 volts DC. This is then passed to a filter to remove the ripples. Then it is fed to a voltage regulator that converts 12 V to 5 V stable voltages and currents. J1 +12V 1A 1 2 POWER SUPPLY U1 LM7805C/TO220 2 IN C1 0.1MFD VCC R1 OUT 1k D2 3 C2 0.1MFD C3 LED 470MFD 25V 2 1N4007 1 GND D1 1 Figure 35 a) STEPDOWN TRANSFORMER: The step down transformer is used to step down the main supply voltage from 230AC to lower value. This 230AC voltage cannot be used directly, thus its stepped down. The transformer consists of primary and secondary coils. To reduce or step down the voltage, the transformer is designed to contain less number of turns in its secondary core. Thus the conversion from AC to DC is essential. This conversion is achieved by using the rectifier circuit. b) RECTIFIER UNIT: The Rectifier circuit is used to convert AC voltage into its corresponding DC voltage. There are Half-Wave and Full-Wave rectifiers available for this specific function. The most important and simple device used in rectifier circuit is the diode. The simple function of the diode is to conduct when forward biased and not to conduct when reverse biased. The forward bias is achieved by connecting the diode‟s positive with of positive of battery and negative with battery‟s negative. The efficient circuit used is full 44 wave bridge rectifier circuit. The output voltage of the rectifier is in rippled form, the ripples from the obtained DC voltage are removed using other circuits available. The circuit used for removing the ripples is called Filter circuit. c) INPUT FILTER: Capacitors are used as filters. The ripples from the DC voltage are removed and pure DC voltage is obtained. The primary action performed by capacitor is charging and discharging. It charges in positive half cycle of the AC voltage and it will discharge in its negative half cycle, so it allows only ACC voltage and does not allow the DC voltage. This filter is fixed before the regulator. Thus the output is free from ripples. d) REGULATOR UNIT: Regulator regulates the output voltage to be always constant. The output voltage is maintained irrespective of the fluctuations in the input AC voltage. As and then the AC voltage changes, the DC voltage also changes. Thus to avoid these changes, regulators are used. Also when the internal resistance of the power supply is greater than 30 ohms, the pull-up gets affected. Thus this can be successfully reduced here. The regulators are mainly classified for low voltage and for high voltage. e) IC VOLTAGE REGULATORS: Voltage regulators comprise a class of widely used ICs. Regulator IC units contain the circuitry for reference source, comparator amplifier, control device and overload protection all in a single IC. Although the internal construction of the IC somewhat is different from that described for discrete voltage regulator circuits, the external operation is much the same. IC units provide the regulation of either a fixed positive voltage or a fixed negative voltage or an adjustably set voltage. A Power Supply can be built using a transformer connected to the AC supply line to step the ac voltage to desired amplitude, then rectifying that ac voltage using IC regulator. The regulators can be selected for operation with load currents from hundreds of milli-amperes to tens of amperes, corresponding to power ratings from milli-watts to tens of watts. The purpose of the regulator is to maintain the output voltage constant irrespective of the fluctuations in the input voltage. The Micro controller and PC work at a constant supply voltage of +5V,-5Vand +12V and -12V respectively. The regulators are mainly classified for positive and negative voltage. LM 7805 VOLTAGE REGULATOR Features: 45 • Output Current up to 1A • Output Voltages of 5, 6, 8, 9, 10, 11, 12, 15, 18, 24V • Thermal Overload Protection • Short Circuit Protection • Output Transistor Safe Operating area Protection Description The MC78XX/LM78XX series of three-terminal positive regulators are available in the TO-220/D-PAK package and with several fixed output voltages, making them useful in a wide range of application. Each type employs internal current limiting, thermal shut-down and safe operating area protection, making it essentially indestructible. If adequate heat sinking is provided, they can deliver over 1A output current. f) OUTPUT FILTER: The filter circuit is often fixed after the regulator circuit. Capacitor is most often used as filter. The principle of the capacitor is to charge and discharge. It charges during the positive half cycle of the AC voltage and discharges during the negative half cycle. So it allows AC voltage and not DC voltage. This filter is fixed after the regulator circuit to filter any of the possibly found ripples in the output received finally. The output at this stage is 5V and is given to Microcontroller. U8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 MCLR RA0 RA1 RA2 RA3 RA4 RA5 RE0 RE1 RE2 VDD VSS Osc1 Osc2 RC0 RC1 RC2 RC3 RD0 RD1 RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 VDD VSS RD7 RD6 RD5 RD4 RC7 RC6 RC5 RC4 RD3 RD2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 PIC16F877A Figure 36: MICRONCONTROLLER 46 RECTIFIER VOLTAGE SENSOR 1 FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 5 PHASE1(R) AD0 4 C7 CAP 8 R3 T1 LOAD RECTIFIER FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 CURRENT T1SENSOR 1 5 AD1 4 C7 CAP 8 R3 1740 RECTIFIER VOLTAGE SENSOR 1 FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 5 PHASE1(Y) AD2 4 C7 CAP 8 R3 T1 LOAD RECTIFIER FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 CURRENT T1SENSOR 1 5 AD3 4 C7 CAP 8 R3 1740 RECTIFIER VOLTAGE SENSOR 1 FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 5 PHASE1(B) AD4 4 C7 CAP 8 R3 T1 LOAD RECTIFIER FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 CURRENT T1SENSOR 1 5 AD5 4 C7 CAP 8 R3 1740 NEUTRAL Figure 37: SENSOR 47 33PF C5 CRY S1 Y 1 4MHZ C4 CRY S2 33PF OSCILLATOR Figure 38: CRYSTAL OSCILLATOR VCC R1 10K RESET C6 CAP SW1 RESET RESET Figure 39: RESET CIRCUIT LIQUID CRYSTAL DISPLAY DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 VCC Figure 40: LCD 48 J1 +12V 1A 1 2 POWER SUPPLY U1 LM7805C/TO220 2 1 C1 0.1MFD VCC R1 OUT 1k D2 3 C2 C3 0.1MFD LED 470MFD 25V 2 1N4007 IN GND D1 1 RECTIFIER FILTER VOLTAGE DIVIDER VCC VOLTAGE SENSOR 1 D3 D3 R2 5 R1 PHASE1(R) AD0 D3 4 D3 10K C7 CAP SW1 RESET 8 R3 C6 CAP T1 RESET LOAD RECTIFIER FILTER VOLTAGE DIVIDER RESET D3 D3 D3 D3 LIQUID CRYSTAL DISPLAY R2 CURRENT T1SENSOR 1 5 AD1 4 DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 C7 CAP 8 R3 1740 VCC RECTIFIER VOLTAGE SENSOR 1 5 4 8 FILTER D3 D3 D3 D3 PHASE1(Y) VOLTAGE DIVIDER U8 RESET R2 AD2 C7 CAP R3 VCC T1 LOAD RECTIFIER FILTER D3 D3 D3 D3 CRYS1 CRYS2 VOLTAGE DIVIDER R2 CURRENT T1SENSOR 1 5 AD3 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 C7 CAP MCLR RA0 RA1 RA2 RA3 RA4 RA5 RE0 RE1 RE2 VDD VSS Osc1 Osc2 RC0 RC1 RC2 RC3 RD0 RD1 RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 VDD VSS RD7 RD6 RD5 RD4 RC7 RC6 RC5 RC4 RD3 RD2 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 VCC PIC16F877A 8 R3 1740 RECTIFIER VOLTAGE SENSOR 1 5 4 8 D3 FILTER VOLTAGE DIVIDER D3 PHASE1(B) 33PF C5 CRYS1 R2 AD4 D3 D3 C4 Y1 4MHZ CRYS2 C7 CAP R3 33PF OSCILLATOR T1 LOAD RECTIFIER FILTER D3 D3 D3 D3 VOLTAGE DIVIDER R2 CURRENT T1SENSOR 1 5 AD5 4 8 C7 CAP R3 1740 NEUTRAL Figure 41: CIRCUIT DIAGRAM 49 4.3 Call Sign function ( ) descriptions In the start from the appendix 7.5pages long of C++ source code [7] for the triple phase energy meter, I initialize a standard call for the library function of standard input/output header files, string header files and pic controller header file. The use of the <stdio.h>is common across all C++ programming command initializing code as we need input and output from all various commands for data and computation. The string header file <string.h>is needed here as it allows me to input a string value (such as EOL, $, % etc:) the preceding function. The <pic.h> is header file as a compiler to call for microchip microcontroller to execute its internal circuitry program to function in C program code running. Next, an assign of a void function is used; it means nothing is returned to the caller. LCD_sendCmd void function is to assign a sending command in the form of calling various address registers to the LCD (Liquid Crystal Display). There is another void function call LCD_SendData is to assign a sending command in character (such as A, B, C, D etc :) string to the LCD. Next an integer and a flag area declared and both are intialised to zero value. There is also a further initialization of 6string named as st, s1, s2, s3, s4 and s5. Both “st” and “s1” are bundled up in a pair for as variables of voltage and current values in Phase ‟A‟. The same theory applies to “s2” and “s3” also in a pair of Phase „B‟ and “s4” and “s5” pair up for Phase „C‟. Integers “four”, “three”, “two” and “one” are the parameters inputs which will be shown reflected in the LCD in either numeric or character outputs. The main function is started with calling for ADCON0 (Analog to Digital control register) by inputting 0x81 (1000 0001 in binary format) ask register to send data. ADCON1 is also initialized by inputting 0x87 (1000 0111) to turn on the inputs to the A/D pins at the PIC16F877A microcontroller. TRISA which is the 6-bit Port „A‟ Data Direction Register helps to add the inputs “s0” and “s1” to get an output. This TRISA register no matter is use as analogue or digital inputs, it also helps to control the direction of the port pins in the microcontroller. TRISB is an 8bit which can be an input or output depending on the setting or clearing of the TRISB bit. TRISB is multiplexed with the In-Circuit Debugger and Low Voltage Programming function. TRISB is set to 0x00 which will turn on the inputs to the A/D pins. TRISE is a data direction register to control the direction of the RE (read & write) pins. It is also set to 0x00 to turn on its inputs to the A/D pins. TRISC is also in 8-bit same characteristic as of TRISB. TRISC is multiplexed with several peripheral functions and has Schmitt trigger input buffers. TRISC is set to 0xb0 which also enable its inputs to the A/D pins. TRISD is similar to TRISC. Additional function in Port „D‟ is it is able to configure into a parallel slave port. TRISD is set to 0xFF to set inputs to A/D pins. 50 Port „B‟, Port „C‟, Port ‟D‟ and Port ‟E‟ are further intialised by setting to 0x00. This is to configure the on/off of the A/D input pins at the microcontroller. SPBRG (Baud Rate Generator Register) which helps to control the period of a free running 8-bit timer is set to 64 to minimize the error percentage and to keep the baud rate as low as possible. SPBRG is available between 0 – 255. BRGH (High Baud Rate Select Bit) is set to 1 to set the microcontroller function in asynchronous high speed mode. This is because BRGH is ignored in the synchronous mode. A 100milliseconds (ms) delay is inserted after this to facilitate timing reaction to the next LCD command and data instructions. LCD_SendCmd is set to 0x38 which means using 8-bit to send data command to LCD. A 100ms delay is follow up after this command. As you can see, there is many CheckBusy() functions along this C++ source code programs in between the LCD_SendCmd and LCD_SendData functions. This CheckBusy() functions is to always make sure the availability of the next preceding inputs inside the LCD is cleared. When it is cleared, it enables new input to slot into the available LCD panel to output display. Next, LCD_SendCmd is set to 0x06 which means to increment to the next cursor. A further action of increment for next cursor is carried out by setting 0x0c from the LCD_SendCmd. LCD_SendCmd is then set to 0x02 for. Then LCD_SendCmd is set to 0x80 to ask the 1st bit to send commands to the first line of the LCD. The next few lines are the series of repeated LCD_SendData and CheckBusy() functions. This is to constantly ask the program to reset the previous inputs inside the LCD output information and replaced it by the ACV and ACC wordings. ACV stands for AC voltage and ACC stands for AC current. A rough sketch of the alphabetical characters which suppose to appear on the LCD is shown below in Figure 42. Figure 42 After the ACV and ACC wordings light up on the LCD, a function of three seconds has been inserted to turn off it off. This is done by inserting three 1000ms delays follow by LCD_SendCmd set to 0x01. A for function is used as infinite loop and while(1) commands functioning. This portion of the program is to in charge of the increment of the counting on the „s1‟, „s2‟, 51 „s3‟,‟s4‟and „s5‟ variables. Integers are set to a for condition from 0 to a maximum of 10. The reason that why a maximum of 10 as integer value is used here is due to the fact in this simulation of the triple phase meter, a 100W/2min calculation is used in replace of 1KW/hr standard power unit convention. A 4ms delay is inserted. ADG0 (Analogue to Digital Gain Register) is set to 1. ADCON0 is set to 0x89 which is the address register for calculation of Phase „A‟. A while loop function is now executed with the calculations of the first variable from its ADRESH (Analogue to Digital Result High Register) in 256 (running in 8bits, 2^8 = 256) total bits to add to its ADRESL (Analogue to Digital Result Low Register). At the same time, calculations of the first variable need to check with the subsequent next phase variables which is why we have s2=s2 +st; The next phase variable „s2‟ is subject to the interval of power dissipation from the light bulbs in the triple phase energy meter. Hence, „s2‟ is used in a „if else‟ conditional function to range out the power consumption of the bulbs. If „s2‟ is zero watts (W), the value will be 0 watt, no light bulb will be glow. If „s2‟ is range between 250W – 450W, it means a light bulb is glow and the value is 60W. If „s2‟ is range between 460W – 500W, two light bulbs will grow and the value is 100W. If „s2‟ is 500W, all the three light bulbs will grow and the value is 200W. Another for function is used with the placement of 0x99 as address register to ADCON0 for the calculation of Phase „B‟. It is followed by a 4ms delay. ADG0 the gain register is set to 1. A while loop function again is executed similar in the case of the Phase „A‟ calculations. At the same time, the next variable „s4‟ is considered to the first variable „st‟ inside the calculation with s4=s4+st; The next phase variable „s4‟ is subject to the interval of power dissipation from the light bulbs in the triple phase energy meter. „s4‟ is used in a „if else‟ conditional function to range out the power consumption of the bulbs. If „s4‟ is zero watts (W), the value will be 0 watt, no light bulb will be glow. If „s4‟ is range between 200W – 340W, it means a light bulb is glow and the value is 60W. If „s4‟ is range between 340W – 450W, two light bulbs will grow and the value is 100W. If „s4‟ is 500W, all the three light bulbs will grow and the value is 200W. Phase „C‟ calculation is done with the use of „s5‟ variable. Mathematical expressions of st = (ADRESH * 256) + ADRESL ; and s5=s5 + st ; are more of less similar compare to Phase „A‟ and Phase „B‟. But the interval range of the power dissipation is different in all the three phases. The next phase variable „s5‟ is subject to the interval of power dissipation from the light bulbs in the triple phase energy meter. „s5‟ is used in a „if else‟ conditional function to range out the power consumption of the bulbs. If „s5‟ is zero watts (W), the value will be 0 watt; no light bulb will be glow. If „s5‟ is range between 10W – 155W, it means a 52 light bulb is glow and the value is 60W. If „s5‟ is range between 155W – 300W, two light bulbs will grow and the value is 100W. If „s5‟ is 500W, all the three light bulbs will grow and the value is 200W. The total power consumption by the three light bulbs will be represented by val3. The calculation is done in the C++ program as val+val1+val2 =val3. The following program code after this is a if conditional for the 1hour=60mins unity power convention and to make sure the calculation only at most count till 60mins and no overshoot to 61mins and beyond. The expression valf in the program is the conversion watt as in total power from the demonstration phase meter of 100W/2mins in aliases with the original power convention of 1KW/hr. The expression un1 is the derivation to check for every 100W/2min unity in this demonstration, how much total power (val3) will be consumed in the load (3light bulbs). Counter is intialised at zero. After which a derivation is also sum up as total power used in specific appliance over the total maximum power of the three light bulbs. un = un2+un1; un2=un; amt = un * 2; // This allows the total amount of power from the loads (three light bulbs) to add together // This is to make sure the addition of total unit is add from un + un1 + un2 and stop // The maximum amount of amt is equal to 2times of un After which, there is a series of CheckBusy() function which helps to check again for previous inputs to be cleared and replaced it with the next preceding new inputs to the LCD. The LCD_SendCmd(0x80) calls for the LCD that the first line of the LCD in the first bit will be start with new inputs. The resultant of the first line will display “ UNIT: ” inside the LCD. The four parameters „U‟, „N‟, „I‟ and „T‟ does not come be straightaway after LCD_SendCmd () function. It goes through the modulus of 10 to change from hexadecimal expression to decimal expression. This is why the program code is inserted with un % 10 in each of the four parameters. The LCD_SendCmd will perform the CheckBusy () function till the last 7th bit which it ends at 0x87 in the first line. The first line is being identified in the representation of the „8‟ in the address register. This is followed by the LCD_SendData () function using the standard ASCII (American Standard Code for Information Interchange) conversion expression 0x30 to change all this four parameters into the machine code which this C++ program recognize and reflected into the LCD as “ UNIT: ”. 53 Figure 43 A delay of 100ms is added after this “ UNIT: ” displayed on LCD. LCD_SendCmd is used again to call 0xc0 for second line in the LCD to start to trigger output from the first bit„0‟. The „c‟ used in the address register is call for the second line in the LCD. The second line will be undergoing another series of CheckBusy() and LCD_SendData () functions similar to first line. The difference will be in the output display which now we will see “ AMT: ” in the second line of the LCD. A conversion expression % 10 is used for displaying of “ AMT: ” in the LCD‟s second line. It is represented by amt % 10 in each of the four parameters. A CheckBusy () function is called and it will check through till the last bit‟7‟ in the second line. This is done by LCD_SendCmd(0xc7). Then, an ASCII conversion is performed by adding 0x30 into each parameter. A delay of 100ms is added after the ASCII conversion. A void function for CheckBusy() is configured towards the ending of the C++ program code. TRISB‟s function over here is to configure ADC inputs. TRISB is set to 0xFF to turn on these inputs. A do function is performed here to select the register (RE0 = 0; , RE is read and write register). Do function also set RE1 to enable high ( RE1 = 1;) and set RE2 to enable high (RE2 = 1;). A delay of 5microseconds (us) is added then follow by a check for all registers into the pointed line if it is free of data and a configuration check if the next preceding inputs can be start to insert into it. (RE2 = 0;) A while program check is used for debugging the information from bit‟0‟ to bit‟7‟ (RB7), ensure CheckBusy() entirely check all the bits before new inputs are inserted. The intialisation turn on of Port „B‟ and TRISB have to be set with 0x00. 54 The last two portions are the void functions call for LCD_SendCmd and LCD_SendData. Read and Write (RE0 / RE1) in set in low and high depending on the requirements of the LCD status. Port „B‟ is used both in the LCD_SendCmd and LCD_SendData as initialization for other ports as well. 4.4 Problems faced at initial As mentioned in the background of the project, many of the synchronization to make sure the designed of PCB layout and schematic diagram able to link together to get a Gerber file pose many problems to me. That is the reason why I have to resort to extend my final year project for another half year. The triple phase energy meter is designed as below with separate portions in terms of the microcontroller unit (MCU) in 40pins. There are many components listings not found in the ExpressPCB software [4]. There are also symbols such as BLK and MLK which I am not sure what it stands for. It can be shown as below figure 44. Figure 44: diagram cited from ExpressPCB software [4] Inside the ADE7878 metering IC circuitry, there is another portion which concerns on the LED circuit and pulse outputs (CF1 and CF2). In order to make modifications for this circuitry, I try my best to alter the parallel or series connections to this diagram, but it seems that I have make lots of connection faults in the print-screen shown below in Figure 45. 55 Figure 45: diagram cited from ExpressPCB software [4] Another PCB drawing which I have done is for the voltage sensing circuit. This is for the three phases which I label it as „VAP‟, „VBP‟ and „VCP‟. There was the problem which I am not sure how to connect this to the MCU 40pins above. Figure 46: diagram cited from ExpressPCB software [4] I have also tried to engage another software call eSketch [5] to do my schematic design and drawing previously. This software has limited options as it does not have a test kit to draw for double layered schematic drawings. Below Figure 47 is the portion which I tried to use the software to draw out the current sensing circuit for the ADE7878. 56 Figure 47: diagram cited from express eSketch software [5] 4.5 Schematic design of the Triple Phase Energy Meter Figure 48: Schematic diagram (Power Supply unit – Bread A) 57 Figure 49: Schematic diagram (MCU unit – Bread B + LCD) Figure 50: Schematic diagram (Relay units – Bread C + Bread D) 58 Figure 51: Schematic diagram (Oscillator circuit) Figure 52: Schematic diagram (Phase A Unit – Bread E) Figure 53: Schematic diagram (Phase B Unit – Bread F) 59 Figure 54: Schematic diagram (Phase C Unit – Bread G) Figure 55: Overall Schematic diagram 4.6 Parts Listing Power Supply Unit (Bread A) R1 200Ω resistor R2 320Ω resistor R3 320Ω resistor C1, C3 10uF capacitor C2, C4 100Nf ceramic capacitor (104) C5, C6 1000uF capacitor D1 1N4007 diode D2 1N4007 diode D3 1N4007 diode D4 1N4007 diode 60 L1, L2 LED translucent white V1 LM7805CV voltage regulator OA1 MC7905CT operational amplifier Figure 56 Microcontroller Unit (Bread B) C7, C8, C9, C10 10uF capacitor U8 PIC16F877A IC R5 1KΩ resistor C11 100nF ceramic capacitor (104) C12, C13 22pF ceramic capacitor (22AEC) SP Serial Port pin holder (used for transmission through MPLABIDE software link from C++ program code to PIC16F877A microcontroller) CO KDS 100 7400 Crystal Oscillator 61 Figure 57 Relay Backup Unit Phase ‘A’ & ‘B’ (Bread C) R6, R7 1KΩ resistor D5 1N4007 diode D6 1N4007 diode T1, T2 SL100B Silicon Transistor RL1, RL2 Electromagnetic Prowest Relay JIHJIQ JQC-3FC (T73) Figure 58 62 Relay Backup Unit ‘C’ (Bread D) T3 SL100B Silicon Transistor RL3 Electromagnetic Prowest Relay JIHJIQ JQC-3FC (T73) R8 1KΩ resistor D7 1N4007 diode Figure 59 Rectifier Unit Phase ‘A’ Unit (Bread E) R9 10KΩ resistor R10 5Ω resistor R11, R12, R16, R18, R19, R22, R23 15KΩ resistor R13, R14, R20, R21 1.3MΩ resistor R15, R26 1Ω resistor R17, R24, R25, R27, R28 1KΩ resistor C14, C15 10uF capacitor C16, C17 DEC/MER 1K250 Metallised Polyester capacitor PA1 HA17458 (0E4) Power Amplifier OA2 MC1458P (XC) Operational Amplifier VP1 BOURNS3296 (122T W501) variable potentiometer VP2 BOURNS3296 (403T W104) variable potentiometer 63 Figure 60 Rectifier Unit Phase ‘B’ Unit (Bread F) R29, R37 10KΩ resistor R30, R38 5Ω resistor R31, R32, R36 15KΩ resistor R33, R34, R41, R42 1.3MΩ resistor R35, R43, R47 1Ω resistor R39, R40, R44 600Ω resistor R45, R46, R48, R49 1KΩ resistor C18, C19 10uF capacitor C20, C21 DEC/MER 1K250 Metallised Polyester capacitor PA2 HA17458 (0E4) Power Amplifier OA3 MC1458P (XC) Operational Amplifier VP3 BOURNS3296 (403T W102) variable potentiometer VP4 BOURNS3296 (902C0 W103) variable potentiometer 64 Figure 61 Rectifier Unit Phase ‘C’ Unit (Bread G) R50, R52, R53, R58, R66, R69 1KΩ resistor R51, R59 100Ω resistor R54, R55, R62, R63 1.3MΩ resistor R56, R67, R68, R70 1Ω resistor R57 2KΩ resistor R60, R61, R64, R65 15KΩ resistor C22, C23 10uF capacitor C24, C25 DEC/MER 1K250 Metallised Polyester capacitor OA4 MC1458P (A) Operational Amplifier OA5 MC1458P XC) Operational Amplifier VP5 BOURNS3296 (403T W104) variable potentiometer VP6 BOURNS3296 (403T W201) variable potentiometer 65 Figure 62 Sideline Unit Saba Power Transformer (Step-Down Transformer, 18V, 1Amp) Figure 63 H1, H2, H3 Light Bulb Holders ( pin type ) Figure 64 CT1, CT2, CT3 Current Transformers (Phase „A‟, Phase „B‟ and Phase „C‟) VT1, VT2, VT3 Voltage Transformers (Phase „A‟, Phase „B‟ and Phase „C‟) 66 Figure 65 LCD Liquid Crystal Display (JHD 162A) Figure 66 4.7 Bread Boards Design Prototype The design at the start is to fabricate out a scale down to size PCB (printed circuit board) of a working triple phase energy meter. Due to the complexity of the software to design with very finite space gaping and surface mounted components to take in consideration, I have decided to take an easier approach to create another type of triple phase energy meter with a fully manual wired separate bread boards in connection triple phase energy meter. As you can see on the left of the Figure 61 below, the power transformer is connected to the main power from either industrial/portable batteries or household power socket. In this demonstration set, household power is the main power supply. The power transformer step down the main power from 220-230V to 5V which is the maximum voltage that this demonstration set can accept. The power from the power transformer will send to the power supply unit which will dissipate it to the current transformers and the voltage transformers. The current transformers from each of the three phases will then convert the AC current from the main power to convert it to the DC current which the rectifier units can accept it to perform its power measurement to the load. Same goes to the voltage transformers from the three phases which will convert the AC voltage to DC voltage to the rectifier units. The microcontroller PIC16F877A as mentioned in the building block section, this is the 67 main brain for the demonstration set. It receives the input data from the rectifier units, and then calculates the unit and amount of the consumed power from the load (three light bulbs). Once the calculation is done, PIC16F877A will send the output data in terms of alphabetical and numerical characters to the LCD displaying out to the user. The electromagnetic relays (in orange colour on Bread C & Bread D) are the deciding factors to call this triple phase energy meter, a “smart” meter. This is because the relays are the feedback system in which the user can choose to ask the triple phase energy meter to cut off the power supply to the load (light bulbs for this demo set) once it reach a certain unit of power. For example, a power unit like „50‟ in the LCD display is set as the cut off power limit to the light bulbs to regulate power consumption. In the start, the triple phase energy meter and the light bulbs are turn on from the main power supply. The LCD starts to accumulate the counting of the power in terms of Unit: (how much the power runs on the light bulbs) and the Amt: (how much the money should charge to the power used). When the counting of the unit reached „50‟ at the LCD, the relays sent the instructions to the PIC16F877A that power has to cut off at the load. Thus light bulbs will be switched off. This is how the „smart‟ triple phase energy meter works in this demonstration set. Figure 67: Front view of triple phase energy meter 68 Figure 68: Front view of triple phase energy meter when it is powered up Figure 69: zoom in view of triple phase energy meter with LCD & LEDs lightings 69 Figure 70: Right side view of assembled triple phase energy meter (powered up) Figure 71: Left side view of assembled triple phase energy meter (powered up) 70 4.8 Things for improvements in future The designed triple phase meter has its own basic feature to do the basic power measurement to output for the power unit and amount throughput. But it is not consider as a full „smart‟ meter. Due to the difficulty in creating the C++ program source code, there is a missing program which is not written to the microcontroller. It is the call sign function for the relays to function as an actual feedback system to link with the microcontroller. Thus, this demonstration set is only capable to measure power consumed and not able to cut off or limit the power used. In the initial, ADE7878 is recommended and chosen to be the microcontroller. The designing of the new circuitry (with ADE7878 on it) with the use of different schematic and PCB layout software has put me into synchronising problems, causing me to delay a lot of time through the second half year of the project time frame. I have to change the plan to design the circuitry using a scale down size PCB layout and used a completely manually wired circuitry to connect each of the components to form the new design prototype. Hopefully, in the future the design is able to form into PCB layout to scale down into smaller size which is compatible for users to bring it easier to use outside, not just inside the home or in the industrial areas. 71 5. CRITICAL REVIEW AND REFLECTION For the past 1.5year in the extended time frame of the project, I have learnt to build a simple design triple phase energy meter. I have learnt how to engage different software to design schematic diagram and PCB layout. I have also use two different microcontroller models to set as the „brain‟ main control system of my design prototype. I admit that I have not able to complete in my first full year of the time frame in my project to base on ADE7878 microcontroller. Although I have seen other models with different brands of metering ICs, I do seen ADE7878 a potential to modify to other prototype of triple phase models in the near future for other researchers to develop it. PCB setup of circuitry requires a lot of consideration to design. In order to make it as compact small as possible, the spacing gap in between components has to take in deep concern. Heat element is the resultant of power loss. If components are built too close to each other, the heat which cost power loss may affect the readings of the actual power output. Not only that, dual-layered components connection or even Qual-layered connection is seen on the real market. This has make the circuit design even more sophisticated and takes even more emphasis on small details which may cause the circuit to malfunction. The decision to make a sudden change from PCB routing of components connection into a compact small size to now a fully manual soldered and wiring based connection is unbearable. I am not able to attain the PCB design and link with a matching schematic diagram to fabricate into a PCB. The difficulty of designing a triple phase model is high. I am not able to do it within a year. I have extended for half year to complete my project. A fully wiring based triple phase energy meter model minimise the risk to consider for PCB layout design routing which have many constraints to consider. 72 6. CONCLUSION After goes through the two completely different models of metering IC to engage into demonstration, I can conclude that using PIC16F877A has to take into programming consideration compare to using ADE7878. Programming software such as Dev/Visual C++ has to set instructions through source code to command the load (light bulbs), relays, voltage transformer, current transformer and rectifier units what to do and execute its actions. This is unlike ADE7878 which has already a programmed system to run its function. Although a certain level of programming knowledge has to put to place when using PIC16F877A, the commands can be able to change according to what is the source code instructs to. My design energy meter was built mainly by wiring based as reason out from the critical review portion. The prototype was tested to be able to interface with the voltage transformer, current transformer and their respective rectifier units depending which phase it is running on. Therefore, it displays the energy value correctly on the LCD. I had also learnt the requisite practical and skills to solve real world engineering problem and solving problems in analog and digital circuit design. Finally I understood the project involving real world systems. 73 7. REFERENCES [1] http://www.analog.com/static/imported-files/eval_boards/EVAL-ADE7878EB.pdf [2]http://www.analog.com/static/imported-files/data_sheets/ADE7854_7858_7868_787 8.pdf [3]http://microstar1.en.ec21.com/3_Phase_Static_Energy_Meter--1441099_1443594.ht ml [4] http://www.expresspcb.com/ [5] http://www.esketch.com [6] Textbook: Cutnell, J.and Johnson, K. (1998), Physics, Vol. 2, Wiley: NY, p. 631, 33, 46, and 49 [7]http://www.softwarepreservation.org/projects/c_plus_plus/cfront/release_e/doc/Refer enceManual.pdf [8] http://www.allaboutcircuits.com/vol_2/chpt_11/2.html [9] http://www.wired.com/science/discoveries/news/2008/08/dayintech_0814 [10]http://books.google.com/books?id=6w5TAAAAMAAJ&q=foucault+currents&dq=foucault +currents&hl=en&ei=AFKbTLm0G47KjAf7uYnyCQ&sa=X&oi=book_result&ct=result&resn um=5&ved=0CDYQ6AEwBDgK [11] http://datasheets.maxim-ic.com/en/ds/71M6513-71M6513H.pdf [12]http://datasheets.maxim-ic.com/en/ds/MAXQ3181.pdf [13] Textbook: A Guide to the Project Management Book Of Knowledge (PMBOK Guide) 4th Edition [14] http://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf [15] http://en.wikipedia.org/wiki/Power_factor [16] http://meettechniek.info/measurement/theory-definitions.html [17] http://www.ganttchart.com/ 74 8. APPENDIX My Gantt Chart Please access (right click and click open hyperlink) the below hyperlink to see the Gantt chart in Microsoft Excel folder: Neo_Jan_Son_Gantt Chart Extended Period 1.5year.xls 75 C++ Program code for the Triple Phase Meter #include #include #include <pic.h> <string.h> <stdio.h> void LCD_SendCmd(unsigned char cmd); void LCD_SendData(unsigned char dat); int i=0, flg=0; int St=0,S1=0,S2=0,S3=0,S4=0,S5=0; int four,three,two,one,val=0,val1=0,val2=0,count=0,valf=0,val3=0; int un=0,un1=0,un2=0,amt=0; void main() { ADCON0 = 0x81; ADCON1 = 0x87; TRISA = 0xff; TRISB = 0x00; TRISE = 0x00; TRISC = 0xb0; TRISD = 0xff; PORTB = 0x00; PORTE = 0x00; PORTC = 0x00; PORTD = 0x00; SPBRG = 64; BRGH = 1; DelayMs(100); LCD_SendCmd(0x38); DelayMs(100); 76 CheckBusy(); LCD_SendCmd(0x06); CheckBusy(); LCD_SendCmd(0x0c); CheckBusy(); LCD_SendCmd(0x01); CheckBusy(); LCD_SendCmd(0x02); CheckBusy(); LCD_SendCmd(0x80); CheckBusy(); LCD_SendData(' '); CheckBusy(); LCD_SendData('A'); CheckBusy(); LCD_SendData('C'); CheckBusy(); LCD_SendData('V'); CheckBusy(); LCD_SendData(' '); CheckBusy(); LCD_SendData('A'); CheckBusy(); LCD_SendData('C'); CheckBusy(); LCD_SendData('C'); CheckBusy(); LCD_SendData(' '); DelayMs(1000); DelayMs(1000); DelayMs(1000); CheckBusy(); LCD_SendCmd(0x01); 77 for(;;) { count = count+1; S1=0; S2=0; S3=0; S4=0; S5=0; for(i = 0; i < 10; i++) DelayMs(4); ADGO = 1; { ADCON0 = 0x89; while(ADGO) continue; St = (ADRESH * 256) + ADRESL; S2=S2 + St; } S2 /= 10; if(S2 == 0) { val = 0; } else if(S2 >= 250 && S2 < 450) { val = 60; } else if(S2 >= 460 && S2 < 500) { val = 100; } else if(S2 >= 500) { val = 200; } for(i = 0; i < 10; i++) { 78 ADCON0 = 0x99; DelayMs(4); ADGO = 1; while(ADGO) continue; St = (ADRESH * 256) + ADRESL; S4=S4 + St; } S4 /= 10; if(S4 == 0) { val1 = 0; } else if(S4 >= 200 && S4 < 340) { val1 = 60; } else if(S4 >= 340 && S4 < 450) { val1 = 100; } else if(S4 >= 450) { val1 = 200; } for(i = 0; i < 10; i++) { DelayMs(4); ADGO = 1; while(ADGO) continue; St = (ADRESH * 256) + ADRESL; S5=S5 + St; } S5 /= 10; if(S5 == 0) { val2 = 0; } 79 else if(S5 >= 10 && S5 < 155) { val2 = 60; } else if(S5 >= 155 && S5 < 300) { val2 = 100; } else if(S5 >= 300) { val2 = 200; } val3 = val+val1+val2; /*if( count <= 60) { valf = valf+val3; } if ( count == 61) { valf = valf/60; un1 = valf/100; count=0; un1 = val3/200; */ un = un2+un1; un2=un; amt = un * 2; CheckBusy(); LCD_SendCmd(0x80); CheckBusy(); LCD_SendData('U'); CheckBusy(); LCD_SendData('N'); CheckBusy(); LCD_SendData('I'); CheckBusy(); LCD_SendData('T'); 80 CheckBusy(); LCD_SendData(':'); CheckBusy(); LCD_SendData(' '); CheckBusy(); four = un % 10; un /= 10; three = un % 10; un /= 10; two = un % 10; un /= 10; one = un % 10; LCD_SendCmd(0x87); CheckBusy(); LCD_SendData(0x30+one); CheckBusy(); LCD_SendData(0x30+two); CheckBusy(); LCD_SendData(0x30+three); CheckBusy(); LCD_SendData(0x30+four); DelayMs(100); LCD_SendCmd(0xc0); CheckBusy(); LCD_SendData('A'); CheckBusy(); LCD_SendData('M'); CheckBusy(); LCD_SendData('T'); CheckBusy(); LCD_SendData(' '); CheckBusy(); LCD_SendData(':'); CheckBusy(); LCD_SendData(' '); CheckBusy(); 81 four = amt % 10; amt /= 10; three = amt % 10; amt /= 10; two = amt % 10; amt /= 10; one = amt % 10; CheckBusy(); LCD_SendCmd(0xc7); CheckBusy(); LCD_SendData(0x30+one); CheckBusy(); LCD_SendData(0x30+two); CheckBusy(); LCD_SendData(0x30+three); CheckBusy(); LCD_SendData(0x30+four); DelayMs(100); //} } } void CheckBusy() { TRISB = 0xff; do { RE0 = 0; RE1 = 1; RE2 = 1; DelayUs(5); RE2 = 0; }while(RB7); 82 TRISB = 0x00; PORTB = 0x00; } void LCD_SendCmd(unsigned char cmd) { PORTB = cmd; RE0 = 0; RE1 = 0; RE2 = 1; DelayUs(5); RE2 = 0; } void LCD_SendData(unsigned char dat) { PORTB = dat; RE0 = 1; RE1 = 0; RE2 = 1; DelayUs(5); RE2 = 0; } 83 IC PIC16F877A Pin Functional Diagram 84 85 86