SPRUJ26A September   2021  – April 2024

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
  5. 2Motor Control Theory
    1. 2.1 Mathematical Model and FOC Structure of PMSM
    2. 2.2 Field Oriented Control of PM Synchronous Motor
    3. 2.3 Sensorless Control of PM Synchronous Motor
      1. 2.3.1 Enhanced Sliding Mode Observer with Phase Locked Loop
        1. 2.3.1.1 Design of ESMO for PMSM
        2. 2.3.1.2 Rotor Position and Speed Estimation With PLL
    4. 2.4 Hardware Prerequisites for Motor Drive
      1. 2.4.1 Motor Phase Voltage Feedback
    5. 2.5 Additional Control Features
      1. 2.5.1 Field Weakening (FW) and Maximum Torque Per Ampere (MTPA) Control
      2. 2.5.2 Flying Start
  6. 3Running the Universal Lab on TI Hardware Kits
    1. 3.1 Supported TI Motor Evaluation Kits
    2. 3.2 Hardware Board Setup
      1. 3.2.1  LAUNCHXL-F280025C Setup
      2. 3.2.2  LAUNCHXL-F280039C Setup
      3. 3.2.3  LAUNCHXL-F2800137 Setup
      4. 3.2.4  TMDSCNCD280025C Setup
      5. 3.2.5  TMDSCNCD280039C Setup
      6. 3.2.6  TMDSCNCD2800137 Setup
      7. 3.2.7  TMDSADAP180TO100 Setup
      8. 3.2.8  DRV8329AEVM Setup
      9. 3.2.9  BOOSTXL-DRV8323RH Setup
      10. 3.2.10 BOOSTXL-DRV8323RS Setup
      11. 3.2.11 DRV8353RS-EVM Setup
      12. 3.2.12 BOOSTXL-3PHGANINV Setup
      13. 3.2.13 DRV8316REVM Setup
      14. 3.2.14 TMDSHVMTRINSPIN Setup
      15.      34
      16.      35
    3. 3.3 Lab Software Implementation
      1. 3.3.1 Importing and Configuring Project
      2.      38
      3.      39
      4. 3.3.2 Lab Project Structure
      5. 3.3.3 Lab Software Overview
    4. 3.4 Monitoring Feedback or Control Variables
      1. 3.4.1 Using DATALOG Function
      2. 3.4.2 Using PWMDAC Function
      3. 3.4.3 Using External DAC Board
    5. 3.5 Running the Project Incrementally Using Different Build Levels
      1. 3.5.1 Level 1 Incremental Build
        1. 3.5.1.1 Build and Load Project
        2. 3.5.1.2 Setup Debug Environment Windows
        3. 3.5.1.3 Run the Code
      2. 3.5.2 Level 2 Incremental Build
        1. 3.5.2.1 Build and Load Project
        2. 3.5.2.2 Setup Debug Environment Windows
        3. 3.5.2.3 Run the Code
      3. 3.5.3 Level 3 Incremental Build
        1. 3.5.3.1 Build and Load Project
        2. 3.5.3.2 Setup Debug Environment Windows
        3. 3.5.3.3 Run the Code
      4. 3.5.4 Level 4 Incremental Build
        1. 3.5.4.1 Build and Load Project
        2. 3.5.4.2 Setup Debug Environment Windows
        3. 3.5.4.3 Run the Code
  7. 4Building a Custom Board
    1. 4.1 Building a New Custom Board
      1. 4.1.1 Hardware Setup
      2. 4.1.2 Migrating Reference Code to a Custom Board
        1. 4.1.2.1 Setting Hardware Board Parameters
        2. 4.1.2.2 Modifying Motor Control Parameters
        3. 4.1.2.3 Changing Pin Assignment
        4. 4.1.2.4 Configuring the PWM Module
        5. 4.1.2.5 Configuring the ADC Module
        6. 4.1.2.6 Configuring the CMPSS Module
        7. 4.1.2.7 Configuring Fault Protection Function
      3. 4.1.3 Adding Additional Functionality to Motor Control Project
        1. 4.1.3.1 Adding Push Buttons Functionality
        2. 4.1.3.2 Adding Potentiometer Read Functionality
        3. 4.1.3.3 Adding CAN Functionality
    2. 4.2 Supporting New BLDC Motor Driver Board
    3. 4.3 Porting Reference Code to New C2000 MCU
  8.   A Appendix A. Motor Control Parameters
  9.   References
  10.   Revision History

