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.

DRV8311HEVM: lab is05 Motor Identification not working

Part Number: DRV8311HEVM
Other Parts Discussed in Thread: LAUNCHXL-F280049C, DRV8311, DRV8316, MOTORWARE, C2000WARE

Hi,

I am trying to get the DRV8311HEVM board working with the LAUNCHXL-F280049C processor board and a small brushless DC motor.

I am running through the labs provided in the solution for the DRV8311HEVM in this post: https://e2e.ti.com/f/1/t/1037895

I have worked through labs 1 to 4 and believe everything is working as expected.

However for lab 5 the values determined by the motor identification routine are way off, and the motor does not spin if I re-enable 'flagRunIdentAndOnLine' after the motor is identified. 

If we start with the winding resistance Rs, my motor is approx 3.3ohms per phase, or 6.6ohms phase to phase. The motor identification is calculating about 200 ohms. 

I have tried adjusting the gain on the current sensing as the default setting gives a measurement range of approx +/- 13A, whereas this motor is limited to +/- 0.6A. This does not fix things.

my user.h file currently has these settings:

//!        DRV8311 = VREF = 3V, GAIN = 1V/A || 3.3V / 1V/A = 3.3A
#define USER_ADC_FULL_SCALE_CURRENT_A ((float32_t)(3.3))

#define IA_OFFSET_A (1.51954913) // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
#define IB_OFFSET_A (1.52126324) // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
#define IC_OFFSET_A (1.51737309) // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A

#define VA_OFFSET_V (0.498054296) // ~=1.0
#define VB_OFFSET_V (0.495817453) // ~=1.0
#define VC_OFFSET_V (0.495953172) // ~=1.0

#define USER_MOTOR NFP_1215_912

......

#elif (USER_MOTOR == NFP_1215_912)
#define USER_MOTOR_TYPE MOTOR_TYPE_PM
#define USER_MOTOR_NUM_POLE_PAIRS (1)
#define USER_MOTOR_Rr_Ohm (NULL)
#define USER_MOTOR_Rs_Ohm (3.3)
#define USER_MOTOR_Ls_d_H (0.00005)
#define USER_MOTOR_Ls_q_H (0.00005)
#define USER_MOTOR_RATED_FLUX_VpHz (NULL)
#define USER_MOTOR_MAGNETIZING_CURRENT_A (NULL)
#define USER_MOTOR_RES_EST_CURRENT_A (0.3)
#define USER_MOTOR_IND_EST_CURRENT_A (-0.3)
#define USER_MOTOR_MAX_CURRENT_A (0.6)
#define USER_MOTOR_FLUX_EXC_FREQ_Hz (60.0)
#define USER_MOTOR_NUM_ENC_SLOTS (500)
#define USER_MOTOR_INERTIA_Kgm2 (1.15e-06)

#define USER_MOTOR_FREQ_MIN_HZ (5.0) // Hz
#define USER_MOTOR_FREQ_MAX_HZ (300.0) // Hz

#define USER_MOTOR_FREQ_LOW_HZ (10.0) // Hz
#define USER_MOTOR_FREQ_HIGH_HZ (400.0) // Hz
#define USER_MOTOR_VOLT_MIN_V (2.0) // Volt
#define USER_MOTOR_VOLT_MAX_V (7.0) // Volt

Any idea what might be happening, and how I can debug it? Its a bit difficult to debug when the code for the motor id is the ROM.

