The MAXQ3120 is a single-chip microcontroller with integrated peripherals to form the heart of a multirate, multifunction electricity meter. This document describes how to build, configure, and operate an electricity meter based on this reference design.
The MAXQ3120 Electric Meter Reference Design helps you produce a standards-compliant electric meter based around the MAXQ3120 RISC microcontroller. The electricity meter meets all Class 1 requirements as defined by IEC 61036 and conforms to the multifunction and multirate requirements of Chinese standards GB/T 15284 and DL/T 614. In addition, the meter records usage according to a user-programmable tariff schedule, and reports this data using a protocol compliant with Chinese standard DL/T 645.
The meter consists of the MAXQ3120 microcontroller and a few other components. Source code, schematics, bill of materials, and sample PCB layouts are available and easily customized to provide the basis for electricity meters that meet specific regional requirements. The files to accompany the application note can be found here. This reference design package provides the information necessary for a designer to construct an electricity meter application; general MAXQ3120 applications should use the MAXQ3120-KIT kit.
Nominal voltage: 220V ±10%
Base current: 10A
Maximum current: 40A
Frequency: 50Hz, ±10%
Communications: Asynchronous IR, EIA485
Meter pulse output: Dry isolated output, variable meter constant, variable pulse width
Besides a few external components, the hardware for this reference design consists of subsystems contained within the MAXQ3120. The economy of design is possible due to the high integration in the MAXQ3120:
- 8MHz, 16-bit RISC CPU core
- 16k, 16-bit words of program storage, implemented as flash memory
- 512 bytes of data RAM.
- Two, 16-bit A/D converters with a conversion interval of 48µs
- A 16 x 16 hardware multiplier with a 40-bit accumulator
- Three timers
- Two UART channels with independent baud rate generators, one with a special mode to ease IR communication
- A time-of-day clock with digital trim and alarm capability
- An LCD controller capable of driving 112 segments in a X4 multiplex configuration
With the MAXQ3120's complement of internal peripherals, only a small set of external parts are needed:
- A power supply that delivers two isolated 3.3V outputs. Isolation is critical, since in normal operation the logic ground is connected to the hot side of the line.
- An LCD. In this design, we selected a 6-digit LCD with custom annunciators.
- A nonvolatile memory component, usually an I2C EEPROM or FRAM. In the reference design, we selected a 128k (16kB) EEPROM.
- Communication peripherals. In this design, we have two channels: an optically isolated RS-485 buffer and an IR channel. The IR channel consists of an IR LED driven by an external PNP transistor, and an integrated IR receiver tuned to a 38kHz carrier frequency.
- An LED and opto-isolator for optical and electrical meter pulse outputs.
The reference design also includes an external time-of-day clock chip, the DS3231. While the MAXQ3120 contains an integrated real-time clock, the clock is not compensated for temperature (although the microcontroller does contain a digital trim register that could be used for this purpose.) The DS3231 contains a time-of-day clock, a trimmed crystal, and a temperature sensor that automatically compensates the clock. This device is fully supported in code.
The reference design also provides for an external voltage reference. Although the MAXQ3120's internal voltage reference provides sufficient accuracy over temperature for most applications, an external reference can be used where high precision is demanded.
The reference design is built around a simple task wheel: tasks are called one after another and generally run until they are finished, or until they need data from another task. Tasks communicate with one another through a simple array of bits called a Message Board and a set of global variables. For example, when the serial port driver receives a character, it loads the character into a global variable and sets the Character Ready bit in the Message Board. The Message Checker then retrieves the character from the global variable and clears the bit in the Message Board.
The software is designed to be flexible and customizable. Each task handles a subset of functionality so that features can be removed or enhanced easily. The Message Checker, for example, interprets the packet structure of the DL/T 645 protocol and sends the payload to the Message Decoder. To use a different packet structure, one only needs to recode elements of the Message Checker (and on the encoding side, the Message Builder); there is no need to rewrite the entire application.
All electrical connections are made from the bottom of the meter, and are designated by numbers embossed in the plastic terminal block:
|WARNING: De-energize all power sources before connecting the meter. Failure to do so could result in damage to the meter or injury to the operator.|
Terminal 1: Service hot—Connect this terminal to the hot side of the incoming service.
Terminal 2: Load hot—Connect this terminal to the hot side of the load.
Terminal 3: Service neutral—Connect this terminal to the neutral side of the incoming service.
Terminal 4: Load neutral—Connect this terminal to the neutral side of the load.
Terminal 5: Meter pulse positive—Connect to the positive side of a meter pulse receiver. See Meter Pulse below in Table 1 and the Calibration section for more information.
Terminal 6: RS-485 positive—Connect to the positive (A) side of an RS-485 network, if used.
Terminal 7: Meter pulse negative—Connect to the negative side of a meter pulse receiver. See Meter Pulse below, for more information.
Terminal 8: RS-485 negative—Connect to the negative (B) side of an RS-485 network, if used.
There are three steps that must be performed before the installation is complete. First, the meter address must be assigned. Second, any custom values must be loaded into the meter's operating registers. Finally, the meter must be calibrated. (Calibration will typically be performed at the factory and not in the field, so this last step may have already been done.)
Assign an address to the meter by using the Set Meter Address command under the DL/T 645 protocol. A newly installed meter will have an address of 00 00 00 00 00 00. The meter will respond only to the Set Meter Address command, and only to the first such command.
You can use either the IR or the EIA-485 interface to perform the address assignment operation. However, if more than one meter is already installed in an EIA-485 network, all these meters will respond to the Set Meter Address network command and will, consequently, have the same address. For this reason, it is recommended to either set meter addresses before installation or use the IR interface to set meter addresses in a multiple-meter installation.
If it becomes necessary to change the address, perform the following steps:
- Remove the meter's cover by removing two screws at the bottom of the cover, and then tilting the cover up and off.
- Locate the square white pushbutton near the row of LEDs. Using a non-conductive instrument, press the button. The meter will display NET-10 and will begin to count down ten seconds.
- Send the DL/T 645 address set message while the meter is displaying NET-xx. If the message is properly received, the meter will display -SEt-.
Typical Meter Values
Once the address has been set, meter-operating parameters must be configured. Several commonly used values and the registers are given in Table 1 below.
Table 1. Typical Values for Configuring an Electricity Meter
|Setting||Register||Units||Typical Value||Entry Value|
|Meter Constant, real||C030||Pulses/kWh||1,600||00 16 00|
|Meter Constant, reactive||C031||Pulses/kVar||1,600||00 16 00|
|Meter Pulse Width||C211||ms||50||50 00|
|Customer Number||C033||001234567890||90 78 56 34 12 00|
|Meter Number||C032||009988776655||55 66 77 88 99 00|
|Voltage Channel Gain||E125||Unity = 0x8000||32,768||00 80|
|Current Channel Gain||E124||Unity = 0x8000||32,768||00 80|
|Phase Offset||E127||See below||0||00 00|
To set these values, you can use any software package capable of operating with DL/T 645-compliant meters. To use the PC demonstration software, see the discussion below.
Before calibrating the meter, make sure that reasonable values are set in the Meter Constant register and the Meter Pulse Width register. You should also verify that voltage and current channel gain are set to unity (0x8000), and that the phase offset is set to zero. Calibration can be performed using the automated mechanisms built into the reference design meter by following these procedures:
- Place a known, calibrated voltage on the line inputs to the meter.
- Place a known, calibrated, resistive load on the meter's load outputs to draw a current between Ib and IMAX.
- Write register EFFF. In the data field, provide four bytes: Vlow, Vhigh, Ilow, Ihigh
For example, if you are providing 10A at 220V, the data field would be:
20 02 00 10
- The display should indicate --CAL-- and, after a few seconds, the meter should reset. Following reset, the meter should be calibrated, and the calibration values can be read from E124, E125 and E127.
Dallas Semiconductor/Maxim provides software to communicate with the reference design meter (or, for that matter, any DL/T 645-compliant meter.) This section describes its use.
The communications software requires an industry-standard PC with the following characteristics:
- Windows® 98SE, Windows ME, Windows 2000, or Windows XP operating system
- One COM port
The software will work with either an IR interface or an RS-485 interface. Note that the IR interface is not IrDA compliant; it is a custom physical layer dictated by the DL/T 645 standard. Any standard RS-232 to RS-485 converter should serve as a link between a standard PC and the electricity meter. Note that some converters use RTS as a transmit signal (that is, data flow is from the RS-232 side to the RS-485 side), and that other converters use the first transition on TxD as a signal to begin transmitting, and an idle condition for one character period as a signal to turn off the transmitter. The software should work with either type of RS-232 to RS-485 converter.
Figure 1. The software for the electricity meter reference design shows the most used commands at the top.
The software's main window (Figure 1) is organized into two general regions: the top half with the most-used controls; and the bottom half, used more for initial calibration and troubleshooting.
The combo box at the very top of the window contains a drop-down list of commonly accessed registers. You can select one of these registers and click the Read Data button. The software will transmit a Read Register message to the meter, and expect a response. The results will be displayed in the text box just below the Read Data button.
Figure 2. The Direct Register Read/Write menu selection lets you read a register not listed in the top-level drop-down menu.
If you wish to read a register not listed in the drop-down box, you can fill in the register number in the Address box in the Direct Register Read/Write section, and then click Read (Figure 2).
Below the results box are three items used to control and monitor the communications port. The window at the extreme left indicates the status or "health" of the selected comm port. If this indicator is not green, you will not be able to communicate with the meter. To the right of the communications status indicator is a drop-down box to select a port. Further to the right is a drop-down box to select a baud rate.
Directly below the communications panel is a set of buttons that perform specialized functions. They are described below:
- Set Time: Sends a DL/T 645 Set Time message with the current time of day from the PC.
- Set Date: Sends a DL/T 645 Set Date message with the current date from the PC.
- Clear Max: Sends a DL/T 645 Clear Maximum Demand message. This causes the meter to reset all maximum demand registers to zero, and to increment the number of times that maximum demand is cleared register.
- Set Addr: Sends a Set Address message to the meter, using the address given in the Data text box. The data must be formatted as six groups of two digits.
In general, a meter will only respond to a DL/T 645 Set Address message if some manual operation has been applied to force the meter to expect the message. In this way, many meters can be connected to the PC through the RS-485 connection without interfering with each another. As explained above, in the reference-design meter the manual operation required is to remove the top cover and activate the net button. When this is done, the display will indicate nEt-10 and begin counting down. When the Set Address message is received, the display will indicate -SEt- and then return to normal operation.
There is one exception to the need to activate the net button: when a meter is installed for the very first time. In this latter case, the meter is operating in Address Set mode until an address is received.
Figure 3. The ID and Passwords dialog lets you set both the network address for the meter and up to ten passwords.
- Set Pwd: Sends a Set Password message to the meter. DL/T 645 supports up to ten passwords, numbered 0 to 9. If passwords are used, they must be provided by means of a write to register, C212, before any operation can occur. Register C212 is a write-only register that expires one minute after the last protected operation.
To set a password, load PP VV VV VV into the Data text box. Here PP is the number of the password to assign, and VV VV VV is the value that you want to assign to the password. The Set Password command will be sent with the currently active Superuser Password as a credential.
- ID: Opens the ID and Passwords dialog (Figure 3):
This dialog is used to set the meter's network address and to set the passwords to use as credentials. The first text box contains the Meter ID, or the network address of the meter. Enter the address of the meter to which you wish to communicate; enter the address as a single string of twelve digits. If you want to use the broadcast address (999999999999), check the Use Broadcast box.
The three text boxes below the Meter ID box contain passwords for three levels of privilege. Password 0, the Superuser Password, is the only password authorized to change other passwords, including itself. Passwords 1 and 2 are the Normal Passwords, and can be presented to change any value in the meter. Finally, passwords 3 through 9 are Read-Only Passwords. Users presenting these latter passwords can only read the meter and cannot change any register, nor can they clear maximum demand.
Suppose, for example, that you are a meter reader and know that password 4 is '123456'. You can select 4 in the drop-down beside the Read-Only Passwords box, and then type '12 34 56' in the text box. Click the radio button beside the Read-Only Passwords text box, and then click the Done button. The software will then present password 4 as its credential the next time it attempts to read a register.
Figure 4. The dialog for automatic calibration makes it an easy three-step process to get calibration values loaded into the meter.
Automatic calibration is the easiest way to get calibration values into the meter. When you click the Cal M1: Auto automatic calibration button, the dialog shown in Figure 4 will appear. Performing calibration is now a quick, three-step process:
- Apply a known voltage and a known current to the meter, at a power factor of 0.5L. Enter the V and I values in the Tester Vn and Tester Ib boxes. (The V_scale (V) and I_scale (A) are for information only; they display the maximum voltage and current which the meter can measure.)
- Click the Run Auto Cal button. The meter will display -CAL- as it calibrates itself, and will finally reset and begin operating normally.
- As a check, click the Read Cal Registers to check the voltage-gain (E125), current-gain (E124), and phase-offset (E127) registers.
When finished, click the Close button to return to the main screen.
Figure 5. You can calibrate the meter manually by using the Cal M2:Manual menu.
If you prefer to calibrate the meter manually, the Cal M2:Manual manual calibration button brings up the manual calibration dialog (Figure 5). Performing manual calibration involves the following steps:
- Apply a known voltage and a known current to the meter, at a power factor of 1.0. Enter the V and I values in the Tester Vn (V) and Tester Ib (A) boxes. (The V_scale (V) and I_scale (A) are for information only; they display the maximum voltage and current which the meter can measure.)
- Click the Reset registers button. This will set the gain registers to unity (0x8000) and the phase offset register to zero.
- Click the Read RMS button. This will read the RMS voltage and current in internal meter units and compare them to the expected values (from the values given in step 1 above.) The results will be displayed in the window at the bottom of the screen.
- Click the Adjust Gains button. The software will read the RMS values and calculate the gain settings necessary to normalize the voltage and current to the values given in step 1.
- Set the test equipment to generate power factor 0.5C. Click the Calc Error (ErrC) button. The error will appear in the box. This represents the difference between the expected value (exactly half the apparent power value) and the value read from the meter.
- Set the test equipment to generate power factor 0.5L. Click the Calc Error (ErrL) button. The error will appear in the box.
- Now click the Do PHC button. The software will calculate the phase offset value from the error values, and write it to the meter.
- To verify the values written, click the Dump Cal Registers button. The values will appear in the window.
The reference design meter contains a built-in debugger that permits reloading the operating firmware. Firmware updates are sent as Intel .HEX files and can be loaded onto the meter using the MAX-IDE software package. This section describes the firmware reloading process.
|WARNING: All power sources to the meter MUST be de-energized before beginning the firmware reload process. Elements of the electric meter operate at line potential. Failure to remove power can damage the meter or the PC to which it is connected, or injure the operator.|
Before you begin the process, you should have a PC with MAX-IDE installed and a serial-to-JTAG adapter configured and connected. You will use this PC to transfer the new .HEX file to the electric meter.
- Remove all power from the meter.
- Remove the meter's cover by removing two screws from lower portion of the transparent cover and tilting up. Retain these screws.
- Remove the PCB from the meter by removing four screws, one from each corner. Retain these screws.
- Connect a wire from pin 1 of BR2 (the positive DC pin) to J10. This wire may be left in place, if desired. In this way, firmware reloading can be performed in the future without removing the PCB from the meter.
- Replace the PCB into the meter case, and secure with the four screws removed in step 3 above.
- Connect a serial-to-JTAG adapter to JH1. Note that pin 1 of the connector is toward the top of the board.
- Start MAX-IDE (Figure 6).
Figure 6. Firmware is loaded onto the meter by using the MAX-IDE software.
- Under the Device menu, select MAXQ JTAG.
- Under the Device menu, select Load.
Figure 7. When you load the firmware, select the .HEX file format.
- Select the HEX Files to load and click Open.
- The file will be transferred to the meter.
- When complete, disconnect the meter from the JTAG board and replace the two screws removed in step 2. The firmware update is now complete.