Run the Code

  1. Power on the appropriate power supply, and gradually increase the output voltage of the power supply to get an appropriate DC-bus voltage.
  2. If using the graph tool, lab 2 uses the same graph configurations and parameters as lab 1 to monitor 2 of the phase currents.
  3. Run the project by clicking on the  button, or click RunResume in the Debug tab. The systemVars.flagEnableSystem should be set to 1 after a fixed time, that means the offsets calibration has completed. The fault flags, motorVars_M1.faultMtrUse.all should be equal to 0. If this is not the case, the user should double check the current and voltage sensing circuit in lab 1 as described in Section 3.5.1.3.
  4. To verify the current and voltage sensing circuits of the motor driver, set the variable motorVars_M1.flagEnableRunAndIdentify to 1 in the Expressions window as shown in Figure 3-33. The motor will run with voltage/frequency (v/f) open loop. If the motor doesn't spin smoothly, tune the v/f profile parameters in the user_mtr1.h file as shown below according to the specification of the motor. See1 for more details on tuning the v/f profile parameters. Note: modification of these parameters will require rebuilding the project. See step 14 of 14 for more information on rebuilding the project in debug mode.
    #define USER_MOTOR1_FREQ_LOW_HZ            (5.0)            // Hz
    #define USER_MOTOR1_FREQ_HIGH_HZ           (400.0)          // Hz
    #define USER_MOTOR1_VOLT_MIN_V             (1.0)            // Volt
    #define USER_MOTOR1_VOLT_MAX_V             (24.0)           // Volt
  5. The motorVars_M1.speedRef_Hz variable is used to set the speed reference for the motor. Check the value of the motorVars_M1.speed_Hz variable in the Expressions window to ensure that the motor speed (motorVars_M1.speed_Hz) is close to the reference speed (motorVars_M1.speedRef_Hz) as shown in Figure 3-33.
  6. In this build level, the current sensing, voltage sensing, rotor angle estimator, and generator need to be validated. This can be done using either the PWMDAC or the DAC128S module with an oscilloscope as described in Section 3.4.2 or Section 3.4.3. Additionally, the DATALOG module can be used to view these sensing waveforms. For more information on using the DATALOG to view the currents, voltages, and angle signals, see step 7. If using the DAC128S module, configure the dac128s.ptrdata[] inputs to correspond with the code shown in each of the following subsections. The code modification can be done by uncommenting the appropriate code section for the DAC128S initialization and by commenting out the rest of the DAC128S initialization that is not needed in the subsection. It will be necessary to rebuild the project after modifying the code to correspond with each subsection. See step 14 of 14 for more information on rebuilding the project in debug mode.
    1. The first set of parameters to monitor is the phase currents. This is done by uncommenting the portion of code shown below, which sets up the dac128s pointer data to the 3 phase currents as well as the angle estimator variable. This code is found in the sys_main.c file. The expected current waveforms should be similar to the waveforms shown on the oscilloscope in Figure 3-35. The current waveforms measured at the DAC128S outputs should be almost the same as the corresponding phase current waveforms capture by a current probe. If this is the case, that indicates the current sensing circuit is good for motor control. If this is not the case, it may be necessary to tune the v/f parameters in the user_mtr1.h file as described in 1.
      dac128s.ptrData[0] = &motorVars_M1.adcData.I_A.value[0];     // CH_A
      dac128s.ptrData[1] = &motorVars_M1.adcData.I_A.value[1];     // CH_B
      dac128s.ptrData[2] = &motorVars_M1.adcData.I_A.value[2];     // CH_C
      dac128s.ptrData[3] = &motorVars_M1.angleGen_rad;             // CH_D
      dac128s.ptrData[4] = &motorVars_M1.angleEST_rad;                // CH_E, N/A
      dac128s.ptrData[5] = &motorVars_M1.adcData.V_V.value[0];        // CH_F, N/A
      dac128s.ptrData[6] = &motorVars_M1.adcData.V_V.value[1];        // CH_G, N/A
      dac128s.ptrData[7] = &motorVars_M1.adcData.V_V.value[2];        // CH_H, N/A
      
      dac128s.gain[0] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A;
      dac128s.gain[1] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A;
      dac128s.gain[2] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A;
      dac128s.gain[3] = 4096.0f / MATH_TWO_PI;
      dac128s.gain[4] = 4096.0f / MATH_TWO_PI;                           // NA
      dac128s.gain[5] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V; // N/A
      dac128s.gain[6] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V; // N/A
      dac128s.gain[7] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V; // N/A
      ... ...
      dac128s.offset[0] = (uint16_t)(0.5f * 4096.0f); 
      dac128s.offset[1] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[2] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[3] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[4] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[5] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[6] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[7] = (uint16_t)(0.5f * 4096.0f); // N/A
    2. The second set of parameters to monitor are the phase voltages. To do this, the section of code that sets up the dac128s pointer data to point to the phase voltage should be uncommented as shown below. This code is found in the sys_main.c file. The output waveform shape of the phase voltage sensing from the DAC128S module should look similar to the image shown in Figure 3-36 or Figure 3-37. If this is the case, that indicates that the voltage sensing sircuit is working as expected. Note that the amplitude can vary depending on the supply voltage and motor used, but the shape of the waveform should be the same. Note the difference in the phase waveforms depending on the SVM mode used. For the Common SVM mode, there is a voltage dip at the upper and the lower peaks of the waveform, whereas for the Minimum SVM mode, the voltage dip only appears on the upper peak, but stays flat on the lower peak. To change the SVM mode, select either SVM_COM_C or SVM_MIN_C from the motorVars_M1.svmMode enumeration in the Expressions window.
      dac128s.ptrData[0] = &motorVars_M1.adcData.V_V.value[0];     // CH_A
      dac128s.ptrData[1] = &motorVars_M1.adcData.V_V.value[1];     // CH_B
      dac128s.ptrData[2] = &motorVars_M1.adcData.V_V.value[2];     // CH_C
      dac128s.ptrData[3] = &motorVars_M1.angleGen_rad;             // CH_D
      dac128s.ptrData[4] = &motorVars_M1.angleEST_rad;                // CH_E, N/A
      dac128s.ptrData[5] = &motorVars_M1.adcData.I_A.value[0];        // CH_F, N/A
      dac128s.ptrData[6] = &motorVars_M1.adcData.I_A.value[1];        // CH_G, N/A
      dac128s.ptrData[7] = &motorVars_M1.adcData.I_A.value[2];        // CH_H, N/A
      
      dac128s.gain[0] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V;
      dac128s.gain[1] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V;
      dac128s.gain[2] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V;
      dac128s.gain[3] = 4096.0f / MATH_TWO_PI;
      dac128s.gain[4] = 4096.0f / MATH_TWO_PI;                             // N/A
      dac128s.gain[5] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A; // N/A
      dac128s.gain[6] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A; // N/A
      dac128s.gain[7] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A; // N/A
      ... ...
      dac128s.offset[0] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[1] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[2] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[3] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[4] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[5] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[6] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[7] = (uint16_t)(0.5f * 4096.0f); // N/A
    3. The third set of parameters to monitor is the angle generator and the angle estimator parameters. To do this, the section of code that sets up the dac128s pointer data to point to the appropriate variables should be uncommented as shown below. This code is found in the sys_main.c file. The angle from the angle generator and the estimator waveforms should be similar to the oscilloscope waveforms shown in Figure 3-38. Notice that the angle of the force angle generator is very similar to the estimated rotor angle of the FAST or eSMO estimator. This indicates that the FAST or eSMO estimator works as expected with the motor parameters and the sampling current and voltage signals.
      dac128s.ptrData[0] = &motorVars_M1.angleGen_rad;            // CH_A
      dac128s.ptrData[1] = &motorVars_M1.angleEST_rad;            // CH_B
      dac128s.ptrData[2] = &motorVars_M1.anglePLL_rad;            // CH_C
      dac128s.ptrData[3] = &motorVars_M1.adcData.I_A.value[0];    // CH_D
      dac128s.ptrData[4] = &motorVars_M1.adcData.V_V.value[0];        // CH_E, N/A
      dac128s.ptrData[5] = &motorVars_M1.adcData.I_A.value[1];        // CH_F, N/A
      dac128s.ptrData[6] = &motorVars_M1.adcData.I_A.value[2];        // CH_G, N/A
      dac128s.ptrData[7] = &motorVars_M1.adcData.V_V.value[1];        // CH_H, N/A
      
      dac128s.gain[0] = 4096.0f / MATH_TWO_PI;
      dac128s.gain[1] = 4096.0f / MATH_TWO_PI;
      dac128s.gain[2] = 4096.0f / MATH_TWO_PI;
      dac128s.gain[3] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A;
      dac128s.gain[4] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V; // N/A
      dac128s.gain[5] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A; // N/A
      dac128s.gain[6] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A; // N/A
      dac128s.gain[7] = 2.0f * 4096.0f / USER_M1_ADC_FULL_SCALE_VOLTAGE_V; // N/A
      
      dac128s.offset[0] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[1] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[2] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[3] = (uint16_t)(0.5f * 4096.0f);
      dac128s.offset[4] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[5] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[6] = (uint16_t)(0.5f * 4096.0f); // N/A
      dac128s.offset[7] = (uint16_t)(0.5f * 4096.0f); // N/A
  7. If using the DATALOG module with the graph tool to check the current sensing signals, voltage sensing signals, and the angle outputs, follow the steps described below. For more info on the datalog module, see Section 3.4.1. Note: It will be necessary to rebuild the project in between each of the below steps after modifying the code. See step 14 of 14 for more information on rebuilding the project in debug mode.
    1. To test the phase currents for phase U and V using the DATALOG module, the following code must be set up in the sys_main.c file.
      Note: This code is already configured by default for build level 2. The phase current sampling signals waveform displayed on the graph tool as shown in Figure 3-39.
      datalogObj->iptr[0] = &motorVars_M1.adcData.I_A.value[0];
      datalogObj->iptr[1] = &motorVars_M1.adcData.I_A.value[1];
    2. To test the phase voltages for phase U and V using the DATALOG module, the following code must be set up in the sys_main.c file and modified to the code shown below. The phase voltage sampling signals waveform on graph tool as shown in Figure 3-40.
      datalogObj->iptr[0] = &motorVars_M1.adcData.V_V.value[0];
      datalogObj->iptr[1] = &motorVars_M1.adcData.V_V.value[1];
    3. Configuring DATALOG module four inputs as the following codes. The angle from the force angle generator or estimator waveforms on the graph tool as shown in Figure 3-41. Notice that the angle of the force angle generator is very similar as the estimated rotor angle of the FAST or eSMO estimator.
      datalogObj->iptr[0] = &motorVars_M1.angleFOC_rad;
      datalogObj->iptr[1] = &motorVars_M1.angleEST_rad;
  8. Verify the over current fault protection by decreasing the value of the variable motorVars_M1.overCurrent_A, the over current protection is implemented by the CMPSS modules. The over current fault will be trigger if the motorVars_M1.overCurrent_A is set to a value less than the motor phase current actual value, the PWM output will be disabled, the motorVars_M1.flagEnableRunAndIdentify is cleared to 0, and the motorVars_M1.faultMtrUse.all will be set to 0x10 ( 16) as shown in Figure 3-34.
  9. Set the variables motorVars_M1.flagEnableRunAndIdentify to 0 to stop run the motor.
  10. Once complete, the controller can now be halted, and the debug connection terminated. Fully halting the controller by first clicking the Halt button on the toolbar  or by clicking TargetHalt. Finally, reset the controller by clicking on  or clicking RunReset.
  11. Close CCS debug session by clicking on Terminate Debug Session  or clicking RunTerminate.
  12. Power off the power supply to the inverter kit.
 Build Level 2: Variables in
          Expressions Window Figure 3-33 Build Level 2: Variables in Expressions Window

