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.

DRV8301: Overcurrent issues when motor has load

Part Number: DRV8301
Other Parts Discussed in Thread: , DRV8353

Hello team,

My customer is using the DRV8301-69M-KIT to evaluate and characterize the motors using the instaspin labs.  The motor works fine with no load, but once the load (propeller) is attached there is an overcurrent issue.  Is there a setting that needs to be changed? or is there other labs that the customer needs to implement to fix this issue?

One other question the customer has is the DRV8353 or DRV8301, capable of driving a motor to 40,000RPMs? and can it be implemented with the current CCS instaspin software?

Thanks!

Errol

Field Applications Engineer

  • Thanks, Errol. Please find attached modified user.h file and the proj_lab05b.c - it would be surprising that we'd have issues spinning up with load levels above 5V on this board. Could really use your support in debugging.

    proj_lab05b_modified.c
    {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
    {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
    {\colortbl;\red255\green255\blue255;\red63\green127\blue95;\red127\green0\blue85;\red42\green0\blue255;
    \red0\green80\blue50;\red100\green40\blue128;\red0\green0\blue192;}
    {\*\expandedcolortbl;;\csgenericrgb\c24706\c49804\c37255;\csgenericrgb\c49804\c0\c33333;\csgenericrgb\c16471\c0\c100000;
    \csgenericrgb\c0\c31373\c19608;\csgenericrgb\c39216\c15686\c50196;\csgenericrgb\c0\c0\c75294;}
    \margl1440\margr1440\vieww10800\viewh8400\viewkind0
    \deftab720
    \pard\pardeftab720\partightenfactor0
    
    \f0\fs20 \cf2 /* --COPYRIGHT--,BSD\cf0 \
    \cf2  * Copyright (c) 2012, Texas Instruments Incorporated\cf0 \
    \cf2  * All rights reserved.\cf0 \
    \cf2  *\cf0 \
    \cf2  * Redistribution and use in source and binary forms, with or without\cf0 \
    \cf2  * modification, are permitted provided that the following conditions\cf0 \
    \cf2  * are met:\cf0 \
    \cf2  *\cf0 \
    \cf2  * *  Redistributions of source code must retain the above copyright\cf0 \
    \cf2  *    notice, this list of conditions and the following disclaimer.\cf0 \
    \cf2  *\cf0 \
    \cf2  * *  Redistributions in binary form must reproduce the above copyright\cf0 \
    \cf2  *    notice, this list of conditions and the following disclaimer in the\cf0 \
    \cf2  *    documentation and/or other materials provided with the distribution.\cf0 \
    \cf2  *\cf0 \
    \cf2  * *  Neither the name of Texas Instruments Incorporated nor the names of\cf0 \
    \cf2  *    its contributors may be used to endorse or promote products derived\cf0 \
    \cf2  *    from this software without specific prior written permission.\cf0 \
    \cf2  *\cf0 \
    \cf2  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\cf0 \
    \cf2  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\cf0 \
    \cf2  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\cf0 \
    \cf2  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\cf0 \
    \cf2  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\cf0 \
    \cf2  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\cf0 \
    \cf2  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\cf0 \
    \cf2  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\cf0 \
    \cf2  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\cf0 \
    \cf2  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\cf0 \
    \cf2  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\cf0 \
    \cf2  * --/COPYRIGHT--*/\cf0 \
    \cf2 //! \\file   solutions/instaspin_foc/\ul src\ulnone /proj_lab05b.c\cf0 \
    \cf2 //! \\brief Adjusting the speed current controller\cf0 \
    \cf2 //!\cf0 \
    \cf2 //! (C) Copyright 2011, Texas Instruments, Inc.\cf0 \
    \
    \cf2 //! \\\ul defgroup\ulnone  PROJ_LAB05b PROJ_LAB05b\cf0 \
    \cf2 //@\{\cf0 \
    \
    \cf2 //! \\\ul defgroup\ulnone  PROJ_LAB05b_OVERVIEW Project Overview\cf0 \
    \cf2 //!\cf0 \
    \cf2 //! Adjusting the supplied speed controller\cf0 \
    \cf2 //!\cf0 \
    \
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the includes\cf0 \
    \
    \cf2 // system includes\cf0 \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #include
    \b0 \cf0  \cf4 <math.h>\cf0 \
    
    \b \cf3 #include
    \b0 \cf0  \cf4 "main.h"\cf0 \
    
    \b \cf3 #include
    \b0 \cf0  \cf4 <stdio.h>\cf0 \
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  FLASH\
    
    \b \cf3 #pragma
    \b0 \cf0  CODE_SECTION(mainISR,\cf4 "\ul ramfuncs\ulnone "\cf0 );\
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    \cf2 // Include header files used in the main function\cf0 \
    \
    \
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the defines\cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #define
    \b0 \cf0  LED_BLINK_FREQ_Hz   5\
    \
    
    \b \cf3 float
    \b0 \cf0  SPEED_BASE_KRPM  = 8.0;  \cf2 // Max motor speed for DJI E300 920 \ul Kv\ulnone  at 11 V\cf0 \
    \
    
    \b \cf3 float
    \b0 \cf0  gSpeedRef_duty = 0.000;   \cf2 // Speed reference from external controller\cf0 \
    \
    
    \b \cf3 float
    \b0 \cf0  PwmDuty = 0.0;\
    \
    
    \b \cf3 float
    \b0 \cf0  gSpeedRef_Ok = 0;       \cf2 // Safety check for speed reference signal\cf0 \
    \
    
    \b \cf3 float
    \b0 \cf0  Smax = 2;     \cf2 // Maximum Speed\cf0 \
    \
    
    \b \cf3 float
    \b0 \cf0  Smin = 0;       \cf2 // Minimum Speed\cf0 \
    \
    
    \b \cf3 float
    \b0 \cf0  tmax = 2;        \cf2 // max pulse width in \ul ms\cf0 \ulnone \
    \
    
    \b \cf3 float
    \b0 \cf0  tmin = 1.1;       \cf2 //\ul min\ulnone  pulse width in \ul ms\cf0 \ulnone \
    \
    
    \b \cf3 float
    \b0 \cf0  Cmax;    \cf2 // \ul ecap\ulnone  maximum count\cf0 \
    \
    
    \b \cf3 float
    \b0 \cf0  Cmin;    \cf2 // \ul ecap\ulnone  counter time relating 1ms \ul pwm\ulnone  input\cf0 \
    \
    \
    \pard\pardeftab720\partightenfactor0
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the globals\cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    \cf5 uint_least16_t\cf0  gCounter_updateGlobals = 0;\
    \
    bool Flag_Latch_softwareUpdate = true;\
    \
    \cf5 CTRL_Handle\cf0  ctrlHandle;\
    \
    \cf5 HAL_Handle\cf0  halHandle;\
    \
    \cf5 USER_Params\cf0  gUserParams;\
    \
    \cf5 HAL_PwmData_t\cf0  gPwmData = \{_IQ(0.0), _IQ(0.0), _IQ(0.0)\};\
    \
    \cf5 HAL_AdcData_t\cf0  gAdcData;\
    \
    \cf5 _iq\cf0  gMaxCurrentSlope = _IQ(0.0);\
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #ifdef
    \b0 \cf0  FAST_ROM_V1p6\
    \pard\pardeftab720\partightenfactor0
    \cf5 CTRL_Obj\cf0  *controller_obj;\
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #else
    \b0 \cf0 \
    CTRL_Obj ctrl;              \cf2 //v1p7 format\cf0 \
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    \cf5 uint16_t\cf0  gLEDcnt = 0;\
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 volatile
    \b0 \cf0  \cf5 MOTOR_Vars_t\cf0  gMotorVars = MOTOR_Vars_INIT;\
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  FLASH\
    \pard\pardeftab720\partightenfactor0
    \cf2 // Used for running BackGround in flash, and ISR in RAM\cf0 \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 extern
    \b0 \cf0  uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;\
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  DRV8301_SPI\
    \pard\pardeftab720\partightenfactor0
    \cf2 // Watch window interface to the 8301 SPI\cf0 \
    \pard\pardeftab720\partightenfactor0
    \cf5 DRV_SPI_8301_Vars_t\cf0  gDrvSpi8301Vars;\
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  DRV8305_SPI\
    \pard\pardeftab720\partightenfactor0
    \cf2 // Watch window interface to the 8305 SPI\cf0 \
    DRV_SPI_8305_Vars_t gDrvSpi8305Vars;\
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    \cf5 _iq\cf0  gFlux_pu_to_Wb_sf;\
    \
    \cf5 _iq\cf0  gFlux_pu_to_VpHz_sf;\
    \
    \cf5 _iq\cf0  gTorque_Ls_Id_Iq_pu_to_Nm_sf;\
    \
    \cf5 _iq\cf0  gTorque_Flux_Iq_pu_to_Nm_sf;\
    \
    \pard\pardeftab720\partightenfactor0
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the functions\cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 void
    \b0 \cf0  
    \b main
    \b0 (
    \b \cf3 void
    \b0 \cf0 )\
    \{\
      \cf5 uint_least8_t\cf0  estNumber = 0;\
      \cf2 //\ul printf\ulnone ("\ul Miccheck\ulnone \\n");\cf0 \
    
    \b \cf3 #ifdef
    \b0 \cf0  FAST_ROM_V1p6\
      \cf5 uint_least8_t\cf0  ctrlNumber = 0;\
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
      \cf2 // Only used if running from FLASH\cf0 \
      \cf2 // Note that the variable FLASH is defined by the project\cf0 \
      
    \b \cf3 #ifdef
    \b0 \cf0  FLASH\
      \cf2 // Copy time critical code and Flash setup code to RAM\cf0 \
      \cf2 // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart\cf0 \
      \cf2 // symbols are created by the linker. Refer to the linker files.\cf0 \
      memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);\
      
    \b \cf3 #endif
    \b0 \cf0 \
    \
      \cf2 // initialize the hardware abstraction layer\cf0 \
      halHandle = 
    \b \cf6 HAL_init
    \b0 \cf0 (&hal,
    \b \cf3 sizeof
    \b0 \cf0 (hal));\
    \
    \
      \cf2 // check for errors in user parameters\cf0 \
      
    \b \cf6 USER_checkForErrors
    \b0 \cf0 (&gUserParams);\
    \
    \
      \cf2 // store user parameter error in global variable\cf0 \
      gMotorVars.\cf7 UserErrorCode\cf0  = 
    \b \cf6 USER_getErrorCode
    \b0 \cf0 (&gUserParams);\
    \
    \
      \cf2 // do not allow code execution if there is a user parameter error\cf0 \
      
    \b \cf3 if
    \b0 \cf0 (gMotorVars.\cf7 UserErrorCode\cf0  != 
    \i \cf7 USER_ErrorCode_NoError
    \i0 \cf0 )\
        \{\
          
    \b \cf3 for
    \b0 \cf0 (;;)\
            \{\
              gMotorVars.\cf7 Flag_enableSys\cf0  = false;\
            \}\
        \}\
    \
    \
      \cf2 // initialize the user parameters\cf0 \
      
    \b \cf6 USER_setParams
    \b0 \cf0 (&gUserParams);\
    \
    \
      \cf2 // set the hardware abstraction layer parameters\cf0 \
      
    \b \cf6 HAL_setParams
    \b0 \cf0 (halHandle,&gUserParams);\
    \
    \
      \cf2 // initialize the controller\cf0 \
    
    \b \cf3 #ifdef
    \b0 \cf0  FAST_ROM_V1p6\
      ctrlHandle = 
    \b \cf6 CTRL_initCtrl
    \b0 \cf0 (ctrlNumber, estNumber);        \cf2 //v1p6 format (06xF and 06xM devices)\cf0 \
      controller_obj = (\cf5 CTRL_Obj\cf0  *)ctrlHandle;\
    
    \b \cf3 #else
    \b0 \cf0 \
      ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,
    \b \cf3 sizeof
    \b0 \cf0 (ctrl)); \cf2 //v1p7 format default\cf0 \
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    \
      \{\
        \cf5 CTRL_Version\cf0  version;\
    \
        \cf2 // get the version number\cf0 \
        
    \b \cf6 CTRL_getVersion
    \b0 \cf0 (ctrlHandle,&version);\
    \
        gMotorVars.\cf7 CtrlVersion\cf0  = version;\
      \}\
    \
    \
      \cf2 // set the default controller parameters\cf0 \
      
    \b \cf6 CTRL_setParams
    \b0 \cf0 (ctrlHandle,&gUserParams);\
    \
    \
      \cf2 // setup faults\cf0 \
      
    \b \cf6 HAL_setupFaults
    \b0 \cf0 (halHandle);\
    \
    \
      \cf2 // initialize the interrupt vector table\cf0 \
      HAL_initIntVectorTable(halHandle);\
    \
    \
      \cf2 // enable the ADC interrupts\cf0 \
      
    \b \cf6 HAL_enableAdcInts
    \b0 \cf0 (halHandle);\
    \
    \
      \cf2 // enable global interrupts\cf0 \
      
    \b \cf6 HAL_enableGlobalInts
    \b0 \cf0 (halHandle);\
    \
    \
      \cf2 // enable debug interrupts\cf0 \
      
    \b \cf6 HAL_enableDebugInt
    \b0 \cf0 (halHandle);\
    \
    \
      \cf2 // disable the PWM\cf0 \
      HAL_disablePwm(halHandle);\
    \
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  DRV8301_SPI\
      \cf2 // turn on the DRV8301 if present\cf0 \
      
    \b \cf6 HAL_enableDrv
    \b0 \cf0 (halHandle);\
      \cf2 // initialize the DRV8301 interface\cf0 \
      
    \b \cf6 HAL_setupDrvSpi
    \b0 \cf0 (halHandle,&gDrvSpi8301Vars);\
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  DRV8305_SPI\
      \cf2 // turn on the DRV8305 if present\cf0 \
      HAL_enableDrv(halHandle);\
      \cf2 // initialize the DRV8305 interface\cf0 \
      HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars);\
    
    \b \cf3 #endif
    \b0 \cf0 \
    \
    \
      \cf2 // enable DC bus compensation\cf0 \
      CTRL_setFlag_enableDcBusComp(ctrlHandle, true);\
    \
    \
      \cf2 // compute scaling factors for \ul flux\ulnone  and torque calculations\cf0 \
      gFlux_pu_to_Wb_sf = 
    \b \cf6 USER_computeFlux_pu_to_Wb_sf
    \b0 \cf0 ();\
      gFlux_pu_to_VpHz_sf = 
    \b \cf6 USER_computeFlux_pu_to_VpHz_sf
    \b0 \cf0 ();\
      gTorque_Ls_Id_Iq_pu_to_Nm_sf = 
    \b \cf6 USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf
    \b0 \cf0 ();\
      gTorque_Flux_Iq_pu_to_Nm_sf = 
    \b \cf6 USER_computeTorque_Flux_Iq_pu_to_Nm_sf
    \b0 \cf0 ();\
    \
    \
      
    \b \cf3 for
    \b0 \cf0 (;;)\
      \{\
        \cf2 // Waiting for enable system flag to be set\cf0 \
        
    \b \cf3 while
    \b0 \cf0 (!(gMotorVars.\cf7 Flag_enableSys\cf0 ));\
    \
        \cf2 // Enable the Library internal PI.  \ul Iq\ulnone  is referenced by the speed PI now\cf0 \
        CTRL_setFlag_enableSpeedCtrl(ctrlHandle, true);\
    \
        \cf2 // loop while the enable system flag is true\cf0 \
        
    \b \cf3 while
    \b0 \cf0 (gMotorVars.\cf7 Flag_enableSys\cf0 )\
          \{\
            \cf5 CTRL_Obj\cf0  *obj = (\cf5 CTRL_Obj\cf0  *)ctrlHandle;\
    \
            \cf2 // increment counters\cf0 \
            gCounter_updateGlobals++;\
    \
            \cf2 // enable/disable the use of motor parameters being loaded from user.h\cf0 \
            CTRL_setFlag_enableUserMotorParams(ctrlHandle,gMotorVars.\cf7 Flag_enableUserParams\cf0 );\
    \
            \cf2 // enable/disable \ul Rs\ulnone  \ul recalibration\ulnone  during motor startup\cf0 \
            
    \b \cf6 EST_setFlag_enableRsRecalc
    \b0 \cf0 (obj->\cf7 estHandle\cf0 ,gMotorVars.\cf7 Flag_enableRsRecalc\cf0 );\
    \
            \cf2 // enable/disable automatic calculation of bias values\cf0 \
            CTRL_setFlag_enableOffset(ctrlHandle,gMotorVars.\cf7 Flag_enableOffsetcalc\cf0 );\
    \
    \
            
    \b \cf3 if
    \b0 \cf0 (CTRL_isError(ctrlHandle))\
              \{\
                \cf2 // set the enable controller flag to false\cf0 \
                CTRL_setFlag_enableCtrl(ctrlHandle,false);\
    \
                \cf2 // set the enable system flag to false\cf0 \
                gMotorVars.\cf7 Flag_enableSys\cf0  = false;\
    \
                \cf2 // disable the PWM\cf0 \
                HAL_disablePwm(halHandle);\
              \}\
            
    \b \cf3 else
    \b0 \cf0 \
              \{\
                \cf2 // update the controller state\cf0 \
                bool flag_ctrlStateChanged = 
    \b \cf6 CTRL_updateState
    \b0 \cf0 (ctrlHandle);\
    \
                \cf2 // enable or disable the control\cf0 \
                CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.\cf7 Flag_Run_Identify\cf0 );\
    \
                
    \b \cf3 if
    \b0 \cf0 (flag_ctrlStateChanged)\
                  \{\
                    \cf5 CTRL_State_e\cf0  ctrlState = CTRL_getState(ctrlHandle);\
    \
                    
    \b \cf3 if
    \b0 \cf0 (ctrlState == 
    \i \cf7 CTRL_State_OffLine
    \i0 \cf0 )\
                      \{\
                        \cf2 // enable the PWM\cf0 \
                        HAL_enablePwm(halHandle);\
                      \}\
                    
    \b \cf3 else
    \b0 \cf0  
    \b \cf3 if
    \b0 \cf0 (ctrlState == 
    \i \cf7 CTRL_State_OnLine
    \i0 \cf0 )\
                      \{\
                        
    \b \cf3 if
    \b0 \cf0 (gMotorVars.\cf7 Flag_enableOffsetcalc\cf0  == true)\
                        \{\
                          \cf2 // update the ADC bias values\cf0 \
                          HAL_updateAdcBias(halHandle);\
                        \}\
                        
    \b \cf3 else
    \b0 \cf0 \
                        \{\
                          \cf2 // set the current bias\cf0 \
                          HAL_setBias(halHandle,
    \i \cf7 HAL_SensorType_Current
    \i0 \cf0 ,0,_IQ(I_A_offset));\
                          HAL_setBias(halHandle,
    \i \cf7 HAL_SensorType_Current
    \i0 \cf0 ,1,_IQ(I_B_offset));\
                          HAL_setBias(halHandle,
    \i \cf7 HAL_SensorType_Current
    \i0 \cf0 ,2,_IQ(I_C_offset));\
    \
                          \cf2 // set the voltage bias\cf0 \
                          HAL_setBias(halHandle,
    \i \cf7 HAL_SensorType_Voltage
    \i0 \cf0 ,0,_IQ(V_A_offset));\
                          HAL_setBias(halHandle,
    \i \cf7 HAL_SensorType_Voltage
    \i0 \cf0 ,1,_IQ(V_B_offset));\
                          HAL_setBias(halHandle,
    \i \cf7 HAL_SensorType_Voltage
    \i0 \cf0 ,2,_IQ(V_C_offset));\
                        \}\
    \
                        \cf2 // Return the bias value for currents\cf0 \
                        gMotorVars.\cf7 I_bias\cf0 .\cf7 value\cf0 [0] = HAL_getBias(halHandle,
    \i \cf7 HAL_SensorType_Current
    \i0 \cf0 ,0);\
                        gMotorVars.\cf7 I_bias\cf0 .\cf7 value\cf0 [1] = HAL_getBias(halHandle,
    \i \cf7 HAL_SensorType_Current
    \i0 \cf0 ,1);\
                        gMotorVars.\cf7 I_bias\cf0 .\cf7 value\cf0 [2] = HAL_getBias(halHandle,
    \i \cf7 HAL_SensorType_Current
    \i0 \cf0 ,2);\
    \
                        \cf2 // Return the bias value for voltages\cf0 \
                        gMotorVars.\cf7 V_bias\cf0 .\cf7 value\cf0 [0] = HAL_getBias(halHandle,
    \i \cf7 HAL_SensorType_Voltage
    \i0 \cf0 ,0);\
                        gMotorVars.\cf7 V_bias\cf0 .\cf7 value\cf0 [1] = HAL_getBias(halHandle,
    \i \cf7 HAL_SensorType_Voltage
    \i0 \cf0 ,1);\
                        gMotorVars.\cf7 V_bias\cf0 .\cf7 value\cf0 [2] = HAL_getBias(halHandle,
    \i \cf7 HAL_SensorType_Voltage
    \i0 \cf0 ,2);\
    \
                        \cf2 // enable the PWM\cf0 \
                        HAL_enablePwm(halHandle);\
                      \}\
                    
    \b \cf3 else
    \b0 \cf0  
    \b \cf3 if
    \b0 \cf0 (ctrlState == 
    \i \cf7 CTRL_State_Idle
    \i0 \cf0 )\
                      \{\
                        \cf2 // disable the PWM\cf0 \
                        HAL_disablePwm(halHandle);\
                        gMotorVars.\cf7 Flag_Run_Identify\cf0  = false;\
                      \}\
    \
                    
    \b \cf3 if
    \b0 \cf0 ((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&\
                      (ctrlState > 
    \i \cf7 CTRL_State_Idle
    \i0 \cf0 ) &&\
                      (gMotorVars.\cf7 CtrlVersion\cf0 .\cf7 minor\cf0  == 6))\
                      \{\
                        \cf2 // call this function to fix 1p6\cf0 \
                        
    \b \cf6 USER_softwareUpdate1p6
    \b0 \cf0 (ctrlHandle);\
                      \}\
    \
                  \}\
              \}\
    \
    \
            
    \b \cf3 if
    \b0 \cf0 (
    \b \cf6 EST_isMotorIdentified
    \b0 \cf0 (obj->\cf7 estHandle\cf0 ))\
              \{\
                \cf2 // set the current ramp\cf0 \
                
    \b \cf6 EST_setMaxCurrentSlope_pu
    \b0 \cf0 (obj->\cf7 estHandle\cf0 ,gMaxCurrentSlope);\
                gMotorVars.\cf7 Flag_MotorIdentified\cf0  = true;\
    \
                \cf2 // set the speed reference\cf0 \
                
    \b \cf6 CTRL_setSpd_ref_krpm
    \b0 \cf0 (ctrlHandle,gMotorVars.\cf7 SpeedRef_krpm\cf0 );\
    \
                \cf2 // set the speed acceleration\cf0 \
                CTRL_setMaxAccel_pu(ctrlHandle,_IQmpy(MAX_ACCEL_KRPMPS_SF,gMotorVars.\cf7 MaxAccel_krpmps\cf0 ));\
                
    \b \cf3 if
    \b0 \cf0 (Flag_Latch_softwareUpdate)\
                \{\
                  Flag_Latch_softwareUpdate = false;\
    \
                  
    \b \cf6 USER_calcPIgains
    \b0 \cf0 (ctrlHandle);\
    \
                  \cf2 // initialize the watch window \ul kp\ulnone  and \ul ki\ulnone  current values with \ul pre\ulnone -calculated values\cf0 \
                  gMotorVars.\cf7 Kp_Idq\cf0  = CTRL_getKp(ctrlHandle,
    \i \cf7 CTRL_Type_PID_Id
    \i0 \cf0 );\
                  gMotorVars.\cf7 Ki_Idq\cf0  = CTRL_getKi(ctrlHandle,
    \i \cf7 CTRL_Type_PID_Id
    \i0 \cf0 );\
    \
                  \cf2 // initialize the watch window \ul kp\ulnone  and \ul ki\ulnone  values with \ul pre\ulnone -calculated values\cf0 \
                  gMotorVars.\cf7 Kp_spd\cf0  = CTRL_getKp(ctrlHandle,
    \i \cf7 CTRL_Type_PID_spd
    \i0 \cf0 );\
                  gMotorVars.\cf7 Ki_spd\cf0  = CTRL_getKi(ctrlHandle,
    \i \cf7 CTRL_Type_PID_spd
    \i0 \cf0 );\
    \
                  \cf2 // TIDA-00643 custom values for speed controller\cf0 \
                  gMotorVars.\cf7 Kp_spd\cf0  = _IQ(2.000);\
                  gMotorVars.\cf7 Ki_spd\cf0  = _IQ(0.059);\
                \}\
    \
              \}\
            
    \b \cf3 else
    \b0 \cf0 \
              \{\
                Flag_Latch_softwareUpdate = true;\
    \
                \cf2 // the \ul estimator\ulnone  sets the maximum current slope during identification\cf0 \
                gMaxCurrentSlope = 
    \b \cf6 EST_getMaxCurrentSlope_pu
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
              \}\
    \
    \
            \cf2 // when appropriate, update the global variables\cf0 \
            
    \b \cf3 if
    \b0 \cf0 (gCounter_updateGlobals >= NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE)\
              \{\
                \cf2 // reset the counter\cf0 \
                gCounter_updateGlobals = 0;\
    \
                updateGlobalVariables_motor(ctrlHandle);\
              \}\
    \
    \
            \cf2 // update \ul Kp\ulnone  and \ul Ki\ulnone  gains\cf0 \
            updateKpKiGains(ctrlHandle);\
    \
            \cf2 // enable/disable the forced angle\cf0 \
            
    \b \cf6 EST_setFlag_enableForceAngle
    \b0 \cf0 (obj->\cf7 estHandle\cf0 ,gMotorVars.\cf7 Flag_enableForceAngle\cf0 );\
    \
            \cf2 // enable or disable power warp\cf0 \
            CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.\cf7 Flag_enablePowerWarp\cf0 );\
    \
    
    \b \cf3 #ifdef
    \b0 \cf0  DRV8301_SPI\
            
    \b \cf6 HAL_writeDrvData
    \b0 \cf0 (halHandle,&gDrvSpi8301Vars);\
    \
            
    \b \cf6 HAL_readDrvData
    \b0 \cf0 (halHandle,&gDrvSpi8301Vars);\
    
    \b \cf3 #endif
    \b0 \cf0 \
    
    \b \cf3 #ifdef
    \b0 \cf0  DRV8305_SPI\
            HAL_writeDrvData(halHandle,&gDrvSpi8305Vars);\
    \
            HAL_readDrvData(halHandle,&gDrvSpi8305Vars);\
    
    \b \cf3 #endif
    \b0 \cf0 \
          \} \cf2 // end of while(gFlag_enableSys) loop\cf0 \
    \
    \
        \cf2 // disable the PWM\cf0 \
        HAL_disablePwm(halHandle);\
    \
        \cf2 // set the default controller parameters (Reset the control to re-identify the motor)\cf0 \
        
    \b \cf6 CTRL_setParams
    \b0 \cf0 (ctrlHandle,&gUserParams);\
        gMotorVars.\cf7 Flag_Run_Identify\cf0  = false;\
    \
      \} \cf2 // end of for(;;) loop\cf0 \
    \
    \} \cf2 // end of main() function\cf0 \
    \
    \
    
    \b \cf3 interrupt
    \b0 \cf0  
    \b \cf3 void
    \b0 \cf0  
    \b mainISR
    \b0 (
    \b \cf3 void
    \b0 \cf0 )\
    \{\
      \cf2 // toggle status LED\cf0 \
      
    \b \cf3 if
    \b0 \cf0 (gLEDcnt++ > (\cf5 uint_least32_t\cf0 )(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))\
      \{\
        HAL_toggleLed(halHandle,(\cf5 GPIO_Number_e\cf0 )
    \i \cf7 HAL_Gpio_LED2
    \i0 \cf0 );\
        gLEDcnt = 0;\
      \}\
    \
      \cf2 // Check if speed reference signal is active\cf0 \
      \cf2 // If more than 2000 service routine cycles pass without signal, disable motor\cf0 \
      
    \b \cf3 if
    \b0 \cf0  (gSpeedRef_Ok++ > 10000)\
      \{\
          gSpeedRef_duty = 0;\
          gMotorVars.\cf7 Flag_Run_Identify\cf0  = 0;\
          gSpeedRef_Ok = 0;\
      \}\
    \
      \cf2 // acknowledge the ADC interrupt\cf0 \
      HAL_acqAdcInt(halHandle,
    \i \cf7 ADC_IntNumber_1
    \i0 \cf0 );\
    \
    \
      \cf2 // convert the ADC data\cf0 \
      HAL_readAdcData(halHandle,&gAdcData);\
    \
    \
      \cf2 // run the controller\cf0 \
      
    \b \cf6 CTRL_run
    \b0 \cf0 (ctrlHandle,halHandle,&gAdcData,&gPwmData);\
    \
    \
      \cf2 // write the PWM compare values\cf0 \
      HAL_writePwmData(halHandle,&gPwmData);\
    \
    \
      \cf2 // setup the controller\cf0 \
      
    \b \cf6 CTRL_setup
    \b0 \cf0 (ctrlHandle);\
    \
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of mainISR() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b updateGlobalVariables_motor
    \b0 (\cf5 CTRL_Handle\cf0  handle)\
    \{\
      \cf5 CTRL_Obj\cf0  *obj = (\cf5 CTRL_Obj\cf0  *)handle;\
    \
      \cf2 // get the speed estimate\cf0 \
      gMotorVars.\cf7 Speed_krpm\cf0  = 
    \b \cf6 EST_getSpeed_krpm
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // set motor speed command dependent\cf0 \
      \cf2 //gMotorVars.SpeedRef_krpm = _IQ24(gSpeedRef_duty*SPEED_BASE_KRPM);\cf0 \
      gMotorVars.\cf7 SpeedRef_krpm\cf0  = _IQ24(gSpeedRef_duty);\
      \cf2 // get the real time speed reference coming out of the speed trajectory generator\cf0 \
      gMotorVars.\cf7 SpeedTraj_krpm\cf0  = _IQmpy(CTRL_getSpd_int_ref_pu(handle),
    \b \cf6 EST_get_pu_to_krpm_sf
    \b0 \cf0 (obj->\cf7 estHandle\cf0 ));\
    \
      \cf2 // get the torque estimate\cf0 \
      gMotorVars.\cf7 Torque_Nm\cf0  = 
    \b \cf6 USER_computeTorque_Nm
    \b0 \cf0 (handle, gTorque_Flux_Iq_pu_to_Nm_sf, gTorque_Ls_Id_Iq_pu_to_Nm_sf);\
    \
      \cf2 // get the \ul magnetizing\ulnone  current\cf0 \
      gMotorVars.\cf7 MagnCurr_A\cf0  = 
    \b \cf6 EST_getIdRated
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // get the \ul rotor\ulnone  resistance\cf0 \
      gMotorVars.\cf7 Rr_Ohm\cf0  = 
    \b \cf6 EST_getRr_Ohm
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // get the \ul stator\ulnone  resistance\cf0 \
      gMotorVars.\cf7 Rs_Ohm\cf0  = 
    \b \cf6 EST_getRs_Ohm
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // get the \ul stator\ulnone  inductance in the direct coordinate direction\cf0 \
      gMotorVars.\cf7 Lsd_H\cf0  = 
    \b \cf6 EST_getLs_d_H
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // get the \ul stator\ulnone  inductance in the quadrature coordinate direction\cf0 \
      gMotorVars.\cf7 Lsq_H\cf0  = 
    \b \cf6 EST_getLs_q_H
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // get the \ul flux\ulnone  in V/Hz in floating point\cf0 \
      gMotorVars.\cf7 Flux_VpHz\cf0  = 
    \b \cf6 EST_getFlux_VpHz
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // get the \ul flux\ulnone  in \ul Wb\ulnone  in fixed point\cf0 \
      gMotorVars.\cf7 Flux_Wb\cf0  = 
    \b \cf6 USER_computeFlux
    \b0 \cf0 (handle, gFlux_pu_to_Wb_sf);\
    \
      \cf2 // get the controller state\cf0 \
      gMotorVars.\cf7 CtrlState\cf0  = CTRL_getState(handle);\
    \
      \cf2 // get the \ul estimator\ulnone  state\cf0 \
      gMotorVars.\cf7 EstState\cf0  = 
    \b \cf6 EST_getState
    \b0 \cf0 (obj->\cf7 estHandle\cf0 );\
    \
      \cf2 // Get the DC buss voltage\cf0 \
      gMotorVars.\cf7 VdcBus_kV\cf0  = _IQmpy(gAdcData.\cf7 dcBus\cf0 ,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of updateGlobalVariables_motor() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b updateKpKiGains
    \b0 (\cf5 CTRL_Handle\cf0  handle)\
    \{\
      
    \b \cf3 if
    \b0 \cf0 ((gMotorVars.\cf7 CtrlState\cf0  == 
    \i \cf7 CTRL_State_OnLine
    \i0 \cf0 ) && (gMotorVars.\cf7 Flag_MotorIdentified\cf0  == true) && (Flag_Latch_softwareUpdate == false))\
        \{\
          \cf2 // set the \ul kp\ulnone  and \ul ki\ulnone  speed values from the watch window\cf0 \
          CTRL_setKp(handle,
    \i \cf7 CTRL_Type_PID_spd
    \i0 \cf0 ,gMotorVars.\cf7 Kp_spd\cf0 );\
          CTRL_setKi(handle,
    \i \cf7 CTRL_Type_PID_spd
    \i0 \cf0 ,gMotorVars.\cf7 Ki_spd\cf0 );\
    \
          \cf2 // set the \ul kp\ulnone  and \ul ki\ulnone  current values for Id and \ul Iq\ulnone  from the watch window\cf0 \
          CTRL_setKp(handle,
    \i \cf7 CTRL_Type_PID_Id
    \i0 \cf0 ,gMotorVars.\cf7 Kp_Idq\cf0 );\
          CTRL_setKi(handle,
    \i \cf7 CTRL_Type_PID_Id
    \i0 \cf0 ,gMotorVars.\cf7 Ki_Idq\cf0 );\
          CTRL_setKp(handle,
    \i \cf7 CTRL_Type_PID_Iq
    \i0 \cf0 ,gMotorVars.\cf7 Kp_Idq\cf0 );\
          CTRL_setKi(handle,
    \i \cf7 CTRL_Type_PID_Iq
    \i0 \cf0 ,gMotorVars.\cf7 Ki_Idq\cf0 );\
        \}\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of updateKpKiGains() function\cf0 \
    \
    \
    
    \b \cf3 interrupt
    \b0 \cf0  
    \b \cf3 void
    \b0 \cf0  
    \b ecapISR
    \b0 (
    \b \cf3 void
    \b0 \cf0 )\
    \{\
    \
    \
        \cf2 // Compute the PWM high period (rising edge to falling edge)\cf0 \
        PwmDuty = (
    \b \cf3 float
    \b0 \cf0 ) CAP_getCap2(halHandle->\cf7 capHandle\cf0 ) - (
    \b \cf3 float
    \b0 \cf0 ) CAP_getCap1(halHandle->\cf7 capHandle\cf0 );\
        Cmax = 90625*tmax;    \cf2 // \ul ecap\ulnone  maximum count\cf0 \
        Cmin = 90625*tmin;    \cf2 // \ul ecap\ulnone  counter time relating 1ms \ul pwm\ulnone  input\cf0 \
    \pard\pardeftab720\partightenfactor0
    \cf2 //    \ul printf\ulnone ("PwmDuty = %f \\n", PwmDuty);\cf0 \
    \
        \cf2 // Assign the appropriate speed command, combine 0-5% and 95-100%\cf0 \
        \cf2 // 0-100% speed is proportional to 1-2ms high period\cf0 \
        \cf2 // 60MHz * 2ms = 120000\cf0 \
    \
    \cf2 //    // 0-1%\cf0 \
    \cf2 //    if (PwmDuty <= 61000)\cf0 \
    \cf2 //    \{\cf0 \
    \cf2 //        gSpeedRef_Ok = 0;\cf0 \
    \cf2 //        gSpeedRef_duty = 0;\cf0 \
    \cf2 //        gMotorVars.Flag_Run_Identify = 0;\cf0 \
    \cf2 //    \}\cf0 \
        \cf2 // 20-80%\cf0 \
        \cf2 //if ((PwmDuty > 35500) && (PwmDuty < 145000)) //change \ul pwm\ulnone  to respective duty % by changing the condition magnitudes here\cf0 \
        \cf2 //\{\cf0 \
        \cf2 //    gSpeedRef_Ok = 0;\cf0 \
        \cf2 //    gSpeedRef_duty = (PwmDuty)/181250; // duty % max value equivalent in \ul ecap\ulnone  timer count (181250)\cf0 \
        \cf2 //    gMotorVars.Flag_Run_Identify = 1;\cf0 \
        \cf2 //\}\cf0 \
    \
        \cf2 // 50-99% : 1ms to 2ms\cf0 \
    \
           
    \b \cf3 if
    \b0 \cf0  ((PwmDuty > Cmin) && (PwmDuty <= Cmax)) \cf2 //change \ul pwm\ulnone  to respective duty % by changing the condition magnitudes here\cf0 \
           \{\
               gSpeedRef_Ok = 0;\
              \cf2 // gSpeedRef_duty = (PwmDuty)/181250; // duty % max value equivalent in \ul ecap\ulnone  timer count (181250)\cf0 \
              \cf2 // gSpeedRef_duty = (PwmDuty-99688)/81562; // duty % max value equivalent in \ul ecap\ulnone  timer count (181250)\cf0 \
               gSpeedRef_duty = (((Smax-Smin)/(Cmax-Cmin))*(PwmDuty-Cmin) + Smin);\
               gMotorVars.\cf7 Flag_Run_Identify\cf0  = 1;\
           \}\
        \cf2 // > 99%\cf0 \
        \cf2 //else if (PwmDuty >= 181250)\cf0 \
        \cf2 //\{\cf0 \
        \cf2 //    gSpeedRef_Ok = 0;\cf0 \
        \cf2 //    gSpeedRef_duty = 1.0;\cf0 \
        \cf2 //    gMotorVars.Flag_Run_Identify = 1;\cf0 \
        \cf2 //\}\cf0 \
        \cf2 // Catch all\cf0 \
        
    \b \cf3 else
    \b0 \cf0 \
        \{\
            gSpeedRef_duty = 0;\
            gMotorVars.\cf7 Flag_Run_Identify\cf0  = 0;\
        \}\
    \
        \cf2 // Clear capture (CAP) interrupt flags\cf0 \
            CAP_clearInt(halHandle->\cf7 capHandle\cf0 , 
    \i \cf7 CAP_Int_Type_All
    \i0 \cf0 );\
    \
        \cf2 // Clears an interrupt defined by group number\cf0 \
        PIE_clearInt(halHandle->\cf7 pieHandle\cf0 , 
    \i \cf7 PIE_GroupNumber_4
    \i0 \cf0 );\
    \}  \cf2 // end of ecapISR() function\cf0 \
    \
    \
    \cf2 //@\} //\ul defgroup\cf0 \ulnone \
    \cf2 // end of file\cf0 \
    \
    \
    \
    }

    3513.user.h

  • Hi Errol, Adnan,

    The over-current is likely caused by the driver reacting to the high current when loaded. You may need to increase the threshold through the driver tab. 

  • Attached is the drv8301.c file. I'm not sure what level it is currently configured to, what it needs to be adjusted to, and which variable to update.

    As far as I know, this setting hasn't been modified from the default settings within the DRV8301-HC-C2-KIT and associated project files. I'm barely able to get it to support current levels above 3A. This doesn't make sense, since the kit was designed for 60A operation. Maybe we're missing something...

    drv8301.c
    {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
    {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
    {\colortbl;\red255\green255\blue255;\red63\green127\blue95;\red127\green0\blue85;\red42\green0\blue255;
    \red0\green80\blue50;\red100\green40\blue128;\red0\green0\blue192;}
    {\*\expandedcolortbl;;\csgenericrgb\c24706\c49804\c37255;\csgenericrgb\c49804\c0\c33333;\csgenericrgb\c16471\c0\c100000;
    \csgenericrgb\c0\c31373\c19608;\csgenericrgb\c39216\c15686\c50196;\csgenericrgb\c0\c0\c75294;}
    \margl1440\margr1440\vieww10800\viewh8400\viewkind0
    \deftab720
    \pard\pardeftab720\partightenfactor0
    
    \f0\fs20 \cf2 /* --COPYRIGHT--,BSD\cf0 \
    \cf2  * Copyright (c) 2015, Texas Instruments Incorporated\cf0 \
    \cf2  * All rights reserved.\cf0 \
    \cf2  *\cf0 \
    \cf2  * Redistribution and use in source and binary forms, with or without\cf0 \
    \cf2  * modification, are permitted provided that the following conditions\cf0 \
    \cf2  * are met:\cf0 \
    \cf2  *\cf0 \
    \cf2  * *  Redistributions of source code must retain the above copyright\cf0 \
    \cf2  *    notice, this list of conditions and the following disclaimer.\cf0 \
    \cf2  *\cf0 \
    \cf2  * *  Redistributions in binary form must reproduce the above copyright\cf0 \
    \cf2  *    notice, this list of conditions and the following disclaimer in the\cf0 \
    \cf2  *    documentation and/or other materials provided with the distribution.\cf0 \
    \cf2  *\cf0 \
    \cf2  * *  Neither the name of Texas Instruments Incorporated nor the names of\cf0 \
    \cf2  *    its contributors may be used to endorse or promote products derived\cf0 \
    \cf2  *    from this software without specific prior written permission.\cf0 \
    \cf2  *\cf0 \
    \cf2  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\cf0 \
    \cf2  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\cf0 \
    \cf2  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\cf0 \
    \cf2  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\cf0 \
    \cf2  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\cf0 \
    \cf2  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\cf0 \
    \cf2  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\cf0 \
    \cf2  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\cf0 \
    \cf2  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\cf0 \
    \cf2  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\cf0 \
    \cf2  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\cf0 \
    \cf2  * --/COPYRIGHT--*/\cf0 \
    \cf2 //! \\file   drivers/\ul drvic\ulnone /drv8301/\ul src\ulnone /32b/f28x/f2806x/drv8301.c\cf0 \
    \cf2 //! \\brief  Contains the various functions related to the DRV8301 object\cf0 \
    \cf2 //!\cf0 \
    \cf2 //! (C) Copyright 2015, Texas Instruments, Inc.\cf0 \
    \
    \
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the includes\cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #include
    \b0 \cf0  \cf4 <math.h>\cf0 \
    \
    \
    \pard\pardeftab720\partightenfactor0
    \cf2 // drivers\cf0 \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 #include
    \b0 \cf0  \cf4 "sw/drivers/drvic/drv8301/src/32b/f28x/f2806x/drv8301.h"\cf0 \
    \
    \
    \pard\pardeftab720\partightenfactor0
    \cf2 // modules\cf0 \
    \
    \
    \cf2 // platforms\cf0 \
    \
    \
    \
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the defines\cf0 \
    \
    \
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the globals\cf0 \
    \
    \
    \cf2 // **************************************************************************\cf0 \
    \cf2 // the function prototypes\cf0 \
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_enable
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 DRV8301_Obj\cf0  *obj = (\cf5 DRV8301_Obj\cf0  *)handle;\
      
    \b \cf3 static
    \b0 \cf0  
    \b \cf3 volatile
    \b0 \cf0  \cf5 uint16_t\cf0  enableWaitTimeOut;\
      \cf5 uint16_t\cf0  n = 0;\
    \
      \cf2 // Enable the drv8301\cf0 \
      
    \b \cf6 GPIO_setHigh
    \b0 \cf0 (obj->\cf7 gpioHandle\cf0 ,obj->\cf7 gpioNumber\cf0 );\
    \
      enableWaitTimeOut = 0;\
    \
      \cf2 // Make sure the Fault bit is not set during startup\cf0 \
      
    \b \cf3 while
    \b0 \cf0 (((DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Status_1
    \i0 \cf0 ) & DRV8301_STATUS1_FAULT_BITS) != 0) && (enableWaitTimeOut < 1000))\
      \{\
        
    \b \cf3 if
    \b0 \cf0 (++enableWaitTimeOut > 999)\
        \{\
          obj->\cf7 enableTimeOut\cf0  = true;\
        \}\
      \}\
    \
      \cf2 // Wait for the DRV8301 registers to update\cf0 \
      
    \b \cf3 for
    \b0 \cf0 (n=0;n<0xffff;n++)\
        
    \b \cf3 asm
    \b0 \cf0 (\cf4 " NOP"\cf0 );\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \}\
    \
    \pard\pardeftab720\partightenfactor0
    \cf5 DRV8301_DcCalMode_e\cf0  
    \b DRV8301_getDcCalMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_ShuntAmpNumber_e\cf0  ampNumber)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      
    \b \cf3 if
    \b0 \cf0 (ampNumber == 
    \i \cf7 DRV8301_ShuntAmpNumber_1
    \i0 \cf0 )\
        \{\
          data &= (~DRV8301_CTRL2_DC_CAL_1_BITS);\
    \
        \}\
      
    \b \cf3 else
    \b0 \cf0  
    \b \cf3 if
    \b0 \cf0 (ampNumber == 
    \i \cf7 DRV8301_ShuntAmpNumber_2
    \i0 \cf0 )\
        \{\
          data &= (~DRV8301_CTRL2_DC_CAL_2_BITS);\
        \}\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_DcCalMode_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getDcCalMode() function\cf0 \
    \
    \
    \cf5 DRV8301_FaultType_e\cf0  
    \b DRV8301_getFaultType
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 DRV8301_Word_t\cf0       readWord;\
      \cf5 DRV8301_FaultType_e\cf0  faultType = 
    \i \cf7 DRV8301_FaultType_NoFault
    \i0 \cf0 ;\
    \
    \
      \cf2 // read the data\cf0 \
      readWord = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Status_1
    \i0 \cf0 );\
    \
      
    \b \cf3 if
    \b0 \cf0 (readWord & DRV8301_STATUS1_FAULT_BITS)\
        \{\
          faultType = (\cf5 DRV8301_FaultType_e\cf0 )(readWord & DRV8301_FAULT_TYPE_MASK);\
    \
          
    \b \cf3 if
    \b0 \cf0 (faultType == 
    \i \cf7 DRV8301_FaultType_NoFault
    \i0 \cf0 )\
            \{\
              \cf2 // read the data\cf0 \
              readWord = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Status_2
    \i0 \cf0 );\
    \
              
    \b \cf3 if
    \b0 \cf0 (readWord & DRV8301_STATUS2_GVDD_OV_BITS)\
                \{\
                  faultType = 
    \i \cf7 DRV8301_FaultType_GVDD_OV
    \i0 \cf0 ;\
                \}\
            \}\
        \}\
    \
      
    \b \cf3 return
    \b0 \cf0 (faultType);\
    \} \cf2 // end of DRV8301_getFaultType() function\cf0 \
    \
    \
    \cf5 uint16_t\cf0  
    \b DRV8301_getId
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Status_2
    \i0 \cf0 );\
    \
      \cf2 // mask bits\cf0 \
      data &= DRV8301_STATUS2_ID_BITS;\
    \
      
    \b \cf3 return
    \b0 \cf0 (data);\
    \} \cf2 // end of DRV8301_getId() function\cf0 \
    \
    \
    \cf5 DRV8301_VdsLevel_e\cf0  
    \b DRV8301_getOcLevel
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_OC_ADJ_SET_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_VdsLevel_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getOcLevel() function\cf0 \
    \
    \
    \cf5 DRV8301_OcMode_e\cf0  
    \b DRV8301_getOcMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_OC_MODE_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_OcMode_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getOcMode() function\cf0 \
    \
    \
    \cf5 DRV8301_OcOffTimeMode_e\cf0  
    \b DRV8301_getOcOffTimeMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL2_OC_TOFF_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_OcOffTimeMode_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getOcOffTimeMode() function\cf0 \
    \
    \
    \cf5 DRV8301_OcTwMode_e\cf0  
    \b DRV8301_getOcTwMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL2_OCTW_SET_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_OcTwMode_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getOcTwMode() function\cf0 \
    \
    \
    \cf5 DRV8301_PeakCurrent_e\cf0  
    \b DRV8301_getPeakCurrent
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_GATE_CURRENT_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_PeakCurrent_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getPeakCurrent() function\cf0 \
    \
    \
    \cf5 DRV8301_PwmMode_e\cf0  
    \b DRV8301_getPwmMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_PWM_MODE_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_PwmMode_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getPwmMode() function\cf0 \
    \
    \
    \cf5 DRV8301_ShuntAmpGain_e\cf0  
    \b DRV8301_getShuntAmpGain
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL2_GAIN_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_ShuntAmpGain_e\cf0 )data);\
    \} \cf2 // end of DRV8301_getShuntAmpGain() function\cf0 \
    \
    \
    \cf5 DRV8301_Handle\cf0  
    \b DRV8301_init
    \b0 (
    \b \cf3 void
    \b0 \cf0  *pMemory,
    \b \cf3 const
    \b0 \cf0  \cf5 size_t\cf0  numBytes)\
    \{\
      \cf5 DRV8301_Handle\cf0  handle;\
    \
    \
      
    \b \cf3 if
    \b0 \cf0 (numBytes < 
    \b \cf3 sizeof
    \b0 \cf0 (\cf5 DRV8301_Obj\cf0 ))\
        
    \b \cf3 return
    \b0 \cf0 ((\cf5 DRV8301_Handle\cf0 )NULL);\
    \
    \
      \cf2 // assign the handle\cf0 \
      handle = (\cf5 DRV8301_Handle\cf0 )pMemory;\
    \
      DRV8301_resetRxTimeout(handle);\
      DRV8301_resetEnableTimeout(handle);\
    \
    \
      
    \b \cf3 return
    \b0 \cf0 (handle);\
    \} \cf2 // end of DRV8301_init() function\cf0 \
    \
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setGpioHandle
    \b0 (\cf5 DRV8301_Handle\cf0  handle,\cf5 GPIO_Handle\cf0  gpioHandle)\
    \{\
      \cf5 DRV8301_Obj\cf0  *obj = (\cf5 DRV8301_Obj\cf0  *)handle;\
    \
      \cf2 // initialize the \ul gpio\ulnone  interface object\cf0 \
      obj->\cf7 gpioHandle\cf0  = gpioHandle;\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setGpioHandle() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setGpioNumber
    \b0 (\cf5 DRV8301_Handle\cf0  handle,\cf5 GPIO_Number_e\cf0  gpioNumber)\
    \{\
      \cf5 DRV8301_Obj\cf0  *obj = (\cf5 DRV8301_Obj\cf0  *)handle;\
    \
      \cf2 // initialize the \ul gpio\ulnone  interface object\cf0 \
      obj->\cf7 gpioNumber\cf0  = gpioNumber;\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setGpioNumber() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setSpiHandle
    \b0 (\cf5 DRV8301_Handle\cf0  handle,\cf5 SPI_Handle\cf0  spiHandle)\
    \{\
      \cf5 DRV8301_Obj\cf0  *obj = (\cf5 DRV8301_Obj\cf0  *)handle;\
    \
      \cf2 // initialize the serial peripheral interface object\cf0 \
      obj->\cf7 spiHandle\cf0  = spiHandle;\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setSpiHandle() function\cf0 \
    \
    \
    bool 
    \b DRV8301_isFault
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 DRV8301_Word_t\cf0  readWord;\
      bool status=false;\
    \
    \
      \cf2 // read the data\cf0 \
      readWord = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Status_1
    \i0 \cf0 );\
    \
      
    \b \cf3 if
    \b0 \cf0 (readWord & DRV8301_STATUS1_FAULT_BITS)\
        \{\
          status = true;\
        \}\
    \
      
    \b \cf3 return
    \b0 \cf0 (status);\
    \} \cf2 // end of DRV8301_isFault() function\cf0 \
    \
    \
    bool 
    \b DRV8301_isReset
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 DRV8301_Word_t\cf0  readWord;\
      bool status=false;\
    \
    \
      \cf2 // read the data\cf0 \
      readWord = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      
    \b \cf3 if
    \b0 \cf0 (readWord & DRV8301_CTRL1_GATE_RESET_BITS)\
        \{\
          status = true;\
        \}\
    \
      
    \b \cf3 return
    \b0 \cf0 (status);\
    \} \cf2 // end of DRV8301_isReset() function\cf0 \
    \
    \
    \pard\pardeftab720\partightenfactor0
    \cf5 uint16_t\cf0  
    \b DRV8301_readSpi
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_RegName_e\cf0  regName)\
    \{\
      \cf5 DRV8301_Obj\cf0  *obj = (\cf5 DRV8301_Obj\cf0  *)handle;\
      \cf5 uint16_t\cf0  ctrlWord;\
      
    \b \cf3 const
    \b0 \cf0  \cf5 uint16_t\cf0  data = 0;\
      
    \b \cf3 volatile
    \b0 \cf0  \cf5 uint16_t\cf0  readWord;\
      
    \b \cf3 static
    \b0 \cf0  
    \b \cf3 volatile
    \b0 \cf0  \cf5 uint16_t\cf0  WaitTimeOut = 0;\
      
    \b \cf3 volatile
    \b0 \cf0  \cf5 SPI_FifoStatus_e\cf0  RxFifoCnt = 
    \i \cf7 SPI_FifoStatus_Empty
    \i0 \cf0 ;\
    \
    \
      \cf2 // build the control word\cf0 \
      ctrlWord = (\cf5 uint16_t\cf0 )DRV8301_buildCtrlWord(
    \i \cf7 DRV8301_CtrlMode_Read
    \i0 \cf0 ,regName,data);\
    \
      \cf2 // reset the \ul Rx\ulnone  \ul fifo\ulnone  pointer to zero\cf0 \
      
    \b \cf6 SPI_resetRxFifo
    \b0 \cf0 (obj->\cf7 spiHandle\cf0 );\
      
    \b \cf6 SPI_enableRxFifo
    \b0 \cf0 (obj->\cf7 spiHandle\cf0 );\
    \
    \
      \cf2 // write the command\cf0 \
      SPI_write(obj->\cf7 spiHandle\cf0 ,ctrlWord);\
      \cf2 // dummy write to return the reply from the 8301\cf0 \
      SPI_write(obj->\cf7 spiHandle\cf0 ,0x0000);\
    \
      \cf2 // wait for two words to populate the RX \ul fifo\ulnone , or a wait timeout will occur\cf0 \
      
    \b \cf3 while
    \b0 \cf0 ((RxFifoCnt < 
    \i \cf7 SPI_FifoStatus_2_Words
    \i0 \cf0 ) && (WaitTimeOut < 0xffff))\
      \{\
        RxFifoCnt = 
    \b \cf6 SPI_getRxFifoStatus
    \b0 \cf0 (obj->\cf7 spiHandle\cf0 );\
    \
          
    \b \cf3 if
    \b0 \cf0 (++WaitTimeOut > 0xfffe)\
          \{\
              obj->\cf7 RxTimeOut\cf0  = true;\
          \}\
      \}\
    \
      \cf2 // Read two words, the dummy word and the data\cf0 \
      readWord = SPI_readEmu(obj->\cf7 spiHandle\cf0 );\
      readWord = SPI_readEmu(obj->\cf7 spiHandle\cf0 );\
    \
      
    \b \cf3 return
    \b0 \cf0 (readWord & DRV8301_DATA_MASK);\
    \}  \cf2 // end of DRV8301_readSpi() function\cf0 \
    \
    \
    \pard\pardeftab720\partightenfactor0
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_reset
    \b0 (\cf5 DRV8301_Handle\cf0  handle)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // set the bits\cf0 \
      data |= DRV8301_CTRL1_GATE_RESET_BITS;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \}  \cf2 // end of DRV8301_reset() function\cf0 \
    \
      \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setDcCalMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_ShuntAmpNumber_e\cf0  ampNumber,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_DcCalMode_e\cf0  mode)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      
    \b \cf3 if
    \b0 \cf0 (ampNumber == 
    \i \cf7 DRV8301_ShuntAmpNumber_1
    \i0 \cf0 )\
        \{\
          data &= (~DRV8301_CTRL2_DC_CAL_1_BITS);\
    \
        \}\
      
    \b \cf3 else
    \b0 \cf0  
    \b \cf3 if
    \b0 \cf0 (ampNumber == 
    \i \cf7 DRV8301_ShuntAmpNumber_2
    \i0 \cf0 )\
        \{\
          data &= (~DRV8301_CTRL2_DC_CAL_2_BITS);\
        \}\
    \
      \cf2 // set the bits\cf0 \
      data |= mode;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setDcCalMode() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setOcLevel
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_VdsLevel_e\cf0  VdsLevel)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_OC_ADJ_SET_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= VdsLevel;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setOcLevel() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setOcMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_OcMode_e\cf0  mode)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_OC_MODE_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= mode;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setOcMode() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setOcOffTimeMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_OcOffTimeMode_e\cf0  mode)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL2_OC_TOFF_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= mode;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setOcOffTimeMode() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setOcTwMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_OcTwMode_e\cf0  mode)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL2_OCTW_SET_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= mode;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setOcTwMode() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setPeakCurrent
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_PeakCurrent_e\cf0  peakCurrent)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_GATE_CURRENT_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= peakCurrent;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setPeakCurrent() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setPwmMode
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_PwmMode_e\cf0  mode)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL1_PWM_MODE_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= mode;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setPwmMode() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setShuntAmpGain
    \b0 (\cf5 DRV8301_Handle\cf0  handle,
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_ShuntAmpGain_e\cf0  gain)\
    \{\
      \cf5 uint16_t\cf0  data;\
    \
    \
      \cf2 // read data\cf0 \
      data = DRV8301_readSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 );\
    \
      \cf2 // clear the bits\cf0 \
      data &= (~DRV8301_CTRL2_GAIN_BITS);\
    \
      \cf2 // set the bits\cf0 \
      data |= gain;\
    \
      \cf2 // write the data\cf0 \
      DRV8301_writeSpi(handle,
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ,data);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \} \cf2 // end of DRV8301_setShuntAmpGain() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_writeSpi
    \b0 (\cf5 DRV8301_Handle\cf0  handle, 
    \b \cf3 const
    \b0 \cf0  \cf5 DRV8301_RegName_e\cf0  regName,
    \b \cf3 const
    \b0 \cf0  \cf5 uint16_t\cf0  data)\
    \{\
      \cf5 DRV8301_Obj\cf0  *obj = (\cf5 DRV8301_Obj\cf0  *)handle;\
      \cf5 uint16_t\cf0  ctrlWord;\
    \
    \
      \cf2 // build the command\cf0 \
      ctrlWord = (\cf5 uint16_t\cf0 )DRV8301_buildCtrlWord(
    \i \cf7 DRV8301_CtrlMode_Write
    \i0 \cf0 ,regName,data);\
    \
      \cf2 // reset the \ul Rx\ulnone  \ul fifo\ulnone  pointer to zero\cf0 \
      
    \b \cf6 SPI_resetRxFifo
    \b0 \cf0 (obj->\cf7 spiHandle\cf0 );\
      
    \b \cf6 SPI_enableRxFifo
    \b0 \cf0 (obj->\cf7 spiHandle\cf0 );\
    \
      \cf2 // write the command (time N)\cf0 \
      SPI_write(obj->\cf7 spiHandle\cf0 ,ctrlWord);\
    \
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \}  \cf2 // end of DRV8301_writeSpi() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_writeData
    \b0 (\cf5 DRV8301_Handle\cf0  handle, \cf5 DRV_SPI_8301_Vars_t\cf0  *Spi_8301_Vars)\
    \{\
      \cf5 DRV8301_RegName_e\cf0   drvRegName;\
      \cf5 uint16_t\cf0  drvDataNew;\
    \
    \
      
    \b \cf3 if
    \b0 \cf0 (Spi_8301_Vars->\cf7 SndCmd\cf0 )\
      \{\
        \cf2 // Update Control Register 1\cf0 \
        drvRegName = 
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ;\
        drvDataNew = Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 DRV8301_CURRENT\cf0  |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 DRV8301_RESET\cf0    |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 PWM_MODE\cf0      |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 OC_MODE\cf0       |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 OC_ADJ_SET\cf0 ;\
        DRV8301_writeSpi(handle,drvRegName,drvDataNew);\
    \
        \cf2 // Update Control Register 2\cf0 \
        drvRegName = 
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ;\
        drvDataNew = Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 OCTW_SET\cf0       |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 GAIN\cf0           |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 DC_CAL_CH1p2\cf0   |  \\\
                     Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 OC_TOFF\cf0 ;\
        DRV8301_writeSpi(handle,drvRegName,drvDataNew);\
    \
        Spi_8301_Vars->\cf7 SndCmd\cf0  = false;\
      \}\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \}  \cf2 // end of DRV8301_writeData() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_readData
    \b0 (\cf5 DRV8301_Handle\cf0  handle, \cf5 DRV_SPI_8301_Vars_t\cf0  *Spi_8301_Vars)\
    \{\
      \cf5 DRV8301_RegName_e\cf0   drvRegName;\
      \cf5 uint16_t\cf0  drvDataNew;\
    \
    \
      
    \b \cf3 if
    \b0 \cf0 (Spi_8301_Vars->\cf7 RcvCmd\cf0 )\
      \{\
        \cf2 // Update Status Register 1\cf0 \
        drvRegName = 
    \i \cf7 DRV8301_RegName_Status_1
    \i0 \cf0 ;\
        drvDataNew = DRV8301_readSpi(handle,drvRegName);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FAULT\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FAULT_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 GVDD_UV\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_GVDD_UV_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 PVDD_UV\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_PVDD_UV_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 OTSD\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_OTSD_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 OTW\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_OTW_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETHA_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETHA_OC_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETLA_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETLA_OC_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETHB_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETHB_OC_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETLB_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETLB_OC_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETHC_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETHC_OC_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETLC_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETLC_OC_BITS);\
    \
        \cf2 // Update Status Register 2\cf0 \
        drvRegName = 
    \i \cf7 DRV8301_RegName_Status_2
    \i0 \cf0 ;\
        drvDataNew = DRV8301_readSpi(handle,drvRegName);\
        Spi_8301_Vars->\cf7 Stat_Reg_2\cf0 .\cf7 GVDD_OV\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS2_GVDD_OV_BITS);\
        Spi_8301_Vars->\cf7 Stat_Reg_2\cf0 .\cf7 DeviceID\cf0  = (\cf5 uint16_t\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS2_ID_BITS);\
    \
        \cf2 // Update Control Register 1\cf0 \
        drvRegName = 
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ;\
        drvDataNew = DRV8301_readSpi(handle,drvRegName);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 DRV8301_CURRENT\cf0  = (\cf5 DRV8301_PeakCurrent_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_GATE_CURRENT_BITS);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 DRV8301_RESET\cf0  = (\cf5 DRV8301_Reset_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_GATE_RESET_BITS);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 PWM_MODE\cf0  = (\cf5 DRV8301_PwmMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_PWM_MODE_BITS);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 OC_MODE\cf0  = (\cf5 DRV8301_OcMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_OC_MODE_BITS);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 OC_ADJ_SET\cf0  = (\cf5 DRV8301_VdsLevel_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_OC_ADJ_SET_BITS);\
    \
        \cf2 // Update Control Register 2\cf0 \
        drvRegName = 
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ;\
        drvDataNew = DRV8301_readSpi(handle,drvRegName);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 OCTW_SET\cf0  = (\cf5 DRV8301_OcTwMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL2_OCTW_SET_BITS);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 GAIN\cf0  = (\cf5 DRV8301_ShuntAmpGain_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL2_GAIN_BITS);\
        Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 DC_CAL_CH1p2\cf0  = (\cf5 DRV8301_DcCalMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )(DRV8301_CTRL2_DC_CAL_1_BITS | DRV8301_CTRL2_DC_CAL_2_BITS));\
        Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 OC_TOFF\cf0  = (\cf5 DRV8301_OcOffTimeMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL2_OC_TOFF_BITS);\
    \
        Spi_8301_Vars->\cf7 RcvCmd\cf0  = false;\
      \}\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \}  \cf2 // end of DRV8301_readData() function\cf0 \
    \
    \
    
    \b \cf3 void
    \b0 \cf0  
    \b DRV8301_setupSpi
    \b0 (\cf5 DRV8301_Handle\cf0  handle, \cf5 DRV_SPI_8301_Vars_t\cf0  *Spi_8301_Vars)\
    \{\
      \cf5 DRV8301_RegName_e\cf0   drvRegName;\
      \cf5 uint16_t\cf0  drvDataNew;\
      \cf5 uint16_t\cf0  n;\
    \
    \
      \cf2 // Update Control Register 1\cf0 \
      drvRegName = 
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ;\
      drvDataNew = (
    \i \cf7 DRV8301_PeakCurrent_0p25_A
    \i0 \cf0    | \\\
                    
    \i \cf7 DRV8301_Reset_Normal
    \i0 \cf0          | \\\
                    
    \i \cf7 DRV8301_PwmMode_Six_Inputs
    \i0 \cf0    | \\\
                    
    \i \cf7 DRV8301_OcMode_CurrentLimit
    \i0 \cf0   | \\\
                    
    \i \cf7 DRV8301_VdsLevel_0p730_V
    \i0 \cf0 );\
      DRV8301_writeSpi(handle,drvRegName,drvDataNew);\
    \
      \cf2 // Update Control Register 2\cf0 \
      drvRegName = 
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ;\
      drvDataNew = (
    \i \cf7 DRV8301_OcTwMode_Both
    \i0 \cf0         | \\\
                    
    \i \cf7 DRV8301_ShuntAmpGain_10VpV
    \i0 \cf0    | \\\
                    
    \i \cf7 DRV8301_DcCalMode_Ch1_Load
    \i0 \cf0    | \\\
                    
    \i \cf7 DRV8301_DcCalMode_Ch2_Load
    \i0 \cf0    | \\\
                    
    \i \cf7 DRV8301_OcOffTimeMode_Normal
    \i0 \cf0 );\
      DRV8301_writeSpi(handle,drvRegName,drvDataNew);\
    \
    \
      Spi_8301_Vars->\cf7 SndCmd\cf0  = false;\
      Spi_8301_Vars->\cf7 RcvCmd\cf0  = false;\
    \
    \
      \cf2 // Wait for the DRV8301 registers to update\cf0 \
      
    \b \cf3 for
    \b0 \cf0 (n=0;n<100;n++)\
        
    \b \cf3 asm
    \b0 \cf0 (\cf4 " NOP"\cf0 );\
    \
    \
      \cf2 // Update Status Register 1\cf0 \
      drvRegName = 
    \i \cf7 DRV8301_RegName_Status_1
    \i0 \cf0 ;\
      drvDataNew = DRV8301_readSpi(handle,drvRegName);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FAULT\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FAULT_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 GVDD_UV\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_GVDD_UV_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 PVDD_UV\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_PVDD_UV_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 OTSD\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_OTSD_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 OTW\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_OTW_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETHA_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETHA_OC_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETLA_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETLA_OC_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETHB_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETHB_OC_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETLB_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETLB_OC_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETHC_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETHC_OC_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_1\cf0 .\cf7 FETLC_OC\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS1_FETLC_OC_BITS);\
    \
      \cf2 // Update Status Register 2\cf0 \
      drvRegName = 
    \i \cf7 DRV8301_RegName_Status_2
    \i0 \cf0 ;\
      drvDataNew = DRV8301_readSpi(handle,drvRegName);\
      Spi_8301_Vars->\cf7 Stat_Reg_2\cf0 .\cf7 GVDD_OV\cf0  = (bool)(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS2_GVDD_OV_BITS);\
      Spi_8301_Vars->\cf7 Stat_Reg_2\cf0 .\cf7 DeviceID\cf0  = (\cf5 uint16_t\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_STATUS2_ID_BITS);\
    \
      \cf2 // Update Control Register 1\cf0 \
      drvRegName = 
    \i \cf7 DRV8301_RegName_Control_1
    \i0 \cf0 ;\
      drvDataNew = DRV8301_readSpi(handle,drvRegName);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 DRV8301_CURRENT\cf0  = (\cf5 DRV8301_PeakCurrent_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_GATE_CURRENT_BITS);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 DRV8301_RESET\cf0  = (\cf5 DRV8301_Reset_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_GATE_RESET_BITS);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 PWM_MODE\cf0  = (\cf5 DRV8301_PwmMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_PWM_MODE_BITS);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 OC_MODE\cf0  = (\cf5 DRV8301_OcMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_OC_MODE_BITS);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_1\cf0 .\cf7 OC_ADJ_SET\cf0  = (\cf5 DRV8301_VdsLevel_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL1_OC_ADJ_SET_BITS);\
    \
      \cf2 // Update Control Register 2\cf0 \
      drvRegName = 
    \i \cf7 DRV8301_RegName_Control_2
    \i0 \cf0 ;\
      drvDataNew = DRV8301_readSpi(handle,drvRegName);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 OCTW_SET\cf0  = (\cf5 DRV8301_OcTwMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL2_OCTW_SET_BITS);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 GAIN\cf0  = (\cf5 DRV8301_ShuntAmpGain_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL2_GAIN_BITS);\
      Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 DC_CAL_CH1p2\cf0  = (\cf5 DRV8301_DcCalMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )(DRV8301_CTRL2_DC_CAL_1_BITS | DRV8301_CTRL2_DC_CAL_2_BITS));\
      Spi_8301_Vars->\cf7 Ctrl_Reg_2\cf0 .\cf7 OC_TOFF\cf0  = (\cf5 DRV8301_OcOffTimeMode_e\cf0 )(drvDataNew & (\cf5 uint16_t\cf0 )DRV8301_CTRL2_OC_TOFF_BITS);\
    \
      
    \b \cf3 return
    \b0 \cf0 ;\
    \}\
    \
    \
    \pard\pardeftab720\partightenfactor0
    \cf2 // end of file\cf0 \
    }

  • Hi Errol, we understand now that this is not an overcurrent issue on the driver . I will move this thread to C2000 team.
  • Did you have any waveforms of motor phase current measured by an oscilloscope during the overcurrent issue, and did you see if there is a low-level output on nFault or nOCTW pins when an overcurrent fault reported.

    You might add "gDrvSpi8301Vars.Ctrl_Reg_1.OC_ADJ_SET" to expression watch window to check the current level configuration. And you could change the current limitation by using below codes.

    // Imax=Vds/RdsOn=0.576V/3.9mOHM=147A(peak)
    gDrvSpi8301Vars.Ctrl_Reg_1.OC_ADJ_SET = DRV8301_VdsLevel_0p576_V;
    gDrvSpi8301Vars.SndCmd = true;
    HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
  • Hi Yanming,

    From our call today I am going to have this continue on the other e2e thread linked below. From our discussion, this does not seem to be a overcurrent issue or hardware issue, but possibly having to do with the main ISR function for the ecap. I am testing it out today as well as the recommendation with the variable values in the user.h file with USER_IQ_FULL_SCALE_CURRENT_A, USER_ADC_FULL_SCALE_CURRENT_A and USER_MOTOR_MAX_CURRENT to achieve 40A.

    e2e.ti.com/.../760828

    Best,
    Errol Leon
    Texas Instruments
    Field Application Engineer
  • Yes, you might check how many CPU cycles will be taken by eCAP ISR, and if there is an overflow from the main ISR. It shouldn't have an overcurrent since you just set USER_MOTOR_MAX_CURRENT to 10A before. You shouldn't change USER_ADC_FULL_SCALE_CURRENT_A, and could set USER_IQ_FULL_SCALE_CURRENT_A to the value of USER_ADC_FULL_SCALE_CURRENT_A, just change USER_MOTOR_MAX_CURRENT to the target torque current you want. It's better to capture some current waveforms by oscilloscope that could help to solve the problem.
  • I haven’t heard from you for a week, so I’m assuming you were able to resolve your issue. If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information. If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.