Post Go back to editing

We are using the ade9113.c/.h example code in our design and we attempting to use the ade9113_convert_to_millivolts() to read data from the x_WAV Registers but there seems to be no accounting for any kind of scaling in the code.

Thread Summary

The user is trying to scale the raw 24-bit two's complement values from the ADE9103's I_WAV, V1_WAV, and V2_WAV registers to millivolts and amperage. The final answer clarifies that the ADC transfer function VxP-VxN = (1.25V * waveform_code) / 2^23 should be used for all ADC channels, regardless of AC or DC measurements. The accompanying answers confirm that the waveform_code is the sign-extended 24-bit value from the respective register, and that the current can be calculated using I = V / R after determining the voltage across a shunt resistor.
AI Generated Content
Category: Software
Product Number: ADE9103
Software Version: None listed on GitHub

We are using the ade9113.c/.h example code in our design and we attempting to use the ade9113_convert_to_millivolts()  to read data from the x_WAV Registers but there seems to be no accounting for any kind of scaling in the code. 

Specifically, we are using the ADE9103 device to measure DC voltage and DC Current.

Each x_WAV Register is 24 bits and stores information in a two's complement format so it can represent a positive and negative voltage range. A 24 bit signed integer can represent a range can be  -8,388,608 to 8,388,607.  

Page 6 of the datasheet indicates:

  • the Analog input Differential Voltage Range for IP and IM pins (current) is +/-  31.25 mV
  • the Analog input Single-ended Voltage Range for IP and IM pins (current) is +/-  500 mV

                   

Current Calculation: +/- 31.25mV

When I read the contents of the I_WAV (current) register,  the value it holds, or each unit should represent the entire range divided by how many units of measurement or  (31.25 mV) / (8,388,607)  or  0.0000037252907425511768521281304512179 mV...

So I would think when I read this register I should be multiplying the contents by  0.00000372529 to properly scale it to mV.

Voltage Calculation: +/- 31.25mV

Using the same reasoning, when I read the contents of the Vx_WAV (voltage) register the value it holds, or each unit should represent the entire range divided by how many units of measurement or  (500 mV) / (8,388,607)  or   .000059604651880818829634050087219487 mV...

Again, I would think when I read this register I should be multiplying the contents by  .0000596046518 to properly scale it to mV. 

The ade9113_convert_to_millivolts() function:

Meanwhile the ade9113_convert_to_millivolts() function does not appear to do any scaling when reading the x_WAV Registers. It only sign extends the value. see code below:          

         /**
         * @brief Convert a 24-bit raw sample to millivolts.
         * @param dev - The device structure.
         * @param dev_no - Device number (0 if in not in daisy-chain setup).
         * @param ch - Device channel.
         * @param mv_val - Value in millivolts.
         * @return 0 in case of success, negative error code otherwise.
         */
         int ade9113_convert_to_millivolts(struct ade9113_dev *dev,
         uint8_t dev_no, enum ade9113_wav_e ch, int32_t *mv_val)
         {
             int64_t value = 0;

             if (!dev)
                 return -ENODEV;

             if (ch > ADE9113_V2_WAV)
                 return -EINVAL;

             switch (ch) {
                 case ADE9113_I_WAV:
                     /* times 2, two's complement data */
                     value = (int64_t)dev->i_wav[dev_no];
                     break;
                 case ADE9113_V1_WAV:
                     value = (int64_t)dev->v1_wav[dev_no];
                     break;
                 default:
                     value = (int64_t)dev->v2_wav[dev_no];
                     break;
             }

              *mv_val = (int32_t)value;

             return 0;
         }I

Questions: 

  1. I want to know if my math (above) for scaling the x_WAV registers for current and voltage is correct or not. If not what am I doing wrong. 
  2. Any idea why there is no scaling done in the ade9113_convert_to_millivolts() function? Are they expecting the calling function has to handle this scaling? 
  3. After scaling is there anything else that needs to be done to convert it to amperage? 

