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.

BOOSTXL-DRV8305EVM: nFault- with AVDD UVLO Fault

Part Number: BOOSTXL-DRV8305EVM
Other Parts Discussed in Thread: MOTORWARE, DRV8305, LAUNCHXL-F28069M, DRV8308EVM

I have just bought a new BOOSTXL-DRV8305EVM board and am using the F28069M Launchpad.

While using Lab 01b and 02a from motorware, as soon as I enable the identify motor to 1, the red LED signifying the fault glows up in the booster pack.

I have tried to check the fault condition by using the InstaSPIN_F2806xM_UNIVERSAL from GUI COmposer, DRV8305 SPI. The same problem gets repeated here, when I enable the system, there is no fault, but as soon as I run the motor the fault appears. I have attached the screenshot below.

Do let me know how to solve the problem?

  • Hi Prabhat,

    I see the AVDD_UVLO bit is also set, is AVDD votlage sufficient? Have you checked the full scale current setting used by the firmware before running the .out file in the directory in the application GUI? The SNS_A_OCP bit is likely a software overcurrent issue because an incorrect FULL_SCALE current value is set in user.h.

    Thanks,
    Aaron


  • I have not changed the default values, I have just updated the user.h for the motor settings as specified by the excel sheet provided in Motorware.

    I don't know the cause of AVDD_UVLO to be set.

    These readings are from a brand new DRV8305EVM.

  • Do I need to change any jumpers on F28069M launchpad before connecting the DRV8305 booster pack,

  • Hi Prabhat,

    I do not know the hardware setup of the LAUNCHXL-F28069M with BOOSTXL-DRV8305, please keep the default configurations of the LAUNCHXL-F28069M and follow any instructions in the BOOSTXL-DRV8305 User's Guide. Does the AVDD_UVLO bit ever clear with a clear fault command (setting CLR_FLT)? Are you ensuring the WAKE and EN_GATE bits are high (device is in operating state) and the device has no faults before doing any MotorWARE initializations? 

    AVDD on the schematic of the BOOSTXL-DRV8305 has no current load since nothing else is implementing AVDD. Also what voltage and current are you operating your motor at? We can double check these calculations are correct in implementing InstaSPIN-FOC. 

    Also forwarding to Yanming Luo for InstaSPIN-FOC support.

    Thanks, 
    Aaron

  •  You might take a look at the InstaSPIN lab user's guide which can be found in the folder below after you install the motorWare. http://www.ti.com/tool/motorware

    C:\ti\motorware\motorware_1_01_00_18\docs\labs

    And make sure that the BOOSTXL-DRV8305 is installed correctly on LAUNCHXL-F28069M.

    1. Attach the BOOSTXL inverter board to J1, J2, J3, J4 on the LAUNCHXL controller board. The inverter board to the controller board such that J1, J2 of BOOSTXL aligns with J1, J2 of LAUNCHXL.

    2. Connect the motor three phases, to MOTA, MOTB, and MOTC on the BOOSTXL inverter board.

    3. Connect the DC power supply (24V) to PVDD and GND on the BOOSTXL inverter board.

    4. Check if the J1 is defined for the using connector in user.h file as below.

    // select whether to use the inverter on connector J1 or J5 of the LaunchPad

    #define J1

  • I tried just setting EN_GATE and WAKE as high, then there are no-fault outputs, that suggest that AVDD is performing as intended. But when I try to run the motor the problem persists, with the same errors SNS_A_OCP and AVDD_UVLO set HIGH.

  •  I followed every step you said, I have also followed the excel sheet instructions provided in motorware. I am attaching the excel sheet and user.c, user.h and user_j1h files for your kind reference.

    5584.motorware_selecting_user_variables.xlsx

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    //! \file   solutions/instaspin_foc/src/user.c
    //! \brief Contains the function for setting initialization data to the CTRL, HAL, and EST modules
    //!
    //! (C) Copyright 2012, Texas Instruments, Inc.
    
    
    // **************************************************************************
    // the includes
    
    #include <math.h>
    #include "user.h"
    #include "sw/modules/ctrl/src/32b/ctrl.h"
    
    
    // **************************************************************************
    // the defines
    
    
    // **************************************************************************
    // the typedefs
    
    
    // **************************************************************************
    // the functions
    
    void USER_setParams(USER_Params *pUserParams)
    {
      pUserParams->iqFullScaleCurrent_A = USER_IQ_FULL_SCALE_CURRENT_A;
      pUserParams->iqFullScaleVoltage_V = USER_IQ_FULL_SCALE_VOLTAGE_V;
    
      pUserParams->iqFullScaleFreq_Hz = USER_IQ_FULL_SCALE_FREQ_Hz;
    
      pUserParams->numIsrTicksPerCtrlTick = USER_NUM_ISR_TICKS_PER_CTRL_TICK;
      pUserParams->numCtrlTicksPerCurrentTick = USER_NUM_CTRL_TICKS_PER_CURRENT_TICK;
      pUserParams->numCtrlTicksPerEstTick = USER_NUM_CTRL_TICKS_PER_EST_TICK;
      pUserParams->numCtrlTicksPerSpeedTick = USER_NUM_CTRL_TICKS_PER_SPEED_TICK;
      pUserParams->numCtrlTicksPerTrajTick = USER_NUM_CTRL_TICKS_PER_TRAJ_TICK;
    
      pUserParams->numCurrentSensors = USER_NUM_CURRENT_SENSORS;
      pUserParams->numVoltageSensors = USER_NUM_VOLTAGE_SENSORS;
    
      pUserParams->offsetPole_rps = USER_OFFSET_POLE_rps;
      pUserParams->fluxPole_rps = USER_FLUX_POLE_rps;
    
      pUserParams->zeroSpeedLimit = USER_ZEROSPEEDLIMIT;
    
      pUserParams->forceAngleFreq_Hz = USER_FORCE_ANGLE_FREQ_Hz;
    
      pUserParams->maxAccel_Hzps = USER_MAX_ACCEL_Hzps;
    
      pUserParams->maxAccel_est_Hzps = USER_MAX_ACCEL_EST_Hzps;
    
      pUserParams->directionPole_rps = USER_DIRECTION_POLE_rps;
    
      pUserParams->speedPole_rps = USER_SPEED_POLE_rps;
    
      pUserParams->dcBusPole_rps = USER_DCBUS_POLE_rps;
    
      pUserParams->fluxFraction = USER_FLUX_FRACTION;
    
      pUserParams->indEst_speedMaxFraction = USER_SPEEDMAX_FRACTION_FOR_L_IDENT;
    
      pUserParams->systemFreq_MHz = USER_SYSTEM_FREQ_MHz;
    
      pUserParams->pwmPeriod_usec = USER_PWM_PERIOD_usec;
    
      pUserParams->voltage_sf = USER_VOLTAGE_SF;
    
      pUserParams->current_sf = USER_CURRENT_SF;
    
      pUserParams->voltageFilterPole_rps = USER_VOLTAGE_FILTER_POLE_rps;
    
      pUserParams->maxVsMag_pu = USER_MAX_VS_MAG_PU;
    
      pUserParams->estKappa = USER_EST_KAPPAQ;
    
      pUserParams->motor_type = USER_MOTOR_TYPE;
      pUserParams->motor_numPolePairs = USER_MOTOR_NUM_POLE_PAIRS;
      pUserParams->motor_ratedFlux = USER_MOTOR_RATED_FLUX;
      pUserParams->motor_Rr = USER_MOTOR_Rr;
      pUserParams->motor_Rs = USER_MOTOR_Rs;
      pUserParams->motor_Ls_d = USER_MOTOR_Ls_d;
      pUserParams->motor_Ls_q = USER_MOTOR_Ls_q;
    
    /*  if((pUserParams->motor_Rr > (float_t)0.0) && (pUserParams->motor_Rs > (float_t)0.0))
        {
          pUserParams->powerWarpGain = sqrt((float_t)1.0 + pUserParams->motor_Rr/pUserParams->motor_Rs);
        }
      else
    */    {
          pUserParams->powerWarpGain = USER_POWERWARP_GAIN;
        }
    
      pUserParams->maxCurrent_resEst = USER_MOTOR_RES_EST_CURRENT;
      pUserParams->maxCurrent_indEst = USER_MOTOR_IND_EST_CURRENT;
      pUserParams->maxCurrent = USER_MOTOR_MAX_CURRENT;
    
      pUserParams->maxCurrentSlope = USER_MAX_CURRENT_SLOPE;
      pUserParams->maxCurrentSlope_powerWarp = USER_MAX_CURRENT_SLOPE_POWERWARP;
    
      pUserParams->IdRated = USER_MOTOR_MAGNETIZING_CURRENT;
      pUserParams->IdRatedFraction_ratedFlux = USER_IDRATED_FRACTION_FOR_RATED_FLUX;
      pUserParams->IdRatedFraction_indEst = USER_IDRATED_FRACTION_FOR_L_IDENT;
      pUserParams->IdRated_delta = USER_IDRATED_DELTA;
    
      pUserParams->fluxEstFreq_Hz = USER_MOTOR_FLUX_EST_FREQ_Hz;
    
      pUserParams->ctrlWaitTime[CTRL_State_Error]         = 0;
      pUserParams->ctrlWaitTime[CTRL_State_Idle]          = 0;
      pUserParams->ctrlWaitTime[CTRL_State_OffLine]       = (uint_least32_t)( 5.0 * USER_CTRL_FREQ_Hz);
      pUserParams->ctrlWaitTime[CTRL_State_OnLine]        = 0;
    
      pUserParams->estWaitTime[EST_State_Error]           = 0;
      pUserParams->estWaitTime[EST_State_Idle]            = 0;
      pUserParams->estWaitTime[EST_State_RoverL]          = (uint_least32_t)( 8.0 * USER_EST_FREQ_Hz);
      pUserParams->estWaitTime[EST_State_Rs]              = 0;
      pUserParams->estWaitTime[EST_State_RampUp]          = (uint_least32_t)((5.0 + USER_MOTOR_FLUX_EST_FREQ_Hz / USER_MAX_ACCEL_EST_Hzps) * USER_EST_FREQ_Hz);
      pUserParams->estWaitTime[EST_State_IdRated]         = (uint_least32_t)(30.0 * USER_EST_FREQ_Hz);
      pUserParams->estWaitTime[EST_State_RatedFlux_OL]    = (uint_least32_t)( 0.2 * USER_EST_FREQ_Hz);
      pUserParams->estWaitTime[EST_State_RatedFlux]       = 0;
      pUserParams->estWaitTime[EST_State_RampDown]        = (uint_least32_t)( 2.0 * USER_EST_FREQ_Hz);
      pUserParams->estWaitTime[EST_State_LockRotor]       = 0;
      pUserParams->estWaitTime[EST_State_Ls]              = 0;
      pUserParams->estWaitTime[EST_State_Rr]              = (uint_least32_t)(20.0 * USER_EST_FREQ_Hz);
      pUserParams->estWaitTime[EST_State_MotorIdentified] = 0;
      pUserParams->estWaitTime[EST_State_OnLine]          = 0;
    
      pUserParams->FluxWaitTime[EST_Flux_State_Error]     = 0;
      pUserParams->FluxWaitTime[EST_Flux_State_Idle]      = 0;
      pUserParams->FluxWaitTime[EST_Flux_State_CL1]       = (uint_least32_t)(10.0 * USER_EST_FREQ_Hz);
      pUserParams->FluxWaitTime[EST_Flux_State_CL2]       = (uint_least32_t)( 0.2 * USER_EST_FREQ_Hz);
      pUserParams->FluxWaitTime[EST_Flux_State_Fine]      = (uint_least32_t)( 4.0 * USER_EST_FREQ_Hz);
      pUserParams->FluxWaitTime[EST_Flux_State_Done]      = 0;
    
      pUserParams->LsWaitTime[EST_Ls_State_Error]        = 0;
      pUserParams->LsWaitTime[EST_Ls_State_Idle]         = 0;
      pUserParams->LsWaitTime[EST_Ls_State_RampUp]       = (uint_least32_t)( 3.0 * USER_EST_FREQ_Hz);
      pUserParams->LsWaitTime[EST_Ls_State_Init]         = (uint_least32_t)( 3.0 * USER_EST_FREQ_Hz);
      pUserParams->LsWaitTime[EST_Ls_State_Coarse]       = (uint_least32_t)( 0.2 * USER_EST_FREQ_Hz);
      pUserParams->LsWaitTime[EST_Ls_State_Fine]         = (uint_least32_t)(30.0 * USER_EST_FREQ_Hz);
      pUserParams->LsWaitTime[EST_Ls_State_Done]         = 0;
    
      pUserParams->RsWaitTime[EST_Rs_State_Error]        = 0;
      pUserParams->RsWaitTime[EST_Rs_State_Idle]         = 0;
      pUserParams->RsWaitTime[EST_Rs_State_RampUp]       = (uint_least32_t)( 1.0 * USER_EST_FREQ_Hz);
      pUserParams->RsWaitTime[EST_Rs_State_Coarse]       = (uint_least32_t)( 2.0 * USER_EST_FREQ_Hz);
      pUserParams->RsWaitTime[EST_Rs_State_Fine]         = (uint_least32_t)( 7.0 * USER_EST_FREQ_Hz);
      pUserParams->RsWaitTime[EST_Rs_State_Done]         = 0;
    
      pUserParams->ctrlFreq_Hz = USER_CTRL_FREQ_Hz;
    
      pUserParams->estFreq_Hz = USER_EST_FREQ_Hz;
    
      pUserParams->RoverL_estFreq_Hz = USER_R_OVER_L_EST_FREQ_Hz;
    
      pUserParams->trajFreq_Hz = USER_TRAJ_FREQ_Hz;
    
      pUserParams->ctrlPeriod_sec = USER_CTRL_PERIOD_sec;
    
      pUserParams->maxNegativeIdCurrent_a = USER_MAX_NEGATIVE_ID_REF_CURRENT_A;
    
      return;
    } // end of USER_setParams() function
    
    
    void USER_checkForErrors(USER_Params *pUserParams)
    {
      USER_setErrorCode(pUserParams, USER_ErrorCode_NoError);
    
      if((USER_IQ_FULL_SCALE_CURRENT_A <= 0.0) ||
        (USER_IQ_FULL_SCALE_CURRENT_A <= (0.02 * USER_MOTOR_MAX_CURRENT * USER_IQ_FULL_SCALE_FREQ_Hz / 128.0)) ||
        (USER_IQ_FULL_SCALE_CURRENT_A <= (2.0 * USER_MOTOR_MAX_CURRENT * USER_IQ_FULL_SCALE_FREQ_Hz * USER_CTRL_PERIOD_sec / 128.0)))
        {
    	  USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleCurrent_A_Low);
        }
    
      if((USER_IQ_FULL_SCALE_CURRENT_A < USER_MOTOR_MAGNETIZING_CURRENT) ||
        (USER_IQ_FULL_SCALE_CURRENT_A < USER_MOTOR_RES_EST_CURRENT) ||
        (USER_IQ_FULL_SCALE_CURRENT_A < USER_MOTOR_IND_EST_CURRENT) ||
        (USER_IQ_FULL_SCALE_CURRENT_A < USER_MOTOR_MAX_CURRENT))
        {
    	  USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleCurrent_A_Low);
        }
    
      if((USER_MOTOR_RATED_FLUX > 0.0) && (USER_MOTOR_TYPE == MOTOR_Type_Pm))
        {
          if(USER_IQ_FULL_SCALE_VOLTAGE_V >= ((float_t)USER_EST_FREQ_Hz * USER_MOTOR_RATED_FLUX * 0.7))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleVoltage_V_High);
            }
        }
    
      if((USER_MOTOR_RATED_FLUX > 0.0) && (USER_MOTOR_TYPE == MOTOR_Type_Induction))
        {
          if(USER_IQ_FULL_SCALE_VOLTAGE_V >= ((float_t)USER_EST_FREQ_Hz * USER_MOTOR_RATED_FLUX * 0.05))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleVoltage_V_High);
            }
        }
    
      if((USER_IQ_FULL_SCALE_VOLTAGE_V <= 0.0) ||
        (USER_IQ_FULL_SCALE_VOLTAGE_V <= (0.5 * USER_MOTOR_MAX_CURRENT * USER_MOTOR_Ls_d * USER_VOLTAGE_FILTER_POLE_rps)) ||
        (USER_IQ_FULL_SCALE_VOLTAGE_V <= (0.5 * USER_MOTOR_MAX_CURRENT * USER_MOTOR_Ls_q * USER_VOLTAGE_FILTER_POLE_rps)))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleVoltage_V_Low);
        }
    
      if((USER_IQ_FULL_SCALE_FREQ_Hz > (4.0 * USER_VOLTAGE_FILTER_POLE_Hz)) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz >= ((128.0 * USER_IQ_FULL_SCALE_CURRENT_A) / (0.02 * USER_MOTOR_MAX_CURRENT))) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz >= ((128.0 * USER_IQ_FULL_SCALE_CURRENT_A) / (2.0 * USER_MOTOR_MAX_CURRENT * USER_CTRL_PERIOD_sec))) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz >= (128.0 * (float_t)USER_MOTOR_NUM_POLE_PAIRS * 1000.0 / 60.0)))
        {
    	  USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleFreq_Hz_High);
        }
    
      if((USER_IQ_FULL_SCALE_FREQ_Hz < 50.0) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz < USER_MOTOR_FLUX_EST_FREQ_Hz) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz < USER_SPEED_POLE_rps) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz <= ((float_t)USER_MOTOR_NUM_POLE_PAIRS * 1000.0 / (60.0 * 128.0))) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz < (USER_MAX_ACCEL_Hzps / ((float_t)USER_TRAJ_FREQ_Hz))) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz < (USER_MAX_ACCEL_EST_Hzps / ((float_t)USER_TRAJ_FREQ_Hz))) ||
        (USER_IQ_FULL_SCALE_FREQ_Hz < ((float_t)USER_R_OVER_L_EST_FREQ_Hz)))
        {
    	  USER_setErrorCode(pUserParams, USER_ErrorCode_iqFullScaleFreq_Hz_Low);
        }
    
      if(USER_NUM_PWM_TICKS_PER_ISR_TICK > 3)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numPwmTicksPerIsrTick_High);
        }
    
      if(USER_NUM_PWM_TICKS_PER_ISR_TICK < 1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numPwmTicksPerIsrTick_Low);
        }
    
      if(USER_NUM_ISR_TICKS_PER_CTRL_TICK < 1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numIsrTicksPerCtrlTick_Low);
        }
    
      if(USER_NUM_CTRL_TICKS_PER_CURRENT_TICK < 1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numCtrlTicksPerCurrentTick_Low);
        }
    
      if(USER_NUM_CTRL_TICKS_PER_EST_TICK < 1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numCtrlTicksPerEstTick_Low);
        }
    
      if((USER_NUM_CTRL_TICKS_PER_SPEED_TICK < 1) ||
        (USER_NUM_CTRL_TICKS_PER_SPEED_TICK < USER_NUM_CTRL_TICKS_PER_CURRENT_TICK))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numCtrlTicksPerSpeedTick_Low);
        }
    
      if(USER_NUM_CTRL_TICKS_PER_TRAJ_TICK < 1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numCtrlTicksPerTrajTick_Low);
        }
    
      if(USER_NUM_CURRENT_SENSORS > 3)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numCurrentSensors_High);
        }
    
      if(USER_NUM_CURRENT_SENSORS < 2)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numCurrentSensors_Low);
        }
    
      if(USER_NUM_VOLTAGE_SENSORS > 3)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numVoltageSensors_High);
        }
    
      if(USER_NUM_VOLTAGE_SENSORS < 3)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_numVoltageSensors_Low);
        }
    
      if(USER_OFFSET_POLE_rps > ((float_t)USER_CTRL_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_offsetPole_rps_High);
        }
    
      if(USER_OFFSET_POLE_rps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_offsetPole_rps_Low);
        }
    
      if(USER_FLUX_POLE_rps > ((float_t)USER_EST_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_fluxPole_rps_High);
        }
    
      if(USER_FLUX_POLE_rps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_fluxPole_rps_Low);
        }
    
      if(USER_ZEROSPEEDLIMIT > 1.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_zeroSpeedLimit_High);
        }
    
      if(USER_ZEROSPEEDLIMIT <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_zeroSpeedLimit_Low);
        }
    
      if(USER_FORCE_ANGLE_FREQ_Hz > ((float_t)USER_EST_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_forceAngleFreq_Hz_High);
        }
    
      if(USER_FORCE_ANGLE_FREQ_Hz <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_forceAngleFreq_Hz_Low);
        }
    
      if(USER_MAX_ACCEL_Hzps > ((float_t)USER_TRAJ_FREQ_Hz * USER_IQ_FULL_SCALE_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxAccel_Hzps_High);
        }
    
      if(USER_MAX_ACCEL_Hzps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxAccel_Hzps_Low);
        }
    
      if(USER_MAX_ACCEL_EST_Hzps > ((float_t)USER_TRAJ_FREQ_Hz * USER_IQ_FULL_SCALE_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxAccel_est_Hzps_High);
        }
    
      if(USER_MAX_ACCEL_EST_Hzps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxAccel_est_Hzps_Low);
        }
    
      if(USER_DIRECTION_POLE_rps > ((float_t)USER_EST_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_directionPole_rps_High);
        }
    
      if(USER_DIRECTION_POLE_rps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_directionPole_rps_Low);
        }
    
      if((USER_SPEED_POLE_rps > USER_IQ_FULL_SCALE_FREQ_Hz) ||
        (USER_SPEED_POLE_rps > ((float_t)USER_EST_FREQ_Hz)))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_speedPole_rps_High);
        }
    
      if(USER_SPEED_POLE_rps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_speedPole_rps_Low);
        }
    
      if(USER_DCBUS_POLE_rps > ((float_t)USER_EST_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_dcBusPole_rps_High);
        }
    
      if(USER_DCBUS_POLE_rps <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_dcBusPole_rps_Low);
        }
    
      if(USER_FLUX_FRACTION > 1.2)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_fluxFraction_High);
        }
    
      if(USER_FLUX_FRACTION < 0.05)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_fluxFraction_Low);
        }
    
      if(USER_SPEEDMAX_FRACTION_FOR_L_IDENT > (USER_IQ_FULL_SCALE_CURRENT_A / USER_MOTOR_MAX_CURRENT))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_indEst_speedMaxFraction_High);
        }
    
      if(USER_SPEEDMAX_FRACTION_FOR_L_IDENT <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_indEst_speedMaxFraction_Low);
        }
    
      if(USER_POWERWARP_GAIN > 2.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_powerWarpGain_High);
        }
    
      if(USER_POWERWARP_GAIN < 1.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_powerWarpGain_Low);
        }
    
      if(USER_SYSTEM_FREQ_MHz > 90.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_systemFreq_MHz_High);
        }
    
      if(USER_SYSTEM_FREQ_MHz <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_systemFreq_MHz_Low);
        }
    
      if(USER_PWM_FREQ_kHz > (1000.0 * USER_SYSTEM_FREQ_MHz / 100.0))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_pwmFreq_kHz_High);
        }
    
      if(USER_PWM_FREQ_kHz < (1000.0 * USER_SYSTEM_FREQ_MHz / 65536.0))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_pwmFreq_kHz_Low);
        }
    
      if(USER_VOLTAGE_SF >= 128.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_voltage_sf_High);
        }
    
      if(USER_VOLTAGE_SF < 0.1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_voltage_sf_Low);
        }
    
      if(USER_CURRENT_SF >= 128.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_current_sf_High);
        }
    
      if(USER_CURRENT_SF < 0.1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_current_sf_Low);
        }
    
      if(USER_VOLTAGE_FILTER_POLE_Hz > ((float_t)USER_EST_FREQ_Hz / MATH_PI))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_voltageFilterPole_Hz_High);
        }
    
      if(USER_VOLTAGE_FILTER_POLE_Hz < (USER_IQ_FULL_SCALE_FREQ_Hz / 4.0))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_voltageFilterPole_Hz_Low);
        }
    
      if(USER_MAX_VS_MAG_PU > (4.0 / 3.0))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxVsMag_pu_High);
        }
    
      if(USER_MAX_VS_MAG_PU <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxVsMag_pu_Low);
        }
    
      if(USER_EST_KAPPAQ > 1.5)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_estKappa_High);
        }
    
      if(USER_EST_KAPPAQ < 1.5)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_estKappa_Low);
        }
    
      if((USER_MOTOR_TYPE != MOTOR_Type_Induction) && (USER_MOTOR_TYPE != MOTOR_Type_Pm))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_motor_type_Unknown);
        }
    
      if(USER_MOTOR_NUM_POLE_PAIRS < 1)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_motor_numPolePairs_Low);
        }
    
      if((USER_MOTOR_RATED_FLUX != 0.0) && (USER_MOTOR_TYPE == MOTOR_Type_Pm))
        {
          if(USER_MOTOR_RATED_FLUX > (USER_IQ_FULL_SCALE_FREQ_Hz * 65536.0 / (float_t)USER_EST_FREQ_Hz / 0.7))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_ratedFlux_High);
            }
    
          if(USER_MOTOR_RATED_FLUX < (USER_IQ_FULL_SCALE_VOLTAGE_V / (float_t)USER_EST_FREQ_Hz / 0.7))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_ratedFlux_Low);
            }
        }
    
      if((USER_MOTOR_RATED_FLUX != 0.0) && (USER_MOTOR_TYPE == MOTOR_Type_Induction))
        {
          if(USER_MOTOR_RATED_FLUX > (USER_IQ_FULL_SCALE_FREQ_Hz * 65536.0 / (float_t)USER_EST_FREQ_Hz / 0.05))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_ratedFlux_High);
            }
    
          if(USER_MOTOR_RATED_FLUX < (USER_IQ_FULL_SCALE_VOLTAGE_V / (float_t)USER_EST_FREQ_Hz / 0.05))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_ratedFlux_Low);
            }
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Pm)
        {
          if(USER_MOTOR_Rr > 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Rr_High);
            }
    
          if(USER_MOTOR_Rr < 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Rr_Low);
            }
        }
    
      if((USER_MOTOR_Rr != 0.0) && (USER_MOTOR_TYPE == MOTOR_Type_Induction))
        {
          if(USER_MOTOR_Rr > (0.7 * 65536.0 * USER_IQ_FULL_SCALE_VOLTAGE_V / USER_IQ_FULL_SCALE_CURRENT_A))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Rr_High);
            }
    
          if(USER_MOTOR_Rr < (0.7 * USER_IQ_FULL_SCALE_VOLTAGE_V / (USER_IQ_FULL_SCALE_CURRENT_A * 65536.0)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Rr_Low);
            }
        }
    
      if(USER_MOTOR_Rs != 0.0)
        {
          if(USER_MOTOR_Rs > (0.7 * 65536.0 * USER_IQ_FULL_SCALE_VOLTAGE_V / USER_IQ_FULL_SCALE_CURRENT_A))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Rs_High);
            }
    
          if(USER_MOTOR_Rs < (0.7 * USER_IQ_FULL_SCALE_VOLTAGE_V / (USER_IQ_FULL_SCALE_CURRENT_A * 65536.0)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Rs_Low);
            }
        }
    
      if(USER_MOTOR_Ls_d != 0.0)
        {
          if(USER_MOTOR_Ls_d > (0.7 * 65536.0 * USER_IQ_FULL_SCALE_VOLTAGE_V / (USER_IQ_FULL_SCALE_CURRENT_A * USER_VOLTAGE_FILTER_POLE_rps)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Ls_d_High);
            }
    
          if(USER_MOTOR_Ls_d < (0.7 * USER_IQ_FULL_SCALE_VOLTAGE_V / (USER_IQ_FULL_SCALE_CURRENT_A * USER_VOLTAGE_FILTER_POLE_rps * 65536.0)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Ls_d_Low);
            }
        }
    
      if(USER_MOTOR_Ls_q != 0.0)
        {
          if(USER_MOTOR_Ls_q > (0.7 * 65536.0 * USER_IQ_FULL_SCALE_VOLTAGE_V / (USER_IQ_FULL_SCALE_CURRENT_A * USER_VOLTAGE_FILTER_POLE_rps)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Ls_q_High);
            }
    
          if(USER_MOTOR_Ls_q < (0.7 * USER_IQ_FULL_SCALE_VOLTAGE_V / (USER_IQ_FULL_SCALE_CURRENT_A * USER_VOLTAGE_FILTER_POLE_rps * 65536.0)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_motor_Ls_q_Low);
            }
        }
    
      if(USER_MOTOR_RES_EST_CURRENT > USER_MOTOR_MAX_CURRENT)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_resEst_High);
        }
    
      if(USER_MOTOR_RES_EST_CURRENT < 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_resEst_Low);
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Pm)
        {
          if(USER_MOTOR_IND_EST_CURRENT > 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_indEst_High);
            }
    
          if(USER_MOTOR_IND_EST_CURRENT < (-USER_MOTOR_MAX_CURRENT))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_indEst_Low);
            }
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Induction)
        {
          if(USER_MOTOR_IND_EST_CURRENT > 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_indEst_High);
            }
    
          if(USER_MOTOR_IND_EST_CURRENT < 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_indEst_Low);
            }
        }
    
      if(USER_MOTOR_MAX_CURRENT > USER_IQ_FULL_SCALE_CURRENT_A)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_High);
        }
    
      if(USER_MOTOR_MAX_CURRENT <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrent_Low);
        }
    
      if(USER_MAX_CURRENT_SLOPE > 1.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrentSlope_High);
        }
    
      if(USER_MAX_CURRENT_SLOPE <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrentSlope_Low);
        }
    
      if(USER_MAX_CURRENT_SLOPE_POWERWARP > 1.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrentSlope_powerWarp_High);
        }
    
      if(USER_MAX_CURRENT_SLOPE_POWERWARP <= 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxCurrentSlope_powerWarp_Low);
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Pm)
        {
          if(USER_MOTOR_MAGNETIZING_CURRENT > 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRated_High);
            }
    
          if(USER_MOTOR_MAGNETIZING_CURRENT < 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRated_Low);
            }
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Induction)
        {
          if(USER_MOTOR_MAGNETIZING_CURRENT > USER_MOTOR_MAX_CURRENT)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRated_High);
            }
    
          if(USER_MOTOR_MAGNETIZING_CURRENT < 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRated_Low);
            }
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Induction)
        {
          if(USER_IDRATED_FRACTION_FOR_RATED_FLUX > (USER_IQ_FULL_SCALE_CURRENT_A / (1.2 * USER_MOTOR_MAX_CURRENT)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRatedFraction_ratedFlux_High);
            }
    
          if(USER_IDRATED_FRACTION_FOR_RATED_FLUX < 0.1)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRatedFraction_ratedFlux_Low);
            }
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Induction)
        {
          if(USER_IDRATED_FRACTION_FOR_L_IDENT > (USER_IQ_FULL_SCALE_CURRENT_A / USER_MOTOR_MAX_CURRENT))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRatedFraction_indEst_High);
            }
    
          if(USER_IDRATED_FRACTION_FOR_L_IDENT < 0.1)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRatedFraction_indEst_Low);
            }
        }
    
      if(USER_MOTOR_TYPE == MOTOR_Type_Induction)
        {
          if(USER_IDRATED_DELTA > (USER_IQ_FULL_SCALE_CURRENT_A / ((float_t)USER_NUM_ISR_TICKS_PER_CTRL_TICK * USER_MOTOR_MAX_CURRENT)))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRated_delta_High);
            }
    
          if(USER_IDRATED_DELTA < 0.0)
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_IdRated_delta_Low);
            }
        }
    
      if(USER_MOTOR_FLUX_EST_FREQ_Hz > USER_IQ_FULL_SCALE_FREQ_Hz)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_fluxEstFreq_Hz_High);
        }
    
      if((USER_MOTOR_FLUX_EST_FREQ_Hz < 0.0) ||
        (USER_MOTOR_FLUX_EST_FREQ_Hz < (USER_ZEROSPEEDLIMIT * USER_IQ_FULL_SCALE_FREQ_Hz)))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_fluxEstFreq_Hz_Low);
        }
    
      if(USER_MOTOR_Ls_d != 0.0)
        {
          if(((float_t)USER_CTRL_FREQ_Hz >= (128.0 * USER_IQ_FULL_SCALE_VOLTAGE_V / (0.5 * (USER_MOTOR_Ls_d + 1e-9) * USER_IQ_FULL_SCALE_CURRENT_A))))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_ctrlFreq_Hz_High);
            }
        }
    
      if(USER_MOTOR_Ls_q != 0.0)
        {
          if(((float_t)USER_CTRL_FREQ_Hz >= (128.0 * USER_IQ_FULL_SCALE_VOLTAGE_V / (0.5 * (USER_MOTOR_Ls_q + 1e-9) * USER_IQ_FULL_SCALE_CURRENT_A))))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_ctrlFreq_Hz_High);
            }
        }
    
      if(((float_t)USER_CTRL_FREQ_Hz < USER_IQ_FULL_SCALE_FREQ_Hz) ||
        ((float_t)USER_CTRL_FREQ_Hz < USER_OFFSET_POLE_rps) ||
        ((float_t)USER_CTRL_FREQ_Hz < 250.0) ||
        ((float_t)USER_CTRL_FREQ_Hz <= (2.0 * USER_IQ_FULL_SCALE_FREQ_Hz * USER_MOTOR_MAX_CURRENT / (128.0 * USER_IQ_FULL_SCALE_CURRENT_A))))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_ctrlFreq_Hz_Low);
        }
    
      if((USER_MOTOR_Rs != 0.0) && (USER_MOTOR_Ls_d != 0.0) && (USER_MOTOR_Ls_q != 0.0))
        {
          if(((float_t)USER_CTRL_FREQ_Hz <= (USER_MOTOR_Rs / (USER_MOTOR_Ls_d + 1e-9))) ||
            ((float_t)USER_CTRL_FREQ_Hz <= (USER_MOTOR_Rs / (USER_MOTOR_Ls_q + 1e-9))))
            {
              USER_setErrorCode(pUserParams, USER_ErrorCode_ctrlFreq_Hz_Low);
            }
        }
    
      if(((float_t)USER_EST_FREQ_Hz < USER_FORCE_ANGLE_FREQ_Hz) ||
        ((float_t)USER_EST_FREQ_Hz < USER_VOLTAGE_FILTER_POLE_rps) ||
        ((float_t)USER_EST_FREQ_Hz < USER_DCBUS_POLE_rps) ||
        ((float_t)USER_EST_FREQ_Hz < USER_FLUX_POLE_rps) ||
        ((float_t)USER_EST_FREQ_Hz < USER_DIRECTION_POLE_rps) ||
        ((float_t)USER_EST_FREQ_Hz < USER_SPEED_POLE_rps) ||
        ((float_t)USER_EST_FREQ_Hz < 0.2))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_estFreq_Hz_Low);
        }
    
      if(USER_R_OVER_L_EST_FREQ_Hz > USER_IQ_FULL_SCALE_FREQ_Hz)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_RoverL_estFreq_Hz_High);
        }
    
      if(((float_t)USER_TRAJ_FREQ_Hz < 1.0) ||
        ((float_t)USER_TRAJ_FREQ_Hz < USER_MAX_ACCEL_Hzps / USER_IQ_FULL_SCALE_FREQ_Hz) ||
        ((float_t)USER_TRAJ_FREQ_Hz < USER_MAX_ACCEL_EST_Hzps / USER_IQ_FULL_SCALE_FREQ_Hz))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_trajFreq_Hz_Low);
        }
    
      if(USER_MAX_NEGATIVE_ID_REF_CURRENT_A > 0.0)
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxNegativeIdCurrent_a_High);
        }
    
      if(USER_MAX_NEGATIVE_ID_REF_CURRENT_A < (-USER_MOTOR_MAX_CURRENT))
        {
          USER_setErrorCode(pUserParams, USER_ErrorCode_maxNegativeIdCurrent_a_Low);
        }
    
      // Only for debug testing, only be commented
    //  USER_setErrorCode(pUserParams, USER_ErrorCode_NoError);
    
      return;
    } // end of USER_checkForErrors() function
    
    
    USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
    {
      return(pUserParams->errorCode);
    } // end of USER_getErrorCode() function
    
    
    void USER_setErrorCode(USER_Params *pUserParams,const USER_ErrorCode_e errorCode)
    {
      pUserParams->errorCode = errorCode;
    
      return;
    } // end of USER_setErrorCode() function
    
    
    void USER_softwareUpdate1p6(CTRL_Handle handle)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
      float_t fullScaleInductance = USER_IQ_FULL_SCALE_VOLTAGE_V/(USER_IQ_FULL_SCALE_CURRENT_A*USER_VOLTAGE_FILTER_POLE_rps);
      float_t Ls_coarse_max = _IQ30toF(EST_getLs_coarse_max_pu(obj->estHandle));
      int_least8_t lShift = ceil(log(obj->motorParams.Ls_d_H/(Ls_coarse_max*fullScaleInductance))/log(2.0));
      uint_least8_t Ls_qFmt = 30 - lShift;
      float_t L_max = fullScaleInductance * pow(2.0,lShift);
      _iq Ls_d_pu = _IQ30(obj->motorParams.Ls_d_H / L_max);
      _iq Ls_q_pu = _IQ30(obj->motorParams.Ls_q_H / L_max);
    
    
      // store the results
      EST_setLs_d_pu(obj->estHandle,Ls_d_pu);
      EST_setLs_q_pu(obj->estHandle,Ls_q_pu);
      EST_setLs_qFmt(obj->estHandle,Ls_qFmt);
    
      return;
    } // end of softwareUpdate1p6() function
    
    
    #ifndef NO_CTRL
    void USER_calcPIgains(CTRL_Handle handle)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
      float_t fullScaleCurrent = USER_IQ_FULL_SCALE_CURRENT_A;
      float_t fullScaleVoltage = USER_IQ_FULL_SCALE_VOLTAGE_V;
      float_t ctrlPeriod_sec = CTRL_getCtrlPeriod_sec(handle);
      float_t Ls_d;
      float_t Ls_q;
      float_t Rs;
      float_t RoverLs_d;
      float_t RoverLs_q;
      _iq Kp_Id;
      _iq Ki_Id;
      _iq Kp_Iq;
      _iq Ki_Iq;
      _iq Kd;
    
    #ifdef __TMS320C28XX_FPU32__
      int32_t tmp;
    
      // when calling EST_ functions that return a float, and fpu32 is enabled, an integer is needed as a return
      // so that the compiler reads the returned value from the accumulator instead of fpu32 registers
      tmp = EST_getLs_d_H(obj->estHandle);
      Ls_d = *((float_t *)&tmp);
    
      tmp = EST_getLs_q_H(obj->estHandle);
      Ls_q = *((float_t *)&tmp);
    
      tmp = EST_getRs_Ohm(obj->estHandle);
      Rs = *((float_t *)&tmp);
    #else
      Ls_d = EST_getLs_d_H(obj->estHandle);
    
      Ls_q = EST_getLs_q_H(obj->estHandle);
    
      Rs = EST_getRs_Ohm(obj->estHandle);
    #endif
    
      RoverLs_d = Rs/Ls_d;
      Kp_Id = _IQ((0.25*Ls_d*fullScaleCurrent)/(ctrlPeriod_sec*fullScaleVoltage));
      Ki_Id = _IQ(RoverLs_d*ctrlPeriod_sec);
    
      RoverLs_q = Rs/Ls_q;
      Kp_Iq = _IQ((0.25*Ls_q*fullScaleCurrent)/(ctrlPeriod_sec*fullScaleVoltage));
      Ki_Iq = _IQ(RoverLs_q*ctrlPeriod_sec);
    
      Kd = _IQ(0.0);
    
      // set the Id controller gains
      PID_setKi(obj->pidHandle_Id,Ki_Id);
      CTRL_setGains(handle,CTRL_Type_PID_Id,Kp_Id,Ki_Id,Kd);
    
      // set the Iq controller gains
      PID_setKi(obj->pidHandle_Iq,Ki_Iq);
      CTRL_setGains(handle,CTRL_Type_PID_Iq,Kp_Iq,Ki_Iq,Kd);
    
      return;
    } // end of calcPIgains() function
    #endif
    
    
    //! \brief     Computes the scale factor needed to convert from torque created by Ld, Lq, Id and Iq, from per unit to Nm
    //!
    _iq USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf(void)
    {
      float_t FullScaleInductance = (USER_IQ_FULL_SCALE_VOLTAGE_V/(USER_IQ_FULL_SCALE_CURRENT_A*USER_VOLTAGE_FILTER_POLE_rps));
      float_t FullScaleCurrent = (USER_IQ_FULL_SCALE_CURRENT_A);
      float_t lShift = ceil(log(USER_MOTOR_Ls_d/(0.7*FullScaleInductance))/log(2.0));
    
      return(_IQ(FullScaleInductance*FullScaleCurrent*FullScaleCurrent*USER_MOTOR_NUM_POLE_PAIRS*1.5*pow(2.0,lShift)));
    } // end of USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf() function
    
    
    //! \brief     Computes the scale factor needed to convert from torque created by flux and Iq, from per unit to Nm
    //!
    _iq USER_computeTorque_Flux_Iq_pu_to_Nm_sf(void)
    {
      float_t FullScaleFlux = (USER_IQ_FULL_SCALE_VOLTAGE_V/(float_t)USER_EST_FREQ_Hz);
      float_t FullScaleCurrent = (USER_IQ_FULL_SCALE_CURRENT_A);
      float_t maxFlux = (USER_MOTOR_RATED_FLUX*((USER_MOTOR_TYPE==MOTOR_Type_Induction)?0.05:0.7));
      float_t lShift = -ceil(log(FullScaleFlux/maxFlux)/log(2.0));
    
      return(_IQ(FullScaleFlux/(2.0*MATH_PI)*FullScaleCurrent*USER_MOTOR_NUM_POLE_PAIRS*1.5*pow(2.0,lShift)));
    } // end of USER_computeTorque_Flux_Iq_pu_to_Nm_sf() function
    
    
    //! \brief     Computes the scale factor needed to convert from per unit to Wb
    //!
    _iq USER_computeFlux_pu_to_Wb_sf(void)
    {
      float_t FullScaleFlux = (USER_IQ_FULL_SCALE_VOLTAGE_V/(float_t)USER_EST_FREQ_Hz);
      float_t maxFlux = (USER_MOTOR_RATED_FLUX*((USER_MOTOR_TYPE==MOTOR_Type_Induction)?0.05:0.7));
      float_t lShift = -ceil(log(FullScaleFlux/maxFlux)/log(2.0));
    
      return(_IQ(FullScaleFlux/(2.0*MATH_PI)*pow(2.0,lShift)));
    } // end of USER_computeFlux_pu_to_Wb_sf() function
    
    
    //! \brief     Computes the scale factor needed to convert from per unit to V/Hz
    //!
    _iq USER_computeFlux_pu_to_VpHz_sf(void)
    {
      float_t FullScaleFlux = (USER_IQ_FULL_SCALE_VOLTAGE_V/(float_t)USER_EST_FREQ_Hz);
      float_t maxFlux = (USER_MOTOR_RATED_FLUX*((USER_MOTOR_TYPE==MOTOR_Type_Induction)?0.05:0.7));
      float_t lShift = -ceil(log(FullScaleFlux/maxFlux)/log(2.0));
    
      return(_IQ(FullScaleFlux*pow(2.0,lShift)));
    } // end of USER_computeFlux_pu_to_VpHz_sf() function
    
    
    //! \brief     Computes Flux in Wb or V/Hz depending on the scale factor sent as parameter
    //!
    _iq USER_computeFlux(CTRL_Handle handle, const _iq sf)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
    
      return(_IQmpy(EST_getFlux_pu(obj->estHandle),sf));
    } // end of USER_computeFlux() function
    
    
    //! \brief     Computes Torque in Nm
    //!
    _iq USER_computeTorque_Nm(CTRL_Handle handle, const _iq torque_Flux_sf, const _iq torque_Ls_sf)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
    
      _iq Flux_pu = EST_getFlux_pu(obj->estHandle);
      _iq Id_pu = PID_getFbackValue(obj->pidHandle_Id);
      _iq Iq_pu = PID_getFbackValue(obj->pidHandle_Iq);
      _iq Ld_minus_Lq_pu = _IQ30toIQ(EST_getLs_d_pu(obj->estHandle)-EST_getLs_q_pu(obj->estHandle));
      _iq Torque_Flux_Iq_Nm = _IQmpy(_IQmpy(Flux_pu,Iq_pu),torque_Flux_sf);
      _iq Torque_Ls_Id_Iq_Nm = _IQmpy(_IQmpy(_IQmpy(Ld_minus_Lq_pu,Id_pu),Iq_pu),torque_Ls_sf);
      _iq Torque_Nm = Torque_Flux_Iq_Nm + Torque_Ls_Id_Iq_Nm;
    
      return(Torque_Nm);
    } // end of USER_computeTorque_Nm() function
    
    
    //! \brief     Computes Torque in Nm
    //!
    _iq USER_computeTorque_lbin(CTRL_Handle handle, const _iq torque_Flux_sf, const _iq torque_Ls_sf)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
    
      _iq Flux_pu = EST_getFlux_pu(obj->estHandle);
      _iq Id_pu = PID_getFbackValue(obj->pidHandle_Id);
      _iq Iq_pu = PID_getFbackValue(obj->pidHandle_Iq);
      _iq Ld_minus_Lq_pu = _IQ30toIQ(EST_getLs_d_pu(obj->estHandle)-EST_getLs_q_pu(obj->estHandle));
      _iq Torque_Flux_Iq_Nm = _IQmpy(_IQmpy(Flux_pu,Iq_pu),torque_Flux_sf);
      _iq Torque_Ls_Id_Iq_Nm = _IQmpy(_IQmpy(_IQmpy(Ld_minus_Lq_pu,Id_pu),Iq_pu),torque_Ls_sf);
      _iq Torque_Nm = Torque_Flux_Iq_Nm + Torque_Ls_Id_Iq_Nm;
    
      return(_IQmpy(Torque_Nm, _IQ(MATH_Nm_TO_lbin_SF)));
    } // end of USER_computeTorque_lbin() function
    
    
    // end of file
    
    
    #ifndef _USER_H_
    #define _USER_H_
    /* --COPYRIGHT--,BSD
     * Copyright (c) 2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    
    //! \file   solutions/instaspin_foc/boards/boostxldrv8305_revA/f28x/f2806xF/src/user.h
    //! \brief  Contains the public interface for user initialization data for the CTRL, HAL, and EST modules 
    //!
    //! (C) Copyright 2015, Texas Instruments, Inc.
    
    
    // **************************************************************************
    // the includes
    
    // modules
    #include "sw/modules/types/src/types.h"
    #include "sw/modules/motor/src/32b/motor.h"
    #include "sw/modules/est/src/32b/est.h"
    #include "sw/modules/est/src/est_states.h"
    #include "sw/modules/est/src/est_Flux_states.h"
    #include "sw/modules/est/src/est_Ls_states.h"
    #include "sw/modules/est/src/est_Rs_states.h"
    #include "sw/modules/ctrl/src/32b/ctrl_obj.h"
    
    
    // select whether to use the inverter on connector J1 or J5 of the LaunchPad
    #define J1
    
    // platforms
    #include "sw/modules/fast/src/32b/userParams.h"
    
    #ifdef J5
    #include "user_j5.h"
    #else
    #include "user_j1.h"
    #endif
    
    //!
    //!
    //! \defgroup USER USER
    //!
    //@{
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // **************************************************************************
    // the defines
    
    
    //! \brief CURRENTS AND VOLTAGES
    // **************************************************************************
    //! \brief Defines the voltage scale factor for the system
    //! \brief Compile time calculation for scale factor (ratio) used throughout the system
    #define USER_VOLTAGE_SF               ((float_t)((USER_ADC_FULL_SCALE_VOLTAGE_V)/(USER_IQ_FULL_SCALE_VOLTAGE_V)))
    
    //! \brief Defines the current scale factor for the system
    //! \brief Compile time calculation for scale factor (ratio) used throughout the system
    #define USER_CURRENT_SF               ((float_t)((USER_ADC_FULL_SCALE_CURRENT_A)/(USER_IQ_FULL_SCALE_CURRENT_A)))
    
    
    //! \brief CLOCKS & TIMERS
    // **************************************************************************
    //! \brief Defines the system clock frequency, MHz
    #define USER_SYSTEM_FREQ_MHz             (90.0)
    
    //! \brief Defines the address of controller handle
    //!
    #define USER_CTRL_HANDLE_ADDRESS   (0x13C40)
    #define USER_CTRL_HANDLE_ADDRESS_1  (0x13D36)
    
    //! \brief Defines the address of estimator handle
    //!
    #define USER_EST_HANDLE_ADDRESS    (0x13840)
    #define USER_EST_HANDLE_ADDRESS_1   (0x13A3E)
    
    //! \brief Defines the direct voltage (Vd) scale factor
    //!
    #define USER_VD_SF                 (0.95)
    
    //! \brief Defines the Pulse Width Modulation (PWM) period, usec
    //! \brief Compile time calculation
    #define USER_PWM_PERIOD_usec       (1000.0/USER_PWM_FREQ_kHz)
    
    //! \brief Defines the Interrupt Service Routine (ISR) frequency, Hz
    //!
    #define USER_ISR_FREQ_Hz           ((float_t)USER_PWM_FREQ_kHz * 1000.0 / (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK)
    
    //! \brief Defines the Interrupt Service Routine (ISR) period, usec
    //!
    #define USER_ISR_PERIOD_usec       (USER_PWM_PERIOD_usec * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK)
    
    
    //! \brief DECIMATION
    // **************************************************************************
    //! \brief Defines the controller frequency, Hz
    //! \brief Compile time calculation
    #define USER_CTRL_FREQ_Hz          (uint_least32_t)(USER_ISR_FREQ_Hz/USER_NUM_ISR_TICKS_PER_CTRL_TICK)
    
    //! \brief Defines the estimator frequency, Hz
    //! \brief Compile time calculation
    #define USER_EST_FREQ_Hz           (uint_least32_t)(USER_CTRL_FREQ_Hz/USER_NUM_CTRL_TICKS_PER_EST_TICK)
    
    //! \brief Defines the trajectory frequency, Hz
    //! \brief Compile time calculation
    #define USER_TRAJ_FREQ_Hz          (uint_least32_t)(USER_CTRL_FREQ_Hz/USER_NUM_CTRL_TICKS_PER_TRAJ_TICK)
    
    //! \brief Defines the controller execution period, usec
    //! \brief Compile time calculation
    #define USER_CTRL_PERIOD_usec      (USER_ISR_PERIOD_usec * USER_NUM_ISR_TICKS_PER_CTRL_TICK)
    
    //! \brief Defines the controller execution period, sec
    //! \brief Compile time calculation
    #define USER_CTRL_PERIOD_sec       ((float_t)USER_CTRL_PERIOD_usec/(float_t)1000000.0)
    
    
    //! \brief LIMITS
    // **************************************************************************
    //! \brief Defines the maximum current slope for Id trajectory during PowerWarp
    //! \brief For Induction motors only, controls how fast Id input can change under PowerWarp control
    #define USER_MAX_CURRENT_SLOPE_POWERWARP   (0.3*USER_MOTOR_RES_EST_CURRENT/USER_IQ_FULL_SCALE_CURRENT_A/USER_TRAJ_FREQ_Hz)  // 0.3*RES_EST_CURRENT / IQ_FULL_SCALE_CURRENT / TRAJ_FREQ Typical to produce 1-sec rampup/down
    
    //! \brief Defines the starting maximum acceleration AND deceleration for the speed profiles, Hz/s
    //! \brief Updated in run-time through user functions
    //! \brief Inverter, motor, inertia, and load will limit actual acceleration capability
    #define USER_MAX_ACCEL_Hzps                 (20.0)      // 20.0 Default
    
    //! \brief Defines maximum acceleration for the estimation speed profiles, Hz/s
    //! \brief Only used during Motor ID (commission)
    #define USER_MAX_ACCEL_EST_Hzps           (5.0)         // 5.0 Default, don't change
    
    //! \brief Defines the maximum current slope for Id trajectory during estimation
    #define USER_MAX_CURRENT_SLOPE           (USER_MOTOR_RES_EST_CURRENT/USER_IQ_FULL_SCALE_CURRENT_A/USER_TRAJ_FREQ_Hz)      // USER_MOTOR_RES_EST_CURRENT/USER_IQ_FULL_SCALE_CURRENT_A/USER_TRAJ_FREQ_Hz Default, don't change
    
    //! \brief Defines the fraction of IdRated to use during rated flux estimation
    //!
    #define USER_IDRATED_FRACTION_FOR_RATED_FLUX (1.0)      // 1.0 Default, don't change
    
    //! \brief Defines the fraction of IdRated to use during inductance estimation
    //!
    #define USER_IDRATED_FRACTION_FOR_L_IDENT    (1.0)      // 1.0 Default, don't change
    
    //! \brief Defines the IdRated delta to use during estimation
    //!
    #define USER_IDRATED_DELTA                  (0.00002)
    
    //! \brief Defines the fraction of SpeedMax to use during inductance estimation
    //!
    #define USER_SPEEDMAX_FRACTION_FOR_L_IDENT  (1.0)      // 1.0 Default, don't change
    
    //! \brief Defines flux fraction to use during inductance identification
    //!
    #define USER_FLUX_FRACTION           (1.0)            // 1.0 Default, don't change
    
    //! \brief Defines the PowerWarp gain for computing Id reference
    //! \brief Induction motors only
    #define USER_POWERWARP_GAIN                   (1.0)         // 1.0 Default, don't change
    
    
    //! \brief POLES
    // **************************************************************************
    //! \brief Defines the analog voltage filter pole location, rad/s
    //! \brief Compile time calculation from Hz to rad/s
    #define USER_VOLTAGE_FILTER_POLE_rps  (2.0 * MATH_PI * USER_VOLTAGE_FILTER_POLE_Hz)
    
    //! \brief Defines the software pole location for the voltage and current offset estimation, rad/s
    //! \brief Should not be changed from default of (20.0)
    #define USER_OFFSET_POLE_rps            (20.0)   // 20.0 Default, do not change
    
    //! \brief Defines the software pole location for the flux estimation, rad/s
    //! \brief Should not be changed from default of (100.0)
    #define USER_FLUX_POLE_rps              (100.0)   // 100.0 Default, do not change
    
    //! \brief Defines the software pole location for the direction filter, rad/s
    #define USER_DIRECTION_POLE_rps             (6.0)   // 6.0 Default, do not change
    
    //! \brief Defines the software pole location for the speed control filter, rad/s
    #define USER_SPEED_POLE_rps           (100.0)   // 100.0 Default, do not change
    
    //! \brief Defines the software pole location for the DC bus filter, rad/s
    #define USER_DCBUS_POLE_rps           (100.0)   // 100.0 Default, do not change
    
    //! \brief Defines the convergence factor for the estimator
    //! \brief Do not change from default for FAST
    #define   USER_EST_KAPPAQ               (1.5)   // 1.5 Default, do not change
    
    // **************************************************************************
    // end the defines
    
    
    //! \brief USER MOTOR & ID SETTINGS
    // **************************************************************************
    // this section defined in user_j1.h or user_j5.h
    
    #ifndef USER_MOTOR
    #error Motor is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_TYPE
    #error The motor type is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_NUM_POLE_PAIRS
    #error Number of motor pole pairs is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Rr
    #error The rotor resistance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Rs
    #error The stator resistance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Ls_d
    #error The direct stator inductance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Ls_q
    #error The quadrature stator inductance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_RATED_FLUX
    #error The rated flux of motor is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_MAGNETIZING_CURRENT
    #error The magnetizing current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_RES_EST_CURRENT
    #error The resistance estimation current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_IND_EST_CURRENT
    #error The inductance estimation current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_MAX_CURRENT
    #error The maximum current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_FLUX_EST_FREQ_Hz
    #error The flux estimation frequency is not defined in user.h
    #endif
    
    
    // **************************************************************************
    // the functions
    
    
    //! \brief      Sets the user parameter values
    //! \param[in]  pUserParams  The pointer to the user param structure
    extern void USER_setParams(USER_Params *pUserParams);
    
    
    //! \brief      Checks for errors in the user parameter values
    //! \param[in]  pUserParams  The pointer to the user param structure
    extern void USER_checkForErrors(USER_Params *pUserParams);
    
    
    //! \brief      Gets the error code in the user parameters
    //! \param[in]  pUserParams  The pointer to the user param structure
    //! \return     The error code
    extern USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams);
    
    
    //! \brief      Sets the error code in the user parameters
    //! \param[in]  pUserParams  The pointer to the user param structure
    //! \param[in]  errorCode    The error code
    extern void USER_setErrorCode(USER_Params *pUserParams,const USER_ErrorCode_e errorCode);
    
    
    //! \brief      Recalculates Inductances with the correct Q Format
    //! \param[in]  handle       The controller (CTRL) handle
    extern void USER_softwareUpdate1p6(CTRL_Handle handle);
    
    
    //! \brief      Updates Id and Iq PI gains
    //! \param[in]  handle       The controller (CTRL) handle
    extern void USER_calcPIgains(CTRL_Handle handle);
    
    
    //! \brief      Computes the scale factor needed to convert from torque created by Ld, Lq, Id and Iq, from per unit to Nm
    //! \return     The scale factor to convert torque from (Ld - Lq) * Id * Iq from per unit to Nm, in IQ24 format
    extern _iq USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf(void);
    
    
    //! \brief      Computes the scale factor needed to convert from torque created by flux and Iq, from per unit to Nm
    //! \return     The scale factor to convert torque from Flux * Iq from per unit to Nm, in IQ24 format
    extern _iq USER_computeTorque_Flux_Iq_pu_to_Nm_sf(void);
    
    
    //! \brief      Computes the scale factor needed to convert from per unit to Wb
    //! \return     The scale factor to convert from flux per unit to flux in Wb, in IQ24 format
    extern _iq USER_computeFlux_pu_to_Wb_sf(void);
    
    
    //! \brief      Computes the scale factor needed to convert from per unit to V/Hz
    //! \return     The scale factor to convert from flux per unit to flux in V/Hz, in IQ24 format
    extern _iq USER_computeFlux_pu_to_VpHz_sf(void);
    
    
    //! \brief      Computes Flux in Wb or V/Hz depending on the scale factor sent as parameter
    //! \param[in]  handle       The controller (CTRL) handle
    //! \param[in]  sf           The scale factor to convert flux from per unit to Wb or V/Hz
    //! \return     The flux in Wb or V/Hz depending on the scale factor sent as parameter, in IQ24 format
    extern _iq USER_computeFlux(CTRL_Handle handle, const _iq sf);
    
    
    //! \brief      Computes Torque in Nm
    //! \param[in]  handle          The controller (CTRL) handle
    //! \param[in]  torque_Flux_sf  The scale factor to convert torque from (Ld - Lq) * Id * Iq from per unit to Nm
    //! \param[in]  torque_Ls_sf    The scale factor to convert torque from Flux * Iq from per unit to Nm
    //! \return     The torque in Nm, in IQ24 format
    extern _iq USER_computeTorque_Nm(CTRL_Handle handle, const _iq torque_Flux_sf, const _iq torque_Ls_sf);
    
    
    //! \brief      Computes Torque in lbin
    //! \param[in]  handle          The controller (CTRL) handle
    //! \param[in]  torque_Flux_sf  The scale factor to convert torque from (Ld - Lq) * Id * Iq from per unit to lbin
    //! \param[in]  torque_Ls_sf    The scale factor to convert torque from Flux * Iq from per unit to lbin
    //! \return     The torque in lbin, in IQ24 format
    extern _iq USER_computeTorque_lbin(CTRL_Handle handle, const _iq torque_Flux_sf, const _iq torque_Ls_sf);
    
    
    #ifdef __cplusplus
    }
    #endif // extern "C"
    
    //@} // ingroup
    #endif // end of _USER_H_ definition
    
    
    #ifndef _USER_J1_H_
    #define _USER_J1_H_
    /* --COPYRIGHT--,BSD
     * Copyright (c) 2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    
    //! \file   solutions/instaspin_foc/boards/boostxldrv8305_revA/f28x/f2806xF/src/user_j1.h
    //! \brief Contains the public interface for user initialization data for the CTRL, HAL, and EST modules 
    //!
    //! (C) Copyright 2015, Texas Instruments, Inc.
    
    
    // **************************************************************************
    // the includes
    
    //!
    //!
    //! \defgroup USER USER
    //!
    //@{
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // **************************************************************************
    // the defines
    
    //! \brief CURRENTS AND VOLTAGES
    // **************************************************************************
    //! \brief Defines the full scale frequency for IQ variable, Hz
    //! \brief All frequencies are converted into (pu) based on the ratio to this value
    //! \brief this value MUST be larger than the maximum speed that you are expecting from the motor
    #define USER_IQ_FULL_SCALE_FREQ_Hz        (1386.0)   // 800 Example with buffer for 8-pole 6 KRPM motor to be run to 10 KRPM with field weakening; Hz =(RPM * Poles) / 120
    
    //! \brief Defines full scale value for the IQ30 variable of Voltage inside the system
    //! \brief All voltages are converted into (pu) based on the ratio to this value
    //! \brief WARNING: this value MUST meet the following condition: USER_IQ_FULL_SCALE_VOLTAGE_V > 0.5 * USER_MOTOR_MAX_CURRENT * USER_MOTOR_Ls_d * USER_VOLTAGE_FILTER_POLE_rps,
    //! \brief WARNING: otherwise the value can saturate and roll-over, causing an inaccurate value
    //! \brief WARNING: this value is OFTEN greater than the maximum measured ADC value, especially with high Bemf motors operating at higher than rated speeds
    //! \brief WARNING: if you know the value of your Bemf constant, and you know you are operating at a multiple speed due to field weakening, be sure to set this value higher than the expected Bemf voltage
    //! \brief It is recommended to start with a value ~3x greater than the USER_ADC_FULL_SCALE_VOLTAGE_V and increase to 4-5x if scenarios where a Bemf calculation may exceed these limits
    //! \brief This value is also used to calculate the minimum flux value: USER_IQ_FULL_SCALE_VOLTAGE_V/USER_EST_FREQ_Hz/0.7
    #define USER_IQ_FULL_SCALE_VOLTAGE_V      (16.8)   // 24.0 Set to Vbus
    
    //! \brief Defines the maximum voltage at the input to the AD converter
    //! \brief The value that will be represented by the maximum ADC input (3.3V) and conversion (0FFFh)
    //! \brief Hardware dependent, this should be based on the voltage sensing and scaling to the ADC input
    #define USER_ADC_FULL_SCALE_VOLTAGE_V       (44.30)  // BOOSTXL-DRV8305EVM = 44.30 V
    
    //! \brief Defines the full scale current for the IQ variables, A
    //! \brief All currents are converted into (pu) based on the ratio to this value
    //! \brief WARNING: this value MUST be larger than the maximum current readings that you are expecting from the motor or the reading will roll over to 0, creating a control issue 
    #define USER_IQ_FULL_SCALE_CURRENT_A         (18.0) // BOOSTXL-DRV8305EVM = 24.0 A
    
    //! \brief Defines the maximum current at the AD converter
    //! \brief The value that will be represented by the maximum ADC input (3.3V) and conversion (0FFFh)
    //! \brief Hardware dependent, this should be based on the current sensing and scaling to the ADC input
    #define USER_ADC_FULL_SCALE_CURRENT_A        (47.14)  // BOOSTXL-DRV8305EVM = 47.14 A
    
    //! \brief Defines the number of current sensors used
    //! \brief Defined by the hardware capability present
    //! \brief May be (2) or (3)
    #define USER_NUM_CURRENT_SENSORS            (3)   // 3 Preferred setting for best performance across full speed range, allows for 100% duty cycle
    
    //! \brief Defines the number of voltage (phase) sensors
    //! \brief Must be (3)
    #define USER_NUM_VOLTAGE_SENSORS            (3) // 3 Required
    
    //! \brief ADC current offsets for A, B, and C phases
    //! \brief One-time hardware dependent, though the calibration can be done at run-time as well
    //! \brief After initial board calibration these values should be updated for your specific hardware so they are available after compile in the binary to be loaded to the controller
    #define   I_A_offset    (1.20)
    #define   I_B_offset    (1.20)
    #define   I_C_offset    (1.20)
    
    //! \brief ADC voltage offsets for A, B, and C phases
    //! \brief One-time hardware dependent, though the calibration can be done at run-time as well
    //! \brief After initial board calibration these values should be updated for your specific hardware so they are available after compile in the binary to be loaded to the controller
    #define   V_A_offset    (0.50)
    #define   V_B_offset    (0.50)
    #define   V_C_offset    (0.50)
    
    
    //! \brief CLOCKS & TIMERS
    // **************************************************************************
    //! \brief Defines the Pulse Width Modulation (PWM) frequency, kHz
    //! \brief PWM frequency can be set directly here up to 30 KHz safely (60 KHz MAX in some cases)
    //! \brief For higher PWM frequencies (60 KHz+ typical for low inductance, high current ripple motors) it is recommended to use the ePWM hardware
    //! \brief and adjustable ADC SOC to decimate the ADC conversion done interrupt to the control system, or to use the software Que example.
    //! \brief Otherwise you risk missing interrupts and disrupting the timing of the control state machine
    #define USER_PWM_FREQ_kHz                (45.0) //30.0 Example, 8.0 - 30.0 KHz typical; 45-80 KHz may be required for very low inductance, high speed motors
    
    //! \brief Defines the maximum Voltage vector (Vs) magnitude allowed.  This value sets the maximum magnitude for the output of the
    //! \brief Id and Iq PI current controllers.  The Id and Iq current controller outputs are Vd and Vq.
    //! \brief The relationship between Vs, Vd, and Vq is:  Vs = sqrt(Vd^2 + Vq^2).  In this FOC controller, the
    //! \brief Vd value is set equal to USER_MAX_VS_MAG*USER_VD_MAG_FACTOR.  Vq = sqrt(USER_MAX_VS_MAG^2 - Vd^2).
    //! \brief Set USER_MAX_VS_MAG = 0.5 for a pure sinewave with a peak at SQRT(3)/2 = 86.6% duty cycle.  No current reconstruction is needed for this scenario.
    //! \brief Set USER_MAX_VS_MAG = 1/SQRT(3) = 0.5774 for a pure sinewave with a peak at 100% duty cycle.  Current reconstruction will be needed for this scenario (Lab10a-x).
    //! \brief Set USER_MAX_VS_MAG = 2/3 = 0.6666 to create a trapezoidal voltage waveform.  Current reconstruction will be needed for this scenario (Lab10a-x).
    //! \brief For space vector over-modulation, see lab 10 for details on system requirements that will allow the SVM generator to go all the way to trapezoidal.
    #define USER_MAX_VS_MAG_PU        (0.5)    // Set to 0.5 if a current reconstruction technique is not used.  Look at the module svgen_current in lab10a-x for more info.
    
    
    //! \brief DECIMATION
    // **************************************************************************
    //! \brief Defines the number of pwm clock ticks per isr clock tick
    //!        Note: Valid values are 1, 2 or 3 only
    #define USER_NUM_PWM_TICKS_PER_ISR_TICK        (3)
    
    //! \brief Defines the number of isr ticks (hardware) per controller clock tick (software)
    //! \brief Controller clock tick (CTRL) is the main clock used for all timing in the software
    //! \brief Typically the PWM Frequency triggers (can be decimated by the ePWM hardware for less overhead) an ADC SOC
    //! \brief ADC SOC triggers an ADC Conversion Done
    //! \brief ADC Conversion Done triggers ISR
    //! \brief This relates the hardware ISR rate to the software controller rate
    //! \brief Typcially want to consider some form of decimation (ePWM hardware, CURRENT or EST) over 16KHz ISR to insure interrupt completes and leaves time for background tasks
    #define USER_NUM_ISR_TICKS_PER_CTRL_TICK       (1)      // 2 Example, controller clock rate (CTRL) runs at PWM / 2; ex 30 KHz PWM, 15 KHz control
    
    //! \brief Defines the number of controller clock ticks per current controller clock tick
    //! \brief Relationship of controller clock rate to current controller (FOC) rate
    #define USER_NUM_CTRL_TICKS_PER_CURRENT_TICK   (1)      // 1 Typical, Forward FOC current controller (Iq/Id/IPARK/SVPWM) runs at same rate as CTRL.
    
    //! \brief Defines the number of controller clock ticks per estimator clock tick
    //! \brief Relationship of controller clock rate to estimator (FAST) rate
    //! \brief Depends on needed dynamic performance, FAST provides very good results as low as 1 KHz while more dynamic or high speed applications may require up to 15 KHz
    #define USER_NUM_CTRL_TICKS_PER_EST_TICK       (1)      // 1 Typical, FAST estimator runs at same rate as CTRL;
    
    //! \brief Defines the number of controller clock ticks per speed controller clock tick
    //! \brief Relationship of controller clock rate to speed loop rate
    #define USER_NUM_CTRL_TICKS_PER_SPEED_TICK  (15)   // 15 Typical to match PWM, ex: 15KHz PWM, controller, and current loop, 1KHz speed loop
    
    //! \brief Defines the number of controller clock ticks per trajectory clock tick
    //! \brief Relationship of controller clock rate to trajectory loop rate
    //! \brief Typically the same as the speed rate
    #define USER_NUM_CTRL_TICKS_PER_TRAJ_TICK   (15)   // 15 Typical to match PWM, ex: 10KHz controller & current loop, 1KHz speed loop, 1 KHz Trajectory
    
    
    //! \brief LIMITS
    // **************************************************************************
    //! \brief Defines the maximum negative current to be applied in Id reference
    //! \brief Used in field weakening only, this is a safety setting (e.g. to protect against demagnetization)
    //! \brief User must also be aware that overall current magnitude [sqrt(Id^2 + Iq^2)] should be kept below any machine design specifications
    #define USER_MAX_NEGATIVE_ID_REF_CURRENT_A     (-0.5 * USER_MOTOR_MAX_CURRENT)   // -0.5 * USER_MOTOR_MAX_CURRENT Example, adjust to meet safety needs of your motor
    
    //! \brief Defines the R/L estimation frequency, Hz
    //! \brief User higher values for low inductance motors and lower values for higher inductance
    //! \brief motors.  The values can range from 100 to 300 Hz.
    #define USER_R_OVER_L_EST_FREQ_Hz (300)               // 300 Default
    
    //! \brief Defines the low speed limit for the flux integrator, pu
    //! \brief This is the speed range (CW/CCW) at which the ForceAngle object is active, but only if Enabled
    //! \brief Outside of this speed - or if Disabled - the ForcAngle will NEVER be active and the angle is provided by FAST only
    #define USER_ZEROSPEEDLIMIT   (0.5 / USER_IQ_FULL_SCALE_FREQ_Hz)     // 0.002 pu, 1-5 Hz typical; Hz = USER_ZEROSPEEDLIMIT * USER_IQ_FULL_SCALE_FREQ_Hz
    
    //! \brief Defines the force angle frequency, Hz
    //! \brief Frequency of stator vector rotation used by the ForceAngle object
    //! \brief Can be positive or negative
    #define USER_FORCE_ANGLE_FREQ_Hz   (2.0 * USER_ZEROSPEEDLIMIT * USER_IQ_FULL_SCALE_FREQ_Hz)      // 1.0 Typical force angle start-up speed
    
    
    //! \brief POLES
    // **************************************************************************
    //! \brief Defines the analog voltage filter pole location, Hz
    //! \brief Must match the hardware filter for Vph
    #define USER_VOLTAGE_FILTER_POLE_Hz  (344.62)   // BOOSTXL-DRV8305 = 344.62 Hz
    
    
    //! \brief USER MOTOR & ID SETTINGS
    // **************************************************************************
    
    //! \brief Define each motor with a unique name and ID number
    // BLDC & SMPM motors
    #define Estun_EMJ_04APB22           101
    #define Anaheim_BLY172S             102
    #define Teknic_M2310PLN04K          104
    #define SS                          401
    // IPM motors
    // If user provides separate Ls-d, Ls-q
    // else treat as SPM with user or identified average Ls
    #define Belt_Drive_Washer_IPM       201
    #define Anaheim_Salient             202
    
    // ACIM motors
    #define Marathon_5K33GN2A           301
    
    //! \brief Uncomment the motor which should be included at compile
    //! \brief These motor ID settings and motor parameters are then available to be used by the control system
    //! \brief Once your ideal settings and parameters are identified update the motor section here so it is available in the binary code
    //#define USER_MOTOR Estun_EMJ_04APB22
    //#define USER_MOTOR Anaheim_BLY172S
    //#define USER_MOTOR Teknic_M2310PLN04K
    //#define USER_MOTOR Belt_Drive_Washer_IPM
    //#define USER_MOTOR Marathon_5K33GN2A
    //#define USER_MOTOR Anaheim_Salient
    #define USER_MOTOR SS
    
    #if (USER_MOTOR == Estun_EMJ_04APB22)                  // Name must match the motor #define
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm  // Motor_Type_Pm (All Synchronous: BLDC, PMSM, SMPM, IPM) or Motor_Type_Induction (Asynchronous ACI)
    #define USER_MOTOR_NUM_POLE_PAIRS       (4)            // PAIRS, not total poles. Used to calculate user RPM from rotor Hz only
    #define USER_MOTOR_Rr                   (NULL)         // Induction motors only, else NULL
    #define USER_MOTOR_Rs                   (2.303403)     // Identified phase to neutral resistance in a Y equivalent circuit (Ohms, float)
    #define USER_MOTOR_Ls_d                 (0.008464367)  // For PM, Identified average stator inductance  (Henry, float)
    #define USER_MOTOR_Ls_q                 (0.008464367)  // For PM, Identified average stator inductance  (Henry, float)
    #define USER_MOTOR_RATED_FLUX           (0.38)         // Identified TOTAL flux linkage between the rotor and the stator (V/Hz)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)         // Induction motors only, else NULL
    #define USER_MOTOR_RES_EST_CURRENT      (1.0)          // During Motor ID, maximum current (Amperes, float) used for Rs estimation, 10-20% rated current
    #define USER_MOTOR_IND_EST_CURRENT      (-1.0)         // During Motor ID, maximum current (negative Amperes, float) used for Ls estimation, use just enough to enable rotation
    #define USER_MOTOR_MAX_CURRENT          (3.82)         // CRITICAL: Used during ID and run-time, sets a limit on the maximum current command output of the provided Speed PI Controller to the Iq controller
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (20.0)         // During Motor ID, maximum commanded speed (Hz, float), ~10% rated
    
    #elif (USER_MOTOR == Anaheim_BLY172S)
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm
    #define USER_MOTOR_NUM_POLE_PAIRS       (4)
    #define USER_MOTOR_Rr                   (NULL)
    #define USER_MOTOR_Rs                   (0.4110007)
    #define USER_MOTOR_Ls_d                 (0.0007092811)
    #define USER_MOTOR_Ls_q                 (0.0007092811)
    #define USER_MOTOR_RATED_FLUX           (0.03279636)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT      (-1.0)
    #define USER_MOTOR_MAX_CURRENT          (5.0)
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (20.0)
    
    #define USER_MOTOR_FREQ_LOW				(10.0)			// Hz - suggested to set to 10% of rated motor frequency
    #define USER_MOTOR_FREQ_HIGH			(100.0)			// Hz - suggested to set to 100% of rated motor frequency
    #define USER_MOTOR_FREQ_MAX				(120.0)			// Hz - suggested to set to 120% of rated motor frequency
    #define USER_MOTOR_VOLT_MIN				(3.0)			// Volt - suggested to set to 15% of rated motor voltage
    #define USER_MOTOR_VOLT_MAX				(18.0)			// Volt - suggested to set to 100% of rated motor voltage
    
    // IPD and AFSEL settings below are not necessarily valid for this motor
    // Added so that proj_lab21 compiles without errors with default user.h settings
    #define IPD_HFI_EXC_FREQ_HZ             (750.0)       // excitation frequency, Hz
    #define IPD_HFI_LP_SPD_FILT_HZ          (35.0)        // lowpass filter cutoff frequency, Hz
    #define IPD_HFI_HP_IQ_FILT_HZ           (100.0)       // highpass filter cutoff frequency, Hz
    #define IPD_HFI_KSPD                    (60.0)       // the speed gain value
    #define IPD_HFI_EXC_MAG_COARSE_PU       (0.25)         // coarse IPD excitation magnitude, pu
    #define IPD_HFI_EXC_MAG_FINE_PU         (0.2)         // fine IPD excitation magnitude, pu
    #define IPD_HFI_EXC_TIME_COARSE_S       (0.5)         // coarse wait time, sec max 0.64
    #define IPD_HFI_EXC_TIME_FINE_S         (0.5)         // fine wait time, sec max 0.4
    #define AFSEL_FREQ_HIGH_PU              (_IQ(20.0 / USER_IQ_FULL_SCALE_FREQ_Hz))
    #define AFSEL_FREQ_LOW_PU               (_IQ(10.0 / USER_IQ_FULL_SCALE_FREQ_Hz))
    #define AFSEL_IQ_SLOPE_EST              (_IQ((float)(1.0/0.1/USER_ISR_FREQ_Hz)))
    #define AFSEL_IQ_SLOPE_HFI              (_IQ((float)(1.0/10.0/USER_ISR_FREQ_Hz)))
    #define AFSEL_IQ_SLOPE_THROTTLE_DWN     (_IQ((float)(1.0/0.05/USER_ISR_FREQ_Hz)))
    #define AFSEL_MAX_IQ_REF_EST            (_IQ(0.4))
    #define AFSEL_MAX_IQ_REF_HFI            (_IQ(0.4))
    
    #elif (USER_MOTOR == Anaheim_Salient)                 // When using IPD_HFI, set decimation to 1 and PWM to 15.0 KHz
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm
    #define USER_MOTOR_NUM_POLE_PAIRS       (4)
    #define USER_MOTOR_Rr                   (NULL)
    #define USER_MOTOR_Rs                   (0.1215855)
    #define USER_MOTOR_Ls_d                 (0.0002298828)
    #define USER_MOTOR_Ls_q                 (0.0002298828)
    #define USER_MOTOR_RATED_FLUX           (0.04821308)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (2.0)         // Enter amperes(float)
    #define USER_MOTOR_IND_EST_CURRENT      (-0.5)        // Enter negative amperes(float)
    #define USER_MOTOR_MAX_CURRENT          (10.0)
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (20.0)
    #define IPD_HFI_EXC_FREQ_HZ             (750.0)       // excitation frequency, Hz
    #define IPD_HFI_LP_SPD_FILT_HZ          (35.0)        // lowpass filter cutoff frequency, Hz
    #define IPD_HFI_HP_IQ_FILT_HZ           (100.0)       // highpass filter cutoff frequency, Hz
    #define IPD_HFI_KSPD                    (15.0)       // the speed gain value
    #define IPD_HFI_EXC_MAG_COARSE_PU       (0.13)         // coarse IPD excitation magnitude, pu
    #define IPD_HFI_EXC_MAG_FINE_PU         (0.12)         // fine IPD excitation magnitude, pu
    #define IPD_HFI_EXC_TIME_COARSE_S       (0.5)         // coarse wait time, sec max 0.64
    #define IPD_HFI_EXC_TIME_FINE_S         (0.5)         // fine wait time, sec max 0.4
    #define AFSEL_FREQ_HIGH_PU              (_IQ(15.0 / USER_IQ_FULL_SCALE_FREQ_Hz))
    #define AFSEL_FREQ_LOW_PU               (_IQ(10.0 / USER_IQ_FULL_SCALE_FREQ_Hz))
    #define AFSEL_IQ_SLOPE_EST              (_IQ((float)(1.0/0.1/USER_ISR_FREQ_Hz)))
    #define AFSEL_IQ_SLOPE_HFI              (_IQ((float)(1.0/10.0/USER_ISR_FREQ_Hz)))
    #define AFSEL_IQ_SLOPE_THROTTLE_DWN     (_IQ((float)(1.0/0.05/USER_ISR_FREQ_Hz)))
    #define AFSEL_MAX_IQ_REF_EST            (_IQ(0.6))
    #define AFSEL_MAX_IQ_REF_HFI            (_IQ(0.6))
    
    #elif (USER_MOTOR == SS)
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm
    #define USER_MOTOR_NUM_POLE_PAIRS       (12)
    #define USER_MOTOR_Rr                   (NULL)
    #define USER_MOTOR_Rs                   (NULL)
    #define USER_MOTOR_Ls_d                 (NULL)
    #define USER_MOTOR_Ls_q                 (NULL)
    #define USER_MOTOR_RATED_FLUX           (NULL)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (5.0)
    #define USER_MOTOR_IND_EST_CURRENT      (-5.0)
    #define USER_MOTOR_MAX_CURRENT          (25.0)
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (15.0)
    
    #define USER_MOTOR_FREQ_LOW             (16.0)          // Hz - suggested to set to 10% of rated motor frequency
    #define USER_MOTOR_FREQ_HIGH            (1600.0)         // Hz - suggested to set to 100% of rated motor frequency
    #define USER_MOTOR_FREQ_MAX             (1920.0)         // Hz - suggested to set to 120% of rated motor frequency
    #define USER_MOTOR_VOLT_MIN             (10.0)           // Volt - suggested to set to 15% of rated motor voltage
    #define USER_MOTOR_VOLT_MAX             (16.0)          // Volt - suggested to set to 100% of rated motor voltage
    
    #elif (USER_MOTOR == Teknic_M2310PLN04K)
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm
    #define USER_MOTOR_NUM_POLE_PAIRS       (4)
    #define USER_MOTOR_Rr                   (NULL)
    #define USER_MOTOR_Rs                   (0.3918252)
    #define USER_MOTOR_Ls_d                 (0.00023495)
    #define USER_MOTOR_Ls_q                 (0.00023495)
    #define USER_MOTOR_RATED_FLUX           (0.03955824)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT      (-0.5)
    #define USER_MOTOR_MAX_CURRENT          (7.0)
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (20.0)
    
    #elif (USER_MOTOR == Belt_Drive_Washer_IPM)
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm
    #define USER_MOTOR_NUM_POLE_PAIRS       (4)
    #define USER_MOTOR_Rr                   (NULL)
    #define USER_MOTOR_Rs                   (2.832002)
    #define USER_MOTOR_Ls_d                 (0.0115)
    #define USER_MOTOR_Ls_q                 (0.0135)
    #define USER_MOTOR_RATED_FLUX           (0.5022156)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT      (-1.0)
    #define USER_MOTOR_MAX_CURRENT          (4.0)
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (20.0)
    
    #elif (USER_MOTOR == Marathon_5K33GN2A)                      // Name must match the motor #define
    #define USER_MOTOR_TYPE                 MOTOR_Type_Induction // Motor_Type_Pm (All Synchronous: BLDC, PMSM, SMPM, IPM) or Motor_Type_Induction (Asynchronous ACI)
    #define USER_MOTOR_NUM_POLE_PAIRS       (2)                  // PAIRS, not total poles. Used to calculate user RPM from rotor Hz only
    #define USER_MOTOR_Rr                   (5.508003)           // Identified phase to neutral in a Y equivalent circuit (Ohms, float)
    #define USER_MOTOR_Rs                   (10.71121)           // Identified phase to neutral in a Y equivalent circuit (Ohms, float)
    #define USER_MOTOR_Ls_d                 (0.05296588)         // For Induction, Identified average stator inductance  (Henry, float)
    #define USER_MOTOR_Ls_q                 (0.05296588)         // For Induction, Identified average stator inductance  (Henry, float)
    #define USER_MOTOR_RATED_FLUX           (0.8165*220.0/60.0)  // sqrt(2/3)* Rated V (line-line) / Rated Freq (Hz)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (1.378)              // Identified magnetizing current for induction motors, else NULL
    #define USER_MOTOR_RES_EST_CURRENT      (0.5)                // During Motor ID, maximum current (Amperes, float) used for Rs estimation, 10-20% rated current
    #define USER_MOTOR_IND_EST_CURRENT      (NULL)               // not used for induction
    #define USER_MOTOR_MAX_CURRENT          (2.0)                // CRITICAL: Used during ID and run-time, sets a limit on the maximum current command output of the provided Speed PI Controller to the Iq controller
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (5.0)                // During Motor ID, maximum commanded speed (Hz, float). Should always use 5 Hz for Induction.
    
    #else
    #error No motor type specified
    #endif
    
    #ifdef __cplusplus
    }
    #endif // extern "C"
    
    //@} // ingroup
    #endif // end of _USER_J1_H_ definition
    
    

  • You might try run the lab01b without connecting the motor, and then connecting the motor to run the lab01b again. What happen in these two steps?

    Don't need to change any settings for this lab, just need to change the v/f profile parameters as below according to the spec. of your motor.

    #define USER_MOTOR_FREQ_LOW_HZ            (20.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt

  • It throws the same error without and with the motor.

  • If you make sure that the boostxl board is connected to the launchxl board correctly, that means the boostxl board maybe damaged.

    Do you measure the PWM output and other control signals when run the lab01b?

  • I have followed every instruction mentioned regarding the use of DRV8305-EVM, and this thing still doesn't work.  So you want to suggest that TI is now delivering damaged boards through their distributor network???

    This thing is entirely unprofessional and disregards other people's time and efforts.  DRV8305 has been a complete failure, and I regret deciding to use it for my designs; this has been an utter waste of time for me. 

    https://e2e.ti.com/support/motor-drivers-group/motor-drivers/f/motor-drivers-forum/1040418/drv8305-problem-in-datasheet

    https://e2e.ti.com/support/motor-drivers-group/motor-drivers/f/motor-drivers-forum/1046779/drv8305-nfault

    Two months ago, I found an error in the datasheet.

    Even after following the reference design, my custom board didn't work, and TI had no explanation for that even after verifying the design.

    Considering the expertise of TI, I thought that maybe I had made some mistakes in the assembly and design of my custom board. So I ordered a new BOOSTXL-DRV8305 EVM from TI. And I am back to the starting point as this thing also doesn't work.

    This is frustrating as an Engineer and an End User.

  • Hi Prabhat,

    I ordered a new BOOSTXL-DRV8305 this week and will connect it to a LAUNCHXL-F28069M LaunchPad and see I can replicate the issue upon InstaSPIN-FOC GUI launch to see if I receive the same issue with AVDD UVLO and SNS_OCP_A. The concern is AVDD_UVLO, since the DIS_SNS_OCP bit can be set to disable overcurrent sensing through the sense resistor. 

    I am surprised to see AVDD_UVLO be set since in the EVM schematic, AVDD does not connect to anything. 



    Please remind me what your initial faults were on your custom board when reviewing the SPx/SNx layout. 

    Thanks,
    Aaron


  • I am attaching the corresponding register values for the BOOSTXL-DRV8305 and my custom-DRV8305 board. I have included all the files for boards connected with motor and without motor nad have used lab01b.out and lab2a.out.

    In all the cases, the voltage rating shown in GUI is correct and no-fault when I press enable. Errors occur instantly when I press run.

    I am sharing with you the zip file.

    DRV_errors.zip

  • Hi Prabhat,

    Thank you for sharing your zip file, I am receiving the BOOSTXL-DRV8305 tomorrow and will reach out back to you about findings and next steps from your screenshots. 

    Regards,
    Aaron

  • Hi Prabhat,

    I used LAUNCHXL-F28069M + BOOSTXL-DRV8305 and was able to run and identify motor without any faults or issues. When the device is powered up, nFAULT does turn on but when I ran the program and set "Flag_enableSys", the fault disappeared. 



    I also did not see the AVDD_UVLO bit set either. 



    These are my default jumper configurations of the LaunchPad. 



    I am continuing to review your zip file and will provide a response tomorrow. 

    Could you try using the firmware from MotorWARE? I was having issues with the Universal GUI. Not sure if the GUI application's appProgram.out is incorrect. 


    Thanks,
    Aaron

  • Dear Aaron,

    Thanks for taking the pain of testing the system for understanding the issue.

    What was the DC input voltage in your test case?

    Did you connect any motor?

    Which lab you are running?

  • Hello Prabhat,

    Aaron is out of office today due to holidays in the US. Sorry if there are any delays in his response, thank you for your patience.

    Best,

    Isaac

  • Awaiting your reply. Hope you had a relaxing thanksgiving vacation.

  • Hello Prahbat,

    Thank you, it was certainly a good break. Aaron is not back until Tuesday afternoon so he should be able to respond to your questions then, if not latest on Wednesday. Thank you for your understanding.

    Best,

    Isaac

  • HI Prabhat,

    Thank you for holiday wishes. 

    Find my answers below:

    What was the DC input voltage in your test case? 12V

    Did you connect any motor? Yes, I connected a Telco motor that comes with DRV8308EVM. I connected the motor phases to SHA, SHB, and SHC of the connector on the BOOSTXL-DRV8305. 

    Which lab you are running? Lab 01b from MotorWARE version 1.01.00.18. I ran the firmware through Code Composer Studio and the program successfully identified the inductance and resistance of the motor phase. I used LAUNCHXL-F28069M + BOOSTXL-DRV8305.


    Thanks,
    Aaron

  • I will try with these settings today and will let you know the progress.