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/TMS320F28379D: Current sampling in IDDK_PM_Servo exmaple

Part Number: TMS320F28379D

Tool/software: Code Composer Studio

Hi community!

After using SDFM for sampling the current in motor drive control successfully, I decided to try using other sensors for current measurement like LEM or shunt sensing without sigma-delta modulator. However, I have trouble in using ADCs. In IDDK_PM_Servo example, ADC_A, ADC_B, and ADC_C are responsible for converting the sampled current of phase A, B, and C. The mentioned ADCs results are read in the "MotorControlISR" through "currentSensorSuite" function.  However, unlike the ADC_D (which stands for resolver samples), an ISR has not been set for those three ADCs which is actuated at the end of the conversion. How does the code assure that when it calls currentSensorSuite function, the conversions of currents are done? And to what time belongs the sample which is read by this function for one the phases?

Regards

  • In the settings.h file, the user need to select the method of current sensing. I hope this is taken care off. There is one interrupt code only, and is timed to work across various current sensors. The EoC from ADC would have happened long before this interrupt timing which is tied to SDFM conversion. If the selection of current sensing is done correctly in the settings.h file, then the ADC results should be available from the currentSensorSuite().

  • Hello Ramesh. Thank you for reply


    I'm not gonna exactly use the IDDK_PM_Servo developed code. I am trying to use its ideas for developing my own motor control code. 
    Actually, my question was about the idea of the code for sampling the currents through ADC. I am a beginner in using ADCs. Would you please let me know how the code makes use of ADCs for current sampling? In my opinion, the current samples in a motor control code should belong to the beginning of the control period a little later than the switching of the inverter changes. for example, if the duration of the control period is 100us, the current should be sampled at t=5us. then considering the conversion latency, the samples would be ready to read after for example t=6us. Reading the result register of ADCs before this time may result in inappropriate current sensing (including old data or noisy data). 

    -Would please explain how the correct timing and sampling and reading the results of ADCs is possible in the IDDK_PM_Servo without using ADC ISRs? 
    -How does the code assure that when it calls currentSensorSuite function, the conversions of currents are done and they are ready to be read? 

    Best regards

  • The new values of PWM compare are loaded into a shadow register and become active at the next sampling instant. Therefore, it does not matter how sooner or later the sampled data is read as long as the sampling is done at the right instant and PWM update happens before the next shadow PWM reg to active PWM reg transition. The FOC algo will run between feedback sampling shadow pwm update.

  • Thank you.

    I have also a question about the manner of reading the results of ADC in this example:

    There is a line in the code as follows:

    current_sensor[LEM_CURRENT_SENSE-1].As   = (float)IFB_LEMV_PPB* ADC_PU_PPB_SCALE_FACTOR * LEM_TO_SHUNT;

    where  IFB_LEMV_PPB and ADC_PU_PPB_SCALE_FACTOR are difined as follows:

    #define IFB_LEMV_PPB ((signed int)AdcaResultRegs.ADCPPB2RESULT.all)
    #define ADC_PU_PPB_SCALE_FACTOR 0.000488281250 //1/2^11

    why the results are divided by 2^11 ? 

    according to the TRM, the analogue value of the results can be calculated as follows:

    ADCINx=(VREFHI-VREFLO)^(ADCRESULTy/4096)+VREFOLO

    where 4096 is 2^12 not 2^11.

    Why this formula is not used in IDDK_PM_Servo example for reading the results? 

    Regards 

  • This is due to signed reading of data, where the 12th bit represents sign. You can use the formula to reproduce the voltage level at the channel input. In this example, the adc data is directly translated to normalized level of current.

  • Thank you Ramesh,

    What about this part of the code (given bellow):

    // ******************************************************
    // static analog trim for all ADCs (A, B, C and D)
    // *******************************************************
    adc_cal=(int*)0x0000743F;
    *adc_cal=0x7000;
    adc_cal=(int*)0x000074BF;
    *adc_cal=0x7000;
    adc_cal=(int*)0x0000753F;
    *adc_cal=0x7000;
    adc_cal=(int*)0x000075BF;
    *adc_cal=0x7000;

    what is it for?

    Regards

  • They are meant for internal calibration of ADCs, and is given redundantly here in this code. You can ignore.

    If the issue is resolved. pls close the thread.

  • Hello again Ramesh and thanks for reply

    According to the TRM, the bits 0:11 (12 bits) reflect the value of PPBRESULT. the bit 12 is sign. So I didn't understand why the PPBRESULT is divided by 2^11 instead of 2^12 ? It is stated in TRM that : "If the conversion associated with this Post Processing Block is a 12-bit conversion, the SIGN bits extend down to bit 13, and reflect the same value as bit 12." So the 12 bits reflect the result (0:11) and the bit 12 is the sign. Therefore I think we should divide the results by 12 and not 11. would you please help me with this?

    Regards

  • Feel free to edit the code to study the performance.

  • Thank you for the reply but it was an unsatisfactory response to my question!

    regards

  • Hi Sana,

    The ADC formulas in the datasheet convert the digital output to the analog voltage sensed at the ADC pin.

    I wouldn't expect this exact transformation to actually be implemented in the code.  Usually we see the results transformed into some more meaningful number, transformed into a normalized range, or sometimes just left as an integer.  

    e.g. if the input range is +/-5V which then gets scaled and offset by the signal conditioning circuits into a range of 0 to 3.0V to be sampled by the ADC you might expect the code to scale the digital results to be a float in the range of -5.0 to 5.0 or -1.0 to 1.0 or just used as-is as 0 to 4095 or maybe an offset is added to get -2047 to 2048.  

  • Hello Devin

    Thanks for the reply. 

    regards