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.

[FAQ] MSP430F67791A: Metering data required within 100 ms with EMDC

Part Number: MSP430F67791A
Other Parts Discussed in Thread: EVM430-F6779, , TUSB3410, MAX3232, MSP-ISO

Hello James,

sorry to bring back this discussion/queries again after several tries.Now looking at some alternate solution.

1) Could not able to get the desired results in 100mSec time using the TI library ( SLAA577G )

2)  If i move to TI's new EMDC library , can you (or TI Team ) help to get the results within 100msec.

     Need Reverse power detection + Voltage, Current,Frequency, PF, Power metering.

3) Looking at critical timing requirement, do you have any application code for the above requirement ( without any library ... just thinking it will give faster result .May be i am wrong !! )

Regards,

Ars

  • that's an innovative way to free-source your engineering to the chip vendor.

  • Hi Ars,

    If you're using a single-phase configuration, then results within 100 ms should be possible. I tested this a few months ago on the i20xx and achieved cycle-by-cycle updates by making a single change in the 'hal_adc.c' file that's generated by EMDC. This is partly possible by the high default baud rate of 250k baud.

    Let's assume your nominal AC mains frequency is 50 Hz. Also, let's assume your sampling rate is 4096 samples. Dividing the sampling rate by the AC mains frequency gives you the number of samples per AC mains cycle. That equals ~81.92 samples or 82 complete samples. Thus, if you want a cycle-by-cycle update, you'd need to change the update limit in 'hal_adc.c' to trigger after 82 samples.

    The else if() is a time-out after 2 seconds to report results when the AC mains are not connected (e.g. no zero crossings are detected). gEmSWConfig.algorithmConfig->mainNomFreq is equal to the sampling rate which is 4096 by default but depends on what's selected in EMDC. This allows the update to happen every 1 second normally. Changing gEmSWConfig.algorithmConfig->mainNomFreq to 82 samples will result in an update rate of ~20 ms which is less than 100 ms. You can obviously adjust the number of samples to report after two, three or four cycles.

    Original code

    if(gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->cycleCount == gEmSWConfig.algorithmConfig->mainNomFreq)
    {
    	phaseDataReady |= HAL_ADC_PHASE_A_DATA_READY;
    	EM_perDataChunk(&gEmSWConfig, (EM_SW_Lib_Result_Handle *) &gEmSWResult, EM_PH_A_IDX);
    }
    else if (gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->sampleCount > (2*EM_SAMPLING_FREQ_HZ))
    {
    	phaseDataReady |= HAL_ADC_PHASE_A_DATA_READY;
    	EM_perDataChunk(&gEmSWConfig, (EM_SW_Lib_Result_Handle *) &gEmSWResult, EM_PH_A_IDX);
    }

    Modified code

    if(gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->cycleCount == 82)
    {
    	phaseDataReady |= HAL_ADC_PHASE_A_DATA_READY;
    	EM_perDataChunk(&gEmSWConfig, (EM_SW_Lib_Result_Handle *) &gEmSWResult, EM_PH_A_IDX);
    }
    else if (gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->sampleCount > (2*EM_SAMPLING_FREQ_HZ))
    {
    	phaseDataReady |= HAL_ADC_PHASE_A_DATA_READY;
    	EM_perDataChunk(&gEmSWConfig, (EM_SW_Lib_Result_Handle *) &gEmSWResult, EM_PH_A_IDX);
    }

    Regards,

    James

  • Hello James,

    Thanks for the support.

    James Evans said:
    If you're using a single-phase configuration, then results within 100 ms should be possible. I tested this a few months ago on the i20xx and achieved cycle-by-cycle updates by making a single change in the 'hal_adc.c' file that's generated by EMDC. This is partly possible by the high default baud rate of 250k baud.

    Yes I am using it for single phase application.your test results sound good !

    As the metering section is  one part of My application project....and it will take some time re-porting new emdc library to the original project.

    is there a way to create a library file out of EMDC source code , add this library to main IAR project and get meter data using certain APIs.

    rgds,

    Ars

  • Hi Args,

    Ars said:
    As the metering section is  one part of My application project....and it will take some time re-porting new emdc library to the original project.

    Yes, that's understandable. While you do that, I would recommend keeping a "golden" EMDC project that just contains the auto-generated code. This way, you have a solid reference if you need to debug (compare) the code in your ported project.

    Ars said:
    is there a way to create a library file out of EMDC source code , add this library to main IAR project and get meter data using certain APIs.

    This should be possible. I would be concerned that it adds some overhead or complexity that can't be debugged easily (at first anyway).

    [FAQ] Creating Library for MSP430 Project using CCS v5

    How to create library for MSP430 in IAR workbench

    Regards,

    James

  • Hi James,

    Thanks for your support.

    James Evans said:
    While you do that, I would recommend keeping a "golden" EMDC project that just contains the auto-generated code. This way, you have a solid reference if you need to debug (compare) the code in your ported project.

    Nice idea.I take this approach in general. surely i would do for this too.

    Thanks & Rgds,

    Ars

  • Hi Ars,

    That sounds great.

    Regards,

    James

  • Hi James,

    James Evans said:
    I would recommend keeping a "golden" EMDC project that just contains the auto-generated code

    I have started getting hands on using EMDC library with the objective that I can get the update of metering parameter <100 msec.Just generated code for MSP430F67791A part keeping 1 voltage and 1  current (PHASE_A) channel ,Sampling Freq = 4096 Hz, OSR = 256,
    SMCLK = 16.777 MHz
    I m using IAR to compile the code.
    And for the EMDC code exercise , I am using same custom board(HW) where metering code based on SLAA577 library working ok.
    To keep the thing clean, I have not merged my main application code to emdc generated code as on date. While I am stepping thru' the code ,Code gets stuck in an infinite loop
    in function call ...void UCS_initFLL(uint16_t fsystem,uint16_t ratio)....where a DCOFFG is being checked.

    while(HWREG8(UCS_BASE + OFS_UCSCTL7_L) & DCOFFG)
    {
        //Clear OSC flaut Flags
        HWREG8(UCS_BASE + OFS_UCSCTL7_L) &= ~(DCOFFG);
    
        //Clear OFIFG fault flag
        HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
    }
    Can you pls advise on where I could have gone wrong.
    
    Next , 
    My measuring signal frequency is 40 Hz to 70 Hz. 
    In EMDC GUI under “Advanced Parameters” There are parameters IIR Max Frequency and IIR Min Frequency.Why they are required ? How to select those frequency ? Can you pls explain in detail.
    What would be those parameters given my measuring signal frequency.
    
    In EMDC GUI under “Basic Parameters” there is selection for AC Mains Frequency.I have selected 50 Hz.Can the generated code work for my signal frequency range of 40 – 70 Hz ?
    
    Thanks & Rgds,
    Ars

  • Hello Ars,

    Ars said:
    I am using same custom board(HW)

    I'm assuming you don't see this issue on the EVM430-F6779. I suspect it's a crystal fault (XT1), but you can read about other things that may cause DCOFFG to set and how to properly configure XT1 in the UCS Module Fail-Safe Operation section in the MSP430x5xx and MSP430x6xx Family User's Guide.

    Ars said:
    In EMDC GUI under “Advanced Parameters” There are parameters IIR Max Frequency and IIR Min Frequency.Why they are required ? How to select those frequency ? Can you pls explain in detail. What would be those parameters given my measuring signal frequency.

    This is the upper and lower input frequency that you expect. For more details, refer to the EMDC Technology Guide.

    Ars said:
    In EMDC GUI under “Basic Parameters” there is selection for AC Mains Frequency.I have selected 50 Hz.Can the generated code work for my signal frequency range of 40 – 70 Hz ?

    The frequency under Basic Parameters is your expected nominal input frequency. The IIR max and min define the frequency range. If you increase that range, you'll want to increase the lookup table size to maintain accuracy across those input frequencies. For more details, refer to the EMDC Technology Guide.

    Regards,

    James

  • Hi James ,

    Thanks.

    James Evans said:
    I'm assuming you don't see this issue on the EVM430-F6779. I suspect it's a crystal fault (XT1), but you can read about other things that may cause DCOFFG to set and how to properly configure XT1 in the UCS Module Fail-Safe Operation section in the MSP430x5xx and MSP430x6xx Family User's Guide.

    No. It's not a crystal fault (XT1) . As i mentioned i am running old SLA577g based code also in the same custom board.And it's working good.No DCOFFG set.

    Only EMDC generated code has stuck at DCOFFG.

    James Evans said:
    The IIR max and min define the frequency range. If you increase that range, you'll want to increase the lookup table size to maintain accuracy across those input frequencies.

    Ok. got the point. That means,  IIR min and max should be 40Hz & 70Hz ....if expected signal is in the 40 - 70 Hz range.

    .(1)...And in my application i want to do following ... hope you can help me by giving guidance or api to use from the emdc code itself.

    Example : R phase volt = 220 V, R phase  current = 5 A at unity pf Active power = 1100 W ,  being 1phase system

    now think , i am giving provision to connect voltage to any of phase R or Y or B but current from R phase and let's consider this :

    Y phase volt = 220 V, R phase  current = 5 A  .at unity pf Active power will be same 1100 W . i.e i would like to virtually phase shift the Y phase voltage by 120 degree in code so that it represents R phase voltage. and then multiply by R phase current to bring Active Power same value.

    can you guide me with any reference/code to do that.Just phase shifting Y phase voltage by 120 degree in this case is my requirement.

    (2) is TI EMDC team considering to make the EMDC GUI communication interface to MSP430 board ...more generic?As i understand ,at present EMDC GUI connects to MSP430 board using MSP4305529 launchpad ( HID bridge ) + MSP ISO . But i can't use it as My custom board connects to EMDC GUI thru' TUSB ic interface . i.e  MSP430F67791A => UART => TUSB3410 => USB PORT => PC EMDC GUI.Hence custom board not able connect to GUI.

    It would have been  better if the interface is just an uart....then as a user i can connect max3232 or tusb ic in between the PC EMDC GUI and  MSP430.I believe like me... many others would be benefited.Appreciate your effort and support. 

    Rgds,

    Ars

  • Hi Ars,

    Ars said:

    No. It's not a crystal fault (XT1) . As i mentioned i am running old SLA577g based code also in the same custom board.And it's working good.No DCOFFG set.

    Only EMDC generated code has stuck at DCOFFG.

    I couldn't duplicate this on the EVM430-F6779. In EMDC, I changed the MCLK frequency to 16,777,216 Hz, generated the code, imported it into CCS and then programmed/debugged the device. As you can see below, there is no DCOFFG. Again, I suspect that your issue stems from your custom board and perhaps the XT1 crystal. For example, the SLAA577 code uses XT1DRIVE_3 whereas EMDC code uses XT1DRIVE_0. You may need to adjust these things according to your design.

    Regards,

    James

  • Hi Ars,

    Your last two questions are wandering outside of the scope of your initial question. I'll address them briefly here, but you'll need to make a new thread for them if you want to discuss them further.

    Ars said:
    can you guide me with any reference/code to do that.Just phase shifting Y phase voltage by 120 degree in this case is my requirement.

    Preload will only adjust a few degrees, so you'll need to use whole sample delays. Those are implemented in the SD ADC ISR per phase in 'hal_adc.c'. Search for "sample alignment variables" in 'hal_adc.c'. For an input signal of 50 Hz and sampling rate of 4096 Hz, the samples per cycle are 4096 / 50 = 81.92 samples per cycle. Each cycle represents 360 degrees. To shift 120 degrees, that's 1/3 cycle, so that's a shift of ~27.3 whole samples between voltage and current. However, keep in mind that the amount of shift per sample depends on the input frequency!

    Ars said:
    It would have been  better if the interface is just an uart....then as a user i can connect max3232 or tusb ic in between the PC EMDC GUI and  MSP430.I believe like me... many others would be benefited.Appreciate your effort and support. 

    The choice to use USB HID over CDC was intentional, so users don't need to worry about installing platform-specific drivers which are required for CDC. The EMDC GUI can still work with your custom board. Just connect the UART RX and TX pins to the MSP-ISO board (and power and ground of course). Keep in mind that you can control your board over UART using a serial terminal on your PC using the command packets described in the Protocol section in the EMDC Technology Guide.

    Regards,

    James

  • James,

    good to know that, you have tried to duplicate the.. things at your end.Thanks.

    James Evans said:
    I couldn't duplicate this on the EVM430-F6779. In EMDC, I changed the MCLK frequency to 16,777,216 Hz, generated the code, imported it into CCS and then programmed/debugged the device. As you can see below, there is no DCOFFG. Again, I suspect that your issue stems from your custom board and perhaps the XT1 crystal. For example, the SLAA577 code uses XT1DRIVE_3 whereas EMDC code uses XT1DRIVE_0. You may need to adjust these things according to your design.

    That could be a point.But theoretically both should have worked given that Crystal frequency and 3.3V is good enough on my custom board.Anyway ...for my case , it worked by replacing the EMDC code generated function UCS_turnOnLFXT1(UCS_XT1_DRIVE_0, UCS_XCAP_0)   <==  by   LFXT_Start(XT1DRIVE_3)  from SLAA577 code.

    static void hal_system_ClockInit(uint32_t mclkFreq)
    {
        PMM_setVCore(PMM_CORE_LEVEL_3);
    
             // UCS_turnOnLFXT1(UCS_XT1_DRIVE_0, UCS_XCAP_0);  // commented
    
        LFXT_Start(XT1DRIVE_3);  // taken from SLAA577g library
    
        UCS_initClockSignal(
           UCS_FLLREF,
           UCS_XT1CLK_SELECT,
           UCS_CLOCK_DIVIDER_1);
    
        UCS_initClockSignal(
           UCS_ACLK,
           UCS_XT1CLK_SELECT,
           UCS_CLOCK_DIVIDER_1);
    
        UCS_initFLLSettle(
            mclkFreq/1000,
            mclkFreq/32768);
    }

    Regards,

    Ars

  • James,

    Thanks for your inputs

    James Evans said:
    Your last two questions are wandering outside of the scope of your initial question. I'll address them briefly here, but you'll need to make a new thread for them if you want to discuss them further.

    Ok.understood.In case require more to discuss  on these 2 questions , i will come back with separate thread.

    James Evans said:
    Preload will only adjust a few degrees, so you'll need to use whole sample delays. Those are implemented in the SD ADC ISR per phase in 'hal_adc.c'. Search for "sample alignment variables" in 'hal_adc.c'. For an input signal of 50 Hz and sampling rate of 4096 Hz, the samples per cycle are 4096 / 50 = 81.92 samples per cycle. Each cycle represents 360 degrees. To shift 120 degrees, that's 1/3 cycle, so that's a shift of ~27.3 whole samples between voltage and current. However, keep in mind that the amount of shift per sample depends on the input frequency!

    Let me apply the concept to my specific requirement.

    James Evans said:
    The choice to use USB HID over CDC was intentional, so users don't need to worry about installing platform-specific drivers which are required for CDC. The EMDC GUI can still work with your custom board. Just connect the UART RX and TX pins to the MSP-ISO board (and power and ground of course). Keep in mind that you can control your board over UART using a serial terminal on your PC using the command packets described in the Protocol section in the EMDC Technology Guide.

    understood ..TI's preference for HID over CDC.but again it requires an extra Kit/board.As you said it still work on UART....let me try with my set-up:

    [CUSTOM BOARD] MSP430F67791A - UART <===> TUSB3410 <===> USB-PC [ EMDC GUI ] . Hope it would work.

    Now coming back to my original question:

    plz note for EMDC library , i am using the same custom board which is well calibrated and functionally ok with SLAA577G library.

    I was trying to calibrate my board programmed with EMDC code via DEBUGGING mode.

    As per your suggestion in earlier post , I have modified the section of the code in hal_adc.c which  triggers the phase data ready as under:

    if(gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->cycleCount == 328) // data worth of 80 msec , 50HZ mains => 82 samples , 80 msec data => 328 sample count
    {
        phaseDataReady |= HAL_ADC_PHASE_A_DATA_READY;
        EM_perDataChunk(&gEmSWConfig, (EM_SW_Lib_Result_Handle *) &gEmSWResult, EM_PH_A_IDX);
    }
    else if (gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->sampleCount > (1*EM_SAMPLING_FREQ_HZ))
    {
        phaseDataReady |= HAL_ADC_PHASE_A_DATA_READY;
        EM_perDataChunk(&gEmSWConfig, (EM_SW_Lib_Result_Handle *) &gEmSWResult, EM_PH_A_IDX);
    }

    and also modified .voltageSF , .currentSF , .activePowerSF, .reactivePowerSF , .phaseCorrection  in the process of calibration.  i have these observations:

    Injected Volt = 220V AC , I = 1Amp , PF =1

    after calibration My product reads Volt = 219.9 V AC , Current = 0.99Amp , PF = 1 , Active Power = 219 W , Apparent Power = 220 VA.

    Then i went for phase calibration with PF =0.5 ( angle 60 deg) , V& I same as above.But surprisingly this time Apparent Power got changed.With PF = 0.5 it reads 215 VA.It should not get effected with Power Factor change.

    To correct it , If i change .phaseCorrection from 0 to 255 , i do not get the require result for both PF = 1 and 0.5 

    What could be the problem.Which file(s) and section of code... i should look for to find solution.

    Thanks & Rgds

    Ars

  • Hi Ars,

    Ars said:
    I was trying to calibrate my board programmed with EMDC code via DEBUGGING mode.

    What does debugging mode mean? Do you mean calibration mode using the EMDC GUI?

    Ars said:
    and also modified .voltageSF , .currentSF , .activePowerSF, .reactivePowerSF , .phaseCorrection  in the process of calibration.

    How did you perform the calibration? I would highly recommend performing the calibration using the EMDC GUI. When completed, you can save them to INFO memory or you can save the EMDC project to update the calibration values in the generated code. If you don't save the EMDC project, then the updated calibration values won't get generated the next time you do that.

    After using the EMDC GUI to perform calibration, you can note the calibration factors and then manually change them in your custom code.

    Ars said:

    Injected Volt = 220V AC , I = 1Amp , PF =1

    after calibration My product reads Volt = 219.9 V AC , Current = 0.99Amp , PF = 1 , Active Power = 219 W , Apparent Power = 220 VA.

    Good details here. Thanks for sharing them.

    Ars said:
    Then i went for phase calibration with PF =0.5 ( angle 60 deg) , V& I same as above.But surprisingly this time Apparent Power got changed.With PF = 0.5 it reads 215 VA.It should not get effected with Power Factor change.

    Actually, Apparent Power depends on both Active Power and Reactive Power. If the phase calibration is not done correctly, then Reactive Power will not be correct which impacts the Apparent Power. This also impacts the Power Factor.

    Ars said:

    To correct it , If i change .phaseCorrection from 0 to 255 , i do not get the require result for both PF = 1 and 0.5 

    What could be the problem.Which file(s) and section of code... i should look for to find solution.

    If you use the EMDC GUI and the EMDC-generated code on your custom board and perform the gain and phase calibration, the results should be correct for PF = 0 and PF = 1. As I mentioned above, after calibration is done, you can save the EMDC project, regenerate the code and see what's changed. For gain, the scaling factors change. For the phase calibration, the preload (fractional delay) and buffer offsets/pointers (whole sample delay done in software) will change.

    I hope this helps.

    Regards,

    James