Thanks in advance.

  • Hi Stephen, 

    Let me look into this a little bit more in the lab today to re-familiarize myself with the setup. 

    Just to confirm, are you following the steps in the EVM user's guide and this video? https://www.youtube.com/watch?v=rm4udhCxBSY

    And none of the GAIN settings are working with the firmware? And you have made no modifications to the EVM out of the box, correct?

    Thanks,
    Aaron

  • Hi Stephen, 

    I did not get to this today, I'll look at this in the morning tomorrow in the lab. 

    Thanks,
    Aaron

  • Hi Aaron, 

    Thanks that would be great if you can help me with this.  Yes I have been through the EVM user guide and the video you have linked.

    To recap, these are the steps I have been through:

    1. I first started with the online universal GUI here: https://dev.ti.com/gallery/view/BLDC/DRV8311xEVM_InstaSPIN_Universal_GUI/ver/1.0.0/

        When I run this with the board set with all its default settings including current gain of 0.25V/A, the first step calculates the offsets as:

    On the second step, I have set the num pole pairs to 1, Max Current for R est  to 0.18 and Max Current for L est to -0.18. The motor identification runs to completion, but the detected parameters don't look correct. My motor has a winding resistance of approx 3.3ohms (6.6 phase to phase) and inductance of approx 50uH. The detected values are: Rs: 202, Ls-d 0.001(mH) ls-q (mH)0.001, Flux (V/Hz) 0.2919.

    If I now run the motor  with these values, the motor spins slowly, not at the right set speed, its drawing a high current, and it doesn't respond to changes in the set speed.

    2. So then I moved on to the labs defined in your post here: https://e2e.ti.com/support/motor-drivers-group/motor-drivers/f/motor-drivers-forum/1037895/faq-drv8311hevm-drv8311hevm-source-code-for-motorcontrol-sdk-instaspin-foc

    I initially used this with the latest version of the SDK (04-00), but now have it setup with version 03-01 as indicated in the post. I am working through the document "InstaSPIN Projects and Labs User’s Guide InstaSPIN-FOC for F28004xC"

    Lab 1 works fine.

    In Lab2, this works fine, but the calculated offsets are different than those detected by the online GUI. The relevant entries in my user.h file are now:

    #define USER_ADC_FULL_SCALE_VOLTAGE_V         ((float32_t)(26.87)) //of the motor

    #define USER_ADC_FULL_SCALE_CURRENT_A         ((float32_t)(13.2))

    #define IA_OFFSET_A (6.0819726) // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    #define IB_OFFSET_A (6.08051252) // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    #define IC_OFFSET_A (6.07770014) // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A

    #define VA_OFFSET_V (0.499282688) // ~=1.0
    #define VB_OFFSET_V (0.496949106) // ~=1.0
    #define VC_OFFSET_V (0.495443225) // ~=1.0

    So the current offsets are approx the same as the online GUI, but the voltage ones are 1/2 the GUI values. Looking through the code, these new values look correct, as the offset is calculated as adcData.V_V.value[0] -= motorVars.offsets_V_V.value[0] * adcData.dcBus_V; So the offset is approx half the VBus voltage, which seems correct, as the motor voltage is considered 0 when the PWM output duty cycle is 50%, which will give us half the Vbus voltage. However, I'm not sure why this is different from the GUI.

    Labs 3 & 4 also work as expected. I am not able to use the PWMDAC outputs, but I can use the DATALOG_DMA output and view the graphs correctly in CCS.

    In Lab 5, the behaviour is similar to the online GUI. The motor identification runs to completion and the motorVars.flagMotorIdentified is set. The values detected are:

    RoverL_rps: 31.416

    Rs_Ohm: 0.719

    Ls_d_H: 0.01777

    Ls_q_H: 0.01777

    flux_VpHz: 2.2149

    3. A final point, I just noticed that in lab5, the offsets are recalculated when the flagEnableSys is set to True. At this point the voltage offsets change from the 0.49 values from the user.h file, to 0.99 values similar to those seen when running the online GUI. From my understanding the 0.49 values are the correct ones? Not sure what is going on here. If I set them back to the 0.49 values before running the motor identification, I get different but still incorrect values.

    RoverL_rps: 31.416

    Rs_Ohm: 171.83

    Ls_d_H: 9.999e-07

    Ls_q_H: 9.999e-07

    flux_VpHz: 72.22

  • seems the difference in the voltage offsets is due to these lines in is05_motor_id.c, line 1062

    //
    // set to the inverse dc bus voltage
    //
    invVdcbus = 2.0f / adcData.dcBus_V;

    in lab02 , this is 1.0f/ adcData.dcBus_V;

    Any idea why it would be 2.0f? I think 1.0f is the correct value.

  • Hi Stephen,

    Thanks for your patience. I was able to spin a motor using an out-of-the-box DRV8311HEVM with the DRV8311HEVM_InstaSPIN_Universal_GUI on the Gallery. It seems to work on all GAIN settings on the EVM, but the firmware is programmed to work with the 0.5V/A GAIN setting to get the correct motor resistances and inductances. If you're off by a factor of 2, you'll get half the correct phase resistance, and 4 yields 1/4 the correct resistance, etc.

    So looking back at the firmware, let's see if I can debug a few high level things. If my suggestions can't solve them, I'll forward this thread to the C2000 who owns the MotorControl SDK firmware and can help dissect any nuances in the labs that are causing incorrect identification.

    1) I developed the DRV8311HEVM MotorControl SDK solution using version 3.01.00.00. https://www.ti.com/tool/download/C2000WARE-MOTORCONTROL-SDK/3.01.00.00

    If you are importing the .zip file I provided into a newer solution, chances are there are many fixes changes to the HAL layer code, user.h code, or user.c code that will make my solution not work the same as the newer solutions. So it's imperative that version 3.01.00.00 of MotorControl SDK is used for this solution while we wait for the C2000 team to import this into the next release of MotorControl SDK. 

    2) 

    On the second step, I have set the num pole pairs to 1, Max Current for R est  to 0.18 and Max Current for L est to -0.18

    Could you try higher estimation currents? I have seen the identification not work if these are too low. Try +0.5A/-0.5A or +1A/-1A to see if this improves the estimation currents. 

    3)

    So the current offsets are approx the same as the online GUI, but the voltage ones are 1/2 the GUI values. Looking through the code, these new values look correct, as the offset is calculated as adcData.V_V.value[0] -= motorVars.offsets_V_V.value[0] * adcData.dcBus_V; So the offset is approx half the VBus voltage, which seems correct, as the motor voltage is considered 0 when the PWM output duty cycle is 50%, which will give us half the Vbus voltage. However, I'm not sure why this is different from the GUI.

    This looks related to your observation about the code snippet below. I can ask the C2000 team for assistance for this after your reply. 

    seems the difference in the voltage offsets is due to these lines in is05_motor_id.c, line 1062

    //
    // set to the inverse dc bus voltage
    //
    invVdcbus = 2.0f / adcData.dcBus_V;

    in lab02 , this is 1.0f/ adcData.dcBus_V;

    4)

    3. A final point, I just noticed that in lab5, the offsets are recalculated when the flagEnableSys is set to True. At this point the voltage offsets change from the 0.49 values from the user.h file, to 0.99 values similar to those seen when running the online GUI. From my understanding the 0.49 values are the correct ones? Not sure what is going on here. If I set them back to the 0.49 values before running the motor identification, I get different but still incorrect values.

    When flagEnableSys is true, this sets the 50% PWM waveforms to calculate the offsets. Before this, it just loads the offsets from the user.h files temporarily. The 0.49 also seems related to the point you made above with the 2.0f comment you made. 

    Thanks,
    Aaron

  • Thanks for looking in to this Aaron.

    1. Yes I am using version 3.01.00.00 of the SDK now. I did also wonder about the FAST ROM code. As I understand it the FAST algorithm that is used in lab 5 to do the motor identification is provided in the ROM of the F280049C chip, and is therefore fixed and not programmed by me. Is my understanding correct? Does this have a version? Are there different versions out there? Which version is this lab compatible with? How do I know which version I have?

    2. For setting the R est current, note that for my setup, the drive voltage is 5V, the winding resistance is about 6.6ohms phase to phase, so the peak current is about 0.75A. The documentation suggests using a value here of about 20% of this full scale value. So I don't think adding an extra 1 Amp to the is is the right way to go. I have tried some different values here without much success. I was thinking that using a high current gain in the measurement would be needed at these relatively low currents. The gains available in the hardware are certainly compatible with these low current values. i.e. 2V/A gives a measurement range of about +/- 0.8A

    3. If I set the board to 0.5V/A I do get a resistance value that is in the right ball park when using the GUI. However the inductance measurements aren't right, and the motor still doesn't spin correctly when running it after the ID has finished. However there's something fishy about this gain setting. In particular the parameter 'ADC Scale Current (A) is fixed at 13.2A in the GUI. This value seems correct for the 0.25V/A gain setting. i.e. 3.3V full scale voltage at the ADC equates to 3.3/0.25 = 13.2A. It seems maybe that a fix is being applied to cover some other error in the code somewhere.

    I note that the instructions on the GUI state to use the DRV8311SEVM, i.e. the spi variant. Is this the case? I am using the HEVM variant, which is what I think you have tried also. 

     

  • Hi Stephen,

    I am going to review your points 1-3 with the MotorControl SDK expert to get some more knowledge myself, so let me get you a reply later today at some point. 

    I note that the instructions on the GUI state to use the DRV8311SEVM, i.e. the spi variant. Is this the case? I am using the HEVM variant, which is what I think you have tried also. 

    I forgot to update the readme on the GUI, you can use DRV8311HEVM as well. 

    Thanks,
    Aaron

  • Thanks. This morning I have the motor running by using user defined motor parameters. i.e. by bypassing the motor id. However it's a bit temperamental in that if I change the speed by too much in one step it looses sync and the motor stalls.

  • Another question, the document SPRUHJ1I - InstaSPIN-FOCTm and InstaSPIN-MOTIONTm User’s Guide is very useful. Its not clear which version of the motor control SDK this document relates to, but I suspect it is 04-00. Is there a version of this document that is compatible with motor control SDK 03-01?

  • Hi Stephen, 

    Got feedback from the C2000 team on your questions:

    1. Yes I am using version 3.01.00.00of the SDK now. I did also wonder about the FAST ROM code. As I understand it the FAST algorithm that is used in lab 5 to do the motor identification is provided in the ROM of the F280049C chip, and is therefore fixed and not programmed by me. Is my understanding correct? Does this have a version? Are there different versions out there? Which version is this lab compatible with? How do I know which version I have?

    A: You are right. The FAST estimator on F280049C uses the library code in the ROM, it only has one version since the codes are stored in the ROM.

    1. For setting the R est current, note that for my setup, the drive voltage is 5V, the winding resistance is about 6.6ohms phase to phase, so the peak current is about 0.75A. The documentation suggests using a value here of about 20% of this full scale value. So I don't think adding an extra 1 Amp to the is is the right way to go. I have tried some different values here without much success. I was thinking that using a high current gain in the measurement would be needed at these relatively low currents. The gains available in the hardware are certainly compatible with these low current values. i.e. 2V/A gives a measurement range of about +/- 0.8A

    A: The dc-bus voltage must be set to the right value according to the motor needed. The identification variables (current and frequency, USER_MOTOR_RES_EST_CURRENT_A, USER_MOTOR_IND_EST_CURRENT_A, USER_MOTOR_FLUX_EXC_FREQ_Hz, USER_MOTOR_MAX_CURRENT_A) must be set to the right values according to the spec. of the motor, not the inverter. Of course, the inverter and the power supply must have enough output capability to provide the current to the motor. Set the right gains of the CSA to achieve a better resolution of the current sampling according to the spec. of the motor that’s very useful to identify or run the motor.

    #define USER_MOTOR_RES_EST_CURRENT      (1.0)                               // A -  10-30% of rated current of the motor

    #define USER_MOTOR_IND_EST_CURRENT      (-1.0)                             // A -  10-30% of rated current of the motor,  just enough to enable rotation

    #define USER_MOTOR_MAX_CURRENT            (5.0)                               // A -  30~150%  of rated current of the motor

    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (40.0)                            // Hz - 10~30% rated frequency of the motor

     

    1. If I set the board to 0.5V/A I do get a resistance value that is in the right ball park when using the GUI. However the inductance measurements aren't right, and the motor still doesn't spin correctly when running it after the ID has finished. However there's something fishy about this gain setting. In particular the parameter 'ADC Scale Current (A) is fixed at 13.2A in the GUI. This value seems correct for the 0.25V/A gain setting. i.e. 3.3V full scale voltage at the ADC equates to 3.3/0.25 = 13.2A. It seems maybe that a fix is being applied to cover some other error in the code somewhere.

    A:  As the answer to item 2. Also need to set the right value of the USER_ADC_FULL_SCALE_CURRENT_A according to the board like the gains of the CSA and the sampling resistor. Also need to set the right USER_ADC_FULL_SCALE_VOLTAGE_V and USER_VOLTAGE_FILTER_POLE_Hz based on the voltage sampling circuit. Make sure that the filter capacitors for phase voltage sensing circuit are populated with a right value.

    Seems like both the DRV8311 and DRV8316 don’t have a very consistent accuracy with the Rdson for current sampling on each board in the wide temperature range, the motor control performance with FAST on DRV8311 or DRV8316 is far lower than the other DRV devices using the external shunt resistor. Maybe, the DRV8311 and DRV8316 are suitable for sensored-FOC or trapezoidal control, not the sensorless-FOC with feedback current signals based estimator.

    seems the difference in the voltage offsets is due to these lines in is05_motor_id.c, line 1062

    //
    // set to the inverse dc bus voltage
    //
    invVdcbus = 2.0f / adcData.dcBus_V;

    in lab02 , this is 1.0f/ adcData.dcBus_V;

    Any idea why it would be 2.0f? I think 1.0f is the correct value.

    A: Yes, please use “1.0f/ adcData.dcBus_V”, but it doesn’t matter, this is only used for the voltage offset calibration which will be eliminated in the Clark transform function.

    ----------------------

    To add to the input above, we have seen the InstaSPIN-FOC algorithm work less effectively with low-inductance motors on the integrated FET devices (DRV8316 & DRV8311) because the internal current sensing can vary the Rds(on) value & measured current with device heating. What is the inductance of the motor from the motor datasheet per phase?

    Thanks,
    Aaron

  • Another question, the document SPRUHJ1I - InstaSPIN-FOCTm and InstaSPIN-MOTIONTm User’s Guide is very useful. Its not clear which version of the motor control SDK this document relates to, but I suspect it is 04-00. Is there a version of this document that is compatible with motor control SDK 03-01?

    I believe InstaSPIN-FOC corresponds to the parameters used in MotorWARE, although many variables are similar in MotorControl SDK. MotorWARE was the previous version of InstaSPIN before MotorControl SDK. 

    Thanks,
    Aaron

  • So I believe I have these values set correctly for lab 5:

    #define USER_MOTOR_RES_EST_CURRENT      (0.18)                               // A -  10-30% of rated current of the motor

    #define USER_MOTOR_IND_EST_CURRENT      (-0.18)                             // A -  10-30% of rated current of the motor,  just enough to enable rotation

    #define USER_MOTOR_MAX_CURRENT            (0.757)                               // A -  30~150%  of rated current of the motor

    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (40.0) 

    //! DRV8311 = VREF = 3V, GAIN = 1V/A || 3.3V / 1V/A = 3.3A
    #define USER_ADC_FULL_SCALE_CURRENT_A ((float32_t)(3.3))

    #define USER_ADC_FULL_SCALE_VOLTAGE_V         ((float32_t)(26.87)) //of the motor

    #define USER_VOLTAGE_FILTER_POLE_Hz           ((float32_t)(172.798)) 

    But this is giving me a resistance value of approx 200 ohms vs 3.3 expected.

    With regards to the comment on the compatibility of the DRV8311 & FAST estimator, especially with regards to the accuracy of current measurement with heating: This may well be the case, but I still think there is something much more fundamental wrong at the moment.

    For example when running lab 5 at the moment, the motor is not turning for both the resistance measurement and the inductance measurement. Increasing the magnitude of the values USER_MOTOR_RES_EST_CURRENT & USER_MOTOR_IND_EST_CURRENT   makes no difference to this.

    Is the motor supposed to turn during both of these measurements? I'm guessing it's supposed to turn at USER_MOTOR_FLUX_EST_FREQ_Hz during the inductance measurement right?

  • Hi Stephen, 

    Thanks for the updated info - 

    We will review and aim to provide a response by early next week 

    Best Regards, 
    Andrew 

  • Hi Stephen, 

    The motor performs the resistance measurement inline during the first state of motor identification, then the next state when identifying the inductance it is supposed to begin spinning. The 200 ohm measurement is likely messing up the inductance measurement thus not causing it to spin. 

    Let me try replicating your settings using your values and lab 5 in CCS today, just to make sure the project code I posted on the E2E forum is accurate compared to my project code. I am especially curious about the inductance of the motor with low estimation currents. I agree there is a fundamental error that is causing issues rather than the heating of the DRV8311.

    I'll provide a reply by end of day today or tomorrow first thing. 

    Thanks,
    Aaron

  • Thanks. Just for reference, the full contents of my user.h file are:

    //#############################################################################
    // $TI Release: MotorControl SDK v3.01.00.00 $
    // $Release Date: Mon Jan 11 11:23:03 CST 2021 $
    // $Copyright:
    // Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
    //
    // 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.
    // $
    //#############################################################################
    
    #ifndef USER_H
    #define USER_H
    
    //! \file   solutions/boostxl_drv8320rs/f28004x/drivers/user.h
    //! \brief  Contains the user related definitions
    //!
    
    
    // **************************************************************************
    // the includes
    
    // modules
    #include "userParams.h"
    
    //!
    //!
    //! \defgroup USER USER
    //!
    //@{
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    
    // **************************************************************************
    // the defines
    #define BOOSTX_to_J1_J2     0
    #define BOOSTX_to_J5_J6     1
    
    #define BOOST_to_LPD        BOOSTX_to_J1_J2
    //#define BOOST_to_LPD        BOOSTX_to_J5_J6
    
    //! \brief Defines the nominal DC bus voltage, V
    //!
    #define USER_NOMINAL_DC_BUS_VOLTAGE_V         ((float32_t)(5.0))
    
    
    //! \brief Defines the maximum voltage at the AD converter
    //!        full scale voltage of AD converter
    #define USER_ADC_FULL_SCALE_VOLTAGE_V         ((float32_t)(26.87)) //of the motor
    
    
    //! \brief Defines the maximum current at the AD converter
    //!        DRV8311 = VREF = 3V, GAIN = 0.25V/A || 3.3V / 0.25V/A = 13.2A
    //!        DRV8311 = VREF = 3V, GAIN = 2V/A || 3.3V / 2V/A = 1.65A
    //!        DRV8311 = VREF = 3V, GAIN = 1V/A || 3.3V / 1V/A = 3.3A
    #define USER_ADC_FULL_SCALE_CURRENT_A         ((float32_t)(3.3))
    
    //! \brief Defines the analog voltage filter pole location, Hz
    //!
    #define USER_VOLTAGE_FILTER_POLE_Hz           ((float32_t)(172.798)) //
    
    
    //! \brief ADC current offsets for A, B, and C phases
    //#define IA_OFFSET_A    (6.0819726)        // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    //#define IB_OFFSET_A    (6.08051252)     // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    //#define IC_OFFSET_A    (6.07770014)        // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    //#define IA_OFFSET_A    (0.75913918)        // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    //#define IB_OFFSET_A    (0.762986541)     // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    //#define IC_OFFSET_A    (0.758168101)        // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    #define IA_OFFSET_A    (1.51806879)        // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    #define IB_OFFSET_A    (1.52205467)     // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    #define IC_OFFSET_A    (1.5179944)        // ~=0.5*USER_ADC_FULL_SCALE_CURRENT_A
    
    //! \brief ADC voltage offsets for A, B, and C phases
    #define VA_OFFSET_V    (0.499282688)    // ~=1.0
    #define VB_OFFSET_V    (0.496949106)    // ~=1.0
    #define VC_OFFSET_V    (0.495443225)    // ~=1.0
    
    //! \brief Vbus used to calculate the voltage offsets A, B, and C
    //!        =0.5*USER_NOMINAL_DC_BUS_VOLTAGE_V
    #define VBUS_OFFSET_V  (0.5*USER_ADC_FULL_SCALE_VOLTAGE_V)
    
    
    //! \brief Defines the maximum negative current to be applied in Id reference
    //!
    #define USER_MAX_NEGATIVE_ID_REF_CURRENT_A    ((float32_t)(-2.0))
    
    
    //! \brief Defines the number of pwm clock ticks per isr clock tick
    //!        Note: Valid values are from 1 to 15
    #define USER_NUM_PWM_TICKS_PER_ISR_TICK         (2)
    
    //! \brief Defines the number of ISR clock ticks per current controller clock tick
    //!
    #define USER_NUM_ISR_TICKS_PER_CURRENT_TICK     (1)
    
    //! \brief Defines the number of ISR clock ticks per speed controller clock tick
    //!
    #define USER_NUM_ISR_TICKS_PER_SPEED_TICK       (10)
    
    
    //! \brief Defines the number of current sensors
    //!
    #define USER_NUM_CURRENT_SENSORS                (3)
    
    
    //! \brief Defines the number of voltage sensors
    //!
    #define USER_NUM_VOLTAGE_SENSORS                (3)
    
    //! \brief Defines the system maximum input frequency, MHz
    //!
    #define USER_MAXIMUM_SCALE_FREQ_Hz      ((float32_t)(1500.0))
    
    //! \brief Defines the system clock frequency, MHz
    //!
    #define USER_SYSTEM_FREQ_MHz            ((float32_t)(100.0))
    
    
    //! \brief Defines the Pulse Width Modulation (PWM) frequency, kHz
    //!
    //#define USER_PWM_FREQ_kHz          ((float32_t)(5.0))      //5KHz PWM frequency
    //#define USER_PWM_FREQ_kHz          ((float32_t)(10.0))     //10KHz PWM frequency
    //#define USER_PWM_FREQ_kHz          ((float32_t)(12.0))     //12KHz PWM frequency
    //#define USER_PWM_FREQ_kHz          ((float32_t)(15.0))     //15KHz PWM frequency
    #define USER_PWM_FREQ_kHz          ((float32_t)(20.0))     //20KHz PWM frequency
    //#define USER_PWM_FREQ_kHz          ((float32_t)(40.0))       //40kHz PWM frequency
    
    //! \brief Defines the Pulse Width Modulation (PWM) period, usec
    //!
    #define USER_PWM_PERIOD_usec    ((float32_t)1000.0/USER_PWM_FREQ_kHz)
    
    
    //! \brief Defines the Interrupt Service Routine (ISR) frequency, Hz
    //!
    #define USER_ISR_FREQ_Hz        (USER_PWM_FREQ_kHz * (float32_t)1000.0 / (float32_t)USER_NUM_PWM_TICKS_PER_ISR_TICK)
    
    
    //! \brief Defines the Interrupt Service Routine (ISR) period, usec
    //!
    #define USER_ISR_PERIOD_usec    (USER_PWM_PERIOD_usec * (float32_t)USER_NUM_PWM_TICKS_PER_ISR_TICK)
    
    
    #ifdef _VSF_EN_
    //! \brief Defines the timer frequency for estimator, kHz
    //!
    #define USER_EST_FREQ_kHz       ((float32_t)(20.0))
    
    
    //! \brief Defines the timer frequency for estimator, Hz
    //!
    #define USER_EST_FREQ_Hz        (USER_EST_FREQ_kHz * (float32_t)1000.0)
    
    
    //! \brief Defines the Interrupt Service Routine (ISR) period, usec
    //!
    #define USER_EST_PERIOD_usec    ((float32_t)1000000.0/USER_EST_FREQ_Hz)
    
    
    //! \brief Defines the timer frequency for controller, Hz
    //!
    #define USER_CTRL_FREQ_Hz        (USER_EST_FREQ_Hz)
    
    
    //! \brief Defines the controller execution period, usec
    //!
    #define USER_CTRL_PERIOD_usec   (USER_EST_PERIOD_usec)
    
    
    //! \brief Defines the controller execution period, sec
    //!
    #define USER_CTRL_PERIOD_sec    ((float32_t)USER_CTRL_PERIOD_usec/(float32_t)1000000.0)
    
    
    //! \brief Defines the timer frequency for trajectory, Hz
    //!
    #define USER_TRAJ_FREQ_Hz       (USER_EST_FREQ_Hz)
    #else
    
    //! \brief Defines the timer frequency for estimator, kHz
    //!
    #define USER_EST_FREQ_Hz        (USER_ISR_FREQ_Hz)
    
    
    //! \brief Defines the Interrupt Service Routine (ISR) period, usec
    //!
    #define USER_EST_PERIOD_usec    (USER_ISR_PERIOD_usec)
    
    
    //! \brief Defines the timer frequency for controller, Hz
    //!
    #define USER_CTRL_FREQ_Hz        (USER_ISR_FREQ_Hz)
    
    
    //! \brief Defines the controller execution period, usec
    //!
    #define USER_CTRL_PERIOD_usec   (USER_ISR_PERIOD_usec)
    
    
    //! \brief Defines the controller execution period, sec
    //!
    #define USER_CTRL_PERIOD_sec    ((float32_t)USER_CTRL_PERIOD_usec/(float32_t)1000000.0)
    
    //! \brief Defines the timer frequency for trajectory, Hz
    //!
    #define USER_TRAJ_FREQ_Hz       (USER_ISR_FREQ_Hz)
    #endif  // _VPF_EN_
    
    
    //! \brief Defines the direct voltage (Vd) scale factor
    //!
    #define USER_VD_SF                 ((float32_t)(0.95))
    
    
    //! \brief Defines the voltage scale factor for the system
    //!
    #define USER_VOLTAGE_SF               (USER_ADC_FULL_SCALE_VOLTAGE_V / (float32_t)4096.0)            // 12 bit ADC, 2^12 = 4096
    #define USER_DCBUS_VOLTAGE_SF         (USER_ADC_FULL_SCALE_DCBUS_VOLTAGE_V / (float32_t)4096.0)      // 12 bit ADC, 2^12 = 4096
    
    //! \brief Defines the current scale factor for the system
    //!
    #define USER_CURRENT_SF               (USER_ADC_FULL_SCALE_CURRENT_A / (float32_t)4096.0)    // 12 bit ADC, 2^12 = 4096
    
    
    //! \brief Defines the pole location for the DC bus filter, rad/sec
    //!
    #define USER_DCBUS_POLE_rps            ((float32_t)(100.0))
    
    
    //! \brief Defines the pole location for the voltage and current offset estimation, rad/s
    //!
    #define USER_OFFSET_POLE_rps            ((float32_t)(20.0))
    
    
    //! \brief Defines the pole location for the speed control filter, rad/sec
    //!
    #define USER_SPEED_POLE_rps        ((float32_t)(100.0))
    
    
    //! \brief Defines the analog voltage filter pole location, rad/s
    //!
    #define USER_VOLTAGE_FILTER_POLE_rps  (MATH_TWO_PI * USER_VOLTAGE_FILTER_POLE_Hz)
    
    
    //! \brief Defines the maximum Vs magnitude in per units allowed
    //!        This value sets the maximum magnitude for the output of the Id and
    //!        Iq PI current controllers. The Id and Iq current controller outputs
    //!        are Vd and Vq. The relationship between Vs, Vd, and Vq is:
    //!        Vs = sqrt(Vd^2 + Vq^2).  In this FOC controller, the Vd value is set
    //!        equal to USER_MAX_VS_MAG*USER_VD_MAG_FACTOR.
    //!        so the Vq value is set equal to sqrt(USER_MAX_VS_MAG^2 - Vd^2).
    //!
    //!        Set USER_MAX_VS_MAG = 0.5 for a pure sinewave with a peak at
    //!        SQRT(3)/2 = 86.6% duty cycle.  No current reconstruction
    //!        is needed for this scenario.
    //!
    //!        Set USER_MAX_VS_MAG = 1/SQRT(3) = 0.5774 for a pure sinewave
    //!        with a peak at 100% duty cycle.  Current reconstruction
    //!        will be needed for this scenario (Lab08).
    //!
    //!        Set USER_MAX_VS_MAG = 2/3 = 0.6666 to create a trapezoidal
    //!        voltage waveform.  Current reconstruction will be needed
    //!        for this scenario (Lab08).
    //!
    //!        For space vector over-modulation, see lab08 for details on
    //!        system requirements that will allow the SVM generator to
    //!        go all the way to trapezoidal.
    //!
    //#define USER_MAX_VS_MAG_PU            (0.66)
    #define USER_MAX_VS_MAG_PU            (0.57)
    //#define USER_MAX_VS_MAG_PU              (0.5)
    
    
    //! \brief Defines the reference Vs magnitude in per units allowed
    //! \      Set the value equal from 0.5 to 0.95 of the maximum Vs magnitude
    #define USER_VS_REF_MAG_PU              ((float32_t)(0.8) * USER_MAX_VS_MAG_PU)
    
    
    //! \brief Defines the R/L excitation frequency, Hz
    //!
    #define USER_R_OVER_L_EXC_FREQ_Hz       ((float32_t)(300.0))
    
    
    //! \brief Defines the R/L Kp scale factor, pu
    //!        Kp used during R/L is USER_R_OVER_L_KP_SF *
    //!        USER_NOMINAL_DC_BUS_VOLTAGE_V / USER_MOTOR_MAX_CURRENT_A;
    #define USER_R_OVER_L_KP_SF        ((float32_t)(0.02))
    
    
    //! \brief Defines maximum acceleration for the estimation speed profiles, Hz/sec
    //!
    #define USER_MAX_ACCEL_Hzps        ((float32_t)(2.0))
    
    
    //! \brief Defines the IdRated delta to use during estimation
    //!
    #define USER_IDRATED_DELTA_A       ((float32_t)(0.0001))
    
    
    //! \brief Defines the forced angle frequency, Hz
    //!
    #define USER_FORCE_ANGLE_FREQ_Hz            ((float32_t)(1.0))
    
    
    //! \brief Defines the fraction of IdRated to use during inductance estimation
    //!
    #define USER_IDRATED_FRACTION_FOR_L_IDENT    ((float32_t)(0.5))
    
    
    //! \brief Defines the fraction of SpeedMax to use during inductance estimation
    //!
    #define USER_SPEEDMAX_FRACTION_FOR_L_IDENT  ((float32_t)(1.0))
    
    
    //! \brief Defines the Power Warp gain for computing Id reference
    //!        If motor parameters are known, set this gain to:
    //!        USER_PW_GAIN = SQRT(1.0 + USER_MOTOR_Rr_Ohm / USER_MOTOR_Rs_Ohm)
    //!
    #define USER_PW_GAIN                        ((float32_t)(1.0))
    
    
    //! \brief Defines the scale factor for the flux estimation
    //! the default value is 1.0f, change the value between 0.1f and 1.25f
    //!
    #define USER_EST_FLUX_HF_SF                 ((float32_t)(0.12f))
    
    
    //! \brief Defines the scale factor for the frequency estimation
    //! the default value is 1.0f, change the value between 0.5f and 1.5f
    //!
    #define USER_EST_FREQ_HF_SF                 ((float32_t)(1.0f))
    
    
    //! \brief Defines the scale factor for the bemf estimation
    //! the default value is 1.0f, change the value between 0.50f and 1.25f
    //!
    #define USER_EST_BEMF_HF_SF                 ((float32_t)(0.75f))
    
    
    //! \brief A flag to bypass motor identification (1/0 : true/false)
    //!
    #define USER_BYPASS_MOTOR_ID       (1)    // No motor parameters identification
    //#define USER_BYPASS_MOTOR_ID     (0)    // Do motor parameters identification
    
    #define USER_ENABLE_MOTOR_ID        0
    #define USER_DISABLE_MOTOR_ID       1
    
    
    //! brief Define the Kp gain for Field Weakening Control
    #define USER_FWC_KP                 0.05
    
    //! brief Define the Ki gain for Field Weakening Control
    #define USER_FWC_KI                 0.0002
    
    //! brief Define the maximum current vector angle for Field Weakening Control
    #define USER_FWC_MAX_ANGLE          (float32_t)(-75.0)                              // degree
    #define USER_FWC_MAX_ANGLE_RAD      USER_FWC_MAX_ANGLE*MATH_PI/((float32_t)(180.0))   // rad
    
    //! brief Define the minimum current vector angle for Field Weakening Control
    #define USER_FWC_MIN_ANGLE          (float32_t)(0.0)                                // degree
    #define USER_FWC_MIN_ANGLE_RAD      USER_FWC_MIN_ANGLE*MATH_PI/((float32_t)(180.0))   // rad
    
    //============================================================================================
    // Motor defines
    
    //************** Motor Parameters **************
    
    // PMSM motors
    #define Estun_EMJ_04APB22_A         101
    #define Estun_EMJ_04APB22_B         102
    
    #define Teknic_M2310PLN04K          121
    #define Anaheim_BLY172S_24V         122
    #define Anaheim_BLY341S_48V         123
    #define Anaheim_BLY341S_24V         124
    #define Teknic_MxxxxPLNxxK          125     // Just for test
    
    #define Traxxas_Velineon_380        131
    #define Traxxas_Velineon_3500       132
    #define Pacific_Scientific          133
    #define Regal_Beloit_5SME39DL0756   134
    #define AutoRadiatorFan             135
    
    #define tekin_redline_4600KV        142
    #define Drone_BLK2BLADE             143
    
    #define AirFan_MFA0500_24V          150
    
    // ACIM motors
    #define Marathon_5K33GN2A           201
    #define Marathon_56H17T2011A        202
    #define Dayton_3N352C               203
    
    //User-defined motors
    #define NFP_1215_912                301
    #define gentherm_1                  302
    #define gentherm_2                  303
    #define gentherm_3                  304
    
    
    
    //#define USER_MOTOR Estun_EMJ_04APB22_A
    //#define USER_MOTOR Estun_EMJ_04APB22_B
    
    //#define USER_MOTOR Teknic_M2310PLN04K
    //#define USER_MOTOR Anaheim_BLY172S_24V
    //#define USER_MOTOR Anaheim_BLY341S_48V
    //#define USER_MOTOR Anaheim_BLY341S_24V
    //#define USER_MOTOR Teknic_MxxxxPLNxxK
    
    //#define USER_MOTOR Traxxas_Velineon_380
    //#define USER_MOTOR Traxxas_Velineon_3500
    //#define USER_MOTOR Pacific_Scientific
    //#define USER_MOTOR Regal_Beloit_5SME39DL0756
    //#define USER_MOTOR AutoRadiatorFan
    
    //#define USER_MOTOR tekin_redline_4600KV
    
    //#define USER_MOTOR AirFan_MFA0500_24V
    
    //#define USER_MOTOR Marathon_5K33GN2A
    //#define USER_MOTOR Marathon_56H17T2011A
    //#define USER_MOTOR Dayton_3N352C
    
    //#define USER_MOTOR my_motor_1
    //#define USER_MOTOR my_motor_2
    
    //#define USER_MOTOR gentherm_1
    //#define USER_MOTOR gentherm_2
    #define USER_MOTOR NFP_1215_912
    
    //#define USER_MOTOR Telco_DT4260
    
    
    //#define USER_MOTOR   Drone_BLK2BLADE
    
    #if (USER_MOTOR == Estun_EMJ_04APB22_A)
    #define USER_MOTOR_TYPE                    MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (2.303403)
    #define USER_MOTOR_Ls_d_H                 (0.008464367)
    #define USER_MOTOR_Ls_q_H                 (0.008464367)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.3821270569)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (3.82)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (2500.0)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (400.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (200.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (20.0)          // Volt
    #define USER_MOTOR_VOLT_MAX_V             (200.0)         // Volt
    
    #elif (USER_MOTOR == Estun_EMJ_04APB22_B)
    #define USER_MOTOR_TYPE                    MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    
    // HV Kit with external OPA
    #define USER_MOTOR_Rs_Ohm                 (2.98774099)
    #define USER_MOTOR_Ls_d_H                 (0.008926632)
    #define USER_MOTOR_Ls_q_H                 (0.008926632)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.445965141)
    
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (3.82)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (2500.0)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (400.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (200.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (20.0)          // Volt
    #define USER_MOTOR_VOLT_MAX_V             (200.0)         // Volt
    
    #elif (USER_MOTOR == AirFan_MFA0500_24V)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.150690928)
    #define USER_MOTOR_Ls_d_H                 (2.34591134e-05)
    #define USER_MOTOR_Ls_q_H                 (2.34591134e-05)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0103964526)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-2.0)
    #define USER_MOTOR_MAX_CURRENT_A          (12.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (100.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (1000)
    #define USER_MOTOR_INERTIA_Kgm2           (7.06154e-06)
    
    #define USER_MOTOR_RATED_VOLTAGE_V        (24.0)
    #define USER_MOTOR_RATED_SPEED_KRPM       (3.0)
    
    #define USER_MOTOR_FREQ_MIN_HZ            (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (2000.0)        // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (20.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Teknic_M2310PLN04K)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.381334811)
    #define USER_MOTOR_Ls_d_H                 (0.000169791776)
    #define USER_MOTOR_Ls_q_H                 (0.000169791776)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0398557819)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.5)
    #define USER_MOTOR_MAX_CURRENT_A          (6.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (40.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (1000)
    #define USER_MOTOR_INERTIA_Kgm2           (7.06154e-06)
    
    #define USER_MOTOR_RATED_VOLTAGE_V        (24.0)
    #define USER_MOTOR_RATED_SPEED_KRPM       (3.0)
    
    #define USER_MOTOR_FREQ_MIN_HZ            (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (600.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (20.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Drone_BLK2BLADE)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (6)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.0680569932)
    #define USER_MOTOR_Ls_d_H                 (1.11856834e-05)
    #define USER_MOTOR_Ls_q_H                 (1.11856834e-05)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0680569932)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (4.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-3.0)
    #define USER_MOTOR_MAX_CURRENT_A          (16.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (100.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (1000)
    #define USER_MOTOR_INERTIA_Kgm2           (7.06154e-06)
    
    #define USER_MOTOR_RATED_VOLTAGE_V        (24.0)
    #define USER_MOTOR_RATED_SPEED_KRPM       (3.0)
    
    #define USER_MOTOR_FREQ_MIN_HZ            (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (600.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (20.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Teknic_MxxxxPLNxxK)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.381885976)
    #define USER_MOTOR_Ls_d_H                 (0.000125865598*0.8)
    #define USER_MOTOR_Ls_q_H                 (0.000125865598*1.2)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0411616899)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.5)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (60.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (1000)
    #define USER_MOTOR_INERTIA_Kgm2           (7.06154e-06)
    
    #define USER_MOTOR_RATED_VOLTAGE_V        (24.0)
    #define USER_MOTOR_RATED_SPEED_KRPM       (3.0)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (600.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (20.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Telco_DT4260)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.127031267)
    #define USER_MOTOR_Ls_d_H                 (0.000235921645)
    #define USER_MOTOR_Ls_q_H                 (0.000235921645)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0343294777)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.5)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    #define USER_MOTOR_INERTIA_Kgm2           (7.06154e-06)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (800.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == NFP_1215_912)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (1)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (3.3)
    #define USER_MOTOR_Ls_d_H                 (0.000111)
    #define USER_MOTOR_Ls_q_H                 (0.000111)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.016)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (0.3)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-0.3)
    #define USER_MOTOR_MAX_CURRENT_A          (0.757)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (40.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (500)
    #define USER_MOTOR_INERTIA_Kgm2           (5e-05)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (300.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (2.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (7.0)          // Volt
    
    #elif (USER_MOTOR == Anaheim_BLY172S_24V)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.4)
    #define USER_MOTOR_Ls_d_H                 (0.0007190173)
    #define USER_MOTOR_Ls_q_H                 (0.0007190173)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0327013217)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.5)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    #define USER_MOTOR_INERTIA_Kgm2           (7.06154e-06)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (800.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Anaheim_BLY341S_48V)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.463800967)
    #define USER_MOTOR_Ls_d_H                 (0.00114538975)
    #define USER_MOTOR_Ls_q_H                 (0.00114538975)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0978558362)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-2.0)
    #define USER_MOTOR_MAX_CURRENT_A          (20.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (300.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (200.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Anaheim_BLY341S_24V)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.4110007)
    #define USER_MOTOR_Ls_d_H                 (0.0007092811)
    #define USER_MOTOR_Ls_q_H                 (0.0007092811)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.03279636)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (10.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (300.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (200.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == Traxxas_Velineon_380)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (1)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (TBD)
    #define USER_MOTOR_Ls_d_H                 (TBD)
    #define USER_MOTOR_Ls_q_H                 (TBD)
    #define USER_MOTOR_RATED_FLUX_VpHz        (TBD)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (4.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-0.5)
    #define USER_MOTOR_MAX_CURRENT_A          (10.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == Traxxas_Velineon_3500)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (1)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.01822988)
    #define USER_MOTOR_Ls_d_H                 (8.322238e-06)
    #define USER_MOTOR_Ls_q_H                 (8.322238e-06)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.010249538)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-2.0)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (40.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == Pacific_Scientific)
    #define USER_MOTOR_TYPE                    MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (0.9428042)
    #define USER_MOTOR_Ls_d_H                 (0.002196057)
    #define USER_MOTOR_Ls_q_H                 (0.002196057)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.3481677)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (8.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == Regal_Beloit_5SME39DL0756)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (3)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (4.581007)
    #define USER_MOTOR_Ls_d_H                 (0.03727356)
    #define USER_MOTOR_Ls_q_H                 (0.03727356)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.6589699)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (2.6)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == AutoRadiatorFan)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (0.0)
    #define USER_MOTOR_Ls_d_H                 (0.0)
    #define USER_MOTOR_Ls_q_H                 (0.0)
    #define USER_MOTOR_RATED_FLUX_VpHz        (TBD)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (10.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (50.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == tekin_redline_4600KV)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (0.0181193)
    #define USER_MOTOR_Ls_d_H                 (8.180002e-06)
    #define USER_MOTOR_Ls_q_H                 (8.180002e-06)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0041173688)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (3.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-3.0)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (60.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == Marathon_5K33GN2A)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_INDUCTION
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (5.508003)
    #define USER_MOTOR_Rs_Ohm                 (10.71121)
    #define USER_MOTOR_Ls_d_H                 (0.05296588)
    #define USER_MOTOR_Ls_q_H                 (0.05296588)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.8165*220.0/60.0)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (1.378)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (NULL)
    #define USER_MOTOR_MAX_CURRENT_A          (3.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (5.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (400.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (200.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (20.0)          // Volt
    #define USER_MOTOR_VOLT_MAX_V             (200.0)         // Volt
    
    
    #elif (USER_MOTOR == Marathon_56H17T2011A)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_INDUCTION
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (5.159403)
    #define USER_MOTOR_Rs_Ohm                 (7.924815)
    #define USER_MOTOR_Ls_d_H                 (0.03904648)
    #define USER_MOTOR_Ls_q_H                 (0.03904648)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.8165*220.0/60.0)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (0.9941965)
    #define USER_MOTOR_RES_EST_CURRENT_A      (0.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (NULL)
    #define USER_MOTOR_MAX_CURRENT_A          (2.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (5.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == Dayton_3N352C)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_INDUCTION
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (2.428799)
    #define USER_MOTOR_Rs_Ohm                 (2.863202)
    #define USER_MOTOR_Ls_d_H                 (0.02391323)
    #define USER_MOTOR_Ls_q_H                 (0.02391323)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.8165*230.0/60.0)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (NULL)
    #define USER_MOTOR_MAX_CURRENT_A          (3.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (5.0)
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    
    #elif (USER_MOTOR == my_motor_1)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (4)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (NULL)
    #define USER_MOTOR_Ls_d_H                 (NULL)
    #define USER_MOTOR_Ls_q_H                 (NULL)
    #define USER_MOTOR_RATED_FLUX_VpHz        (NULL)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-2.0)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (40.0)
    
    // Number of lines on the motor's quadrature encoder
    #define USER_MOTOR_NUM_ENC_SLOTS          (1000)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (300.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == my_motor_2)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_INDUCTION
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (NULL)
    #define USER_MOTOR_Rs_Ohm                 (NULL)
    #define USER_MOTOR_Ls_d_H                 (NULL)
    #define USER_MOTOR_Ls_q_H                 (NULL)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.8165*230.0/60.0)
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT_A      (0.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (NULL)
    #define USER_MOTOR_MAX_CURRENT_A          (5.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (5.0)
    
    
    
    // Number of lines on the motor's quadrature encoder
    #define USER_MOTOR_NUM_ENC_SLOTS          (1000)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (5.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (300.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (10.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (400.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (4.0)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #elif (USER_MOTOR == gentherm_1)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (2)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (3.37838626)
    #define USER_MOTOR_Ls_d_H                 (0.0034717049)
    #define USER_MOTOR_Ls_q_H                 (0.0034717049)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0302085076)
    
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (0.0000)
    #define USER_MOTOR_RES_EST_CURRENT_A      (0.5)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-0.5)
    #define USER_MOTOR_MAX_CURRENT_A          (3.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    
    // Number of lines on the motor's quadrature encoder
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    #define USER_MOTOR_INERTIA_Kgm2           (4.8e-06)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (1.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (1000.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (5.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (750.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (3.6)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (12.0)          // Volt
    
    #elif (USER_MOTOR == gentherm_2)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (3)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (1.28197825)
    #define USER_MOTOR_Ls_d_H                 (0.00109424221)
    #define USER_MOTOR_Ls_q_H                 (0.00109424221)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.028716296)
    
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (0.0000)
    #define USER_MOTOR_RES_EST_CURRENT_A      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-1.0)
    #define USER_MOTOR_MAX_CURRENT_A          (10.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    
    // Number of lines on the motor's quadrature encoder
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    #define USER_MOTOR_INERTIA_Kgm2           (4.8e-06)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (1.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (700.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (5.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (500.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (3.6)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (12.0)          // Volt
    
    #elif (USER_MOTOR == gentherm_3)
    #define USER_MOTOR_TYPE                   MOTOR_TYPE_PM
    #define USER_MOTOR_NUM_POLE_PAIRS         (3)
    #define USER_MOTOR_Rr_Ohm                 (0.0)
    #define USER_MOTOR_Rs_Ohm                 (0.189529806)
    #define USER_MOTOR_Ls_d_H                 (0.000334463344)
    #define USER_MOTOR_Ls_q_H                 (0.000334463344)
    #define USER_MOTOR_RATED_FLUX_VpHz        (0.0239277277)
    
    #define USER_MOTOR_MAGNETIZING_CURRENT_A  (0.0000)
    #define USER_MOTOR_RES_EST_CURRENT_A      (2.0)
    #define USER_MOTOR_IND_EST_CURRENT_A      (-2.0)
    #define USER_MOTOR_MAX_CURRENT_A          (10.0)
    #define USER_MOTOR_FLUX_EXC_FREQ_Hz       (20.0)
    
    // Number of lines on the motor's quadrature encoder
    #define USER_MOTOR_NUM_ENC_SLOTS          (NULL)
    #define USER_MOTOR_INERTIA_Kgm2           (4.8e-06)
    
    #define USER_MOTOR_FREQ_MIN_HZ             (1.0)           // Hz
    #define USER_MOTOR_FREQ_MAX_HZ            (1000.0)         // Hz
    
    #define USER_MOTOR_FREQ_LOW_HZ            (5.0)          // Hz
    #define USER_MOTOR_FREQ_HIGH_HZ           (800.0)         // Hz
    #define USER_MOTOR_VOLT_MIN_V             (3.6)           // Volt
    #define USER_MOTOR_VOLT_MAX_V             (24.0)          // Volt
    
    #else
    #error No motor type specified
    #endif
    
    
    //! \brief Defines the maximum current slope for Id trajectory
    //!
    #define USER_MAX_CURRENT_DELTA_A        (USER_MOTOR_RES_EST_CURRENT_A / USER_ISR_FREQ_Hz)
    
    
    //! \brief Defines the maximum current slope for Id trajectory during power warp mode
    //!
    #define USER_MAX_CURRENT_DELTA_PW_A    (0.3 * USER_MOTOR_RES_EST_CURRENT_A / USER_ISR_FREQ_Hz)
    
    
    #ifndef USER_MOTOR
    #error Motor type is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_TYPE
    #error The motor type is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_NUM_POLE_PAIRS
    #error Number of motor pole pairs is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Rr_Ohm
    #error The rotor resistance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Rs_Ohm
    #error The stator resistance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Ls_d_H
    #error The direct stator inductance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_Ls_q_H
    #error The quadrature stator inductance is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_RATED_FLUX_VpHz
    #error The rated flux of motor is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_MAGNETIZING_CURRENT_A
    #error The magnetizing current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_RES_EST_CURRENT_A
    #error The resistance estimation current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_IND_EST_CURRENT_A
    #error The inductance estimation current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_MAX_CURRENT_A
    #error The maximum current is not defined in user.h
    #endif
    
    #ifndef USER_MOTOR_FLUX_EXC_FREQ_Hz
    #error The flux excitation frequency is not defined in user.h
    #endif
    
    #if ((USER_NUM_CURRENT_SENSORS < 2) || (USER_NUM_CURRENT_SENSORS > 3))
    #error The number of current sensors must be 2 or 3
    #endif
    
    #if (USER_NUM_VOLTAGE_SENSORS != 3)
    #error The number of voltage sensors must be 3
    #endif
    
    
    // **************************************************************************
    // the typedefs
    
    
    // **************************************************************************
    // the globals
    
    
    // **************************************************************************
    // the functions
    
    //! \brief      Sets the user parameter values
    //! \param[in]  pUserParams  The pointer to the user param structure
    extern void USER_setParams(USER_Params *pUserParams);
    
    
    //! \brief      Sets the private user parameter values
    //! \param[in]  pUserParams  The pointer to the user param structure
    extern void USER_setParams_priv(USER_Params *pUserParams);
    
    
    //! \brief      Sets the private user parameter values
    //! \param[in]  pUserParams  The pointer to the user param structure
    extern void cla_USER_setParams_priv(USER_Params *pUserParams);
    
    
    #ifdef __cplusplus
    }
    #endif // extern "C"
    
    //@}  // ingroup
    #endif // end of USER_H definition
    
    

  • Another couple of questions:

    The lab user guide in the SDK - 

    C2000Ware_MotorControl_SDK_3_01_00_00\solutions\sensorless_foc\docs\labs\MotorControl SDK InstaSPIN Lab Guide.pdf

    in lab is06 talks about using the following values from the user.h file:

    USER_IQ_FULL_SCALE_CURRENT_A

    USER_IQ_FULL_SCALE_VOLTAGE_V

    However these don't exist. Nor do they in the user.h file of any of the other solutions provided with the SDK. I assume these are supposed to be:

    USER_ADC_FULL_SCALE_CURRENT_A

    USER_ADC_FULL_SCALE_VOLTAGE_V

    Can I just check this is only a documentation issue?

    And also, lab is07 asks you to run the motor in a speed control mode but set the reference speed to 0. However I don't think you can do this for sensorless control can you? 

  • Hi Stephen,

    in lab is06 talks about using the following values from the user.h file:

    USER_IQ_FULL_SCALE_CURRENT_A

    USER_IQ_FULL_SCALE_VOLTAGE_V

    However these don't exist. Nor do they in the user.h file of any of the other solutions provided with the SDK. I assume these are supposed to be:

    USER_ADC_FULL_SCALE_CURRENT_A

    USER_ADC_FULL_SCALE_VOLTAGE_V

    Can I just check this is only a documentation issue?

    I believe this is a documentation issue. My user.h in lab 6 pulls from the same user.h include file used across all labs. 

    I tried to replicate your issue of getting high Rs values on my motor with the firmware but could not replicate the results. My only guess is that the motor phases may not be connected well. I can send you my user.h and user.c files I am using for lab 5. 

    user.c
    //#############################################################################
    //
    // FILE:   user.c
    //
    // TITLE:  C28x InstaSPIN function for setting initialization data for the
    //         CTRL, HAL, and EST modules (floating point)
    //
    //#############################################################################
    // $TI Release: MotorControl SDK v3.01.00.00 $
    // $Release Date: Mon Jan 11 11:23:03 CST 2021 $
    // $Copyright:
    // Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
    //
    // 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.
    // $
    //#############################################################################
    
    #include "user.h"
    
    #ifdef __TMS320C28XX_CLA__
    #pragma CODE_SECTION(USER_setParams,"Cla1Prog2");
    #endif
    
    #ifdef _F28002x
    #pragma CODE_SECTION(USER_setParams, "user_code");
    #endif
    
    //*****************************************************************************
    //
    // USER_setParams
    //
    //*****************************************************************************
    void USER_setParams(USER_Params *pUserParams)
    {
        pUserParams->dcBus_nominal_V = USER_NOMINAL_DC_BUS_VOLTAGE_V;
    
        pUserParams->numIsrTicksPerCtrlTick = 1;
        pUserParams->numIsrTicksPerEstTick = 1;
        pUserParams->numIsrTicksPerTrajTick = 1;
    
        pUserParams->numCtrlTicksPerCurrentTick = USER_NUM_ISR_TICKS_PER_CURRENT_TICK;
        pUserParams->numCtrlTicksPerSpeedTick = USER_NUM_ISR_TICKS_PER_SPEED_TICK;
    
        pUserParams->numCurrentSensors = USER_NUM_CURRENT_SENSORS;
        pUserParams->numVoltageSensors = USER_NUM_VOLTAGE_SENSORS;
    
        pUserParams->systemFreq_MHz = USER_SYSTEM_FREQ_MHz;
    
        pUserParams->voltage_sf = USER_VOLTAGE_SF;
    
        pUserParams->current_sf = USER_CURRENT_SF;
    
        pUserParams->dcBusPole_rps = USER_DCBUS_POLE_rps;
    
        pUserParams->offsetPole_rps = USER_OFFSET_POLE_rps;
    
        pUserParams->speedPole_rps = USER_SPEED_POLE_rps;
    
        pUserParams->voltageFilterPole_rps = USER_VOLTAGE_FILTER_POLE_rps;
    
        pUserParams->RoverL_excFreq_Hz = USER_R_OVER_L_EXC_FREQ_Hz;
    
        pUserParams->maxVsMag_pu = USER_MAX_VS_MAG_PU;
    
        pUserParams->motor_type = USER_MOTOR_TYPE;
    
        pUserParams->motor_numPolePairs = USER_MOTOR_NUM_POLE_PAIRS;
        pUserParams->motor_numEncSlots = USER_MOTOR_NUM_ENC_SLOTS;
    
        pUserParams->motor_ratedFlux_Wb = USER_MOTOR_RATED_FLUX_VpHz / MATH_TWO_PI;
    
        pUserParams->motor_Rr_d_Ohm = USER_MOTOR_Rr_Ohm;
        pUserParams->motor_Rr_q_Ohm = USER_MOTOR_Rr_Ohm;
    
        pUserParams->motor_Rs_a_Ohm = USER_MOTOR_Rs_Ohm;
        pUserParams->motor_Rs_b_Ohm = USER_MOTOR_Rs_Ohm;
    
        pUserParams->motor_Rs_d_Ohm = USER_MOTOR_Rs_Ohm;
        pUserParams->motor_Rs_q_Ohm = USER_MOTOR_Rs_Ohm;
    
        pUserParams->motor_Ls_d_H = USER_MOTOR_Ls_d_H;
        pUserParams->motor_Ls_q_H = USER_MOTOR_Ls_q_H;
    
        pUserParams->maxCurrent_A = USER_MOTOR_MAX_CURRENT_A;
    
        pUserParams->IdRated_A = USER_MOTOR_MAGNETIZING_CURRENT_A;
    
        pUserParams->Vd_sf = USER_VD_SF;
        pUserParams->maxVsMag_V = USER_NOMINAL_DC_BUS_VOLTAGE_V;
    
        /*LDRA_INSPECTED 139 S MR12 14.3 ""Its a compile time flag providing user a
           choice to use or bypass motor identification; so OK"*/
        if((USER_BYPASS_MOTOR_ID == 1) && (pUserParams->flag_bypassMotorId == true))
        {
    
    #if (USER_MOTOR == Estun_EMJ_04APB22_A)
            // Estun
            pUserParams->BWc_rps = MATH_TWO_PI * 100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    #elif (USER_MOTOR == Estun_EMJ_04APB22_B)
            // Estun
            pUserParams->BWc_rps = MATH_TWO_PI * 100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #elif (USER_MOTOR == Marathon_N56PNRA10102)
            // Marathon
            pUserParams->BWc_rps = MATH_TWO_PI * 100.0f;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #elif (USER_MOTOR == Anaheim_BLWS235D_160V)
            // Marathon
            pUserParams->BWc_rps = MATH_TWO_PI * 100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #elif (USER_MOTOR == Anaheim_BLWS235D)
            // Anaheim_BLWS235D
            pUserParams->BWc_rps = MATH_TWO_PI * (float32_t)100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #elif (USER_MOTOR == Anaheim_BLY172S_24V)
            // Anaheim_BLY172S_24V
            pUserParams->BWc_rps = MATH_TWO_PI * (float32_t)100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    #elif (USER_MOTOR == Teknic_M2310PLN04K)
            // M2310PLN04K
            pUserParams->BWc_rps = MATH_TWO_PI * (float32_t)100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #elif (USER_MOTOR == Marathon_5K33GN2A)
             Marathon 56H17T2001
             pUserParams->BWc_rps = MATH_TWO_PI * 100.0;
             pUserParams->BWdelta = (float32_t)8.0;
    
             // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
             pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                            pUserParams->motor_numPolePairs *
                                            pUserParams->motor_ratedFlux_Wb /
                                         (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #elif (USER_MOTOR == Teknic_MxxxxPLNxxK)
            // MxxxxPLNxxK
            pUserParams->BWc_rps = MATH_TWO_PI * (float32_t)100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * numPolesPairs * rotorFlux_Wb / (2.0 * J_kg_m2);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           pUserParams->motor_ratedFlux_Wb /
                                        (float32_t) (2.0 * USER_MOTOR_INERTIA_Kgm2);
    
    #else
            pUserParams->BWc_rps = MATH_TWO_PI * (float32_t)1000.0;
            pUserParams->BWdelta = (float32_t)40.0;
    
            // 3.0 * pUserParams->motor_numPolePairs * 0.1 / (2.0 * 0.00001);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           (float32_t)(0.001f) /
                                           (float32_t)(2.0f * 1000.0f);
    #endif
    
        }
        else
        {
            pUserParams->flag_bypassMotorId = false;
    
            pUserParams->BWc_rps = MATH_TWO_PI * (float32_t)100.0;
            pUserParams->BWdelta = (float32_t)8.0;
    
            // 3.0 * pUserParams->motor_numPolePairs * 0.1 / (2.0 * 0.00001);
            pUserParams->Kctrl_Wb_p_kgm2 = (float32_t)3.0 *
                                           pUserParams->motor_numPolePairs *
                                           (float32_t)(0.001) /
                                           (float32_t)(2.0 * 0.000001);
        }
    
        pUserParams->angleDelayed_sf_sec = (float32_t)0.5 * USER_CTRL_PERIOD_sec;
    
        pUserParams->fluxExcFreq_Hz = USER_MOTOR_FLUX_EXC_FREQ_Hz;
    
        pUserParams->ctrlWaitTime[CTRL_STATE_ERROR] = 0;
        pUserParams->ctrlWaitTime[CTRL_STATE_IDLE] = 0;
        pUserParams->ctrlWaitTime[CTRL_STATE_ONLINE] = 0;
    
        pUserParams->estWaitTime[EST_STATE_ERROR] = 0;
        pUserParams->estWaitTime[EST_STATE_IDLE] = 0;
        pUserParams->estWaitTime[EST_STATE_ROVERL] =
            (int32_t)(5.0 * USER_EST_FREQ_Hz);
        pUserParams->estWaitTime[EST_STATE_RS] = 0;
        pUserParams->estWaitTime[EST_STATE_RAMPUP] =
            (int32_t)((USER_MOTOR_FLUX_EXC_FREQ_Hz / USER_MAX_ACCEL_Hzps +
                             (float32_t)1.0) * USER_EST_FREQ_Hz);
        pUserParams->estWaitTime[EST_STATE_CONSTSPEED] =
            (int32_t)(1.0 * USER_EST_FREQ_Hz);
        pUserParams->estWaitTime[EST_STATE_IDRATED] =
            (int32_t)(20.0 * USER_EST_FREQ_Hz);
        pUserParams->estWaitTime[EST_STATE_RATEDFLUX_OL] =
            (int32_t)(1.0 * USER_EST_FREQ_Hz);
        pUserParams->estWaitTime[EST_STATE_RATEDFLUX] = 0;
        pUserParams->estWaitTime[EST_STATE_RAMPDOWN] =
            (int32_t)(0.0 * USER_EST_FREQ_Hz);
        pUserParams->estWaitTime[EST_STATE_LOCKROTOR] = 0;
        pUserParams->estWaitTime[EST_STATE_LS] = 0;
        pUserParams->estWaitTime[EST_STATE_RR] =
            (int32_t)(5.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] =
            (int32_t)(10.0 * USER_EST_FREQ_Hz);
        pUserParams->FluxWaitTime[EST_FLUX_STATE_CL2] =
            (int32_t)(0.2 * USER_EST_FREQ_Hz);
        pUserParams->FluxWaitTime[EST_FLUX_STATE_FINE] =
            (int32_t)(20.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] =
            (int32_t)(10.0 * USER_EST_FREQ_Hz);
        pUserParams->LsWaitTime[EST_LS_STATE_COARSE] =
            (int32_t)(30.0 * USER_EST_FREQ_Hz);
        pUserParams->LsWaitTime[EST_LS_STATE_FINE] =
            (int32_t)(30.0 * USER_EST_FREQ_Hz);
        pUserParams->LsWaitTime[EST_LS_STATE_DONE] = 0;
    
        pUserParams->RrWaitTime[EST_RR_STATE_ERROR] = 0;
        pUserParams->RrWaitTime[EST_RR_STATE_IDLE] = 0;
        pUserParams->RrWaitTime[EST_RR_STATE_RAMPUP] =
            (int32_t)(1.0 * USER_EST_FREQ_Hz);
        pUserParams->RrWaitTime[EST_RR_STATE_COARSE] =
            (int32_t)(10.0 * USER_EST_FREQ_Hz);
        pUserParams->RrWaitTime[EST_RR_STATE_FINE] =
            (int32_t)(30.0 * USER_EST_FREQ_Hz);
        pUserParams->RrWaitTime[EST_RR_STATE_DONE] = 0;
    
        pUserParams->RsWaitTime[EST_RS_STATE_ERROR] = 0;
        pUserParams->RsWaitTime[EST_RS_STATE_IDLE] = 0;
        pUserParams->RsWaitTime[EST_RS_STATE_RAMPUP] =
            (int32_t)(1.0 * USER_EST_FREQ_Hz);
        pUserParams->RsWaitTime[EST_RS_STATE_COARSE] =
            (int32_t)(2.0 * USER_EST_FREQ_Hz);
        pUserParams->RsWaitTime[EST_RS_STATE_FINE] =
            (int32_t)(10.0 * USER_EST_FREQ_Hz);
        pUserParams->RsWaitTime[EST_RS_STATE_DONE] = 0;
    
        pUserParams->trajWaitTime[EST_TRAJ_STATE_ERROR] = 0;
        pUserParams->trajWaitTime[EST_TRAJ_STATE_IDLE] = 0;
        pUserParams->trajWaitTime[EST_TRAJ_STATE_EST] = 0;
        pUserParams->trajWaitTime[EST_TRAJ_STATE_ONLINE] = 0;
    
        pUserParams->estFreq_Hz = USER_EST_FREQ_Hz;
        pUserParams->ctrlFreq_Hz = USER_CTRL_FREQ_Hz;
        pUserParams->trajFreq_Hz = USER_TRAJ_FREQ_Hz;
    
        pUserParams->pwmPeriod_usec = USER_PWM_PERIOD_usec;
        pUserParams->ctrlPeriod_sec = USER_CTRL_PERIOD_sec;
    
        pUserParams->maxAccel_Hzps = USER_MAX_ACCEL_Hzps;
    
        pUserParams->maxCurrent_resEst_A = USER_MOTOR_RES_EST_CURRENT_A;
        pUserParams->maxCurrent_indEst_A = USER_MOTOR_IND_EST_CURRENT_A;
    
        pUserParams->maxCurrentDelta_A = USER_MAX_CURRENT_DELTA_A;
        pUserParams->maxCurrentDelta_pw_A = USER_MAX_CURRENT_DELTA_PW_A;
    
        pUserParams->IdRated_delta_A = USER_IDRATED_DELTA_A;
    
        pUserParams->forceAngleFreq_Hz = USER_FORCE_ANGLE_FREQ_Hz;
    
        pUserParams->indEst_speedMaxFraction = USER_SPEEDMAX_FRACTION_FOR_L_IDENT;
    
        pUserParams->IdRatedFraction_indEst = USER_IDRATED_FRACTION_FOR_L_IDENT;
    
        pUserParams->pwGain = USER_PW_GAIN;
    
        pUserParams->Kp_min_VpA = (float32_t)0.001;
        pUserParams->Kp_max_VpA = (float32_t)1000.0;
    
        pUserParams->RoverL_Kp_sf = USER_R_OVER_L_KP_SF;
        pUserParams->RoverL_min_rps = MATH_TWO_PI * (float32_t)5.0;
        pUserParams->RoverL_max_rps = MATH_TWO_PI * (float32_t)5000.0;
    
        pUserParams->oneOverDcBus_min_invV = (float32_t)1.0 / (float32_t)400.0;
        pUserParams->oneOverDcBus_max_invV = (float32_t)1.0 / (float32_t)10.0;
    
        pUserParams->Ls_d_H = (float32_t)1.0e-6;
        pUserParams->Ls_q_H = (float32_t)1.0e-6;
        pUserParams->Ls_coarseDelta_H = (float32_t)0.0000001;
        pUserParams->Ls_fineDelta_H = (float32_t)0.00000001;
        pUserParams->Ls_min_H = (float32_t)0.000001;
        pUserParams->Ls_max_H = (float32_t)100.0;
    
        pUserParams->Rr_Ohm = (float32_t)0.0;
        pUserParams->Rr_coarseDelta_Ohm = (float32_t)0.0001;
        pUserParams->Rr_fineDelta_Ohm = (float32_t)0.00001;
        pUserParams->Rr_min_Ohm = (float32_t)0.0;
        pUserParams->Rr_max_Ohm = (float32_t)1000.0;
    
        pUserParams->Rs_Ohm = (float32_t)0.0;
        pUserParams->Rs_coarseDelta_Ohm = (float32_t)0.01;
        pUserParams->Rs_fineDelta_Ohm = (float32_t)0.00001;
        pUserParams->Rs_min_Ohm = (float32_t)0.001;
        pUserParams->Rs_max_Ohm = (float32_t)1000.0;
    
        pUserParams->RsOnLine_DeltaInc_Ohm = (float32_t)0.00001;
        pUserParams->RsOnLine_DeltaDec_Ohm = (float32_t)0.00001;
        pUserParams->RsOnLine_min_Ohm = (float32_t)0.001;
        pUserParams->RsOnLine_max_Ohm = (float32_t)1000.0;
    
        pUserParams->RsOnLine_angleDelta_rad = (float32_t)0.00001;
        pUserParams->RsOnLine_pole_rps = MATH_TWO_PI * (float32_t)0.2;
    
        pUserParams->flag_bypassMotorId = USER_BYPASS_MOTOR_ID;
    
        pUserParams->maxFrequency_Hz = USER_MAXIMUM_SCALE_FREQ_Hz;
    
        return;
    } // end of USER_setParams() function
    
    
    // end of file
    

    8053.user.h

    Thanks,
    Aaron

  • Hi Aaron,

    I have made some partial progress on this.

    It seems one reason the measurements are not working, is that the PI controller gains are being set very small during the motor identification. As such when performing the resistance measurement, the FAST estimator set the d-axis current demand to the value set in the user.h file. in my case 0.18A. But the actual value achieved by the controller is never getting anywhere near this value, as the gains in the controller are too low.

    By increasing the time duration of the steps in the resistance measurement sequence by the code changes in user.c as follows:

        pUserParams->RsWaitTime[EST_RS_STATE_RAMPUP] =
            (int32_t)(10.0 * USER_EST_FREQ_Hz);
        pUserParams->RsWaitTime[EST_RS_STATE_COARSE] =
            (int32_t)(20.0 * USER_EST_FREQ_Hz);
        pUserParams->RsWaitTime[EST_RS_STATE_FINE] =
            (int32_t)(100.0 * USER_EST_FREQ_Hz);
        pUserParams->RsWaitTime[EST_RS_STATE_DONE] = 0;

    I can see that the measured d-axis current is ramping up very slowly, but only gets to about 0.06A even after 130 seconds.

    It seems the controller gain values are initialized according to the following formulae in the function CTRL_setParams:

        //
        // Set the Id current controller gain
        //
        Kp = Ls_d_H * pUserParams->BWc_rps;
        RoverL_rps = Rs_d_Ohm / Ls_d_H;
        Ki = RoverL_rps * currentCtrlPeriod_sec;
        CTRL_setGains(handle,CTRL_TYPE_PI_ID,Kp,Ki);

    This gives me values of Kp = 0.0697433576 & Ki = 2.97297287. However, when the motor identification is started by setting motorVars.flagRunIdentAndOnLine = True, the FAST estimator overwrites these value through the EST_configureCtrl function (line 721 in is05_motor_id.c). 

    After this call the control gains are Kp = 0.00100000005 & Ki = 0.00314159272.

    I've tried hacking the PI controller to force the gains to be 50 times these values. With these values the current controller achieves the desired d-axis current of 0.18A is about 1 second. The measured Rs value is then about 5.1 ohms which is significantly better, though still not very accurate. 

    So the question is, do you know how the FAST estimator is setting these gain values in the EST_configureCtrl function? I assume it is based on values in the userParams structure, but I don't know which ones.

  • Yes, the gains of PI controllers will be set in the FAST initialization functions. You may set a draft motor parameters in the user.h per the datasheet of the motor if possible, that can help to identify the motor successfully. 

    Also, you need to set the identification variables according to the spec. of the motor.