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.

gMotorVars.SpinTAC.VelCtlErrorID = 5 , not much documentation for SpinTac Velocity Controller

Other Parts Discussed in Thread: MOTORWARE

I successfully managed to do uptil Lab 5c with my custom  board but got stuck in Lab 5d. so the default PI speed controller in FOC works fine but I cant get Spintac velocity controller to work. The rotor just doesn't move when I go through the steps if Lab 5d. I did see gMotorVars.SpinTAC.VelCtlErrorID = 5 . I went through the documentation in spruhj1f-InstaSpin-UserGuide.pdf for ErroID and found the description for various codes in Section 12.2.5.1  and how to set configuration variables  in 12.2.3 but alas, the documentation is not very descriptive. It doesnt explain what does each configuration variable mean and what values to set and why the default values are hard coded the way they are. So, I am unable to clear the VelCtlErrorID. Please advise.

  • Subrat,

    According to section 12.2.5.1 if you see gMotorVars.SpinTAC.VelCtlErrorID = 5, this means that the provided value for cfg.OutMin is outside of the acceptable range. My guess is that if you look in the user.h file you will find that you have set USER_MOTOR_MAX_CURRENT larger than USER_IQ_FULL_SCALE_CURRENT_A.

    If you look in the spintac_velocity.h file for the function STVELCTL_setOutputMaximums you will see how the defaults are established. The code example in the User Guide is provided as an example, but it it slightly different than what is in the labs.

    If you add st_obj.vel.ctl.cfg.OutMin (which is an IQ24 variable) into the watch window what is the value you see?

    The configuration variables are described for SpinTAC Velocity Control in 3.5.1.1.
  • My USER_MOTOR_MAX_CURRENT is set at 10.0 while the USER_IQ_FULL_SCALE_CURRENT_A is at 166.0 , so USER_MOTOR_MAX_CURRENT is less than USER_IQ_FULL_SCALE_CURRENT_A.

    st_obj.vel.ctl.cfg.OutMin (in IQ24 variable) into the watch window shows 0.0326603651

    Any ideas whats happening or what I need to do to clear the error id 5.
  • The value for st_obj.vel.ctl.cfg.OutMin should not be a positive number.  What is the value for st_obj.vel.ctl.cfg.OutMax?

    If you look at the code in spintac_velocity.h, this is the relevant code:

    _iq24 maxCurrent_PU = _IQ24(USER_MOTOR_MAX_CURRENT / USER_IQ_FULL_SCALE_CURRENT_A);
    
    STVELCTL_setOutputMaximums(obj->velCtlHandle, maxCurrent_PU, -maxCurrent_PU);

    If you manually calculate 10.0/166.0 which is your USER_MOTOR_MAX_CURRENT / USER_IQ_FULL_SCALE_CURRENT_A, you should be getting a value of 0.0602, not 0.03266.  Seems like there is some memory not being set correctly.

    You did run the code via the debugger, correct?  What modifications have you made to the software?

  • Thanks Adam.

    So once I run the Lab 5d, the values I see in the watch window are
    st_obj.vel.ctl.cfg.OutMin = -0.06024092436
    st_obj.vel.ctl.cfg.OutMax = 0.06024092436

    After I turn enable sys = 1 and Run_identify = 1,

    the two variables change to
    st_obj.vel.ctl.cfg.OutMin = 0.0326603651
    st_obj.vel.ctl.cfg.OutMax = -0.03266042471



    For // setup the SpinTAC Components
    ST_setupVelCtl(stHandle);


    the code is as is that came with motorware, didnt touch it.

    here is what i got for ST_setupVelCtl inside spintac_velocity.h

    //! \brief Setups SpinTAC Velocity Control
    inline void ST_setupVelCtl(ST_Handle handle) {

    // get object from the handle
    ST_Obj *obj = (ST_Obj *)handle;
    _iq24 maxCurrent_PU = _IQ24(USER_MOTOR_MAX_CURRENT / USER_IQ_FULL_SCALE_CURRENT_A);

    // Initalize SpinTAC Position Control
    STVELCTL_setAxis(obj->velCtlHandle, ST_AXIS0);
    STVELCTL_setSampleTime_sec(obj->velCtlHandle, _IQ24(ST_SAMPLE_TIME));
    STVELCTL_setInertiaMaximums(obj->velCtlHandle, _IQ24(10.0), _IQ24(0.001));
    STVELCTL_setOutputMaximums(obj->velCtlHandle, maxCurrent_PU, -maxCurrent_PU);
    STVELCTL_setVelocityMaximums(obj->velCtlHandle, _IQ24(1.0), _IQ24(-1.0));
    STVELCTL_setBandwidthScaleMaximums(obj->velCtlHandle, _IQ24((0.2) / (ST_SAMPLE_TIME * 20.0)), _IQ24(0.01));
    STVELCTL_setInertia(obj->velCtlHandle, _IQ24(ST_SYSTEM_INERTIA_PU));
    STVELCTL_setFriction(obj->velCtlHandle, _IQ24(ST_SYSTEM_FRICTION_PU));
    STVELCTL_setBandwidthScale(obj->velCtlHandle, _IQ24(USER_SYSTEM_BANDWIDTH_SCALE));
    STVELCTL_setEnable(obj->velCtlHandle, false);
    STVELCTL_setReset(obj->velCtlHandle, false);
    }



    Yes, I am running it through the debugger and I have not made any modifications. Only changes I made are in HAL relevant to my board and in user.h relevant to my motor and board.

    Any comments?

    thanks.
  • I also see some more relevant code that i didnt touch, its as is from motorware.


    // initialize the watch window with maximum and minimum Iq reference
    gMotorVars.SpinTAC.VelCtlOutputMax_A = _IQmpy(STVELCTL_getOutputMaximum(stObj->velCtlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));
    gMotorVars.SpinTAC.VelCtlOutputMin_A = _IQmpy(STVELCTL_getOutputMinimum(stObj->velCtlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));

    and also

    // set the maximum and minimum values for Iq reference
    STVELCTL_setOutputMaximums(stObj->velCtlHandle, _IQmpy(gMotorVars.SpinTAC.VelCtlOutputMax_A, _IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A)), _IQmpy(gMotorVars.SpinTAC.VelCtlOutputMin_A, _IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A)));


    thanks
    Subrat
  • The problem is in the lines:
    gMotorVars.SpinTAC.VelCtlOutputMax_A = _IQmpy(STVELCTL_getOutputMaximum(stObj->velCtlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));
    gMotorVars.SpinTAC.VelCtlOutputMin_A = _IQmpy(STVELCTL_getOutputMinimum(stObj->velCtlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));

    Your value for USER_IQ_FULL_SCALE_CURRENT_A is larger than what can be represented in an IQ24 variable. My recommendation would be to reduce the value for USER_IQ_FULL_SCALE_CURRENT_A. Since your motor max current is only 10A you don't need the base scaling to be set so large.

    Additionally there is a post on E2E about how to change your system to use kA instead of A.
  • Thanks. but I cant change USER_IQ_FULL_SCALE_CURRENT_A. I have to make sure.
    USER_ADC_FULL_SCALE_CURRENT_A =< ( USER_IQ_FULL_SCALE_CURRENT_A * 2 )

    My USER_ADC_FULL_SCALE_CURRENT_A is fixed at (330.0) by hardware design ie the current sensor I am using. So, I have to use USER_IQ_FULL_SCALE_CURRENT_A at 165.0 or more.

    that means the only option for me is to make the type bigger than IQ24 . right?
  • My USER_MOTOR_MAX_CURRENT is actually not 10.0, I set it to 10A because of the limitations of my current power supply. So, it should be some thing around 90.0 when working with a battery pack or a bigger power supply.
  • Your best option than is to rework that calculation so that you are using a Q type as the intermediate value.  My recommendation is below:

    gMotorVars.SpinTAC.VelCtlOutputMax_A = _IQ16toIQ24(_IQ16mpy(_IQ24toIQ16(STVELCTL_getOutputMaximum(stObj->velCtlHandle)), _IQ16(USER_IQ_FULL_SCALE_CURRENT_A)));
    gMotorVars.SpinTAC.VelCtlOutputMin_A = _IQ16toIQ24(_IQ16mpy(_IQ24toIQ16(STVELCTL_getOutputMinimum(stObj->velCtlHandle)), _IQ16(USER_IQ_FULL_SCALE_CURRENT_A)));

  • Can you please point me to post on E2E about how to change your system to use kA instead of A ? I dont see any results when i search for kA instead of A
  • Hi Adam,

    The post you pointed me to doesn't actually show how to convert A to kA. It just shows how to change the display variable
    gMotorVars.Id_kA

    when I run with 150A current sensors run at 3.3v supply ( so max current measurable = 125A), so in user.h
    #define USER_IQ_FULL_SCALE_CURRENT_A (125.0)
    #define USER_ADC_FULL_SCALE_CURRENT_A (248.12)

    My code works fine but I want to run with 200A current sensors run at 3.3v supply ( so max current measurable = 165A), so in user.h
    //#define USER_IQ_FULL_SCALE_CURRENT_A (165.0)
    //#define USER_ADC_FULL_SCALE_CURRENT_A (330.0)

    Any suggestions on what changes do I need to do to use higher current values?
  • The issue you will run into is when you convert from scaled amps into amps.  So anyplace in the code where it is multiplying by USER_IQ_FULL_SCALE_CURRENT, you need to remove that multiplication.  This will change unit for your display variable from amps into scaled amps (which is normalized from 0 to 1, where 1 represents USER_IQ_FULL_SCALE_CURRENT).