• Resolved

MSP430I2021: Modifying EMDC library to support large currents

Prodigy 140 points

Replies: 14

Views: 337

Part Number: MSP430I2021

Hello,

Is it possible to modify the EMDC library to suit my particular needs?  For example, i would like to design a meter with a maximum range of 6000A.  The IRMS register is in uA, which cannot represent more than 4294A (32bit unsigned).  Do you offer source code or have any idea how to trick the library into giving me mA?

Thanks,

Scott

  • Part Number: MSP430I2021

    The technology guide seems to be very light.  Are there more detailed guides available?  I have generated code using the energy measurement design center with the intent of adding some application code.  I would like to act on the IRMS current data each time it is available.  From the guide, this should be roughly every 80ms.  I have added code to toggle an LED to the EM_processForegroundData() routine, but it only seems to hit that code roughly every 7s.  Am i incorrectly understanding how this code works?

    Thanks,

    Scott

  • In reply to S.L:

    Hey Scott,

    I've merged your EMDC questions into one thread. I'm working on getting a response for you on these questions!

    Thanks,
    JD

    _____________________________________________________________________________


  • Hi Scott,

    Thanks for your interest in using EMDC.

    S.L
    Is it possible to modify the EMDC library to suit my particular needs?  For example, i would like to design a meter with a maximum range of 6000A.  The IRMS register is in uA, which cannot represent more than 4294A (32bit unsigned).  Do you offer source code or have any idea how to trick the library into giving me mA?

    Basically, this should be possible. It's more a matter of translating between what's actually being measured (e.g. 6000A) versus what EMDC thinks is being measured (e.g. 60A).

    The trick here would be to configure EMDC to have a maximum RMS current of 60A in the current sensor configuration window (while tweaking the parameters to match the max sensor output voltage (if it's RMS, you'll need to convert to peak) at 6000A) and calibrating at a lower current such as 6A (which would actually be 600A). Notice there's a factor of 100 here between both the max RMS current and calibration current. This effectively shifts the RMS current resolution from uA to 0.1mA. On the host side, you'll just need to multiply the RMS current value (and perhaps others such as Active Power, etc.) sent from MSP430 running the EMDC-generated code by 100 to achieve this. I hope this makes sense. If it doesn't, let me know and we can break it up into smaller details to clear things up.

    Regards,

    James

  • In reply to James Evans:

    Thank you James.  I will give it a shot.  Are you able to help with my other question above regarding timing of the processes?

    Scott

  • In reply to S.L:

    S.L
    From the guide, this should be roughly every 80ms.  I have added code to toggle an LED to the EM_processForegroundData() routine, but it only seems to hit that code roughly every 7s.  Am i incorrectly understanding how this code works?

    Were you doing this without the high voltage inputs? I suspect that's what's causing the delay. If you don't want to connect to the board when it's connected to high voltage, one way of debugging that we have found to be effective is using a target socket board with two AC sinusoidal wave form generators with frequency and amplitudes equal to what your voltage and current sensor output voltages would be at specific voltages and currents respectively. This works as long as those inputs are less than the max Full-scale range (FSR) defined in the datasheet for the PGA gain selected (which gets automatically selected by EMDC based on your max sensor voltage in the GUI).

    I hope that helps.

    Regards,

    James

  • In reply to James Evans:

    Ah.  That makes sense.  For my application, i would like to only meter current.  Is it possible to hard-code the sampling interval or switch the timing to be based on current instead of voltage?  Or do i need to use a different architecture?

    Thanks,

    Scott

  • In reply to S.L:

    Hi Scott,

    If no zero crossings are detected on the voltage inputs, then the updates are done every two seconds. This way, you could also measure DC voltages which don't have zero crossings. You could change this update frequency in the code to shorten this time. Look for the line of code that's similar to this in the 'hal_adc.c' file.

    else if (gEmSWResult.phaseMetrologyPing[EM_PH_A_IDX]->sampleCount > (2*EM_SAMPLING_FREQ_HZ))

    If the sampling frequency is 4kHz, then 4k samples "EM_SAMPLING_FREQ_HZ" equals 1 second. Multiplying this by 2 means the results are updated every 2 seconds. I hope this makes sense.

    Regards,

    James

  • In reply to James Evans:

    Hi James,

    I tried to use your approach above and believe i may have found a bug. I set the above comparison to "> EM_SAMPLING_FREQ_HZ" which I believe should toggle once a second, regardless of sampling frequency, but i see a weird behavior.

    EM_SAMPLING_FREQ_HZ = 16000, toggles at 4s period
    EM_SAMPLING_FREQ_HZ = 8000, toggles at 2s period
    EM_SAMPLING_FREQ_HZ = 4000, toggles at 1s period

    It appears fixed at 4kHz no matter what sampling freq i choose. Digging deeper, it doesn't appear the SD24OSR0/1 registers are being set. In hal_adc.c, HAL_ADC_initializeGroup(), the following code doesn't make sense to me:

    switch(param.oversampleRatio)
    {
    case HAL_ADC_OSR_256:
    param.oversampleRatio = SD24_OVERSAMPLE_256;
    break;
    case HAL_ADC_OSR_128:
    param.oversampleRatio = SD24_OVERSAMPLE_128;
    break;
    case HAL_ADC_OSR_64:
    param.oversampleRatio = SD24_OVERSAMPLE_64;
    break;
    case HAL_ADC_OSR_32:
    param.oversampleRatio = SD24_OVERSAMPLE_32;
    break;
    }

    should that switch be on config->oversampleRatio instead? I tried that here and the OSR registers now get set but it doesn't appear to be interrupting anymore so there may be more work to do. Would you mind taking a look at it?

    Thanks,
    Scott
  • In reply to S.L:

    Hi Scott,

    Maybe I'm misunderstanding your initial question. Are you asking about how to increase the actual ADC sampling rate or the update rate? If you'd like to increase the ADC sampling rate, I would recommend that you change this using the EMDC GUI and regenerating the code.

    Regards,

    James

  • In reply to James Evans:

    James,

    My question is "can you or your colleagues evaluate the generated code in hal_adc.c to see if the code above is a bug?" I just regenerated the code from EMDC as 16000 HZ sampling. Still sets SD24/OSR01 to 0, default value. Should be 10b = 64. So it always runs at 4khz sampling. I think this is because of a bug in the generated code (the above case statement doesn't work). Can you please try on your own?

    Thanks,
    Scott