TIDUF72 August   2024

 

  1.   1
  2.   Description
  3.   Resources
  4.   Features
  5.   Applications
  6.   6
  7. 1System Description
    1. 1.1 Key System Specifications
    2. 1.2 End Equipment
    3. 1.3 Electricity Meter
    4. 1.4 Power Quality Meter, Power Quality Analyzer
  8. 2System Overview
    1. 2.1 Block Diagram
    2. 2.2 Design Considerations
      1. 2.2.1 Magnetic Tamper Detection With TMAG5273 Linear 3D Hall-Effect Sensor
      2. 2.2.2 Analog Inputs of Standalone ADCs
      3. 2.2.3 Voltage Measurement Analog Front End
      4. 2.2.4 Analog Front End for Current Measurement
    3. 2.3 Highlighted Products
      1. 2.3.1 AMC131M03
      2. 2.3.2 ADS131M02
      3. 2.3.3 MSPM0G1106
      4. 2.3.4 TMAG5273
      5. 2.3.5 ISO6731
      6. 2.3.6 TRS3232E
      7. 2.3.7 TPS709
  9. 3Hardware, Software, Testing Requirements, and Test Results
    1. 3.1 Hardware Requirements
      1. 3.1.1  Software Requirements
      2. 3.1.2  UART for PC GUI Communication
      3. 3.1.3  Direct Memory Access (DMA)
      4. 3.1.4  ADC Setup
      5. 3.1.5  Foreground Process
      6. 3.1.6  Formulas
        1. 3.1.6.1 Standard Metrology Parameters
        2. 3.1.6.2 Power Quality Formulas
      7. 3.1.7  Background Process
      8. 3.1.8  Software Function per_sample_dsp()
      9. 3.1.9  Voltage and Current Signals
      10. 3.1.10 Pure Waveform Samples
      11. 3.1.11 Frequency Measurement and Cycle Tracking
      12. 3.1.12 LED Pulse Generation
      13. 3.1.13 Phase Compensation
    2. 3.2 Test Setup
      1. 3.2.1 Power Supply Options and Jumper Setting
      2. 3.2.2 Electricity Meter Metrology Accuracy Testing
      3. 3.2.3 Viewing Metrology Readings and Calibration
        1. 3.2.3.1 Calibrating and Viewing Results From PC
      4. 3.2.4 Calibration and FLASH Settings for MSPM0+ MCU
      5. 3.2.5 Gain Calibration
      6. 3.2.6 Voltage and Current Gain Calibration
      7. 3.2.7 Active Power Gain Calibration
      8. 3.2.8 Offset Calibration
      9. 3.2.9 Phase Calibration
    3. 3.3 Test Results
      1. 3.3.1 Energy Metrology Accuracy Results
  10. 4Design and Documentation Support
    1. 4.1 Design Files
      1. 4.1.1 Schematics
      2. 4.1.2 BOM
      3. 4.1.3 PCB Layout Recommendations
      4. 4.1.4 Layout Prints
      5. 4.1.5 Altium Project
      6. 4.1.6 Gerber Files
      7. 4.1.7 Assembly Drawings
    2. 4.2 Tools and Software
    3. 4.3 Documentation Support
    4. 4.4 Support Resources
    5. 4.5 Trademarks
  11. 5About the Authors

Background Process

Figure 3-3 shows the different events that occur when sampling voltage and current, where the items in green are done by the MSPM0G1106 hardware modules.

TIDA-010944 Voltage and
          Current Sampling Events Figure 3-3 Voltage and Current Sampling Events

New current samples for each phase are ready every OSR, or 1024 modulation clock cycles for this design, thus resulting in 4000 samples per second over the SPI bus to MSPM0+ MCU. The data transfer consists of two transactions: sample contains 12 Bytes, with three Bytes data on each of the two ADS131M02 channels and then another 15 Bytes, with data for one channel for the shunt and twice 0x00 00 00 data for the unused and disabled per software other two analog input channels for AMC131M03.

Suppose the most recently ready phase current and voltage samples from the ADS131M02 and AMC131M03 devices corresponds to the Nth – 1 current and voltage sample, or Iphx[N – 1] and Vphx[N – 1]. Once new samples are ready, the DRDY pin is asserted low by the ADS131M02. The falling edge on the DRDY pin on the ADS131M02 causes a GPIO port interrupt on the MSPM0+ MCU, which triggers the Port ISR, and the background process is run within the Port ISR. The AMC131M03 also raises the DRDY pin interrupt and that is served immediately after the ADS131M02 read out over SPI is finished.

Figure 3-4 shows the background process, which mainly deals with timing-critical events in the test software.

TIDA-010944 Background
          Process Figure 3-4 Background Process

In the background process, the previously-obtained voltage samples (Vphx[N – 2]) and previously obtained current samples (Iphx[N – 2]) are stored so that these samples can be used later by the per_sample_dsp () function, which is responsible for updating the intermediate dot product quantities used to calculate metrology parameters.

After the previously-obtained voltage and current samples from ADS131M02 and AMC131M03 are stored, communication to the ADS131M02 is enabled by asserting the respective chip select signal low. The DMA is then configured to both send a request for the newest current and voltage samples (Iphx[N – 1] and
Vphx[N – 1]) of the ADS131M02 device and also to receive the data packet response from the ADS131M02. The request (transmitting dummy data of 0x00) and reception of the latest ADC data samples is done automatically by the DMA module.