Adjust the value of motorVars_M1.overCurrent_A in Expression window to trigger the over current fault as shown in Figure 3-34.

 Build Level 2: Current Protection
          Setting Figure 3-34 Build Level 2: Current Protection Setting

Use DAC128S085EVM with an oscilloscope to monitor three phase sensing current of the motor and compare the sampling value to the measurement value with a current probe as shown in Figure 3-35.

 Build Level 2: Motor Phase Current
          Waveforms Figure 3-35 Build Level 2: Motor Phase Current Waveforms

Use DAC128S085EVM with an oscilloscope to monitor three phase sensing voltage of the motor, and use common mode SVPWM by setting motorVars_M1.svmMode equal to SVM_COM_C as shown in Figure 3-36.

 Build Level 2: Motor Phase Voltage
          Waveforms Using Common SVM Mode Figure 3-36 Build Level 2: Motor Phase Voltage Waveforms Using Common SVM Mode

Use DAC128S085EVM with an oscilloscope to monitor three phase sensing voltage of the motor, and use minimum mode SVPWM by setting motorVars_M1.svmMode equal to SVM_MIN_C as shown in Figure 3-37.

 Build Level 2: Motor Phase Voltage
          Waveforms Using Minimum SVM Mode Figure 3-37 Build Level 2: Motor Phase Voltage Waveforms Using Minimum SVM Mode

Use DAC128S085EVM with an oscilloscope to monitor the rotor angle of the motor from the angle generator and the angle from the FAST estimator as shown in Figure 3-38.

 Build Level 2: Motor Rotor Angle and
          Phase Current Waveforms Figure 3-38 Build Level 2: Motor Rotor Angle and Phase Current Waveforms

Use Datalog with Graph Tool to monitor three phase sensing current of the motor as shown in Figure 3-39.

 Build Level 2: Motor Phase Current
          Waveforms With Graph Tool Figure 3-39 Build Level 2: Motor Phase Current Waveforms With Graph Tool

Use Datalog with Graph Tool to monitor three phase sensing voltage of the motor as shown in Figure 3-40.

 Build Level 2: Motor Phase Voltage
          Waveforms With Graph Tool Figure 3-40 Build Level 2: Motor Phase Voltage Waveforms With Graph Tool

Use Datalog with Graph Tool to monitor rotor angle of the motor from the angle generator and angle from the FAST estimator as shown in Figure 3-41.

 Build Level 2: Motor Rotor Angle
          Waveforms With Graph Tool Figure 3-41 Build Level 2: Motor Rotor Angle Waveforms With Graph Tool