electrical.measurement.by.microcontroller

Upload: sandeep-kumar

Post on 14-Oct-2015

14 views

Category:

Documents


0 download

DESCRIPTION

it deals with measurement of electrical parameters with micro processors and latest trends in measurement technology with the micro processors and micro controllers

TRANSCRIPT

  • Power Electronics Technology June 2005 www.powerelectronics.com June 2005 www.powerelectronics.com30

    Aquiet revolution is in progress in the utility industry. Electromechanical metering devices, in use for the better part of a century to record electrical energy usage in kilowatt hours, are gradually being

    replaced by multirate, multifunction meters capable of more accurately accounting for utility usage. A new generation of microcontrollers is speeding the progress of this revolution.

    BeginningsIn 1885, Galileo Ferraris discovered that a solid armature

    placed in an out-of-phase ac magnetic eld would rotate at a rate proportional to the ow of electrical energy in the coils that generated the eld. This discovery is the principle on which the great majority of electric meters still operate today.

    In the typical meter, a solid armature is mounted on jeweled bearings and allowed to rotate freely in a sealed container. Coils apply the ac magnetic eld proportional to the amount of power owing through the meter, and a counter detects the number of revolutions made by the disk.

    Microcontrollers Fit the Bill for Electricity MeteringNew MCUs integrate the measurement, computation, communications, memory and display driver functions needed in multirate, multifunction electronic energy meters.

    By Ben Smith, Staff Engineer, Dallas Semiconductor/Maxim, Dallas

    While a century of re nement has made the kilowatt-hour meter one of the most reliable mechanical products in wide production, it remains a mechanical device prone to wear, shock and other events that affect anything with moving parts. Another limitation is that the meter, as usually deployed, maintains no record of the time when usage occurred. The meter only counts revolutions of the wheel and does not record the times when the wheel is moving faster or slower.

    It is useful to know when electric power is consumed, because the demand placed on the electric utility is not constant over time. In fact, much more power is used during waking hours than overnight. Utilities must design their delivery systems to meet demand in the peak hour. This means that for all other times, generators will be operating at less than peak capacity; and since electricity cant be stored, an expensive capital resource is being partially wasted.

    For this reason, electric utility providers have an interest in encouraging energy conservation during peak periods and consumption during off-peak periods. The best way to do this is through selective pricing; that is, charging the customer more for energy consumed during peak periods and providing a discount during slack periods. This is a function of which static kilowatt-hour meters are incapable.

    A third limitation of traditional meters is that they measure only real power. In an ideal world, measuring real power is all that would be necessarycurrent and voltage would ow in phase. However, devices such as induction motors and uorescent lamp ballasts cause current to ow out of phase with the applied voltage. Only the in-phase component is usable as power, the remainder is re ected back into the power grid. As a result, fewer actual watts are used compared to the number of volt-amperes delivered.

    For large industrial customers, electric utilities have long used VAR-hour meters to determine the amount of out-of-phase or reactive power delivered to the customer. With a multifunction meter, utilities can extend power factor monitoring to smaller commercial customers and, in

    400 k

    1 k

    0.1 F

    0.1 F

    1 k

    Neutral

    Hot

    Voltage Sense Hi

    Voltage Sense Lo

    Fig. 1. The voltage channel of the reference electric meter consists of a simple voltage divider providing a ratio of 400-to-1.

  • Power Electronics Technology June 2005 www.powerelectronics.com June 2005 www.powerelectronics.com32

    some cases, to residences. By making multifunction meters standard, a utility can more easily determine where contract terms may need to be adjusted to include power factor penalty language.

    Finally, there is the question of reading the meter and transferring the collected usage data to the billing department. Sending personnel into the eld to record usage is expensive and prone to human error. Add the complexity of having to record usage during several tariff periods, and the burden becomes unacceptable. Some form of automated reading is needed.

    The requirements for increased exibility in measuring usage by time and power factor, improved reading speed and accuracy, combined with the expectation of reliability long provided by mechanical meters, suggests the need for an all-electronic meter built around a microcontroller. In

    fact, electric meter manufacturers since the early 1990s have been producing meters that measure usage electronically and use digital circuits to accumulate and display energy. Now a new generation of microcontrollers are making the design task easier and faster.

    Design FundamentalsThe hardware components of a multirate, multifunction

    meter are simple: a means of taking samples of the input voltage and current through the meter, a display mechanism, a communications subsystem, a nonvolatile memory, a power supply, and a stored-program microcontroller to keep everything in step. The good news for meter designers is that many of these components can be found integrated on the microcontroller itself.

    For example, the MAXQ3120 from Dallas Semiconductor/Maxim, headquartered in Dallas, integrates two 16-bit A/D converters for the voltage and current channels, two UARTS (one con gured for IR communication), an LCD controller and a 16 16 multiply-accumulate unit on a single die, with suf cient data RAM and program ash to provide all the functions mentioned above for a multirate, multifunction electric meter.

    Designing the operating software for such a meter is more challenging. First, since the software de nes the fundamental behavior of the product, it will of necessity be different for each locale. Second, even if designed in a high-level language (like C), the software will have to be customized for the particular hardware environment in which it will run.

    The relative simplicity of the hardware for an electric meter as compared to its operating software actually provides an opportunity for the electric meter manufacturer: since loading the operating software can be a late-stage operation, it is possible to build and stock many base circuit boards for an electric meter, customizing them with individual software loads as they are ordered by the various electric utilities. This is important since overall product cost may well be the make-or-break factor in selling the product to an end customer. Dallas Semiconductor/Maxim provides a reference design in C that can be customized and modi ed to provide any level of functionality needed by the end user.

    Since most modern A/D converters are voltage-input devices, measuring the input voltage is easy, in that it is only necessary to scale the voltage on the input to the range (usually from a few tens of millivolts to about 1 V) required by the differential input of the A/D converter. In the reference design, a resistor network divides the input voltage by a factor of 400. The resistor divider converts the line voltage to the 1-V to 1-V range required by the A/D converter (Fig. 1).

    On the current side, a current shunt converts the current through the meter to a small, millivolt-level voltage. The voltage across the shunt must be kept small to minimize the power dissipated by the shunt: a 0.5-m shunt will provide only a 20-mV full-scale signal, but will dissipate almost 1 W at 40 A (Fig. 2).

    0.1 F

    1 k

    1 kLoad

    Line

    350 Shunt

    Current Sense Hi

    Current Sense Lo

    Fig. 2. The current channel of the reference electric meter uses a current shunt to convert the load current to a millivolt-level voltage.

    From 1 Watt to200 WattsTransformersInductorsFiltersEMI/RFI CMCs

    For UL/CSA recognized magneticcomponents...for SMPSapplications...designed for use with leading semiconductors...forapplication notes and referencecircuits...call Premier, the"Innovators in Magnetics Technology".

    www.premiermag.com

    20381 Barents Sea CircleLake Forest, CA 92630 Tel. (949) 452-0511

    96817.4p1c.Switcher Mag_C&K 1/12/05 9:12 AM Page 1

    CIRCLE 221 on Reader Service Card or freeproductinfo.net/pet

    MICROCONTROLLERS

  • www.powerelectronics.com Power Electronics Technology June 2005www.powerelectronics.com Power Electronics Technology 33

    Now its time to focus on the data conver ters themselves. At rst, the requirements to measure a 50-Hz or 60-Hz signal seem trivial. But on closer inspection, the job is a little tougher. Look at accuracy rst: most specifications call for the meter to have 1% accuracy over i t s en t i re rangenot just full-scale accuracy. T h e r e f e r e n c e design described here has guaranteed accuracy from 1 A to 40 A. To meet this requirement, the meter must successfully resolve current as low as 10 mA, but not saturate until it is measuring more than 40 Aa 4000-to-1 ratio. This means that the data converter can be no less than 12 bits, with a 14-bit or better converter preferable.

    What about sample rate? If the fundamental frequency was all that was of concern, then sampling at some rate above the Nyquist frequency (120 Hz for a 60-Hz system) consistent with conservative anti-aliasing filter design would be suf cient. However, most speci cations require that the meter accurately measure power containing frequencies as high as the 21st harmonic. In a 60-Hz system, that corresponds to a frequency response of 1260 Hz and a sampling frequency of no less than 2520 Hz. While these speci cations are no challenge for modern data converters, they may stretch the capabilities of some of the A/D converters built into many microcontroller devices.

    Hardware Design AnalysisThe hardware for the reference design is shown in Fig. 3.

    The entire meter consists of the MAXQ3120 microcontroller, a power supply, a display, an I2C EEPROM, the input sensors and communication peripherals.

    The reference design described here uses an LCD as a display element. The advantage is obvious. By using annunciators, the display can indicate anything from energy to voltage to time of day.

    The disadvantage of an electronic display is that it shows nothing when the power is off. And while a mechanical counter is inherently nonvolatile, measures must be taken to

    ensure that the last reading displayed is maintained internally by the meter.

    There are simply too many communications schemes in the market today to ever hope to cover every one in an integrated peripheral. It is a reasonable bet, however, that for an inexpensive metering apparatus, it is likely going to be some variant on simple asynchronous serial.

    In the reference design for the MAXQ3120, we settled on two serial peripheral channels. The rst is based on the EIA-485 standard. In this arrangement, the meters reside on a network that is managed by a PC acting as a central controller. As the PC polls the meters, they respond with data packets that represent usage. The PC can then aggregate and transmit the information to a billing facility.

    The second communication channel is an IR transmitter and receiver system based on simple asynchronous protocols. The communications protocol is based on a Chinese electric meter speci cation, DL/T 645, which speci es an IR physical layer that differs signi cantly from those found in commonly used standards. For details on physical layer encoding, see Fig. 4. In the transmitter channel, a circuit modulates the output of the UART so that a 0 is transmitted as a 38-kHz signal and a 1 is represented by the absence of the signal. The receiver is implemented in an inexpensive IC that integrates an IR photodiode and a 38-kHz detector. In this way, only the optical components themselves are required to implement a fully functional IR transceiver system.

    Power is the simplest block. Since modern micro-controllers are low-power devices, a simple transformer-

    CPU

    MAXQ3120 JTAG

    DisplayVoltage Channel

    Segments

    Common

    TxRx

    TxRx

    Tx Enable

    Current Channel

    InfraredCommunications

    Interface

    NetAddressButton

    MeterPulse

    IsolatedEIA485

    EEPROMTim

    e ofDay

    Vdd

    Isolated Vdd

    CurrentShunt

    Load

    Line

    SignalConditioning

    PowerSupply

    Fig 3. Hardware components of the reference design meter. Because of the highly integrated microcontroller, all that is needed is a display, a power supply, a nonvolatile memory, physical devices for communication, and passive signal conditioning for measuring voltage and current.

    MICROCONTROLLERS

  • Power Electronics Technology June 2005 www.powerelectronics.com June 2005 www.powerelectronics.com34

    based linear supply is all that is needed.In the reference design, the microcontroller is not isolated

    from the power line; in fact, the system ground is at line voltage. This makes it impossible to directly connect the network to the microcontroller, because equipment on the network would be exposed to line-level voltages. In this design, a separate winding on the transformer provides power to the network transceiver, and the transceiver is optically coupled to the microcontroller, thus preserving isolation.

    There are two major contenders for a nonvolatile data store for the reference design: semiconductor EEPROM and ferroelectric RAM (FRAM.) The former is much less expensive, but has relatively long write timeson the order of millisecondsand, depending on model, is only guaranteed

    AsynchronousData

    StartBit

    Bit0

    Bit1

    38 kHz Carrier

    Bit2

    Bit3

    Bit4

    Bit5

    Bit6

    833 s Bit Time

    Bit7

    OddParity

    StopBit

    TransmittedCarrier

    Fig. 4. The IR communications channel uses a simple on-off modulation scheme. The presence of a 38-kHz carrier represents a 0 bit, while the absence of a carrier represents a 1 bit. The character format is 8 bits, one stop bit and odd parity.

    to endure between 10,000 and 1 million write cycles. While this might sound like a large number, consider that the software subsystem would like to update the nonvolat i le memory every line cycle. At 50 Hz, that

    means even the best EEPROM might wear out in as little as 5- hours. In practice, a caching subsystem prevents this from happening, but the problem is not trivial.

    FRAM solves these problems at a price. A FRAM has a write cycle that takes no longer than a read cyclea few microseconds, with the bulk of the time being communications overheadand it has an unlimited endurance. The downside is that it can cost several times an equivalently sized EEPROM.

    Choosing a MicrocontrollerThere are several factors to consider when choosing

    a microcontroller for an electric meter. Consider the following:

    Feature set. Does the microcontroller have the

    Part Number VCES IC(90C) VCE(ON, 25C)@ IC(90C) (TYP) EOFF@TJ=125Typ RTH(J-C) Package IGBT CopacksIXGH16N170AH1 1700 V 11 A 4.00 V 1.1 mJ 0.65C/W TO-247 IXGT16N170AH1 1700 V 11 A 4.00 V 1.1 mJ 0.65C/W TO-268 IXGR16N170AH1 1700 V 8 A 4.20 V 1.1 mJ 1.10C/W ISOPLUS247IXGH24N170AH1 1700 V 16 A 4.50 V 2.2 mJ 0.5C/W TO-247 IXGT24N170AH1 1700 V 16 A 4.50 V 2.2 mJ 0.5C/W TO-268 IXGX32N170AH1 1700 V 24 A 4.20 V 3.0 mJ 0.35C/W PLUS247 IXGR32N170AH1 1700 V 17 A 4.20 V 3.0 mJ 0.65C/W ISOPLUS247Phase Leg PackagesFII24N17AH1 1700 V 11.5 A 4.20 V 1.7 mJ 0.95C/W ISOPLUS i4-PAK FII24N17AH1S 1700 V 11.5 A 4.20 V 1.7 mJ 0.95C/W ISOPLUS i4-PAK-Swww.ixys.com

    Cost-Effective Discrete IGBT Copacks for 480VAC to 575VAC Applications

    Optimized for fast-switiching tFI(TYP) < 50ns (25C) for switching frequency up to 100kHz Lower EON/EOFF than series connected devices

    Advantages Induction Heating Induction Cooking Microwave Ovens Offline High Voltage PWM Power Converters 480 to 575VAC Offline Inverter and UPS Applications

    Applications

    1700V NPT IGBTs with SONIC-FRDTM Fast Recovery Diodes

    TO-268-(T)TO-247-(H)

    ISOPLUS247TM-(R)PLUS247TM-(X)

    ISOPLUS-i4PAK-STM-(F..S)ISOPLUS-i4PAKTMISOPLUS-i4PAKTMISOPLUS-i4PAK -(F)

    Efficiency Through Technology

    (1) Samples and datasheets available 6/05. (2) Samples and datasheets available early 7/05. 2500V isolated packages; consult datasheets for more details.

    IGBT COPACK

    PHASE LEG

    G

    C

    E

    GU

    CU

    EU, CL

    GL

    EL

    QU

    QL

    C

    M

    Y

    CM

    MY

    CY

    CMY

    K

    CIRCLE 222 on Reader Service Card or freeproductinfo.net/pet

    MICROCONTROLLERS

  • www.powerelectronics.com Power Electronics Technology June 2005www.powerelectronics.com Power Electronics Technology 35

    peripherals you will need? Look for an integrated time-of-day clock, serial communicat ion peripherals, timers and counters, IR communication, a n d a d i s p l a y controller. You will also require some f o r m o f s i g n a l processing, either on the microcontroller or in an external device.

    Code space. If the application will be written in C, plan on between 16 kbytes and 64 kbytes of code space. The reference design presented here ts comfortably in 32 kbytes.

    Data space. Make sure your microcontroller has enough data RAM to accommodate your data structures.

    Data converters. While many microcontrollers have data acquisition systems built onto the die, often they are low speed, low resolution or both. An ideal converter for a Class-1 meter as defined in IEC61036 would have 14-bits or better resolution, and 10-ksps sample rate or better.

    Real-time clock. Make sure the clock is trimmable to a half-second-per-month accuracy. If it is not, consider an external oscillator or clock module.

    Getting the Software RightIn the reference design, a full, pre-emptive OS was

    considered and rejected on the grounds that it would be unnecessarily wasteful of resources. While the design does need some degree of multitasking, full pre-emption is not required. Instead, a simple main process was built that calls tasks one after another, and each task is designed to do its work and then relinquish control of the processor after a short time. This main process is called the task wheel and performs the work of a simple task scheduler. In this way, every task executes when it must and no task is starved for cycles. See Fig. 5 for an overview of the major software blocks.

    In the electric meter design, every task monitors its input conditions to see if there is anything to be done; if not, it simply returns to the task wheel. For some tasks, the input conditions are based on external events. For example, a sample becomes ready at the A/D converter or a character becomes available at one of the serial ports.

    For other tasks, the condition is strictly internal: an update to the cumulative energy needs to be made or the display

    Priority

    TaskWheel

    IRDriver

    EIA485Driver

    Message Processing

    DSP EngineAsynchronous

    Events

    DisplayFormatter

    MessageBoard

    RegisterManager

    Time ofDay

    Manager

    Scheduling

    Highest

    Normal

    Lowest

    Fig 5. Software components of the reference design meter. Each of the tasks is called by a central task wheel without pre-emption. Higher priority tasks occur earlier in the task list and thus get an earlier chance at processor cycles. The message board facilitates inter-task noti cations, as depicted by bold arrows in the diagram.

    needs to be updated. For these events, the system maintains a set of bits, each of which is set by one task to alert another task that there is a condition that requires its attention. This set of bits is called the message board.

    In a practical meter design, the data elements to be

    CIRCLE 223 on Reader Service Card or freeproductinfo.net/pet

    MICROCONTROLLERS

  • Power Electronics Technology June 2005 www.powerelectronics.com June 2005 www.powerelectronics.com36

    MICROCONTROLLERS

    maintained in storage and the data formats will depend strongly on the communication protocols that are used. The reference design was based on DL/T 645, a Chinese electric meter communication standard. In this standard, usage

    data, configuration information, and many commandsare transferred to and from the meter using a series of registers. Each reg-ister is designated by a four-digit hexa-decimal number and contains one piece of informa-tion: register 9010 contains information about current usage while register C032 contains the serial n u m b e r o f t h e meter.

    Figure 6 i l lu-strates how a mes-sage re ques t ing data from a register

    would be handled. In the illustration, the request begins as it is received at the serial port manager and flows counterclockwise, activating each task along the way until the requested data is nally transmitted at the serial port manger.

    SerialPort

    Driver

    MessageChecker

    MessageBuilder

    MessageFormatter

    RegisterManager

    MessageDecoder

    1. Character by character, the Serial Port Driver alerts the Message Checker that data is incoming.

    5. The Register Manager retrieves data from the register and passes it to the Register Formatter.

    10. As each flag is cleared, completion notification flows up the chain until finally the Message Checker is notified. The system is now ready to process the next message.

    3. When Message Checker receives a complete, valid message, it alerts the Message Decoder.

    4. Messages that require a register read are routed to the Register Manager.

    2. Message Checker acknowledges each character as received.

    6. After creating the response, the Message Formatter alerts the Message Builder.

    8. The Serial Port Driver acknowledges each byte as it is transmitted.

    9. After the last byte, the Message Builder

    clears the flag toward the Message Formatter.

    7. The Message Builder appends a preamble and calculates the checksum and passes the message, byte by byte, to the Serial Port Driver.

    Fig. 6. Message processing in the electric meter reference design. Inbound messages are assembled, decoded and processed; outbound messages are formatted and built by separate tasks that communicate with one another using a message board.

    CIRCLE 224 on Reader Service Card or freeproductinfo.net/pet

  • www.powerelectronics.com Power Electronics Technology 37

    Then, acknowledgments ow clockwise, clearing the busy indication at each task until the entire system is ready for the next inbound message.

    The following narrative provides more detail on the message passing and processing system:

    The message comes in, byte by byte, from the IR receiver module. As each byte comes in, the serial port driver sets a bit in the message board to notify the message checker task of the event.

    When noti ed, the message checker consumes the character from the serial port driver and, if contextually correct, adds the byte to the message queue. The message checker understands message syntax, but does not understand anything about the message payload. When the message has been completely received, the message decoder task is alerted by setting a message board bit.

    The message decoder inspects the incoming message and determines that: (1) it is a read command; (2) it is for a valid register; and (3) there is no other condition that would prevent the execution of the command. If all this is true, the register manager is notified via the message board that a register read is required. Note that the message decoder does not at this time clear the notification given by the message checker. Only one message is handled at a time.

    The register manager interacts with the EEPROM to retrieve the requested information. When nished, it noti es the message formatter that a register is ready to be transmitted. As in the previous step, it does not clear the message ag set by the message decoder.

    The message formatter moves the data just read from the register manager data buffer to the communication buffer. It also sets the message length in the communication buffer before notifying the message builder that a buffer is ready to be transmitted.

    The message builder then sends each byte of the message one at a time to the serial port driver. It is also responsible for calculating the message checksum. When the last byte has been sent, it clears the noti cation bit from the message formatter. On its next turn, the message formatter clears its noti cation bit from the register manager, and so forth until the message chain is clear.

    Every process in the meter works in this way, setting bits in the message board and notifying other tasks of conditions. The primary advantage of using this method is that it requires very little RAM to implement: the entire reference design ts in less than 1/2 kbyte of data RAM. Fully documented source code is available from Dallas Semiconductor/Maxim.

    As utilities are increasingly squeezed by generation prices on the one hand and regulatory pressure on the other, they are increasingly seeking ways of enhancing market ef ciency. With the new generation of microcontrollers now available, meter manufacturers can deliver the means of more ef cient electric power delivery, metering and billing. PETech

    just everywhere

    For superior solutions:Power capacitors

    Power electronics Motor run and lighting Power factor correction

    More information at www.epcos.com

    CIRCLE 225 on Reader Service Card or freeproductinfo.net/pet

    MICROCONTROLLERS