Figure 3-5 shows the packet that is transmitted by the DMA of the MSPM0+ MCU and the response packet from the ADS131M02 or AMC131M03 that is received by the DMA as well. The transmission and reception packets contain four or five words, where each word is three bytes long, resulting in 12 or 15 Bytes DMA transaction over the SPI bus. Note that the ADS131M02 packet is 12 Bytes long, as only two channels with three bytes each are read out through the DMA transaction, while AMC131M03 needs 15 Bytes. The firmware handles the ADC device selection automatically and reads data out in a round-robin manner, as the firmware updates the DMA parameters for each ADC, including the packet data length and activates the correct CS line to each ADC.

TIDA-010944 ADS131M02 and
          AMC131M03 ADC Sample Request Packet Figure 3-5 ADS131M02 and AMC131M03 ADC Sample Request Packet

When requesting the ADC data from the ADS131M02 device, the first word that has to be sent to by MSPM0+ MCU is the command word. Since the test software does not need to change the settings of the ADS131M02 or read any registers during typical ADC sample readouts, a NULL command is sent to the ADS131M02, which allows the designer to get the ADC samples from the ADS131M02 without changing the state of the device.

The actual size of the null command is 16 bits; however, since 24-bit words are used, the 16-bit command must be padded with an extra value of 0x00 at the end of the command. The NULL command word sent; therefore, has a value of 0x00 00 00. While the MSPM0+ MCU is shifting out the command word, the MCU is simultaneously shifting in the response word to the command word of the previous packet. The response word to a NULL command is the contents of the STATUS register. The contents of the STATUS register is not used in this design so the first word received from the ADS131M02 is ignored (not processed in the software code).

After writing the command word, a dummy write must be performed for each byte that is to be read. The dummy byte write is necessary to enable the SPI clock, which is necessary to read a byte from the ADS131M02 device. For each dummy byte write, a value of 0x00 is written to the SPI transmit register. Immediately after writing the command byte, writing three dummy bytes allows the MSPM0+ MCU to receive the 3-byte ADC value from channel 0 of the ADS131M02. Writing the next 3 dummy bytes gets the ADC data for channel 1 and writing the next three dummy bytes gets the CRC word. The CRC word is 24-bits; however, note that the actual CRC is only 16 bits, which are placed in the most significant bits of the 24-bit word. As a result, when parsing the CRC word, the last byte is not needed (note though that the dummy write for this zero-padded byte must still be sent though for proper ADS131M02 operation).

Whenever the DMA has received the entire Iphx[N – 1] packet, the DMA ISR is automatically called. Within the ISR, the CRC is calculated over the three command and the ADC channel data words (3 × 3 = 9 Bytes in total). This CRC calculation can be done in two modes: either using the CRC module of the MSPM0G110 MCU or using the memcpy() function to move the 9 Bytes ADC data to a special memory area where CRC16 is auto-calculated.

Immediately after the SPI data from AMC131M03 is read out, but using the NULL command and three channels of 24-bit data and CRC16 with a padded 0x00 Byte. This completes the read in of the current samples Iphx[N – 1] of the AMC131M03 device, then the CRC16 checksum is also checked.

See the ADS_verifyADSCRC() and AMC_verifyAMCCRC() routines for details of the CRC16 check implementation. The memcpy() implementation achieves almost 5 × faster calculation than using the CRC16 registers with bytewise feed and is hence used by default. The CRC module can be fed with 8- or 16-bit data, and since there are nine bytes total, the CRC module is being updated byte for byte. Once the CRC has been calculated over the packet, the check is compared to the CRC obtained in the packet sent from the ADS131M02. The sent CRC is parsed from Bytes 10 and 11 (the last Byte 12 is the zero-padding for CRC16, so this value gets ignored).

If the calculated CRC and the parsed CRC are equal, then the CRC check is correct and the ADC data is parsed to get the values of the voltage and current samples at time N – 1. Two variables are used to count the good and bad CRC16 packets for each ADC, called crcPassCount and crcFailCount. The parsed voltage and current samples are put in temporary buffers so that this information is used when the per_sample_dsp() function is called at the next interrupt. When the SPI transfer over DMA ends, the CS (chip select) line is automatically pulled back high again from the MSPM0+ MCU to properly reset the AMC131M03 communication before the next time current samples are ready for readout.

In parallel to transferring the latest current and voltage samples Iphx[N – 1] and Vphx[N – 1] to the MSPM0+ MCU using the DMA channels, the ADS131M02 is already sampling the next voltage (Vphx[N]) and current samples (Iphx[N]) while the test software performs per-sample processing on the earlier voltage (Vphx[N – 2]) and current samples (Iphx[N – 2] ) obtained from the ADS131M02 and AMC131M03. This per-sample processing is used to update the intermediate dot product quantities that are used to calculate the metrology parameters. After sample processing, the background process uses the per_sample_energy_pulse_processing for the calculation and output of energy-proportional pulses. The test software exits from the port ISR once the per_sample_energy_pulse_processing is completed.

In summary there are two SPI read data cycles during a single DRDY cycle, the ADS131M02 device is read out first and then the AMC131M03. The only difference between these two SPI transactions is that ADS131M02 has two channels while AMC131M03 has three, so the SPI data packet length is either 12 Bytes or 15 Bytes total.