This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F6779A: Energy calculation in datasheet

Part Number: MSP430F6779A


In the datasheet: Implementation of a Three-Phase Electronic Watt-Hour Meter Using MSP430F677x(A) (Rev. G), a formula for calculating the enerqy is presented. According to me this formula is incorrect because it does not take time into account. Also, it seems dependent of the number of samples you take durring one second. Could someone explain why they do it this way and if its correct or not. The formula is in the image below. 

  • An MSP430 team member is assigned to review your issue, please expect a response shortly.

  • Hello,

    The power calculations shown are correct. At a high level, the result is the average power across a set number of samples, SampleCount. However, keep in mind that SampleCount doesn't need to equal the sampling rate - this would average the power across 1 second which is fine. On the flip side, it probably wouldn't make sense to run the calculations after each sample.

    The energy calculations are fundamentally correct - they just don't show the conversion from Watts to KWH. The final result just depends on the sampling frequency, number of seconds per hour, etc. to convert from Watts seconds to KWH units. While there doesn't seem to be a time element on the surface here, multiplying the average power by SampleCount to get energy actually includes a time element. How? Well, there's the time between each sample. Thus, the time taken for SampleCount can be found by multiplying it by the sampling period, 1/sampling frequency.

    I hope this makes more sense.

    Regards,

    James

  • Dear James,

    Thank you for your prompt reply. We did figure out most of what you wrote, from the datasheet. And, it was a mistake from our part for not clearly specifying the energy unit of WattSecond (J). We also  figured out that you equate 1s = 4096 samples (sampling rate), thus energy = power * sampling rate. We just cant figure out how do you maintain the same energy value (W-s) with a different sampling rate, say at 2048 samples/s or 8192 samples/s. Whereas the power value stays true irrespective of the sampling rate.

    Could you please elaborate on it, preferably with a few examples with varying sampling rate. 

    Waiting for your earliest reply.

    With Warm Regards,

    Neal

  • Hello,

    Thanks for your detailed reply.

    Subhronil Chaudhuri said:

    We just cant figure out how do you maintain the same energy value (W-s) with a different sampling rate, say at 2048 samples/s or 8192 samples/s. Whereas the power value stays true irrespective of the sampling rate.

    Could you please elaborate on it, preferably with a few examples with varying sampling rate. 

    Good question. Assuming that SampleCount is fixed and we just double the sampling frequency, the average power calculation would get calculated in half the time. Now, for the average energy calculation, we're multiplying the average power by SampleCount which includes a time-element based on the sampling frequency. Keep in mind that energy here has [Watts-samples] units. To convert to [Watts-second] units, you need to divide by the sampling frequency (or multiply by the inverse of the sampling frequency): Eact [Watts-samples] x 1/sampling frequency [seconds/samples] = Eact [Watts-seconds].

    Does that make sense? This way, the energy value is correct for any sampling frequency. I hope this helps.

    Regards,

    James

  • Dear James,

    Thanks for the explanation, it makes complete sense. Except when I look into this bit from the document SLAA577G (attached in the image below), we are a bit confused with your distinction between Sample Count and Sampling frequency.  The datasheet defines "Sample count = Number of samples in one second". 

    If we were to double the sampling rate from 4096 Hz to 8192 Hz, the sample count would double as well, as per the document's definition. 

    Eagerly waiting for your reply. 

    Regards,

    Neal

  • Hello,

    In my previous post, I just assumed that the SampleCount was a fixed value for both sampling frequencies for sake of discussion. To maintain the same periodic update/calculation at varied sampling frequencies, then yes, SampleCount would need to change too.

    Regards,

    James

  • Dear James,

    With all due respect, the following statement; "To maintain the same periodic update/calculation at varied sampling frequencies, then yes, SampleCount would need to change too." means that that with twice the sampling rate, their is twice the energy, and half the energy with half the sampling rate. 

    Eagerly waiting for your response. 

    P.s. we have run the scenarios in matlab, and our statement holds true.

    Regards,

    Neal

  • Hello,

    Subhronil Chaudhuri said:
    With all due respect, the following statement; "To maintain the same periodic update/calculation at varied sampling frequencies, then yes, SampleCount would need to change too." means that that with twice the sampling rate, their is twice the energy, and half the energy with half the sampling rate. 

    Sure, but keep in mind that the units here would be Watts-samples, not Watts-seconds.

    James Evans said:
    To convert to [Watts-second] units, you need to divide by the sampling frequency (or multiply by the inverse of the sampling frequency): Eact [Watts-samples] x 1/sampling frequency [seconds/samples] = Eact [Watts-seconds].

    Did you do this? This ensures that the calculated energy is the same for all sampling rates across the same period of time. For fixed Vrms and Irms inputs as a reference, the energy calculation should remain the same whatever the sampling rate is.

    I've demonstrated this in my Matlab script below. Feel free to change "Fsample" and "SampleCount" to match your desired sampling frequency. As I mentioned earlier, change "SampleCount" according to "Fsample" to maintain the same update rate. For example, if you'd like to perform the calculation every 1/2 second, then "SampleCount" should be 1/2 "Fsample". Notice that the energy calculation gets halved compared to performing the calculation every 1 second - this makes sense because energy is based on time.

    % Initialize workspace and command window
    close all;
    clear;
    clc;
    
    % Declare variables
    Fsample = 8000;                         % Units: Hertz
    SampleCount = 8000;                     % Units: Samples
    
    % Declare AC mains inputs
    Vrms = zeros(1,SampleCount);
    Irms = zeros(1,SampleCount);
    for n = 1:SampleCount
        Vrms(n) = 230;                      % Units: RMS Volts
        Irms(n) = 10;                       % Units: RMS Amps
    end
    Pact = 0;
    Eact = 0;
    
    % Calculate active power
    for n = 1:SampleCount
        Pact = Pact + (Vrms(n)*Irms(n));
        if n == SampleCount
            Pact = Pact/SampleCount;        % Units: Watts
        end
    end
    
    % Calculate active energy
    Eact = Pact*SampleCount;                % Units: Watts-samples
    Eact = Eact/Fsample;                    % Units: Watts-seconds
    
    % Print calculated values
    X = sprintf('For a sampling frequency of %d Hz with SampleCount equal to %d samples, Pact = %d W and Eact = %d W-s.',Fsample,SampleCount,Pact,Eact);
    disp(X)

    Results:

    For a sampling frequency of 8000 Hz with SampleCount equal to 4000 samples, Pact = 2300 W and Eact = 1150 W-s.

    For a sampling frequency of 8000 Hz with SampleCount equal to 8000 samples, Pact = 2300 W and Eact = 2300 W-s.

    Does this answer your question? If so, please mark the thread resolved. Thanks.

    Regards,

    James

  • Yes, we agree and have been in unison with your statement, but unfortunately, the last bit of information of converting watt-samples to watt-seconds is missing from the datasheet, hence our uproar.

  • Hello,

    Subhronil Chaudhuri said:
    Yes, we agree and have been in unison with your statement, but unfortunately, the last bit of information of converting watt-samples to watt-seconds is missing from the datasheet, hence our uproar.

    I wouldn't call it an uproar - it was a valid question, and I've submitted the feedback internally to update the equation in the future.

    Also, thanks for marking the thread resolved. If you have any further questions, please feel free to open a new thread. Thanks.

    Regards,

    James

**Attention** This is a public forum