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

Supporting New BLDC Motor Driver Board

C2000 MCUs can be used with BLDC motor drivers for driving three-phase BLDC or PMSM motor applications. This universal lab project can support various pre-defined BLDC motor drivers. The user can refer to the example code in the lab project and follow the steps described in this section to implement newer or otherwise unsupported BLDC motor drivers. This section uses DRV8323RS with SPI as an example.

  1. Design the driver file for the new BLDC motor driver EVM board.

    If the BLDC motor driver supports SPI, refer to the existing BLDC motor driver files (drv8323s.h and drv8323s.c) and change the registers and API function definitions where necessary in the drv8xxx.h and drv8xxx.c files. The detailed description of the BLDC motor driver register maps can be found in the data sheet of the BLDC motor driver device.

    Create a new set of folders for the driver file, as with the DRV8323 ("\libraries\drvic\drv8323\include" and "\libraries\drvic\drv8323\source").

  2. Add the BLDC motor driver source files to the motor control project.

    First, add the BLDC motor driver source files to the project you are working. There are two methods to add the files.

    Using an Editor to open the universal_motorcontrol_lab.projectspec projectspec file, add the files to the project as follows.

    <file action="link" path="SDK_ROOT/libraries/drvic/drv8323/source/drv8323s.c" targetDirectory="src_board" applicableConfigurations="Flash_lib_DRV8323RS" />
    <file action="link" path="SDK_ROOT/libraries/drvic/drv8323/include/drv8323s.h" targetDirectory="src_board" applicableConfigurations="Flash_lib_DRV8323RS" />

    Alternatively, right-click on the project name in the CCS project explorer window, and select “Add Files.” Next, navigate to the following folder and select the designed driver files from " \libraries\drvic\drv8323\source", and then select "Link to Files".

  3. Add the header file to the include list in the hal_obj.h file.
    #include "drv8323s.h"

    To ensure that the header files can be correctly found, add the directory to the header files in "Project Properties"->"Build"->"C2000 Compiler"->"Include Options"->"Add dir to #include search path".

    Alternatively, add the directory to the header files by adding the following content in the universal_motorcontrol_lab.projectspec projectspec file.

    -I${SDK_ROOT}/libraries/drvic/drv8323/include
  4. Edit the HAL_Obj to add the drvic interface handle and SPI handle.

    Refer to the DRV8323 files to add the supporting code as follows.

    Add the defines in the hal_obj.h file.

    #define DRAdd the defines in hal_obj.h fileVIC_Obj               DRV8323_Obj
    #define DRVIC_VARS_t            DRV8323_VARS_t
    #define DRVIC_Handle            DRV8323_Handle
    #define DRVICVARS_Handle        DRV8323VARS_Handle
    
    #define DRVIC_init              DRV8323_init
    #define DRVIC_enable            DRV8323_enable
    #define DRVIC_writeData         DRV8323_writeData
    #define DRVIC_readData          DRV8323_readData
    
    #define DRVIC_setupSPI          DRV8323_setupSPI
    
    #define DRVIC_setSPIHandle      DRV8323_setSPIHandle
    #define DRVIC_setGPIOCSNumber   DRV8323_setGPIOCSNumber
    #define DRVIC_setGPIOENNumber   DRV8323_setGPIOENNumber

    Add the drvic interface handle and SPI handle to HAL_Obj:

      uint32_t       spiHandle;          //!< the SPI handle
    
      DRVIC_Handle   drvicHandle;        //!< the drvic interface handle
      DRVIC_Obj      drvic;              //!< the drvic interface object
    
      uint32_t       gateEnableGPIO;
      // BSXL8353RS_REVA
  5. Configure SPI for communication with the BLDC motor driver.

    When using a motor driver with SPI, the SPI must be configured correctly from the MCU to match the format needed to communicate with the BLDC motor driver device properly.

    Configure the related GPIOs for SPI function in HAL_setupGPIOs() of the hal.c file. Ensure to check the BLDC motor driver data sheet to determine if each SPI pin requires an external pullup or pull down resistor, or if it is configured as a push-pull pin.

        // GPIO5->Connect to GPIO5 using a jumper wire->M1_DRV_SCS
        GPIO_setPinConfig(GPIO_5_SPIA_STE);
        GPIO_setDirectionMode(5, GPIO_DIR_MODE_OUT);
        GPIO_setPadConfig(5, GPIO_PIN_TYPE_STD);
    
        // GPIO09->M1_DRV_SCLK*
        GPIO_setPinConfig(GPIO_9_SPIA_CLK);
        GPIO_setDirectionMode(9, GPIO_DIR_MODE_OUT);
        GPIO_setPadConfig(9, GPIO_PIN_TYPE_PULLUP);
    
        // GPIO10->SPIA_SOMI->M1_DRV_SDO*
        GPIO_setPinConfig(GPIO_10_SPIA_SOMI);
        GPIO_setDirectionMode(10, GPIO_DIR_MODE_IN);
        GPIO_setPadConfig(10, GPIO_PIN_TYPE_PULLUP);
    
        // GPIO11->SPIA_SIMO->M1_DRV_SDI*
        GPIO_setPinConfig(GPIO_11_SPIA_SIMO);
        GPIO_setDirectionMode(11, GPIO_DIR_MODE_OUT);
        GPIO_setPadConfig(11, GPIO_PIN_TYPE_PULLUP);

    Configure the SPI control registers for baud rate, data frame in HAL_setupSPI() in the hal.c file:

        // Must put SPI into reset before configuring it
        SPI_disableModule(obj->spiHandle);
    
        // SPI configuration. Use a 500kHz SPICLK and 16-bit word size, 25MHz LSPCLK
        SPI_setConfig(obj->spiHandle, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,
                      SPI_MODE_MASTER, 400000, 16);
    
        SPI_disableLoopback(obj->spiHandle);
    
        SPI_setEmulationMode(obj->spiHandle, SPI_EMULATION_FREE_RUN);
    
        SPI_enableFIFO(obj->spiHandle);
        SPI_setTxFifoTransmitDelay(obj->spiHandle, 0x10);
    
        SPI_clearInterruptStatus(obj->spiHandle, SPI_INT_TXFF);
    
        // Configuration complete. Enable the module.
        SPI_enableModule(obj->spiHandle);
  6. Configure the GPIOs for the other input and output pins, such as ENABLE, nFAULT. You might refer to the example codes in HAL_setupGPIOs() , HAL_setupGate() of the hal.c file and the defines in the hal.h file as follows:
    //! \brief Defines the gpio for enabling Power Module
    #define MTR1_GATE_EN_GPIO       29
    
    //! \brief Defines the gpio for the nFAULT of Power Module
    #define MTR1_PM_nFAULT_GPIO     34
  7. Call the HAL_setupSPI() and HAL_setupGate() functions in HAL_MTR_setParams() of the hal.c file:
        // setup the spi for drv8323/drv8353/drv8316
        HAL_setupSPI(handle);
    
        // setup the drv8323s/drv8353s/drv8316s interface
        HAL_setupGate(handle);
  8. Call the drivers functions in the motor1_drive.c file as the following:
        // turn on the DRV8323/DRV8353/DRV8316 if present
        HAL_enableDRV(obj->halMtrHandle);
    
        // initialize the DRV8323/DRV8353/DRV8316 interface
        HAL_setupDRVSPI(obj->halMtrHandle, &drvicVars_M1);
  9. Change the default setting value for the BLDC motor driver, if needed.
        drvicVars_M1.ctrlReg05.bit.VDS_LVL = DRV8323_VDS_LEVEL_1P700_V;
        drvicVars_M1.ctrlReg05.bit.OCP_MODE = DRV8323_AUTOMATIC_RETRY;
        drvicVars_M1.ctrlReg05.bit.DEAD_TIME = DRV8323_DEADTIME_100_NS;
        drvicVars_M1.ctrlReg06.bit.CSA_GAIN = DRV8323_Gain_10VpV;
    
        drvicVars_M1.ctrlReg06.bit.LS_REF = false;
        drvicVars_M1.ctrlReg06.bit.VREF_DIV = true;
        drvicVars_M1.ctrlReg06.bit.CSA_FET = false;
    
        drvicVars_M1.writeCmd = 1;
        HAL_writeDRVData(obj->halMtrHandle, &drvicVars_M1);