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.

THD Calculation MSP430F779

Other Parts Discussed in Thread: MSP430F6779, EVM430-F6779, TIDM-THDREADING

Hello,

I am working on Total Harmonics Distrotions calculation on MSP430f6779. I am developing my own code for meter. My sampling frequency is 5000 samples per second. I have gone through the TI MSP documentation for calculation of THD and tried accordingly but it didn't worked out.

Can I have flow daigram or some formula which will be helpful in calculation of THD.

Thanks 

Regards

Abhishek Parikh

  • Hello Abhishek,

    So I imagine that you have already looked at the TIDM-THDREADING and EVM430-F6779? You will have to be more descriptive regarding which part of calculation of the THD didn't work out, since a User's Guide as well as hardware and firmware files are provided for you to reference. Here are some E2E threads that concern THD calculations:

    e2e.ti.com/.../433028
    e2e.ti.com/.../447982

    Regards,
    Ryan
  • Hello Ryan Sir,

    Thanks for the reply..

    In the below link the last question is asked by me but it is not replied that's why I've asked the new question.

    e2e.ti.com/.../433028

    Also I have tried applying two methodologies

    1> Using FFT as mentioned in above post e2e.ti.com/.../433028

    In this what I've asked is

    " I want to calculate THD for upto 7th or 15th Harmonic so is there any flow diagram available for that.

    What I am doing for that is I am taking samples and doing fourier transform of it for 16 samples every cycle and because of that what I get is frequency response of it.

    Than I find power of each component by SQRT(real^2 + img^2)

    THD=SQRT(3rd Harmonic^2 + 5th Harmonic^2 + 7th Harmonic^2)/ Fundamental

    But I am getting incorrect THD."


    2> Using formulas from www.ti.com/.../TIDM-THDREADING

    And also I've implemented this by

    for pure sine wave I've made one array of sine wave of my voltage waveform

    _iq12 THDMUL[101]= {_IQ12(0), _IQ12(197.790221174 ),_IQ12(394.799854038),_IQ12(590.251390909),_IQ12(783.373473205),_IQ12(973.403935642),_IQ12(1159.59281416),_IQ12(1341.205305686),_IQ12(1517.524668074),_IQ12(1687.855048756),_IQ12(1851.524230961),_IQ12(2007.886286645),_IQ12(2156.324125682),_IQ12(2296.251931234),_IQ12(2427.117471706),_IQ12(2548.404280154),_IQ12(2659.633692545),_IQ12(2760.366736829),_IQ12(2850.20586536),_IQ12(2928.796523837),_IQ12(2995.828550569),_IQ12(3051.037400546),_IQ12(3094.205189472),_IQ12(3125.161553659),_IQ12(3143.784322376),_IQ12(3149.999999999),_IQ12(3143.784056069),_IQ12(3125.161022096),_IQ12(3094.204394751),_IQ12(3051.036345804 ),_IQ12(2995.827239968),_IQ12(2928.794962549 ),_IQ12(2850.204059547 ),_IQ12(2760.364693619 ),_IQ12(2659.63142 ),_IQ12(2548.401787243 ),_IQ12(2427.114768268 ),_IQ12(2296.249027937 ),_IQ12(2156.321033985 ),_IQ12(2007.883018749 ),_IQ12(1851.520799763 ),_IQ12(1687.851467798 ),_IQ12(1517.520951488 ),_IQ12(1341.20146814 ),_IQ12(1159.588870798 ),_IQ12(973.399902028),_IQ12(783.369365257 ),_IQ12(590.24722484 ),_IQ12(394.795646288 ),_IQ12(19.7785988351 ),_IQ12(-00.004241192 ),_IQ12(-197.794453997 ),_IQ12(-394.804061786 ),_IQ12(-590.255556978 ),_IQ12(-783.377581152 ),_IQ12(-973.407969255 ),_IQ12(-1159.596757519 ),_IQ12(-1341.20914323 ),_IQ12(-1517.528384657 ),_IQ12(-1687.858629711 ),_IQ12(-1851.527662155 ),_IQ12(-2007.889554537 ),_IQ12(-2156.327217375 ),_IQ12(-2296.254834527 ),_IQ12(-2427.12017514 ),_IQ12(-2548.40677306 ),_IQ12(-2659.635965086 ),_IQ12(-2760.368780035 ),_IQ12(-2850.207671167 ),_IQ12(-2928.798085119 ),_IQ12(-2995.829861165 ),_IQ12(-3051.038455283 ),_IQ12(-3094.205984187 ),_IQ12(-3125.162085216 ),_IQ12(-3143.784588677 ),_IQ12(-3149.999999994 ),_IQ12(-3143.783789756 ),_IQ12(-3125.160490528 ),_IQ12(-3094.203600025 ),_IQ12(-3051.035291057 ),_IQ12(-2995.825929362 ),_IQ12(-2928.793401256 ),_IQ12(-2850.20225373 ),_IQ12(-2760.362650403 ),_IQ12(-2659.62914745 ),_IQ12(-2548.399294327 ),_IQ12(-2427.112064825 ),_IQ12(-2296.246124636 ),_IQ12(-2156.317942284 ),_IQ12(-2007.87975085 ),_IQ12(-1851.517368562 ),_IQ12(-1687.847886837 ),_IQ12(-1517.517234899 ),_IQ12(-1341.197630591 ),_IQ12(-1159.584927435 ),_IQ12(-973.395868412 ),_IQ12(-783.365257308 ),_IQ12(-590.243058769 ),_IQ12(-394.791438538 ),_IQ12(-197.781755527 ),_IQ12(00.008482384)};

    than for each and every cycle I detect cross over than from that I multiply pure wave with samples I've got and at end of every wave I divide the addidtion of all the samples of that wave and multiply it by the Kv Voltage multiplier.

    And than I apply the formula .

    I've tried both formula IEC and IEEE but didn't get THD.

    I can provide code if you want.

    Thanks in advance

    Regards
    Abhishek
  • Hello,

    I want to add another little doubt also...

    THD(%) = 100 * SQRT[(V2^2 + V3^2 + V4^2 + ... + Vn^2)] / V1

    May I know how to get values of V2,V3..Vn

    Is FFT's frequency responce gives me this V2, V3..etc?

    Thanks
    Regards
    Abhishek
  • Hi Abhishek,

    Thank you for that detailed response, I apologize that your previous inquiry was ignored. I will consult with a metering expert and return with their response as soon as possible.

    Regards,
    Ryan
  • The response of our metering expert is as such:

    "I would recommend that you use the TIDM-THDREADING software and refer to the documentation in this TI design. We cannot any additional details on how THD is calculated beyond what is mentioned in the design guide. The TIDM-THDREADING TI design works with the MSP430F6779 so this software can even be used as a starting point for your project."

    Regards,
    Ryan
  • Hello Ryan,

    Thank you for your reply.

    I have already gone through  TIDM-THDREADING

    hARMONICS.xls

    Please find this Calculation XLS file in which my sampled data and pure sinewave is there.

    According to IEC formula I'm getting 16% voltage harmonics in excel also same in controller and I have checked in Harmonics Analyzer that 4% voltage harmonics are present in my wave.

    I know I'm making mistake please help me out.

    Thanks

    Regards

    Abhishek

  • Hello Ryan Brown1 (3460875) ,

    According to formula given in   TIDM-THDREADING.

    Please can help me out with following things

    1>Vrms = Kv * (sqrt (SUM (Vph)^2 / Sample Count))

    Page 10 in  TIDM-THDREADING Formulea (3.2.2.1.1(1))

    Vrms = 230 V in normal case and also I've obtained the same. You can check in excel file on above message.

    2> Formulea 3.2.2.1.2(17) Page no. 12

    V fund,ph = Kv *(SUM(Vpure(n) ́* Vph(n))) / Sample Count
    Here V fund,ph = 47260.1348892729

    One question is  1] V fund,ph = Kv *(SUM(Vpure(n) ́* Vph(n))) / Sample Count

    OR

    2] V fund,ph = Kv *sqrt((SUM(Vpure(n) ́* Vph(n))))/ Sample Count

    3> Formulea 3.2.2.1.2 (21) Page no. 13

    IEC   :      V _ THD ph = sqrt(Vrms^2 - V fund,ph^2)/V fund,ph 

    IEEE :      V _ THD ph = Vrms^2 - V fund,ph^2/V fund,ph ^2

    In Case 2] mentioned in 2> if that formula is correct I am getting THD nearby IEEE value.

    Please help

    Thanks 

    Abhishek Parikh

  • Hello

    Have you find anything? Apology for again and again queries but I am bound by timeline and it is urgent for me. Please help.

    Regards
    Abhishek
  • Hello Abhishek,

    I have very little knowledge regarding this topic and can only communicate through the metering expert, I've alerted them as to your recent inquiries and will let you know as soon as they provide a response. Please understand that they are kept busy dealing with multiple issues and require some time before being able to service your request.

    Regards,
    Ryan
  • Hey Ryan,

    Its been a week since you've replied but no one has replied yet. I've tried calculating harmonics using FFT and DFT but nothing comes out.
    Only this part of meter is remaining in our meter please understand the urgency.

    Regards,
    Abhishek
  • Hey Abhishek,

    We can only provide the following comments:

    •Check how your test equipment actually calculates THD. There are a few ways to calculate THD and you must make sure that the calculation method between the MSP430 and the test equipment matches. In the software, there are 3 calculation options(equations 21, 22, and 23). Please follow the instructions in section 3.2.2.1.2 to configure the F6779 to use the proper formula for calculating THD.
    •After making changes to the metrology-template.h file, the metrology project must first be compiled(figure 19) before compiling and loading(figure 20) the app project.
    •Please make sure that the system is calibrated (as described in Section 7.2) before performing any THD accuracy tests.

    Regards,
    Ryan
  • Hello

    Thanks for your reply.

    I am not using TI's code slaa621c or its Meterology Library but developing my own. I'm trying to go through it but can you please provide the flow chart or something which will be easy to understand rather than to understand code.

    Because in meterology-harmonics.c there are formulas like

    amp = cos(phasex)*1.0 + cos(3.0*phasex)*0.10 + cos(5.0*phasex)*0.75;
    phasex += (freq/10.0)*2.0*3.1415926/3276.8;
    iamp = amp*1900.0;

    Which are never mentioned in ti_tidub70a.pdf.

    Also as mentioned in equations 21, 22, and 23 I am not able to find implementation of any of this formula in code.

    So please if Flow chart or algorithm would be available it would be helpful.

    Thanks

    Regards
    Abhishek
  • amp represents a harmonic wave function (can be visualized on a graph), phasex is the frequency step size which increments on each iteration, and iamp is simply a scaling factor.

    Equations 21 through 23 can be found in scaling_tests.c inside of the Energy Code Library -> emeter -> emeter-metrology -> tests folder

    There are no additional flow charts that can be provided outside of the material already available online.

    Regards,
    Ryan
  • I do not understand what you mean by "I am taking samples and doing fourier transform of it for 16 samples every cycle ...".

    Your sample rate is 5000 samples/second, and your fundamental frequency is 50 Hz. Correct? Do you mean you feed the Fourier transform with 1600 samples?

    When you use pure sine wave as input for your Fourier transform, did you get almost no harmonics?
  • Hello ,

    It means 5000 samples/second Frequency is 50Hz so for each wave I get 100 samples.

    I was doing 16 point FFT so I select 16 samples from 100 samples wave like (1st,6th,13th..etc) So I get 16 point FFT response.

    For pure sine wave it should give zero but as I am taking only 16 samples because of this low rate error occurs and it gives me harmonics.

    Now I am trying it with Goertzel Algorithm.

    Thanks for the reply

    Regards
    Abhishek
  • ABHISHEK PARIKH said:
    I was doing 16 point FFT so I select 16 samples from 100 samples wave like (1st,6th,13th..etc) So I get 16 point FFT response.

    That means your effective sampling rate is actually 5000*(16/100)=800 samples/second. You have collected but discarded the other 5000-800=4200 samples/second.

    The 7th and higher harmonic is 7*50=350 Hz and higher. You are destined to get unacceptable results when you only use 800 samples/second.

  • That's exactly where I am suffering. Reason throwing samples away and low point FFT is the calculation of FFT exceeds beyond the time and code size limits.
  • You could try to use FFT and/or fix-point (instead of floating point) with the help of the hardware multiplier to speed up the computation.

**Attention** This is a public forum