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.

Encoder speed overflow (SpinTAC Position Converter)

Other Parts Discussed in Thread: MOTORWARE, BOOSTXL-DRV8305EVM, TMS320F28069M

Hello,

this question has already been asked here, but I think it better fits in the InstaSPIN forum, so I re-ask it here.

I noticed that the speed measured by the encoder (`gMotorVars.SpeedQEP_krpm`) suffers from an overflow already at relatively low speed (2.5 krpm). When running the velocity controller (lab12b), everything works fine until reaching 2.5 krpm. At this point, `SpeedQEP_krpm` jumps from +2.5 to -2.5, resulting in the motor speeding up to maximum speed (around 6 krpm in my case).

When changing the PWM frequency (USER_PWM_FREQ_kHz) from 15 kHz to 30 kHz also the point where the overflow occurs doubles to 5 krpm.

When only doing torque control, It works well even after the overflow occurs, so I guess the electrical angle is still measured correctly and it is probably only an issue with the conversion from angle to speed.

Is this expected behaviour? Is there any way to prevent the overflow besides changing PWM frequency?

In case it matters: My encoder has 500 lines. I am using a LaunchPad XL TMS320F28069M with BOOSTXL-DRV8305EVM. MotorWare 1.01.00.16.

Best, Felix

  • Felix,

    I think the issue is the scaling in your system. Converting from electrical angle to speed uses the system scaling including the sample time. By changing the pwm frequency, this will change the sample time of the speed conversion algorithm. The easy thing to try would be to increase the value for USER_IQ_FULL_SCALE_FREQ_Hz. You can also post your user.h file and I can try to find the source of the problem.
  • Hi Adam,

    USER_IQ_FULL_SCALE_FREQ_Hz is currently set to 1310.0, which is (according to the excel spreadsheet delivered with motorware) the maximum allowed value for the hardware. Is it save to increase it significantly beyond that value or do I risk to damage something?

    This is my user_j1.h:

    //! \brief CURRENTS AND VOLTAGES
    // **************************************************************************
    #define USER_IQ_FULL_SCALE_FREQ_Hz        (1310.0)  // value given by the excel spreadsheet
    
    #define USER_IQ_FULL_SCALE_VOLTAGE_V      (24.0)  // 24.0 Set to Vbus
    #define USER_ADC_FULL_SCALE_VOLTAGE_V     (44.30) // BOOSTXL-DRV8305EVM = 44.30 V
    #define USER_IQ_FULL_SCALE_CURRENT_A      (24.0)  // BOOSTXL-DRV8305EVM = 24.0 A
    #define USER_ADC_FULL_SCALE_CURRENT_A     (47.14) // BOOSTXL-DRV8305EVM = 47.14 A
    #define USER_NUM_CURRENT_SENSORS          (3)
    #define USER_NUM_VOLTAGE_SENSORS          (3)
    
    #define   I_A_offset    (1.004728198)
    #define   I_B_offset    (1.005483985)
    #define   I_C_offset    (1.006817698)
    
    #define   V_A_offset    (0.4910094738)
    #define   V_B_offset    (0.4885113835)
    #define   V_C_offset    (0.4871017337)
    
    //! \brief CLOCKS & TIMERS
    // **************************************************************************
    #define USER_PWM_FREQ_kHz         (30.0)
    #define USER_MAX_VS_MAG_PU        (0.5)
    
    //! \brief DECIMATION
    // **************************************************************************
    #define USER_NUM_PWM_TICKS_PER_ISR_TICK        (1)
    #define USER_NUM_ISR_TICKS_PER_CTRL_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_CURRENT_TICK   (1)
    #define USER_NUM_CTRL_TICKS_PER_EST_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_SPEED_TICK    (15)
    #define USER_NUM_CTRL_TICKS_PER_TRAJ_TICK     (15)
    
    //! \brief LIMITS
    // **************************************************************************
    #define USER_MAX_NEGATIVE_ID_REF_CURRENT_A   (-0.5 * USER_MOTOR_MAX_CURRENT)
    #define USER_R_OVER_L_EST_FREQ_Hz            (300)
    #define USER_ZEROSPEEDLIMIT                  (1.0 / USER_IQ_FULL_SCALE_FREQ_Hz)
    #define USER_FORCE_ANGLE_FREQ_Hz             (2.0 * USER_ZEROSPEEDLIMIT * USER_IQ_FULL_SCALE_FREQ_Hz)
    
    //! \brief POLES
    // **************************************************************************
    #define USER_VOLTAGE_FILTER_POLE_Hz  (344.62)   // BOOSTXL-DRV8305 = 344.62 Hz
    
    
    //! \brief USER MOTOR & ID SETTINGS
    // **************************************************************************
    
    #define USER_SYSTEM_BANDWIDTH      (100.0) // tuned in lab 13a
    
    #define USER_MOTOR_TYPE                 MOTOR_Type_Pm
    #define USER_MOTOR_NUM_POLE_PAIRS       (12)
    #define USER_MOTOR_Rr                   (0.0)
    #define USER_MOTOR_Rs                   (0.2319251)
    #define USER_MOTOR_Ls_d                 (0.0001494264)
    #define USER_MOTOR_Ls_q                 (0.0001494264)
    #define USER_MOTOR_RATED_FLUX           (0.009320291)
    #define USER_MOTOR_MAGNETIZING_CURRENT  (NULL)
    #define USER_MOTOR_RES_EST_CURRENT      (1.0)
    #define USER_MOTOR_IND_EST_CURRENT      (-1.0)
    #define USER_MOTOR_MAX_CURRENT          (9.0)
    #define USER_MOTOR_FLUX_EST_FREQ_Hz     (120.0) // Given by excel spreadsheet. Default 20.
    #define USER_MOTOR_MAX_SPEED_KRPM       (6.0)
    
    #define USER_MOTOR_ENCODER_LINESi       (500.0)
    #define USER_SYSTEM_INERTIA             (0.02391791343688965)  // determined with lab12a
    #define USER_SYSTEM_FRICTION            (0.042265355587005615)  // determined with lab12a
    

  • you are running the entire control system at 30 KHz, which is overflowing the interrupt I'm sure.

    Add in this HW decimation tick to run the interrupt, current, and estimator at 30 / 2 = 15 KHz

    and the speed, position at 15 / 15 = 1 KHz

    #define USER_NUM_PWM_TICKS_PER_ISR_TICK        (2)
  • Hi Chris,

    when I set USER_NUM_PWM_TICKS_PER_ISR_TICK to 2, the overflow already occurs at 2.5 krpm instead of 5 krpm. So it has the same effect as setting PWM frequency to 15 kHz instead.

    I tracked it down, using the different levels of decimation rates and at each level, halving the frequency also halved the maximum speed before the overflow. In the end it seems like the maximum possible speed is directly proportional to the frequency of the the speed controller. Examples:

    #define USER_PWM_FREQ_kHz                   (30.0)
    #define USER_NUM_PWM_TICKS_PER_ISR_TICK        (1)
    #define USER_NUM_ISR_TICKS_PER_CTRL_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_CURRENT_TICK   (1)
    #define USER_NUM_CTRL_TICKS_PER_EST_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_SPEED_TICK    (15)

    --> overflow at 5 krpm

    #define USER_PWM_FREQ_kHz                   (30.0)
    #define USER_NUM_PWM_TICKS_PER_ISR_TICK        (1)
    #define USER_NUM_ISR_TICKS_PER_CTRL_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_CURRENT_TICK   (1)
    #define USER_NUM_CTRL_TICKS_PER_EST_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_SPEED_TICK    (30)

    --> overflow at 2.5 krpm

    #define USER_PWM_FREQ_kHz                   (30.0)
    #define USER_NUM_PWM_TICKS_PER_ISR_TICK        (1)
    #define USER_NUM_ISR_TICKS_PER_CTRL_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_CURRENT_TICK   (1)
    #define USER_NUM_CTRL_TICKS_PER_EST_TICK       (1)
    #define USER_NUM_CTRL_TICKS_PER_SPEED_TICK    (10)

    --> motor reaches maximum speed of around 6 krpm without overflow.

  • I just tried to increase USER_IQ_FULL_SCALE_FREQ_Hz, as Adam suggested, but I immediately get USER_ErrorCode_voltageFilterPole_Hz_Low.
  • are you sure this is a 24 pole motor? do you have a link to any documentation on it?
    Any information on max RPM, or KV?

    have you tried running proj_lab05a or 5b and see if you can reach > 6 KRPM?
    I suppose this comments means that you did?
    "When only doing torque control, It works well even after the overflow occurs, so I guess the electrical angle is still measured correctly and it is probably only an issue with the conversion from angle to speed."

    How do you know the overflow is occurring? You're still running proj_lab12 so you can see the speed from the encoder but running with just an IqRef_A command?


    Your USER_IQ_FULL_SCALE_FREQ_HZ is already at the maximum for the HW, don't increase. This should allow Speeds up to 6550 RPM before an overflow. So hopefully your motor is rated for < 6 KRPM.

    As for the decimation I would use the default values to start:
    #define USER_PWM_FREQ_kHz (45.0)

    #define USER_NUM_PWM_TICKS_PER_ISR_TICK (3)

    #define USER_NUM_ISR_TICKS_PER_CTRL_TICK (1)

    #define USER_NUM_CTRL_TICKS_PER_CURRENT_TICK (1)

    #define USER_NUM_CTRL_TICKS_PER_EST_TICK (1)

    #define USER_NUM_CTRL_TICKS_PER_SPEED_TICK (15)

    #define USER_NUM_CTRL_TICKS_PER_TRAJ_TICK (15)
  • The motor we are using is a T Motor Antigravity 4004 KV300 (see here for details: www.rctigermotor.com/.../288.html). They don't explicitly mention a max RPM, but if I understand it correctly, it should be 7200 rpm (given KV=300, max I = 9A, max P = 216W). We won't need the full speed, though, so it is no problem for us if we have to stay below 6000 rpm.

    I set PWM frequency and decimation as you suggested. Overflow is now occuring at 2500 rpm.

    I just realized, I did not explicitly mention this in the question, not sure if this was clear: Only measurement from the encoder (SpeedQEP_krpm) is affected by the overflow, FAST estimation (Speed_krpm) is working correctly.

    For torque control, I indeed use a modified version of lab12b (removed the velocity controller and set IqRef directly). I also see the overflow when using the original 12b, though.
    I also tried it with lab05a and 05b now. Even after increasing USER_MOTOR_MAX_SPEED_KRPM to 7, the motor won't spin faster than approx. 6 krpm with any of these labs.

  • Felix,

    There is a limitation inside of SpinTAC Position Covert where it needs to get at least three samples of an electrical angle in order to calculate the speed. Since your motor has such a high number of pole pairs this causes the electrical speed to be very fast which means when running SpinTAC Position Convert at 1ms it won't be able to keep up.

    My advice would be to move SpinTAC Position Convert so that it runs at the same decimation as a main motor control code. You will need to make sure that you have updated the sample time for SpinTAC Position Convert in spintac_position.h to reflect it's new decimation.
  • Hi Adam,

    Thanks, this indeed solved the problem.

    For future readers, these are the exact changes I made:

    Instead of running the position converter directly in the control loop, I gave it its own decimation in user_j1.h:

    #define USER_NUM_CTRL_TICKS_PER_POSCONV_TICK (5)

    (5 is enought in my case to support the max. velocity of 6 krpm)

    In the mainISR of lab12b, I separated the calls of position converter and velocity controller:

    static uint16_t stCnt = 0;
    static uint16_t stPosConvCnt = 0;
    
    ...
    
    // Run the SpinTAC Components
    if(stPosConvCnt++ >= ISR_TICKS_PER_POSCONV_TICK) {
    ST_runPosConv(stHandle, encHandle, ctrlHandle);
    stPosConvCnt = 1;
    }
    if(stCnt++ >= ISR_TICKS_PER_SPINTAC_TICK) {
    //ST_runPosConv(stHandle, encHandle, ctrlHandle);
    ST_runVelCtl(stHandle, ctrlHandle);
    stCnt = 1;
    }

    Finally in spintac_velocity.h (not in spintac_position.h !), I added

    #define ISR_TICKS_PER_POSCONV_TICK (USER_NUM_ISR_TICKS_PER_CTRL_TICK * USER_NUM_CTRL_TICKS_PER_POSCONV_TICK)
    #define ST_POS_CONV_SAMPLE_TIME (ISR_TICKS_PER_POSCONV_TICK / USER_ISR_FREQ_Hz)

    and in the definition of ST_setupPosConv() in the same file, I replaced all occurences of ST_SAMPLE_TIME with ST_POS_CONV_SAMPLE_TIME.
    (I guess the same changes have to be made in spintac_position.h for labs that are using this one.)

    I hope, I got everything right. At least it seems to work without problems :)

    Thanks both of you for the effort!

    Best, Felix