Thanks - mike

  • Hi Mike, 

    The ADC isn't designed quite like that. Slight smile 

    In the ADC Transfer Function section, there is a an equation for both ADC channels. Solve it for the differential output voltage. That's going to give you something close to what the ADC is seeing at the input of the V1 or V2 channels.

    VxP-VxN=(1.25V * waveform_code)/2^23  

    What you will ultimately do with calibration, is put a known voltage on the far side of the field side of the voltage divider. That is how you calibrate away the ADC offset, ADC gain error,... and tolerances of the voltage divider and other components. 

    Regards,

    Jason

  • Hi Jason,

    I don't understand a few things. 

  • Hi Jason,

    Thank you for getting back to me. I have some questions.  I am really just trying to figure out what formula we need to apply to the raw data we read from the three X_WAV 24bit registers. Just to make sure we are on the same page, here is a step by step list of what we are currently doing, and where we are stuck.

    • First we read the three separate 8-bit registers (HI, MD, LO) for each of the i_wav, v1_wav, and v2_wav Registers.
    • We then combine the HI, MD, and LO for each register together into a single 32 bit integer and extend the sign (Bit 23) accordingly.
    • We are stuck trying to figure out what math do we need to apply to each of the following registers i_wav, v1_wav, and v2_wav registers to get the current and voltage reading?  If it just applying the formula you gave us that’s great and we’ll give it a shot.

     

    That said, I have some questions about the formula you gave us, see below.

                        (VxP-VxN = (1.25V * waveform_code)/2^23)  

                                                             OR 

                                        (1.25V * waveform_code)

                 (VxP-VxN  =   -------------------------------------

                                                           2^23        

     

    1. We are using the ADE9103 for DC only should we still use the formula above to calculate the V1 and V2 voltage or the Current?

     

    1. Is the formula above good for calculating the V1 voltage, V2 voltage, or the Current?

     

    1. We are using the ADE9103 for DC only should we still use the differential formula (above) to calculate the V1 voltage, V2 voltage, or the Current?

     

    1. What is the “waveform_code” in the formula above?
      1. Is this the actual contents of the I_WAV Register (after we combine the three bytes and sign extend it into a single two’s complement integer)?
      2. Same question for the V1_WAV Register?
      3. Same question for the V2_WAV Register?

     

    1. I do not see the formula above in the datasheet. Is it derived from either of the two formulas mentioned in the “ADC Transfer Function” section on page 25  ade9103 datasheet (see below)?   If not what is its origin?

                           

      6. There is a DC Metering section on page 30 of the data sheet. However there are no formulas mentioned here. We are using the ADE9103 to measure DC only and would expect this section to describe what needs to be done when reading the three 24-bit registed.... its very confusing. 

    i apologize for all the questions, i am just trying to undertand it all and get it right. As i said before the example code does not show what to do here. 

    Thanks - mike

     

  • I'd highly recommend doing a long format operation to bring back all ADC samples at the same time. 

    The ADC waveform data is a representation of the instantaneous voltage. Its the same formula if you are measuring an AC or DC. 

    All ADC channels measure voltage. The I_WAV is a representation of the voltage, its the voltage on the IP pin minus the voltage on the IM pin. Presumably, you are measuring across a shunt with those pins. You use the formula in the datasheet (Equation 2) to get the voltage across the shunt. You know the shunt value from the datasheet of that part. Then you solve for current with I=V/R. 

    The 24-bit registers are two's compliment. Convert that into base 10 which is what the formulas in the datasheet is calculating and what I was referring to with waveform_code. The formulas I wrote are just rearranging the terms from equations 1 for the voltage channels in the datasheet.

    Regards,

    Jason 

  • Hi Jason,  

    Yes, I took your advice a while back and we are doing a long read of the scratchpad register to retrieve all three wav Registers, STATUS0 and 1 Registers. 

    Initially I had no idea on how the device worked. After integrating the driver it became obvious to me why you had suggested the Long register operations. This way, as you said a while back, we get everything we need for calculating the current and voltage measurements in one operation. 

    Thanks - mike