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

Configuring the PWM Module

The HAL module configures the PWM channels. The base addresses of the PWM channels that are used for the motor controller PWM inputs are defined in the hal.h file, and the base addresses are assigned to the PWM handles in the hal.c file. The connection diagram for the PWM signals between the LAUNCHXL-F280025C and BOOSTXL-DRV8323RS is shown in Figure 4-2.

 PWM Connection Diagram Figure 4-2 PWM Connection Diagram

The code to configure the PWM signals is shown below, taken from the hal.h and hal.c files that are located in the solutions\universal_motorcontrol_lab\f28002x\drivers\include and \source folder. Motor driver board dependent and MCU dependent changes are highlighted in bold.

  1. The base addresses of the PWM modules are defined in the hal.h file as shown below.
    //! \ Motor 1
    #define MTR1_PWM_U_BASE         EPWM1_BASE
    #define MTR1_PWM_V_BASE         EPWM2_BASE
    #define MTR1_PWM_W_BASE         EPWM6_BASE
  2. The GPIOs are set up as PWM outputs in the HAL_setupGpios() function located in the hal.c file.
    // GPIO0->EPWM1A->M1_UH*
    GPIO_setPinConfig(GPIO_0_EPWM1_A);
    GPIO_setDirectionMode(0, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD);
    
    // GPIO1->EPWM1B->M1_UL*
    GPIO_setPinConfig(GPIO_1_EPWM1_B);
    GPIO_setDirectionMode(1, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(1, GPIO_PIN_TYPE_STD);
    
    // GPIO2->EPWM2A->M1_VH*
    GPIO_setPinConfig(GPIO_2_EPWM2_A);
    GPIO_setDirectionMode(2, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(2, GPIO_PIN_TYPE_STD);
    
    // GPIO3->EPWM2B->M1_VL*
    GPIO_setPinConfig(GPIO_3_EPWM2_B);
    GPIO_setDirectionMode(3, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(3, GPIO_PIN_TYPE_STD);
    
    // GPIO4->EPWM3A->M1_WH* 
    GPIO_setPinConfig(GPIO_4_EPWM3_A);
    GPIO_setDirectionMode(4, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(4, GPIO_PIN_TYPE_STD); 
    
    // GPIO15->EPWM3B->M1_WL* 
    GPIO_setPinConfig(GPIO_15_EPWM3_B);
    GPIO_setDirectionMode(15, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(15, GPIO_PIN_TYPE_STD); 
  3. The below code assigns the corresponding base addresses of the PWM modules to the PWM handle in the HAL_MTR1_init() function that is located in the hal.c file. The below code does not need to be changed when adapting the code to a new board or C2000 MCU, it is just to show how the PWM handle is initialized in the code.
    // initialize PWM handles for Motor 1
    obj->pwmHandle[0] = MTR1_PWM_U_BASE;        //!< the PWM handle
    obj->pwmHandle[1] = MTR1_PWM_V_BASE;        //!< the PWM handle
    obj->pwmHandle[2] = MTR1_PWM_W_BASE;        //!< the PWM handle
  4. The code below shows the configuration of the PWMs that occurs in the HAL_setupPWMs() function that is located in the hal.c file. Notice that the desired PWM period (USER_M1_PWM_TBPRD_NUM) for setting the PWM frequency, the SOC event prescale number (USER_M1_PWM_TBPRD_NUM), and the dead-band values (MTR1_PWM_DBRED_CNT, MTR1_PWM_DBFED_CNT) are defined in the hal.h file. The value of these defines can be changed according to the hardware board and control requirement. The PWM counter mode and the PWM action qualifier outputs need to be set up based on the hardware board.
    void HAL_setupPWMs(HAL_MTR_Handle handle) 
    { 
    	HAL_MTR_Obj *obj = (HAL_MTR_Obj *)handle; 
    	uint16_t cnt; 
    	uint16_t pwmPeriodCycles = (uint16_t)(USER_M1_PWM_TBPRD_NUM); 
    	uint16_t numPWMTicksPerISRTick = USER_M1_NUM_PWM_TICKS_PER_ISR_TICK; 
    	... ... 
    	for(cnt=0; cnt<3; cnt++) 
    	{ 
    		// setup the Time-Base Control Register (TBCTL) 
    		EPWM_setTimeBaseCounterMode(obj->pwmHandle[cnt], EPWM_COUNTER_MODE_UP_DOWN); 
    		... ... 
    		// setup the Action-Qualifier Output A Register (AQCTLA) 
    		EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
    			EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); 
    		EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A, 
    			EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD); 
    		EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
                EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); 
    		EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
                EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO); 
    		... ... 
    		// setup the Dead-Band Generator Control Register (DBCTL) 
    		EPWM_setDeadBandDelayMode(obj->pwmHandle[cnt], EPWM_DB_RED, true); 
    		EPWM_setDeadBandDelayMode(obj->pwmHandle[cnt], EPWM_DB_FED, true); 
    		
    		// select EPWMA as the input to the dead band generator 
    		EPWM_setRisingEdgeDeadBandDelayInput(obj->pwmHandle[cnt], EPWM_DB_INPUT_EPWMA); 
    		
    		// configure the right polarity for active high complementary config. 
    		EPWM_setDeadBandDelayPolarity(obj->pwmHandle[cnt], EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH); 
    		EPWM_setDeadBandDelayPolarity(obj->pwmHandle[cnt], EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW); 
    		
    		// setup the Dead-Band Rising Edge Delay Register (DBRED) 
    		EPWM_setRisingEdgeDelayCount(obj->pwmHandle[cnt], MTR1_PWM_DBRED_CNT); 
    		
    		// setup the Dead-Band Falling Edge Delay Register (DBFED) 
    		EPWM_setFallingEdgeDelayCount(obj->pwmHandle[cnt], MTR1_PWM_DBFED_CNT); 
    		... ... 
    	} 
    	... ... 
    	// setup the Event Trigger Selection Register (ETSEL) 
    	EPWM_setInterruptSource(obj->pwmHandle[0], EPWM_INT_TBCTR_ZERO); 
    	EPWM_enableInterrupt(obj->pwmHandle[0]); 
    	EPWM_setADCTriggerSource(obj->pwmHandle[0], EPWM_SOC_A, EPWM_SOC_TBCTR_D_CMPC); 
    	EPWM_enableADCTrigger(obj->pwmHandle[0], EPWM_SOC_A);
    	... ...
    	
        return;
    }  // end of HAL_setupPWMs() function
  5. The below code is located in the hal.h file and defines the source of the ADC start of conversion trigger. It is important that this ePWM SOC trigger corresponds to the same ePWM SOC that was enabled in the code shown in step 4 and the same ePWM that is associated with pwmHandle[0]. This is because these are the ones used in step 4 to set up the trigger source. In this case, EPWM1 A is used as the SOC for the ADC.
    // Three-shunt
    #define MTR1_ADC_TRIGGER_SOC     ADC_TRIGGER_EPWM1_SOCA // EPWM1_SOCA