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.

CCS/TMS320F28377D: Current sensing using ADC

Part Number: TMS320F28377D
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Hello community

I want to measure the motor three phase currents using shunt resistance and read them by ADC. Actually, I want to read the three phase current simultaneously and when the measured data is converted to digital values, use them in my control system. I have read the TRM but it was so confusing for me! I don't know how to simultaneously trigger sampling and get 3 new current data. Should I use the same SOC for these three references? How can I get for example 3 or 5 samples from each phase to improve the reliability of sampling (e.g. by making an average value of that 3-5 data)?

Would somebody please help me with this?

Regards

  • Hi Lio,

    Yes, it could be daunting to start with the TRM as there are several features in the F28377D ADC and different options to sample.  I would suggest looking at example codes for the ADC as a start and make modifications to those example codes depending on your requirements.  Two good examples to look at are adc_soc_epwm and adc_soc_software.  The first example, adc_soc_epwm, uses the ePWM module to trigger adc conversions. ePWM in the example is configured to count at regular intervals based from system clock so triggers to the ADC can be attained at regular intervals.  The second example, adc_soc_software, allows the user to trigger ADC conversion tentatively, meaning ADC will only trigger if software command is issued by the user.  On the first example, only one SOC is used.  On the second example, 2 SOCs are used.

    For 3 phase current sampling, you can modify the examples and use 3 SOCs, one for each phase that you want to measure.  Note that each SOC can be exclusively mapped to a channel so you can connect shunt resistances to 3 different channels (one for each phase).  This could be one solution - using one ADC module, 3 different SOCs and 3 different channels to sample the 3 phases.  The drawback with this approach is that the conversions will happen serially with lower numbered SOCs converting first and conversion time (acquisition time + quantization time) will serially add up, more so if you need to do 3-5 conversions.  This might be significant if the timing requirement in your control system is tight.  If timing requirement is tight, you can use 3 of the 4 ADC modules in the F23877D to attain a true simultaneous sampling on 3 ADCs.  You can start with the first example (adc_soc_epwm) but modify it so 3 ADCs will be used, instead of one.  You can use SOC0 for all 3 ADCs (note that each ADC has its own set of 16 SOCs) and map them to their respective channels and to ensure all 3 ADC convert simultaneously, use the same ePWM module/trigger for all the 3 ADCs that you choose.

    Hope this gets you started.  Let me know if you have additional questions on this topic.

    Regards,

    Joseph

  • Hi Joseph and thanks for your prompt response,

    Actually, I have to use 7 sensors in my work. 3 for current sensing and 4 for voltage sensing.

    As I noticed, I should 3 ADCs for current sensing and the other one for voltage sensing. If I do so, the ADC which is responsible for converting the voltage samples (for 4 sensors) should work in serial mode. In other words, I have to use a common SOC with different channels for these sensors. Then each time that I want to read the currents and voltages, I have to wait for the fourth ADC which is mapped to 4 channels (4 sensors). Is is true?

    The acquisition time is commonly about 20 sysclck (20*5ns) is it right? what about quantization time?

    I will start with that two examples as you mentioned.

    Best regards.

  • Hi Lio,

    Section 11.2.1 ADC Timing Diagrams shows when the conversion values will be available at the result registers depending on the mode (16 or 12-bit mode) and the ADC clock prescaler used.  Tables 11-10 or 11-11 (again depending on mode selected) shows TLAT duration when conversion result is available once TINT (ADC interrupt - triggered when end of conversion occurs) flag goes high.  To get approximate overall conversion time, you can add ADC SH (acquisition time) + TLAT using the values from the tables and multiply it by sysclk duration.

    20 sysclk cycles is about right for 12-bit mode.  You can have a tradeoff of increasing acquisition time versus averaging multiple conversions.  You can experiment on this later once you have the conversion routines working.  A suggested approach based on your requirements would be:

    - Use 3 ADCs for the 3 phase current sensing, use SOC0 for highest priority and, trigger all 3 ADCs from a single ePWM and use ADC ISRs for reading conversion values for faster, simultaneous conversion.

    - For the remaining 4 voltage sensors that can be converted in series, use the 4th ADC module and use SOC0 to SOC3 so conversion will be done in the same order.  Each SOC can be assigned to a different ADC channel - example below:

    AdcdRegs.ADCSOC0CTL.bit.CHSEL = 5; // channel ADCIND5 assigned to SOC0

    AdcdRegs.ADCSOC1CTL.bit.CHSEL = 2; // channel ADCIND2 assigned to SOC1

    AdcdRegs.ADCSOC2CTL.bit.CHSEL = 4; // channel ADCIND4 assigned to SOC2

    AdcdRegs.ADCSOC3CTL.bit.CHSEL = 1; // channel ADCIND1 assigned to SOC3

    Hope the above pointers would help.

    Regards,

    Joseph

     

  • Hi Joseph and thanks for the reply


    I followed your suggestion and investigated the code examples. Besides I read the TRM ADC section again and know I have a better understanding of ADCs than before. Thank you.


    I have a question that may seem to be a stupid question for you! Is each channel correspondingly connected to a DSP ADC pin? In TRM, inputs to ADC are ADCIN1~ADCIN15. However, in DSP I could find these pins: ADCINA0~A5   ADCINB0~B5  ADCC0~C5  ADCD0~D5 and ADCIN14~15.
    I don't know which channel corresponds to which pin! would you please help me?


    Another question is that as you mentioned, I have to use 4 channels of ADCD to sample 4 voltages. So I have to assign 4 SOCs to one channel. My control method could not be started until all voltage and current samples are read. So, I have to wait for 4 voltage samples which are converted in series. For using the time more efficiently, isn't it better that during this period (conversion of 4 SOCs of ADCD), I let the ADCA~ADCC get more samples through SOC1~3? Then I can use theses samples to enhance the reliability of the stored results by averaging the samples related to each ADC module. Is it possible and a good idea?
    Regards

  • Hi Lio,

    That is a perfectly a valid question.  You are correct, the TRM provides you with a diagram showing channels ADCIN0 to ADCIN15 and those are available in all ADC modules however due to package and pin limitations, only specific channels are brought out physically.  Some of these ADC channels are also multiplexed to other module functions like comparator inputs and DAC output in order to accommodate as much pin functionality on finite number of pins on a given package.  Take note that the F2837x family is a microcontroller with several embedded digital control modules as well as analog subsystems that comes in several device pin outs and these make the C2000 device an ideal choice for a single-chip control system.  It is for this reason that not all the ADC channels are brought out physically on the chip.  To better understand which of the ADC channels are available or which ones are multiplexed to some other functions, check out the Analog Subsystem Block Diagrams for each pin type.  These diagrams are also available in the datasheet with accompanying terminal description and function that is tabulated and would be excellent reference guide.

    I might have misunderstood the voltage sample requirement.  I thought the 4 voltages are coming from 4 independent sources but going back to your post, I think what you wanted is to take 4 voltage samples in series from one source.  Is this correct?  If this is the case then, you can just use 1 SOC that is mapped to one channel and just take 4 readings  by triggering the conversions with software or EPWM or timers, depending on the spacing of readings.

    Best regards,

    Joseph

  • Hello again Joseph and thank you for such a thorough response,


    I got the point about ADCA0~5, ADCB0~5, ADCC0~5, and ADCD0~5. But what about the pins ADCIN14 and ADCIN15? What are these two pins and to which ADC modules do they belong? 


    About the second question, you were thinking right! the mistake was from my side. I want to sample 4 voltages from 4 different channels. so I would write the below code (as you mentioned):


    AdcdRegs.ADCSOC0CTL.bit.CHSEL = 5; // channel ADCIND5 assigned to SOC0
    AdcdRegs.ADCSOC1CTL.bit.CHSEL = 2; // channel ADCIND2 assigned to SOC1
    AdcdRegs.ADCSOC2CTL.bit.CHSEL = 4; // channel ADCIND4 assigned to SOC2
    AdcdRegs.ADCSOC3CTL.bit.CHSEL = 1; // channel ADCIND1 assigned to SOC3


    Using this code would make the conversions in channels 5,2,4, and 1 done in series (because SOC0 is the highest priority, then SOC1, then SOC2 and finally SOC3 would convert the channel 1 ) Is it true? It is however in current sampling, the data of each channel (each phase of current) would be ready faster (due to the assigning only one SOC (SOC0) of the ADCx to that phase). Therefore, after converting SOC0 of ADCA, ADCB, and ADCC in parallel, I have to wait for the samples of voltage which would convert in series. So, I was pointing out this idle time. The question is about the possibility of converting 2 or 3 more current samples for each phase to fill out the idling time of my control code.

    Best regards

  • Hi Lio,

    Good observation.  Channels 14 and 15, per the diagram connect to all 4 ADCs, meaning any signal connected to these channels can be converted by any of the 4 ADCs.

    Another good point on the conversion sequencing that you brought out.  There is a section in the TRM that discusses about Synchronous Operation.  There are a lot of diagrams and explanations but the key takeaway from that section is that as long as all the ADCs are running at the same speed, have the same ACQPS and are triggered at the same time (e.g.- trigger source is the same for all ADCs), then it will guarantee Synchronous Operation and conversion results will be fine, otherwise conversion would be in Asynchronous mode and this can have some impact on the conversion accuracy.

    Best regards,

    Joseph

  • Hello again Joseph

    Thank you for your time spending on helping me.

    Best regards

  • Hi Lio,

    You're welcome.  Hopefully you will find the F2837x as the best solution for your control system with its rich features.  If you have further questions on the other features of the F2837x, feel free to post it in the forum.  Also if you are looking for a guidance on what are the other capabilities of the C2000 Family of microcontrollers, you can browse the C2000 Key Technology Guide in this link.  There are also several resources bundled in C2000ware as well as examples to get you started.

    Best regards,

    Joseph