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.

About Identify (DRV8312-69M-KIT -->My own board)

Other Parts Discussed in Thread: DRV8312, MOTORWARE, INSTASPINUNIVERSALGUI, DRV8301

Hi.

I developed my own board based on DRV8312-69M-KIT.

Use the Lab3a, it was detected the bias of current and voltage. Also, I'm writing the its value to User.h.

Using the data, I was moving the Lab2a.
However, I identified the data is strange. Rs, Ld, Lq, Flax_Vp

I think I have failed to identify.

If you make your own board, or I have a place to be careful with software changes such as Lab2a?

ADC, PWM, and the RESET port I am together with KIT.

The motor that comes with the kit I'm using.

 

  • your Ls values are incorrect. The smallest real value would be a few uH

    this would be for very high speed motors.

    if you have one of these types of motor use proj_lab02c to identify (even just use your DRV8312 kit to make sure you get the right values)

    you can follow some of the tips for these types of motors in the Universal GUI QSG (which was accidently left out of MotorWare _13 release but I've attached here)

    qsg_gui_universal.pdf
  • Hi,Chris

    Thank you your help.

    >your Ls values are incorrect. The smallest real value would be a few uH

    I think so too.

    I used DRV8312-kit and my own board with lab2a.

    I can get correct value by KIT+lab2a.
    However,I was failed to get MyB+lab2a.

    I'm using both the included motor kit. (DT4260-24-055-04)
    Therefore, the motor identification fails, it is due to the difference of the board.

    I consider it is because I have failed to detect the motor current and voltage.

    The pin voltage of 28069F I was confirmed by oscilloscope.

    As a result, the offset is different for KIT and MB, the slope was the same.

     

  • you must have changed something in the user.h, perhaps the IQ_VOLTAGE

    Out of the box it should ID the included motor with no issue.

    attach the user.h that is being used

  • Hi,Chris

    Thank you your help.

    >I have confirmed the contents of user.h, there was no defined the IQ_VOLTAGE.

    you must have changed something in the user.h, perhaps the IQ_VOLTAGE

     

    >attach the user.h that is being used

    45853.user.h

  • Thank  you for your help.

    Current operating order
    1: motor vibrates. 314Hz
    2: 0.7A about direct current flows.
    3: motor is rotating at 20Hz. (Dirty triangle wave current)
    4: it becomes 1Hz, current is disturbed severely.

    Until 1.2 No. KIT and movement are the same.
    3 or later is is strange.
    No. 3 should sine wave comes out, but it is close to a triangular wave. (Observed in the motor current .U phase)
    In the fourth phase, the current is reduced by a sine wave, then should flowing maximum current. However, it is a movement, such as the motor is to step-out and vibration.

    HAL_setupAdcs () to have been defined as follows
    A1: I-U
    B5: I-V
    A5: I-W
    A2: I-Total (Only connect / Not define)
    B7: V-U
    A7: V-V
    B4: V-W
    B2: V-DCBUS
    (A3,B1 is not connect in my board)
    For my universal board noise is large, the voltage and current detection unit, you have to insert the LPF (1kΩ, 0.1uF) in front of the ADC input.

    It may be have failed to identify a problem of the time constant.

    Those who have similar experience, please information to me.

    I leave to attach a file to reference.

    /* --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/boards/drv8312kit_revD/f28x/f2806xF/src/hal.c
    //! \brief Contains the various functions related to the HAL object (everything outside the CTRL system) 
    //!
    //! (C) Copyright 2011, Texas Instruments, Inc.
    
    
    // **************************************************************************
    // the includes
    
    // drivers
    
    // modules
    
    // platforms
    #include "hal.h"
    #include "user.h"
    #include "hal_obj.h"
    
    #ifdef FLASH
    #pragma CODE_SECTION(HAL_setupFlash,"ramfuncs");
    #endif
    
    // **************************************************************************
    // the defines
    
    
    
    // **************************************************************************
    // the globals
    
    HAL_Obj hal;
    
    
    // **************************************************************************
    // the functions
    
    void HAL_cal(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      // enable the ADC clock
      CLK_enableAdcClock(obj->clkHandle);
    
    
      // Run the Device_cal() function
      // This function copies the ADC and oscillator calibration values from TI reserved
      // OTP into the appropriate trim registers
      // This boot ROM automatically calls this function to calibrate the interal 
      // oscillators and ADC with device specific calibration data.
      // If the boot ROM is bypassed by Code Composer Studio during the development process,
      // then the calibration must be initialized by the application
      ENABLE_PROTECTED_REGISTER_WRITE_MODE;
      (*Device_cal)();
      DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
      // run offsets calibration in user's memory
      HAL_AdcOffsetSelfCal(handle);
    
      // run oscillator compensation
      HAL_OscTempComp(handle);
    
      // disable the ADC clock
      CLK_disableAdcClock(obj->clkHandle);
    
      return;
    } // end of HAL_cal() function
    
    
    void HAL_OscTempComp(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
      uint16_t Temperature;
    
      // disable the ADCs
      ADC_disable(obj->adcHandle);
    
      // power up the bandgap circuit
      ADC_enableBandGap(obj->adcHandle);
    
      // set the ADC voltage reference source to internal
      ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
    
      // enable the ADC reference buffers
      ADC_enableRefBuffers(obj->adcHandle);
    
      // Set main clock scaling factor (max45MHz clock for the ADC module)
      ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
    
      // power up the ADCs
      ADC_powerUp(obj->adcHandle);
    
      // enable the ADCs
      ADC_enable(obj->adcHandle);
    
      // enable non-overlap mode
      ADC_enableNoOverlapMode(obj->adcHandle);
    
      // connect channel A5 internally to the temperature sensor
      ADC_setTempSensorSrc(obj->adcHandle, ADC_TempSensorSrc_Int);
    
      // set SOC0 channel select to ADCINA5
      ADC_setSocChanNumber(obj->adcHandle, ADC_SocNumber_0, ADC_SocChanNumber_A5);
    
      // set SOC0 acquisition period to 26 ADCCLK
      ADC_setSocSampleDelay(obj->adcHandle, ADC_SocNumber_0, ADC_SocSampleDelay_64_cycles);
    
      // connect ADCINT1 to EOC0
      ADC_setIntSrc(obj->adcHandle, ADC_IntNumber_1, ADC_IntSrc_EOC0);
    
      // clear ADCINT1 flag
      ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_1);
    
      // enable ADCINT1
      ADC_enableInt(obj->adcHandle, ADC_IntNumber_1);
    
      // force start of conversion on SOC0
      ADC_setSocFrc(obj->adcHandle, ADC_SocFrc_0);
    
      // wait for end of conversion
      while (ADC_getIntFlag(obj->adcHandle, ADC_IntNumber_1) == 0){}
    
      // clear ADCINT1 flag
      ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_1);
    
      Temperature = ADC_readResult(obj->adcHandle, ADC_ResultNumber_0);
    
      HAL_osc1Comp(handle, Temperature);
    
      HAL_osc2Comp(handle, Temperature);
    
      return;
    } // end of HAL_OscTempComp() function
    
    
    void HAL_osc1Comp(HAL_Handle handle, const int16_t sensorSample)
    {
    	int16_t compOscFineTrim;
    	HAL_Obj *obj = (HAL_Obj *)handle;
    
    	ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        compOscFineTrim = ((sensorSample - getRefTempOffset())*(int32_t)getOsc1FineTrimSlope()
                          + OSC_POSTRIM_OFF + FP_ROUND )/FP_SCALE + getOsc1FineTrimOffset() - OSC_POSTRIM;
    
        if(compOscFineTrim > 31)
          {
            compOscFineTrim = 31;
          }
    	else if(compOscFineTrim < -31)
          {
            compOscFineTrim = -31;
          }
    
        OSC_setTrim(obj->oscHandle, OSC_Number_1, HAL_getOscTrimValue(getOsc1CoarseTrim(), compOscFineTrim));
    
        DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        return;
    } // end of HAL_osc1Comp() function
    
    
    void HAL_osc2Comp(HAL_Handle handle, const int16_t sensorSample)
    {
    	int16_t compOscFineTrim;
    	HAL_Obj *obj = (HAL_Obj *)handle;
    
    	ENABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        compOscFineTrim = ((sensorSample - getRefTempOffset())*(int32_t)getOsc2FineTrimSlope()
                          + OSC_POSTRIM_OFF + FP_ROUND )/FP_SCALE + getOsc2FineTrimOffset() - OSC_POSTRIM;
    
        if(compOscFineTrim > 31)
          {
            compOscFineTrim = 31;
          }
    	else if(compOscFineTrim < -31)
          {
            compOscFineTrim = -31;
          }
    
        OSC_setTrim(obj->oscHandle, OSC_Number_2, HAL_getOscTrimValue(getOsc2CoarseTrim(), compOscFineTrim));
    
        DISABLE_PROTECTED_REGISTER_WRITE_MODE;
    
        return;
    } // end of HAL_osc2Comp() function
    
    
    uint16_t HAL_getOscTrimValue(int16_t coarse, int16_t fine)
    {
      uint16_t regValue = 0;
    
      if(fine < 0)
        {
          regValue = ((-fine) | 0x20) << 9;
        }
      else
        {
          regValue = fine << 9;
        }
    
      if(coarse < 0)
        {
          regValue |= ((-coarse) | 0x80);
        }
      else
        {
          regValue |= coarse;
        }
    
      return regValue;
    } // end of HAL_getOscTrimValue() function
    
    
    void HAL_AdcOffsetSelfCal(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
      uint16_t AdcConvMean;
    
      // disable the ADCs
      ADC_disable(obj->adcHandle);
    
      // power up the bandgap circuit
      ADC_enableBandGap(obj->adcHandle);
    
      // set the ADC voltage reference source to internal
      ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
    
      // enable the ADC reference buffers
      ADC_enableRefBuffers(obj->adcHandle);
    
      // Set main clock scaling factor (max45MHz clock for the ADC module)
      ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
    
      // power up the ADCs
      ADC_powerUp(obj->adcHandle);
    
      // enable the ADCs
      ADC_enable(obj->adcHandle);
    
      //Select VREFLO internal connection on B5
      ADC_enableVoltRefLoConv(obj->adcHandle);
    
      //Select channel B5 for all SOC
      HAL_AdcCalChanSelect(handle, ADC_SocChanNumber_B5);
    
      //Apply artificial offset (+80) to account for a negative offset that may reside in the ADC core
      ADC_setOffTrim(obj->adcHandle, 80);
    
      //Capture ADC conversion on VREFLO
      AdcConvMean = HAL_AdcCalConversion(handle);
    
      //Set offtrim register with new value (i.e remove artical offset (+80) and create a two's compliment of the offset error)
      ADC_setOffTrim(obj->adcHandle, 80 - AdcConvMean);
    
      //Select external ADCIN5 input pin on B5
      ADC_disableVoltRefLoConv(obj->adcHandle);
    
      return;
    } // end of HAL_AdcOffsetSelfCal() function
    
    
    void HAL_AdcCalChanSelect(HAL_Handle handle, const ADC_SocChanNumber_e chanNumber)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_8,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_9,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_10,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_11,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_12,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_13,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_14,chanNumber);
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_15,chanNumber);
    
      return;
    } // end of HAL_AdcCalChanSelect() function
    
    
    uint16_t HAL_AdcCalConversion(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
      uint16_t index, SampleSize, Mean;
      uint32_t Sum;
      ADC_SocSampleDelay_e ACQPS_Value;
    
      index       = 0;     //initialize index to 0
      SampleSize  = 256;   //set sample size to 256 (**NOTE: Sample size must be multiples of 2^x where is an integer >= 4)
      Sum         = 0;     //set sum to 0
      Mean        = 999;   //initialize mean to known value
    
      //Set the ADC sample window to the desired value (Sample window = ACQPS + 1)
      ACQPS_Value = ADC_SocSampleDelay_7_cycles;
    
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_8,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_9,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_10,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_11,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_12,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_13,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_14,ACQPS_Value);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_15,ACQPS_Value);
    
      // Enabled ADCINT1 and ADCINT2
      ADC_enableInt(obj->adcHandle, ADC_IntNumber_1);
      ADC_enableInt(obj->adcHandle, ADC_IntNumber_2);
    
      // Disable continuous sampling for ADCINT1 and ADCINT2
      ADC_setIntMode(obj->adcHandle, ADC_IntNumber_1, ADC_IntMode_EOC);
      ADC_setIntMode(obj->adcHandle, ADC_IntNumber_2, ADC_IntMode_EOC);
    
      //ADCINTs trigger at end of conversion
      ADC_setIntPulseGenMode(obj->adcHandle, ADC_IntPulseGenMode_Prior);
    
      // Setup ADCINT1 and ADCINT2 trigger source
      ADC_setIntSrc(obj->adcHandle, ADC_IntNumber_1, ADC_IntSrc_EOC6);
      ADC_setIntSrc(obj->adcHandle, ADC_IntNumber_2, ADC_IntSrc_EOC14);
    
      // Setup each SOC's ADCINT trigger source
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_0, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_1, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_2, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_3, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_4, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_5, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_6, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_7, ADC_Int2TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_8, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_9, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_10, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_11, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_12, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_13, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_14, ADC_Int1TriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_15, ADC_Int1TriggersSOC);
    
      // Delay before converting ADC channels
      usDelay(ADC_DELAY_usec);
    
      ADC_setSocFrcWord(obj->adcHandle, 0x00FF);
    
      while( index < SampleSize )
        {
          //Wait for ADCINT1 to trigger, then add ADCRESULT0-7 registers to sum
          while (ADC_getIntFlag(obj->adcHandle, ADC_IntNumber_1) == 0){}
    
          //Must clear ADCINT1 flag since INT1CONT = 0
          ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_1);
    
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_0);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_1);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_2);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_3);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_4);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_5);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_6);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_7);
    
          //Wait for ADCINT2 to trigger, then add ADCRESULT8-15 registers to sum
          while (ADC_getIntFlag(obj->adcHandle, ADC_IntNumber_2) == 0){}
    
          //Must clear ADCINT2 flag since INT2CONT = 0
          ADC_clearIntFlag(obj->adcHandle, ADC_IntNumber_2);
    
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_8);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_9);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_10);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_11);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_12);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_13);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_14);
          Sum += ADC_readResult(obj->adcHandle, ADC_ResultNumber_15);
    
          index+=16;
    
      } // end data collection
    
      //Disable ADCINT1 and ADCINT2 to STOP the ping-pong sampling
      ADC_disableInt(obj->adcHandle, ADC_IntNumber_1);
      ADC_disableInt(obj->adcHandle, ADC_IntNumber_2);
    
      //Calculate average ADC sample value
      Mean = Sum / SampleSize;
    
      // Clear start of conversion trigger
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_0, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_1, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_2, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_3, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_4, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_5, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_6, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_7, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_8, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_9, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_10, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_11, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_12, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_13, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_14, ADC_NoIntTriggersSOC);
      ADC_setupSocTrigSrc(obj->adcHandle, ADC_SocNumber_15, ADC_NoIntTriggersSOC);
    
      //return the average
      return(Mean);
    } // end of HAL_AdcCalConversion() function
    
    
    void HAL_disableWdog(HAL_Handle halHandle)
    {
      HAL_Obj *hal = (HAL_Obj *)halHandle;
    
    
      WDOG_disable(hal->wdogHandle);
    
    
      return;
    } // end of HAL_disableWdog() function
    
    
    void HAL_disableGlobalInts(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      CPU_disableGlobalInts(obj->cpuHandle);
    
      return;
    } // end of HAL_disableGlobalInts() function
    
    
    void HAL_enableAdcInts(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      // enable the PIE interrupts associated with the ADC interrupts
      PIE_enableAdcInt(obj->pieHandle,ADC_IntNumber_1);
    
    
      // enable the ADC interrupts
      ADC_enableInt(obj->adcHandle,ADC_IntNumber_1);
    
    
      // enable the cpu interrupt for ADC interrupts
      CPU_enableInt(obj->cpuHandle,CPU_IntNumber_10);
    
      return;
    } // end of HAL_enableAdcInts() function
    
    
    void HAL_enableDebugInt(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      CPU_enableDebugInt(obj->cpuHandle);
    
      return;
    } // end of HAL_enableDebugInt() function
    
    
    void HAL_enableGlobalInts(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      CPU_enableGlobalInts(obj->cpuHandle);
    
      return;
    } // end of HAL_enableGlobalInts() function
    
    
    void HAL_enablePwmInt(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      PIE_enablePwmInt(obj->pieHandle,PWM_Number_1);
    
    
      // enable the interrupt
      PWM_enableInt(obj->pwmHandle[PWM_Number_1]);
    
    
      // enable the cpu interrupt for EPWM1_INT
      CPU_enableInt(obj->cpuHandle,CPU_IntNumber_3);
    
      return;
    } // end of HAL_enablePwmInt() function
    
    
    void HAL_setupFaults(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
      uint_least8_t cnt;
    
    
      // Configure Trip Mechanism for the Motor control software
      // -Cycle by cycle trip on CPU halt
      // -One shot fault trip zone
      // These trips need to be repeated for EPWM1 ,2 & 3
      for(cnt=0;cnt<3;cnt++)
        {
          PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_CycleByCycle_TZ6_NOT);
    
          PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_OneShot_TZ3_NOT);
    
          PWM_enableTripZoneSrc(obj->pwmHandle[cnt],PWM_TripZoneSrc_OneShot_TZ2_NOT);
    
          // What do we want the OST/CBC events to do?
          // TZA events can force EPWMxA
          // TZB events can force EPWMxB
    
          PWM_setTripZoneState_TZA(obj->pwmHandle[cnt],PWM_TripZoneState_EPWM_Low);
          PWM_setTripZoneState_TZB(obj->pwmHandle[cnt],PWM_TripZoneState_EPWM_Low);
        }
    
      return;
    } // end of HAL_setupFaults() function
    
    
    HAL_Handle HAL_init(void *pMemory,const size_t numBytes)
    {
      uint_least8_t cnt;
      HAL_Handle handle;
      HAL_Obj *obj;
    
    
      if(numBytes < sizeof(HAL_Obj))
        return((HAL_Handle)NULL);
    
    
      // assign the handle
      handle = (HAL_Handle)pMemory;
    
    
      // assign the object
      obj = (HAL_Obj *)handle;
    
    
      // initialize the watchdog driver
      obj->wdogHandle = WDOG_init((void *)WDOG_BASE_ADDR,sizeof(WDOG_Obj));
    
    
      // disable watchdog
      HAL_disableWdog(handle);
    
    
      // initialize the ADC
      obj->adcHandle = ADC_init((void *)ADC_BASE_ADDR,sizeof(ADC_Obj));
    
    
      // initialize the clock handle
      obj->clkHandle = CLK_init((void *)CLK_BASE_ADDR,sizeof(CLK_Obj));
    
    
      // initialize the CPU handle
      obj->cpuHandle = CPU_init(&cpu,sizeof(cpu));
    
    
      // initialize the FLASH handle
      obj->flashHandle = FLASH_init((void *)FLASH_BASE_ADDR,sizeof(FLASH_Obj));
    
    
      // initialize the GPIO handle
      obj->gpioHandle = GPIO_init((void *)GPIO_BASE_ADDR,sizeof(GPIO_Obj));
    
    
      // initialize the current offset estimator handles
      for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
        {
          obj->offsetHandle_I[cnt] = OFFSET_init(&obj->offset_I[cnt],sizeof(obj->offset_I[cnt]));
        }
    
    
      // initialize the voltage offset estimator handles
      for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
        {
          obj->offsetHandle_V[cnt] = OFFSET_init(&obj->offset_V[cnt],sizeof(obj->offset_V[cnt]));
        }
    
    
      // initialize the oscillator handle
      obj->oscHandle = OSC_init((void *)OSC_BASE_ADDR,sizeof(OSC_Obj));
    
    
      // initialize the PIE handle
      obj->pieHandle = PIE_init((void *)PIE_BASE_ADDR,sizeof(PIE_Obj));
    
    
      // initialize the PLL handle
      obj->pllHandle = PLL_init((void *)PLL_BASE_ADDR,sizeof(PLL_Obj));
    
    
      // initialize PWM handles
      obj->pwmHandle[0] = PWM_init((void *)PWM_ePWM1_BASE_ADDR,sizeof(PWM_Obj));
      obj->pwmHandle[1] = PWM_init((void *)PWM_ePWM2_BASE_ADDR,sizeof(PWM_Obj));
      obj->pwmHandle[2] = PWM_init((void *)PWM_ePWM3_BASE_ADDR,sizeof(PWM_Obj));
    
    
      // initialize PWM DAC handles
      obj->pwmDacHandle[0] = PWMDAC_init((void *)PWM_ePWM6_BASE_ADDR,sizeof(PWM_Obj));
      obj->pwmDacHandle[1] = PWMDAC_init((void *)PWM_ePWM5_BASE_ADDR,sizeof(PWM_Obj));
      obj->pwmDacHandle[2] = PWMDAC_init((void *)PWM_ePWM4_BASE_ADDR,sizeof(PWM_Obj));
    
    
      // initialize power handle
      obj->pwrHandle = PWR_init((void *)PWR_BASE_ADDR,sizeof(PWR_Obj));
    
    
      // initialize timer handles
      obj->timerHandle[0] = TIMER_init((void *)TIMER0_BASE_ADDR,sizeof(TIMER_Obj));
      obj->timerHandle[1] = TIMER_init((void *)TIMER1_BASE_ADDR,sizeof(TIMER_Obj));
      obj->timerHandle[2] = TIMER_init((void *)TIMER2_BASE_ADDR,sizeof(TIMER_Obj));
    
    #ifdef QEP
      // initialize QEP driver
      obj->qepHandle[0] = QEP_init((void*)QEP1_BASE_ADDR,sizeof(QEP_Obj));
      obj->qepHandle[1] = QEP_init((void*)QEP2_BASE_ADDR,sizeof(QEP_Obj));
    #endif
    
      return(handle);
    } // end of HAL_init() function
    
    
    void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams)
    {
      uint_least8_t cnt;
      HAL_Obj *obj = (HAL_Obj *)handle;
      _iq beta_lp_pu = _IQ(pUserParams->offsetPole_rps/(float_t)pUserParams->ctrlFreq_Hz);
    
    
      HAL_setNumCurrentSensors(handle,pUserParams->numCurrentSensors);
      HAL_setNumVoltageSensors(handle,pUserParams->numVoltageSensors);
    
    
      for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
        {
          HAL_setOffsetBeta_lp_pu(handle,HAL_SensorType_Current,cnt,beta_lp_pu);
          HAL_setOffsetInitCond(handle,HAL_SensorType_Current,cnt,_IQ(0.0));
          HAL_setOffsetValue(handle,HAL_SensorType_Current,cnt,_IQ(0.0));
        }
    
    
      for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
        {
          HAL_setOffsetBeta_lp_pu(handle,HAL_SensorType_Voltage,cnt,beta_lp_pu);
          HAL_setOffsetInitCond(handle,HAL_SensorType_Voltage,cnt,_IQ(0.0));
          HAL_setOffsetValue(handle,HAL_SensorType_Voltage,cnt,_IQ(0.0));
        }
    
    
      // disable global interrupts
      CPU_disableGlobalInts(obj->cpuHandle);
    
    
      // disable cpu interrupts
      CPU_disableInts(obj->cpuHandle);
    
    
      // clear cpu interrupt flags
      CPU_clearIntFlags(obj->cpuHandle);
    
    
      // setup the clocks
      HAL_setupClks(handle);
    
    
      // Setup the PLL
      HAL_setupPll(handle,PLL_ClkFreq_90_MHz);
    
    
      // setup the PIE
      HAL_setupPie(handle);
    
    
      // run the device calibration
      HAL_cal(handle);
    
    
      // setup the peripheral clocks
      HAL_setupPeripheralClks(handle);
    
    
      // setup the GPIOs
      HAL_setupGpios(handle);
    
    
      // setup the flash
      HAL_setupFlash(handle);
    
    
      // setup the ADCs
      HAL_setupAdcs(handle);
    
    
      // setup the PWMs
      HAL_setupPwms(handle,
                    pUserParams->systemFreq_MHz,
                    pUserParams->pwmPeriod_usec,
                    USER_NUM_PWM_TICKS_PER_ISR_TICK);
    
    
      // setup the PWM DACs
      HAL_setupPwmDacs(handle);
    
    
      // setup the timers
      HAL_setupTimers(handle,
                      pUserParams->systemFreq_MHz);
    
    
      // set the default current bias
     {
       uint_least8_t cnt;
       _iq bias = _IQ12mpy(ADC_dataBias,_IQ(pUserParams->current_sf));
       
       for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++)
         {
           HAL_setBias(handle,HAL_SensorType_Current,cnt,bias);
         }
     }
    
    
      //  set the current scale factor
     {
       _iq current_sf = _IQ(pUserParams->current_sf);
    
      HAL_setCurrentScaleFactor(handle,current_sf);
     }
    
    
      // set the default voltage bias
     {
       uint_least8_t cnt;
       _iq bias = _IQ(0.0);
       
       for(cnt=0;cnt<HAL_getNumVoltageSensors(handle);cnt++)
         {
           HAL_setBias(handle,HAL_SensorType_Voltage,cnt,bias);
         }
     }
    
    
      //  set the voltage scale factor
     {
       _iq voltage_sf = _IQ(pUserParams->voltage_sf);
    
      HAL_setVoltageScaleFactor(handle,voltage_sf);
     }
    
     return;
    } // end of HAL_setParams() function
    
    
    void HAL_setupAdcs(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      // disable the ADCs
      ADC_disable(obj->adcHandle);
    
    
      // power up the bandgap circuit
      ADC_enableBandGap(obj->adcHandle);
    
    
      // set the ADC voltage reference source to internal 
      ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);
    
    
      // enable the ADC reference buffers
      ADC_enableRefBuffers(obj->adcHandle);
    
    
      // Set main clock scaling factor (max45MHz clock for the ADC module)
      ADC_setDivideSelect(obj->adcHandle,ADC_DivideSelect_ClkIn_by_2);
    
    
      // power up the ADCs
      ADC_powerUp(obj->adcHandle);
    
    
      // enable the ADCs
      ADC_enable(obj->adcHandle);
    
    
      // set the ADC interrupt pulse generation to prior
      ADC_setIntPulseGenMode(obj->adcHandle,ADC_IntPulseGenMode_Prior);
    
    
      // set the temperature sensor source to external
      ADC_setTempSensorSrc(obj->adcHandle,ADC_TempSensorSrc_Ext);
    
    
      // configure the interrupt sources
      ADC_disableInt(obj->adcHandle,ADC_IntNumber_1);
      ADC_setIntMode(obj->adcHandle,ADC_IntNumber_1,ADC_IntMode_ClearFlag);
      ADC_setIntSrc(obj->adcHandle,ADC_IntNumber_1,ADC_IntSrc_EOC7);
    
    
      // configure the SOCs for drv8312kit_revD
      // EXT IA-FB
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,ADC_SocChanNumber_A1);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_0,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ADC_SocSampleDelay_9_cycles);
    
      // EXT IA-FB
      // Duplicate conversion due to ADC Initial Conversion bug (SPRZ342)
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,ADC_SocChanNumber_A1);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_1,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ADC_SocSampleDelay_9_cycles);
    
      // EXT IB-FB
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,ADC_SocChanNumber_B5);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_2,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ADC_SocSampleDelay_9_cycles);
    
      // EXT IC-FB
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,ADC_SocChanNumber_A5);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_3,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ADC_SocSampleDelay_9_cycles);
    
      // ADC-Vhb1
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,ADC_SocChanNumber_B7);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_4,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ADC_SocSampleDelay_9_cycles);
    
      // ADC-Vhb2
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,ADC_SocChanNumber_A7);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_5,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ADC_SocSampleDelay_9_cycles);
    
      // ADC-Vhb3
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,ADC_SocChanNumber_B4);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_6,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ADC_SocSampleDelay_9_cycles);
    
      // VDCBUS
      ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,ADC_SocChanNumber_B2);
      ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_7,ADC_SocTrigSrc_EPWM1_ADCSOCA);
      ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ADC_SocSampleDelay_9_cycles);
    
    
      return;
    } // end of HAL_setupAdcs() function
    
    
    void HAL_setupClks(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      // enable internal oscillator 1
      CLK_enableOsc1(obj->clkHandle);
    
      // set the oscillator source
      CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_Internal);
    
      // disable the external clock in
      CLK_disableClkIn(obj->clkHandle);
    
      // disable the crystal oscillator
      CLK_disableCrystalOsc(obj->clkHandle);
    
      // disable oscillator 2
      CLK_disableOsc2(obj->clkHandle);
    
      // set the low speed clock prescaler
      CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_4);
    
      // set the clock out prescaler
      CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);
    
      return;
    } // end of HAL_setupClks() function
    
    
    void HAL_setupFlash(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      FLASH_enablePipelineMode(obj->flashHandle);
    
      FLASH_setNumPagedReadWaitStates(obj->flashHandle,FLASH_NumPagedWaitStates_3);
    
      FLASH_setNumRandomReadWaitStates(obj->flashHandle,FLASH_NumRandomWaitStates_3);
    
      FLASH_setOtpWaitStates(obj->flashHandle,FLASH_NumOtpWaitStates_5);
    
      FLASH_setStandbyWaitCount(obj->flashHandle,FLASH_STANDBY_WAIT_COUNT_DEFAULT);
    
      FLASH_setActiveWaitCount(obj->flashHandle,FLASH_ACTIVE_WAIT_COUNT_DEFAULT);
    
      return;
    } // HAL_setupFlash() function
    
    
    void HAL_setupGpios(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      // PWM1
      GPIO_setMode(obj->gpioHandle,GPIO_Number_0,GPIO_0_Mode_EPWM1A);
    
      // PWM2
      GPIO_setMode(obj->gpioHandle,GPIO_Number_1,GPIO_1_Mode_EPWM1B);
    
      // PWM3
      GPIO_setMode(obj->gpioHandle,GPIO_Number_2,GPIO_2_Mode_EPWM2A);
    
      // PWM4
      GPIO_setMode(obj->gpioHandle,GPIO_Number_3,GPIO_3_Mode_EPWM2B);
    
      // PWM5
      GPIO_setMode(obj->gpioHandle,GPIO_Number_4,GPIO_4_Mode_EPWM3A);
    
      // PWM6
      GPIO_setMode(obj->gpioHandle,GPIO_Number_5,GPIO_5_Mode_EPWM3B);
    
      // PWM-DAC4
      GPIO_setMode(obj->gpioHandle,GPIO_Number_6,GPIO_6_Mode_EPWM4A);
    
      // Input
      GPIO_setMode(obj->gpioHandle,GPIO_Number_7,GPIO_7_Mode_GeneralPurpose);
    
      // PWM-DAC3
      GPIO_setMode(obj->gpioHandle,GPIO_Number_8,GPIO_8_Mode_ADCSOCAO_NOT);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_9,GPIO_9_Mode_GeneralPurpose);
    
      // PWM-DAC1
      GPIO_setMode(obj->gpioHandle,GPIO_Number_10,GPIO_10_Mode_EPWM6A);
    
      // PWM-DAC2
      GPIO_setMode(obj->gpioHandle,GPIO_Number_11,GPIO_11_Mode_EPWM6B);
    
      // FAULTn
      GPIO_setMode(obj->gpioHandle,GPIO_Number_12,GPIO_12_Mode_GeneralPurpose);
      GPIO_setLow(obj->gpioHandle,GPIO_Number_12);
      GPIO_setDirection(obj->gpioHandle,GPIO_Number_12,GPIO_Direction_Output);
    
      // OCTWn
      GPIO_setMode(obj->gpioHandle,GPIO_Number_13,GPIO_13_Mode_TZ2_NOT);
    
      // FAULTn
      GPIO_setMode(obj->gpioHandle,GPIO_Number_14,GPIO_14_Mode_TZ3_NOT);
    
    
      // LED2
      GPIO_setMode(obj->gpioHandle,GPIO_Number_15,GPIO_15_Mode_GeneralPurpose);
    
    
      // SPI-SIMO
      GPIO_setMode(obj->gpioHandle,GPIO_Number_16,GPIO_16_Mode_GeneralPurpose);
    
      // SPI-SOMI
      GPIO_setMode(obj->gpioHandle,GPIO_Number_17,GPIO_17_Mode_GeneralPurpose);
    
      // SPI-CLK
      GPIO_setMode(obj->gpioHandle,GPIO_Number_18,GPIO_18_Mode_GeneralPurpose);
    
      // SPI-STE
      GPIO_setMode(obj->gpioHandle,GPIO_Number_19,GPIO_19_Mode_GeneralPurpose);
    
    #ifdef QEP
      // EQEPA
      GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_EQEP1A);
    
      // EQEPB
      GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_EQEP1B);
    
      // STATUS
      GPIO_setMode(obj->gpioHandle,GPIO_Number_22,GPIO_22_Mode_GeneralPurpose);
    
      // EQEP1I
      GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_EQEP1I);
    #else
      // EQEPA
      GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_GeneralPurpose);
    
      // EQEPB
      GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_GeneralPurpose);
    
      // STATUS
      GPIO_setMode(obj->gpioHandle,GPIO_Number_22,GPIO_22_Mode_GeneralPurpose);
    
      // EQEP1I
      GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_GeneralPurpose);
    #endif
    
      // SPI SIMO B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_24,GPIO_24_Mode_GeneralPurpose);
    
      // SPI SOMI B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_25,GPIO_25_Mode_GeneralPurpose);
    
      // SPI CLK B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_26,GPIO_26_Mode_GeneralPurpose);
    
      // SPI CSn B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_27,GPIO_27_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_28,GPIO_28_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_29,GPIO_29_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_30,GPIO_30_Mode_GeneralPurpose);
    
    
    #ifdef MMD_CNG_SAKURA
      GPIO_setMode(obj->gpioHandle,GPIO_Number_42,GPIO_42_Mode_GeneralPurpose);
      GPIO_setLow(obj->gpioHandle,GPIO_Number_42);
      GPIO_setDirection(obj->gpioHandle,GPIO_Number_42,GPIO_Direction_Output);
    #else
      // ControlCARD LED2
      GPIO_setMode(obj->gpioHandle,GPIO_Number_31,GPIO_31_Mode_GeneralPurpose);
      GPIO_setLow(obj->gpioHandle,GPIO_Number_31);
      GPIO_setDirection(obj->gpioHandle,GPIO_Number_31,GPIO_Direction_Output);
    #endif
    
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_32,GPIO_32_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_33,GPIO_33_Mode_GeneralPurpose);
    
    #ifdef MMD_CNG_SAKURA
      GPIO_setMode(obj->gpioHandle,GPIO_Number_43,GPIO_43_Mode_GeneralPurpose);
      GPIO_setLow(obj->gpioHandle,GPIO_Number_43);
      GPIO_setDirection(obj->gpioHandle,GPIO_Number_43,GPIO_Direction_Output);
    #else
      // ControlCARD LED3
      GPIO_setMode(obj->gpioHandle,GPIO_Number_34,GPIO_34_Mode_GeneralPurpose);
      GPIO_setLow(obj->gpioHandle,GPIO_Number_34);
      GPIO_setDirection(obj->gpioHandle,GPIO_Number_34,GPIO_Direction_Output);
    #endif
    
    
    
    
    
    
      // JTAG
      GPIO_setMode(obj->gpioHandle,GPIO_Number_35,GPIO_35_Mode_JTAG_TDI);
      GPIO_setMode(obj->gpioHandle,GPIO_Number_36,GPIO_36_Mode_JTAG_TMS);
      GPIO_setMode(obj->gpioHandle,GPIO_Number_37,GPIO_37_Mode_JTAG_TDO);
      GPIO_setMode(obj->gpioHandle,GPIO_Number_38,GPIO_38_Mode_JTAG_TCK);
    
      // DRV8301 Enable
      GPIO_setMode(obj->gpioHandle,GPIO_Number_39,GPIO_39_Mode_GeneralPurpose);
    
      // CAP1
      GPIO_setMode(obj->gpioHandle,GPIO_Number_40,GPIO_40_Mode_GeneralPurpose);
    
      // CAP2
      GPIO_setMode(obj->gpioHandle,GPIO_Number_41,GPIO_41_Mode_GeneralPurpose);
    
      // CAP3
      GPIO_setMode(obj->gpioHandle,GPIO_Number_42,GPIO_42_Mode_GeneralPurpose);
    
      // DC_CAL
      GPIO_setMode(obj->gpioHandle,GPIO_Number_43,GPIO_43_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_44,GPIO_44_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_50,GPIO_50_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_51,GPIO_51_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_52,GPIO_52_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_53,GPIO_53_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_54,GPIO_54_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_55,GPIO_55_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_56,GPIO_56_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_57,GPIO_57_Mode_GeneralPurpose);
    
      // No Connection
      GPIO_setMode(obj->gpioHandle,GPIO_Number_58,GPIO_58_Mode_GeneralPurpose);
    
      return;
    }  // end of HAL_setupGpios() function
    
    
    void HAL_setupPie(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      PIE_disable(obj->pieHandle);
    
      PIE_disableAllInts(obj->pieHandle);
    
      PIE_clearAllInts(obj->pieHandle);
    
      PIE_clearAllFlags(obj->pieHandle);
    
      PIE_setDefaultIntVectorTable(obj->pieHandle);
    
      PIE_enable(obj->pieHandle);
    
      return;
    } // end of HAL_setupPie() function
    
    
    void HAL_setupPeripheralClks(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      CLK_enableAdcClock(obj->clkHandle);
    
      CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_1);
      CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_2);
      CLK_enableCompClock(obj->clkHandle,CLK_CompNumber_3);
    
      CLK_enableEcap1Clock(obj->clkHandle);
    
      CLK_disableEcanaClock(obj->clkHandle);
    
    #ifdef QEP
      CLK_enableEqep1Clock(obj->clkHandle);
    #endif
    
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_1);
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_2);
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_3);
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_4);
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_5);
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_6);
      CLK_enablePwmClock(obj->clkHandle,PWM_Number_7);
    
      CLK_disableHrPwmClock(obj->clkHandle);
    
      CLK_disableI2cClock(obj->clkHandle);
    
      CLK_disableLinAClock(obj->clkHandle);
    
      CLK_disableClaClock(obj->clkHandle);
    
      CLK_enableSciaClock(obj->clkHandle);
    
      CLK_disableSpiaClock(obj->clkHandle);
      CLK_disableSpibClock(obj->clkHandle);
      
      CLK_enableTbClockSync(obj->clkHandle);
    
      return;
    } // end of HAL_setupPeripheralClks() function
    
    
    void HAL_setupPll(HAL_Handle handle,const PLL_ClkFreq_e clkFreq)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
    
      // make sure PLL is not running in limp mode
      if(PLL_getClkStatus(obj->pllHandle) != PLL_ClkStatus_Normal)
        {
          // reset the clock detect
          PLL_resetClkDetect(obj->pllHandle);
    
          // ???????
          asm("        ESTOP0");
        }
    
    
      // Divide Select must be ClkIn/4 before the clock rate can be changed
      if(PLL_getDivideSelect(obj->pllHandle) != PLL_DivideSelect_ClkIn_by_4)
        {
          PLL_setDivideSelect(obj->pllHandle,PLL_DivideSelect_ClkIn_by_4);
        }
    
    
      if(PLL_getClkFreq(obj->pllHandle) != clkFreq)
        {
          // disable the clock detect
          PLL_disableClkDetect(obj->pllHandle);
    
          // set the clock rate
          PLL_setClkFreq(obj->pllHandle,clkFreq);
        }
    
    
      // wait until locked
      while(PLL_getLockStatus(obj->pllHandle) != PLL_LockStatus_Done) {}
    
    
      // enable the clock detect
      PLL_enableClkDetect(obj->pllHandle);
    
    
      // set divide select to ClkIn/2 to get desired clock rate
      // NOTE: clock must be locked before setting this register
      PLL_setDivideSelect(obj->pllHandle,PLL_DivideSelect_ClkIn_by_2);
    
      return;
    } // end of HAL_setupPll() function
    
    
    void HAL_setupPwms(HAL_Handle handle,
                       const uint_least16_t systemFreq_MHz,
                       const float_t pwmPeriod_usec,
                       const uint_least16_t numPwmTicksPerIsrTick)
    {
      HAL_Obj   *obj = (HAL_Obj *)handle;
      uint16_t   halfPeriod_cycles = (uint16_t)((float_t)systemFreq_MHz*pwmPeriod_usec) >> 1;
      uint_least8_t    cnt;
    
    
      // turns off the outputs of the EPWM peripherals which will put the power switches
      // into a high impedance state.
      PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
      PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
      PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
    
      for(cnt=0;cnt<3;cnt++)
        {
          // setup the Time-Base Control Register (TBCTL)
          PWM_setCounterMode(obj->pwmHandle[cnt],PWM_CounterMode_UpDown);
          PWM_disableCounterLoad(obj->pwmHandle[cnt]);
          PWM_setPeriodLoad(obj->pwmHandle[cnt],PWM_PeriodLoad_Immediate);
          PWM_setSyncMode(obj->pwmHandle[cnt],PWM_SyncMode_EPWMxSYNC);
          PWM_setHighSpeedClkDiv(obj->pwmHandle[cnt],PWM_HspClkDiv_by_1);
          PWM_setClkDiv(obj->pwmHandle[cnt],PWM_ClkDiv_by_1);
          PWM_setPhaseDir(obj->pwmHandle[cnt],PWM_PhaseDir_CountUp);
          PWM_setRunMode(obj->pwmHandle[cnt],PWM_RunMode_FreeRun);
    
          // setup the Timer-Based Phase Register (TBPHS)
          PWM_setPhase(obj->pwmHandle[cnt],0);
    
          // setup the Time-Base Counter Register (TBCTR)
          PWM_setCount(obj->pwmHandle[cnt],0);
    
          // setup the Time-Base Period Register (TBPRD)
          // set to zero initially
          PWM_setPeriod(obj->pwmHandle[cnt],0);
    
          // setup the Counter-Compare Control Register (CMPCTL)
          PWM_setLoadMode_CmpA(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
          PWM_setLoadMode_CmpB(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
          PWM_setShadowMode_CmpA(obj->pwmHandle[cnt],PWM_ShadowMode_Shadow);
          PWM_setShadowMode_CmpB(obj->pwmHandle[cnt],PWM_ShadowMode_Immediate);
    
          // setup the Action-Qualifier Output A Register (AQCTLA) 
          PWM_setActionQual_CntUp_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Set);
          PWM_setActionQual_CntDown_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Clear);
    
          // setup the Action-qualifier Continuous Software Force Register (AQCSFRC)
          PWM_setActionQualContSWForce_PwmB(obj->pwmHandle[cnt],PWM_ActionQualContSWForce_Set);
    
          // setup the Dead-Band Generator Control Register (DBCTL)
          PWM_setDeadBandOutputMode(obj->pwmHandle[cnt],PWM_DeadBandOutputMode_Bypass);
    
          // setup the PWM-Chopper Control Register (PCCTL)
          PWM_disableChopping(obj->pwmHandle[cnt]);
    
          // setup the Trip Zone Select Register (TZSEL)
          PWM_disableTripZones(obj->pwmHandle[cnt]);
        }
    
    
      // setup the Event Trigger Selection Register (ETSEL)
      PWM_disableInt(obj->pwmHandle[PWM_Number_1]);
      PWM_setSocAPulseSrc(obj->pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualZero);
      PWM_enableSocAPulse(obj->pwmHandle[PWM_Number_1]);
      
    
      // setup the Event Trigger Prescale Register (ETPS)
      if(numPwmTicksPerIsrTick == 3)
        {
          PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_ThirdEvent);
          PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_ThirdEvent);
        }
      else if(numPwmTicksPerIsrTick == 2)
        {
          PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_SecondEvent);
          PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_SecondEvent);
        }
      else
        {
          PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_FirstEvent);
          PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_FirstEvent);
        }
    
    
      // setup the Event Trigger Clear Register (ETCLR)
      PWM_clearIntFlag(obj->pwmHandle[PWM_Number_1]);
      PWM_clearSocAFlag(obj->pwmHandle[PWM_Number_1]);
    
      // first step to synchronize the pwms
      CLK_disableTbClockSync(obj->clkHandle);
    
      // since the PWM is configured as an up/down counter, the period register is set to one-half 
      // of the desired PWM period
      PWM_setPeriod(obj->pwmHandle[PWM_Number_1],halfPeriod_cycles);
      PWM_setPeriod(obj->pwmHandle[PWM_Number_2],halfPeriod_cycles);
      PWM_setPeriod(obj->pwmHandle[PWM_Number_3],halfPeriod_cycles);
    
      // last step to synchronize the pwms
      CLK_enableTbClockSync(obj->clkHandle);
    
      return;
    }  // end of HAL_setupPwms() function
    
    
    void HAL_setupPwmDacs(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
      uint16_t halfPeriod_cycles = 512;       // 3000->10kHz, 1500->20kHz, 1000-> 30kHz, 500->60kHz
      uint_least8_t    cnt;
    
    
      for(cnt=0;cnt<3;cnt++)
        {
          // initialize the Time-Base Control Register (TBCTL)
          PWMDAC_setCounterMode(obj->pwmDacHandle[cnt],PWM_CounterMode_UpDown);
          PWMDAC_disableCounterLoad(obj->pwmDacHandle[cnt]);
          PWMDAC_setPeriodLoad(obj->pwmDacHandle[cnt],PWM_PeriodLoad_Immediate);
          PWMDAC_setSyncMode(obj->pwmDacHandle[cnt],PWM_SyncMode_EPWMxSYNC);
          PWMDAC_setHighSpeedClkDiv(obj->pwmDacHandle[cnt],PWM_HspClkDiv_by_1);
          PWMDAC_setClkDiv(obj->pwmDacHandle[cnt],PWM_ClkDiv_by_1);
          PWMDAC_setPhaseDir(obj->pwmDacHandle[cnt],PWM_PhaseDir_CountUp);
          PWMDAC_setRunMode(obj->pwmDacHandle[cnt],PWM_RunMode_FreeRun);
    
          // initialize the Timer-Based Phase Register (TBPHS)
          PWMDAC_setPhase(obj->pwmDacHandle[cnt],0);
    
          // setup the Time-Base Counter Register (TBCTR)
          PWMDAC_setCount(obj->pwmDacHandle[cnt],0);
    
          // Initialize the Time-Base Period Register (TBPRD)
          // set to zero initially
          PWMDAC_setPeriod(obj->pwmDacHandle[cnt],0);
    
          // initialize the Counter-Compare Control Register (CMPCTL)
          PWMDAC_setLoadMode_CmpA(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
          PWMDAC_setLoadMode_CmpB(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
          PWMDAC_setShadowMode_CmpA(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
          PWMDAC_setShadowMode_CmpB(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
    
          // Initialize the Action-Qualifier Output A Register (AQCTLA) 
          PWMDAC_setActionQual_CntUp_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
          PWMDAC_setActionQual_CntDown_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
    
          // account for EPWM6B
          if(cnt == 0)
            {
              PWMDAC_setActionQual_CntUp_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
              PWMDAC_setActionQual_CntDown_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
            }
    
          // Initialize the Dead-Band Control Register (DBCTL) 
          PWMDAC_disableDeadBand(obj->pwmDacHandle[cnt]);
    
          // Initialize the PWM-Chopper Control Register (PCCTL)
          PWMDAC_disableChopping(obj->pwmDacHandle[cnt]);
    
          // Initialize the Trip-Zone Control Register (TZSEL)
          PWMDAC_disableTripZones(obj->pwmDacHandle[cnt]);
    
          // Initialize the Trip-Zone Control Register (TZCTL)
          PWMDAC_setTripZoneState_TZA(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
          PWMDAC_setTripZoneState_TZB(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
          PWMDAC_setTripZoneState_DCAEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
          PWMDAC_setTripZoneState_DCAEVT2(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
          PWMDAC_setTripZoneState_DCBEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
        }
    
      // since the PWM is configured as an up/down counter, the period register is set to one-half 
      // of the desired PWM period
      PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_1],halfPeriod_cycles);
      PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_2],halfPeriod_cycles);
      PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_3],halfPeriod_cycles);
    
      return;
    }  // end of HAL_setupPwmDacs() function
    
    
    void HAL_setupTimers(HAL_Handle handle,const uint_least16_t systemFreq_MHz)
    {
      HAL_Obj  *obj = (HAL_Obj *)handle;
      uint32_t  timerPeriod_cnts = ((uint32_t)systemFreq_MHz * 1000000) - 1;
    
      // use timer 0 for frequency diagnostics
      TIMER_setDecimationFactor(obj->timerHandle[0],0);
      TIMER_setEmulationMode(obj->timerHandle[0],TIMER_EmulationMode_RunFree);
      TIMER_setPeriod(obj->timerHandle[0],timerPeriod_cnts);
      TIMER_setPreScaler(obj->timerHandle[0],0);
    
      // use timer 1 for CPU usage diagnostics
      TIMER_setDecimationFactor(obj->timerHandle[1],0);
      TIMER_setEmulationMode(obj->timerHandle[1],TIMER_EmulationMode_RunFree);
      TIMER_setPeriod(obj->timerHandle[1],timerPeriod_cnts);
      TIMER_setPreScaler(obj->timerHandle[1],0);
    
      return;
    }  // end of HAL_setupTimers() function
    
    // end of file
    

    2627.hal.h

    /* --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 "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->powerWarpGain = USER_POWERWARP_GAIN;
    
      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;
    
      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.25 * (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.25 * (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);
        }
    
      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
    
    
    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
    
    
    //! \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
    
    

    8055.user.h

    /* --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/proj_lab02a.c
    //! \brief Using InstaSPIN�-FOC for the first time, Motor ID, full control system from ROM 
    //!
    //! (C) Copyright 2011, Texas Instruments, Inc.
    
    //! \defgroup PROJ_LAB02a PROJ_LAB02a
    //@{
    
    //! \defgroup PROJ_LAB02a_OVERVIEW Project Overview
    //!
    //! Using InstaSPIN�-FOC for the first time, Motor ID, full control system from ROM 
    //!
    
    // **************************************************************************
    // the includes
    
    // system includes
    #include <math.h>
    #include "main.h"
    
    #ifdef FLASH
    #pragma CODE_SECTION(mainISR,"ramfuncs");
    #endif
    
    // Include header files used in the main function
    
    
    // **************************************************************************
    // the defines
    
    #define LED_BLINK_FREQ_Hz   5
    
    
    // **************************************************************************
    // the globals
    
    uint_least16_t gCounter_updateGlobals = 0;
    
    bool Flag_Latch_softwareUpdate = true;
    
    CTRL_Handle ctrlHandle;
    
    HAL_Handle halHandle;
    
    USER_Params gUserParams;
    
    HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
    
    HAL_AdcData_t gAdcData;
    
    _iq gMaxCurrentSlope = _IQ(0.0);
    
    #ifdef FAST_ROM_V1p6
    CTRL_Obj *controller_obj;
    #else
    CTRL_Obj ctrl;				//v1p7 format
    #endif
    
    uint16_t gLEDcnt = 0;
    
    volatile MOTOR_Vars_t gMotorVars = MOTOR_Vars_INIT;
    
    #ifdef FLASH
    // Used for running BackGround in flash, and ISR in RAM
    extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
    #endif
    
    
    #ifdef DRV8301_SPI
    // Watch window interface to the 8301 SPI
    DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
    #endif
    
    // **************************************************************************
    // the functions
    
    void main(void)
    {
      uint_least8_t estNumber = 0;
    
    #ifdef FAST_ROM_V1p6
      uint_least8_t ctrlNumber = 0;
    #endif
    
      // Only used if running from FLASH
      // Note that the variable FLASH is defined by the project
      #ifdef FLASH
      // Copy time critical code and Flash setup code to RAM
      // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
      // symbols are created by the linker. Refer to the linker files.
      memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
      #endif
    
      // initialize the hardware abstraction layer
      halHandle = HAL_init(&hal,sizeof(hal));
    
    
      // check for errors in user parameters
      USER_checkForErrors(&gUserParams);
    
    
      // store user parameter error in global variable
      gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
    
    
      // do not allow code execution if there is a user parameter error
      if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
        {
          for(;;)
            {
              gMotorVars.Flag_enableSys = false;
            }
        }
    
    
      // initialize the user parameters
      USER_setParams(&gUserParams);
    
    
      // set the hardware abstraction layer parameters
      HAL_setParams(halHandle,&gUserParams);
    
    
      // initialize the controller
    #ifdef FAST_ROM_V1p6
      ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber);  		//v1p6 format (06xF and 06xM devices)
      controller_obj = (CTRL_Obj *)ctrlHandle;
    #else
      ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl));	//v1p7 format default
    #endif
    
    
      {
        CTRL_Version version;
    
        // get the version number
        CTRL_getVersion(ctrlHandle,&version);
    
        gMotorVars.CtrlVersion = version;
      }
    
    
      // set the default controller parameters
      CTRL_setParams(ctrlHandle,&gUserParams);
    
    
      // setup faults
      HAL_setupFaults(halHandle);
    
    
      // initialize the interrupt vector table
      HAL_initIntVectorTable(halHandle);
    
    
      // enable the ADC interrupts
      HAL_enableAdcInts(halHandle);
    
    
      // enable global interrupts
      HAL_enableGlobalInts(halHandle);
    
    
      // enable debug interrupts
      HAL_enableDebugInt(halHandle);
    
    
      // disable the PWM
      HAL_disablePwm(halHandle);
    
    
    #ifdef DRV8301_SPI
      // turn on the DRV8301 if present
      HAL_enableDrv(halHandle);
      // initialize the DRV8301 interface
      HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
    #endif
    
    
      // enable DC bus compensation
      CTRL_setFlag_enableDcBusComp(ctrlHandle, true);
    
    
      for(;;)
      {
        // Waiting for enable system flag to be set
        while(!(gMotorVars.Flag_enableSys));
    
        // loop while the enable system flag is true
        while(gMotorVars.Flag_enableSys)
          {
            CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
    
            // increment counters
            gCounter_updateGlobals++;
    
    
            if(CTRL_isError(ctrlHandle))
              {
                // set the enable controller flag to false
                CTRL_setFlag_enableCtrl(ctrlHandle,false);
    
                // set the enable system flag to false
                gMotorVars.Flag_enableSys = false;
    
                // disable the PWM
                HAL_disablePwm(halHandle);
              }
            else
              {
                // update the controller state
                bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);
    
                // enable or disable the control
                CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.Flag_Run_Identify);
    
                if(flag_ctrlStateChanged)
                  {
                    CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
                    EST_State_e estState = EST_getState(obj->estHandle);
    
                    if(ctrlState == CTRL_State_OffLine)
                      {
                        // enable the PWM
                        HAL_enablePwm(halHandle);
                      }
                    else if(ctrlState == CTRL_State_OnLine)
                      {
                        if((estState < EST_State_LockRotor) || (estState > EST_State_MotorIdentified))
                          {
                            // update the ADC bias values
                            HAL_updateAdcBias(halHandle);
                          }
    
                        // Return the bias value for currents
                        gMotorVars.I_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Current,0);
                        gMotorVars.I_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Current,1);
                        gMotorVars.I_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Current,2);
    
                        // Return the bias value for voltages
                        gMotorVars.V_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Voltage,0);
                        gMotorVars.V_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Voltage,1);
                        gMotorVars.V_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Voltage,2);
    
                        // enable the PWM
                        HAL_enablePwm(halHandle);
                      }
                    else if(ctrlState == CTRL_State_Idle)
                      {
                        // disable the PWM
                        HAL_disablePwm(halHandle);
                        gMotorVars.Flag_Run_Identify = false;
                      }
    
                    if((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&
                      (ctrlState > CTRL_State_Idle) &&
                      (gMotorVars.CtrlVersion.minor == 6))
                      {
                        // call this function to fix 1p6
                        USER_softwareUpdate1p6(ctrlHandle);
                      }
    
                  }
              }
    
    
            if(EST_isMotorIdentified(obj->estHandle))
              {
                // set the current ramp
                EST_setMaxCurrentSlope_pu(obj->estHandle,gMaxCurrentSlope);
                gMotorVars.Flag_MotorIdentified = true;
    
                // set the speed reference
                CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
    
                // set the speed acceleration
                CTRL_setMaxAccel_pu(ctrlHandle,_IQmpy(MAX_ACCEL_KRPMPS_SF,gMotorVars.MaxAccel_krpmps));
    
                if(Flag_Latch_softwareUpdate)
                {
                  Flag_Latch_softwareUpdate = false;
    
                  USER_calcPIgains(ctrlHandle);
                }
    
              }
            else
              {
                Flag_Latch_softwareUpdate = true;
    
                // the estimator sets the maximum current slope during identification
                gMaxCurrentSlope = EST_getMaxCurrentSlope_pu(obj->estHandle);
              }
    
    
            // when appropriate, update the global variables
            if(gCounter_updateGlobals >= NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE)
              {
                // reset the counter
                gCounter_updateGlobals = 0;
    
                updateGlobalVariables_motor(ctrlHandle);
              }
    
            // recalculate Kp and Ki gains to fix the R/L limitation of 2000.0, and Kp limit to 0.11
            recalcKpKi(ctrlHandle);
    
            if(CTRL_getMotorType(ctrlHandle) == MOTOR_Type_Induction)
              {
                // set electrical frequency limit to zero while identifying an induction motor
                setFeLimitZero(ctrlHandle);
    
                // calculate Dir_qFmt for acim motors
                acim_Dir_qFmtCalc(ctrlHandle);
              }
    
            // enable/disable the forced angle
            EST_setFlag_enableForceAngle(obj->estHandle,gMotorVars.Flag_enableForceAngle);
    
            // enable or disable power warp
            CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.Flag_enablePowerWarp);
    
    #ifdef DRV8301_SPI
            HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
    
            HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
    #endif
    
          } // end of while(gFlag_enableSys) loop
    
    
        // disable the PWM
        HAL_disablePwm(halHandle);
    
        // set the default controller parameters (Reset the control to re-identify the motor)
        CTRL_setParams(ctrlHandle,&gUserParams);
        gMotorVars.Flag_Run_Identify = false;
    
      } // end of for(;;) loop
    
    } // end of main() function
    
    
    interrupt void mainISR(void)
    {
      HAL_PwmData_t negPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
    
      // toggle status LED
      if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
      {
        HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
        gLEDcnt = 0;
      }
    
    
      // acknowledge the ADC interrupt
      HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
    
    
      // convert the ADC data
      HAL_readAdcData(halHandle,&gAdcData);
    
    
      // run the controller
      CTRL_run(ctrlHandle,halHandle,&gAdcData,&negPwmData);
    
    
      // negate PwmData generated by SVGEN module in ROM
      gPwmData.Tabc.value[0] = _IQmpy(negPwmData.Tabc.value[0], _IQ(-1.0));
      gPwmData.Tabc.value[1] = _IQmpy(negPwmData.Tabc.value[1], _IQ(-1.0));
      gPwmData.Tabc.value[2] = _IQmpy(negPwmData.Tabc.value[2], _IQ(-1.0));
    
    
      // write the PWM compare values
      HAL_writePwmData(halHandle,&gPwmData);
    
    
      // setup the controller
      CTRL_setup(ctrlHandle);
    
    
      return;
    } // end of mainISR() function
    
    
    void updateGlobalVariables_motor(CTRL_Handle handle)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
    
      // get the speed estimate
      gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle);
    
      // get the real time speed reference coming out of the speed trajectory generator
      gMotorVars.SpeedTraj_krpm = _IQmpy(CTRL_getSpd_int_ref_pu(handle),EST_get_pu_to_krpm_sf(obj->estHandle));
    
      // get the magnetizing current
      gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle);
    
      // get the rotor resistance
      gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle);
    
      // get the stator resistance
      gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle);
    
      // get the stator inductance in the direct coordinate direction
      gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle);
    
      // get the stator inductance in the quadrature coordinate direction
      gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle);
    
      // get the flux
      gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle);
    
      // get the controller state
      gMotorVars.CtrlState = CTRL_getState(handle);
    
      // get the estimator state
      gMotorVars.EstState = EST_getState(obj->estHandle);
    
      // Get the DC buss voltage
      gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));
    
      return;
    } // end of updateGlobalVariables_motor() function
    
    
    void recalcKpKi(CTRL_Handle handle)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
      EST_State_e EstState = EST_getState(obj->estHandle);
    
      if((EST_isMotorIdentified(obj->estHandle) == false) && (EstState == EST_State_Rs))
        {
          float_t Lhf = CTRL_getLhf(handle);
          float_t Rhf = CTRL_getRhf(handle);
          float_t RhfoverLhf = Rhf/Lhf;
          _iq Kp = _IQ(0.25*Lhf*USER_IQ_FULL_SCALE_CURRENT_A/(USER_CTRL_PERIOD_sec*USER_IQ_FULL_SCALE_VOLTAGE_V));
          _iq Ki = _IQ(RhfoverLhf*USER_CTRL_PERIOD_sec);
    
          // set Rhf/Lhf
          CTRL_setRoverL(handle,RhfoverLhf);
    
          // set the controller proportional gains
          CTRL_setKp(handle,CTRL_Type_PID_Id,Kp);
          CTRL_setKp(handle,CTRL_Type_PID_Iq,Kp);
    
          // set the Id controller gains
          CTRL_setKi(handle,CTRL_Type_PID_Id,Ki);
          PID_setKi(obj->pidHandle_Id,Ki);
    
          // set the Iq controller gains
          CTRL_setKi(handle,CTRL_Type_PID_Iq,Ki);
          PID_setKi(obj->pidHandle_Iq,Ki);
        }
    
      return;
    } // end of recalcKpKi() function
    
    
    void setFeLimitZero(CTRL_Handle handle)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
      EST_State_e EstState = EST_getState(obj->estHandle);
    
      _iq fe_neg_max_pu;
      _iq fe_pos_min_pu;
    
      if((EST_isMotorIdentified(obj->estHandle) == false) && (CTRL_getMotorType(handle) == MOTOR_Type_Induction))
        {
    	  fe_neg_max_pu = _IQ30(0.0);
    
    	  fe_pos_min_pu = _IQ30(0.0);
        }
      else
        {
    	  fe_neg_max_pu = _IQ30(-USER_ZEROSPEEDLIMIT);
    
    	  fe_pos_min_pu = _IQ30(USER_ZEROSPEEDLIMIT);
        }
    
      EST_setFe_neg_max_pu(obj->estHandle, fe_neg_max_pu);
    
      EST_setFe_pos_min_pu(obj->estHandle, fe_pos_min_pu);
    
      return;
    } // end of setFeLimitZero() function
    
    
    void acim_Dir_qFmtCalc(CTRL_Handle handle)
    {
      CTRL_Obj *obj = (CTRL_Obj *)handle;
      EST_State_e EstState = EST_getState(obj->estHandle);
    
      if(EstState == EST_State_IdRated)
        {
          EST_setDir_qFmt(obj->estHandle, EST_computeDirection_qFmt(obj->estHandle, 0.7));
        }
    
      return;
    } // end of acim_Dir_qFmtCalc() function
    
    
    //@} //defgroup
    // end of file
    
    
    
    

     

     

  • no one has similar experiences. this kit works perfectly out of the box.

    please check your toggle switches on the DRV8312 kit, they need to be in the middle MCU position

  • user.h

    I don't know why you added this IFDEF. You should just set-up a new motor if you want different settings. But what you did should work I suppose.

    #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.4051206)
    #define USER_MOTOR_Ls_d                 (0.0006398709)
    #define USER_MOTOR_Ls_q                 (0.0006398709)
    #define USER_MOTOR_RATED_FLUX           (0.03416464)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT      (-1.0)
    #ifdef MMD_CNG_SAKURA
     #define USER_MOTOR_MAX_CURRENT          (1.0)
    #else
     #define USER_MOTOR_MAX_CURRENT          (5.0)
    #endif
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (20.0)

  • I would do a fresh install of MotorWare and try to just run the DRV8312 proj_lab02a as-is.

    It should work.

  • Hi,Chris

    Thank you your help.

    I confirmed connect between F28069 and DRV8312(RESET[A..C] ports)

    It is no problem...


    Thank you.

  • Thank you for your help.

    >I don't know why you added this IFDEF.

    Because it is the first board, in order to suppress the maximum current of the motor, I rewrite the definition for test.
    There is no special meaning.

  • are you sure you have the phase wires hooked up correctly to the A, B, C terminals.

    Don't use the GND terminal and don't use any of the hall sensor wires from the motor.

    there is something grossly wrong though

  • Hi,Chris.


    Thank  you very much for your help.


    I sure about connect the wires.A,B,C.It's fine.


    I think current feedback isuue on my board.

    It' s noisy in my board.

    hal.c

    ADC_SocSampleDelay_9_cycles

    It is delaying the time to ADC from the switching timing.

    Thus, I have done the measurement of current in the flat position.

    Do I understand correctly?

    Now,sysclk=20MHz,

    1/20 x 9cycle =0.05usec x 9cycle =450nsec

    This waveform is detect of B current.

     

  • the system clock is 90 MHz

    please confirm:

    can you use the included Telco/Anaheim NEMA17 motor and run proj_lab02a from MotorWare _13?

    Does it work? Post the parameters that are identified.

    maybe your kit is damaged (though I've never seen this happen, unless wrong voltage is applied)

  • Hi,Chris

    Thank you for your help!!


    >can you use the included Telco/Anaheim NEMA17 motor and run proj_lab02a from MotorWare _13?

    I can not understand.

    I am using the following combination.

    Motor:DT4260-24-055-04(It has been included in the kit.)

    SW:C:\TI\motorware\motorware_1_01_00_13\sw\solutions\instaspin_foc\boards\drv8312kit_revD\f28x\f2806xF\projects\ccs5\proj_lab02a

    I have ordered the DRV. Because it is delivered next week, I will to be confirmed again.

    Thank you very much agein for youe help.

     

     

     

  • I just read back through the post and realized that you have CUSTOM hardware.

    Obviously something is wrong with your custom HW circuit.  It's hard to say exactly what, but you need to start with your current and voltage sensing...and make sure that your pin assignments in your hal files matches up with your HW.

  • Thank you for your help.

    After replacing the DRV8312 has changed a little situation.

    The identified yet I will fail.
    Should the current is reduced during of identification, has changed the frequency.
    For this waveform, What do you think?


    KIT The current and voltage bias is different, it was confirmed that it has been entered correctly F28069M.
    Pin assignment of the ADC of HAL file is also correct.
    Basically, I think that there is no need to change I have been together KIT and pin assignments.

     

    I have question.

    C:\TI\guicomposer\webapps\InstaSPIN_FOC_F2806xM\InstaSPIN_FOC_F2806xM.exe

    Since the pin assignment is the same, so I want to try using this. However, identification target hardware does not become DRV8312. Where can I Will have to determine the type of kit in the software?

    Also, is it possible I want to build the same as the appProgram from the source?

  • the GUI you are trying to use is "frozen", meaning we don't give you the source and let you recompile.

    if you want to have a GUI to instrument a MotorWare based project for one of the kits or your own hardware please use INSTASPINUNIVERSALGUI

    I can't debug from your scope shot. I would still look at your voltages/currents.

  • Thank you for your reply.

    <Regarding to Lab02a>

    1. Using this software, the pin assignment of the MPU needed to complete the identification, are understood to be those described below.

    Is my understanding correct?

    GPIO0(PWM_A)

    GPIO1(RESET_A)

    GPIO2(PWM_B)

    GPIO3(RESET_B)

    GPIO4(PWM_C)

    GPIO5(RESET_C)

    ADC-A1(IA-FB)

    ADC-B5(IB-FB)

    ADC-A5(IC-FB)

    ADC-B7(ADC-Vhb1)

    ADC-A7(ADC-Vhb2)

    ADC-B4(ADC-Vhb3)

    ADC-B2( VDCBUS)

    If any other pin is not connected that is fine to working the software. I was understand.

    Is there a pull-up/down is necessary pin?

     



    2. Input of the noise of the AD conversion (voltage ripple)
    How likely are you affect the identification?
    DRV8312EVM_RevD was about 80mV.
    My board was about 140mV.



    <Regarding hardware target type at GUI>
    Please let me know,how do appProgram determine type of hardware?
    Is it the pin assignment?
    or Is it ID in ram/rom?

    I want to to know is the discrimination of the target.

     

    Thank you very much your help!!

     

  • 1. all peripherals used are set-up in the HAL.C file for the specific board + MCU combination, ex:

    C:\ti\motorware\motorware_1_01_00_13\sw\modules\hal\boards\drv8312kit_revD\f28x\f2806x\src

    2. I can't give you a min/max value, that's not something we specify

    3. The source for the "frozen" GUI looks at differences in some key GPIO to determine if the hardware is the DRV8301 EVM, DRV8312 EVM, or HVMTR EVM. Let me re-iterate - you can NOT use this frozen binary on your own HW. I guarantee it will not work. Create your own binary using MotorWare.

  • Hi Chris.

    Thank you for your reply!!

    I am grateful for your great help.

    >1. all peripherals used are set-up in the HAL.C file for the specific board + MCU combination,

    My intention does not seem conveys to you well.

    I will use a combination of Pro2a and DRV8312EVA_REVD.
    At that time, for the identification of the motor, minimum required signals required becomes 13 pins. So I will not understand.


    And is input to the ADC of the MPU, captured data are converted to a physical quantity required, and then changes the PWM duty of to control the motor.

    For example, current
    It is determined by the hardware of value(R54,R30,R16,R35,R26,VCC)
    USER_ADC_FULL_SCALE_CURRENT_A
    And, it is determined 1.2 to 1.3 times the value of the peak current DRV8312
    USER_IQ_FULL_SCALE_CURRENT_A
    , The data of the captured ADC is converted into a current, to determine the duty of the PWM.

    Some settings such as the CPU clock, but in the purpose of the identification of the motor, the minimum required thing as a peripheral module will ADC and PWM.


    In addition, in order to convert the data captured by the ADC, if defined, such as USER_ADC_FULL_SCALE_CURRENT_A is long as be set correctly, the goal should be achieved.

    I understand as this.
    These understanding correct?, I want to make sure.

     

    >2. I can't give you a min/max value, that's not something we specify

    OK.

    >3.in some key GPIO to determine

    I'm not looking for a guarantee.

    You if possible, I wanted to know whether is set how GPIO of KEY is.:) Thank you!!

     

    4.The IQ, What does the abbreviation?

    InstaSPINTM-FOC User’s Guide

    Since the commentary to guide did not, I want to know.

    //! \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        (800.0)   // 800 Example with buffer for 8-pole 6 KRPM motor to be run to 10 KRPM with field weakening; Hz =(RPM * Poles) / 120

     

    Thanks for your help again.