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.

Instaspin motor with encoder problem

Other Parts Discussed in Thread: MOTORWARE

Hello,

I am using  DRV8312-69M-KIT 

My system is using motor from http://www.iflight-rc.com/product/iPower-Brushless-Motor-iPower-GBM-Series-iPower-Gimbal-Brushless-Motor-GBM4008-150T.html

It has Magnetic Quadrature encoder AS5047D attached externally.

I have run the lab 2a/2b/5c successfully for Motor Identification

I am trying to run lab12a but the motor does not even move and it is holding the position firmly.

also My Motor winding are getting Hot if gMotorVars.Flag_Run_Identify” equal to 1

I have check the polarity of A/B/I correctly. I have even check the output from encoder using scope to make sure that encoder is giving out signals.

What might be the possible reason that sensorless project work fine and with sensored system the motor is not moving at all.

Tushar

  • Tushar,

    When using an encoder it is important that the rotation direction of the encoder agrees with the rotation direction of the motor.  

    When you were running the previous labs without the encoder did the motor spin in the anti-clockwise direction?

    Follow this procedure to ensure that your encoder is setup correctly:

    1. In lab 12a set gMotorVars.Flag_enableSys to 1

    2. Add st_obj.vel.conv.Pos_mrev to the watch window (this is an IQ24 variable)

    3. Manually rotate the encoder anti-clockwise 1 rotation

    4. Check that the value in st_obj.vel.conv.Pos_mrev is equal to 1.  If this value is not equal to 1 than there is a problem with the encoder configuration.  This means that the Motor Pole Pairs or Encoder Line Count is incorrect.  If this value is -1 than you need to switch A & B lines in your encoder.  

    5. If this value is 1 and it still doesn't work, it means that the encoder and motor disagree on which direction is positive and you need to switch two of the motor phase wires.

  • Hello Adam,

    Thanks for the quick reply.

    The actual arrangement is that Motor is attached to a Gear ratio of 14:54. and the Encoder is attached to the Gear Shaft.

    That means my motor and gear will rotate in different direction and so the encoder with respect to motor direction.

    Can you comment on this and how to make hardware wiring with configuration.

    Tushar

  • Adam,

    I even tried this method and the value for this variable st_obj.vel.conv.Pos_mrev is changing unexpectedly 

    something from 6000 to -6000.

    How do I check that the motor pole pairs are assigned correctly.

    I will provide you with motors parameters tomorrow.

    Thanks,

    Tushar

  • Tushar,

    You will face some difficulty in getting this system to work. Our control system assumes that the encoder is directly mounted to the motor shaft. You will also face some difficulty in how responsive this control system is because there will be backlash in between the motor and the encoder. This will cause vibration and audible noise in your system. 

  • Hello Adam,

    These are the motor parameters

    #elif (USER_MOTOR == iPOWER_GBM4008_150T) // Name must match the motor #define
    #define USER_MOTOR_TYPE MOTOR_Type_Pm // Motor_Type_Pm (All Synchronous: BLDC, PMSM, SMPM, IPM) or Motor_Type_Induction (Asynchronous ACI)
    #define USER_MOTOR_NUM_POLE_PAIRS (7) // PAIRS, not total poles. Used to calculate user RPM from rotor Hz only
    #define USER_MOTOR_Rr (NULL) // Induction motors only, else NULL
    #define USER_MOTOR_Rs (8.284804344) // Identified phase to neutral resistance in a Y equivalent circuit (Ohms, float)
    #define USER_MOTOR_Ls_d (0.0009627654) // For PM, Identified average stator inductance (Henry, float)
    #define USER_MOTOR_Ls_q (0.0009627654) // For PM, Identified average stator inductance (Henry, float)
    #define USER_MOTOR_RATED_FLUX (0.158176) // Identified TOTAL flux linkage between the rotor and the stator (V/Hz)
    #define USER_MOTOR_MAGNETIZING_CURRENT (NULL) // Induction motors only, else NULL
    #define USER_MOTOR_RES_EST_CURRENT (1.0) // During Motor ID, maximum current (Amperes, float) used for Rs estimation, 10-20% rated current
    #define USER_MOTOR_IND_EST_CURRENT (-1.0) // During Motor ID, maximum current (negative Amperes, float) used for Ls estimation, use just enough to enable rotation
    #define USER_MOTOR_MAX_CURRENT (3.82) // CRITICAL: Used during ID and run-time, sets a limit on the maximum current command output of the provided Speed PI Controller to the Iq controller
    #define USER_MOTOR_FLUX_EST_FREQ_Hz (20.0) // During Motor ID, maximum commanded speed (Hz, float), ~10% rated
    #define USER_MOTOR_ENCODER_LINES (7714.0)
    #define USER_MOTOR_MAX_SPEED_KRPM (2.0)
    #define USER_SYSTEM_INERTIA (0.016667)
    #define USER_SYSTEM_FRICTION (0.042809)

    What value should I put if my Maximum RPM of motor is suppose to be 2000 RPM and 7 pole pairs

    #define USER_IQ_FULL_SCALE_FREQ_Hz        (USER_MOTOR_NUM_POLE_PAIRS/????????)   // (4/0.008) = 500 Example with buffer for 8-pole 6 KRPM motor to be run to 6 KRPM; Hz = (RPM * Poles) / 120

    Tushar

  • Tushar,

    This value needs to define the maximum frequency in the project. So this value can be set to much greater than your motor's true maximum speed and it will operate fine. For your specific case you should set it to 300. This will give you a maximum speed of ~2500rpm. Since FULL_SCALE_FREQ * 60 / POLE_PAIRS Is the maximum speed in rpm that is allowed.

  • Hello Adam,

    If I rotate my motor manually I can see that the value of  maximum value st_obj.vel.conv.Pos_erev is 16677702

    and st_obj.vel.conv.Pos_mrev is between 2779617 to -660433.

    Can you please Comment on this why I am having such values.

    Thanks

    Tushar 

  • Tushar,

    These are fixed point IQ24 variables.  So a value of 16777216 corresponds to 1.0.  You can tell CCS to do this calculation for you by right clicking on the variable in the expressions window and selecting Q-Value.  

    The output of the ENC module has a value going from 0 to 1 for electrical angle.  That is the input into the Position Converter and is shown in the variable st_obj.vel.conv.Pos_erev.

    The output of the Position Converter is a mechanical angle of the motor.  This is a value that varies from -10 to 10.  This is done so that as larger and larger positions are achieved, there will not be any fixed point math issues.  This value is shown in st_obj.vel.conv.Pos_mrev.

  • Hello Adam,

    My motor was not spinning because there was noise running on ABI lines.

    Here is what I found as soon as I enable PWM on motor I see noise on ABI lines, I tried to shield the motor but it didn't help. Can you tell me if I am grounding the Motor correctly or not.

    I used GND pin from the board and connect it to the motor case. I also want to know that is this board grounded to earth or I need to ground it to earth and how?

    I am also developing to read SPI data from encoder and use that value in the motorware project lab12x

    I need your help If I get the angle data from encoder then How to use these angle value and modify in the current lab12x project.

    Tushar

  • Tushar,

    I've run into this issue a couple times.  One thing I can suggest is to try to use a shielded cable for your encoder lines.  You should also try not to run them next to the motor phase lines.  I've found that grounding the motor case like you mentioned also helps. 

    This board does not ground to the earth.  I'm not sure if that would help much with your noise issues.

    The InstaSPIN setup expects that the electrical angle varies between 0 and 1 in IQ24.  This value needs to be provided to the FOC and to SpinTAC Position Convert.  Each place in the software that you see the code for ENC_getElecAngle you should replace that function call with your function call that returns the electrical angle from the SPI encoder.

  • Adam,

    I also found interesting fact about the board if I am measuring noise on oscilloscope without connecting my encoder lines to board. I am seeing noise on the ABI lines on connector J4.

    is it normal?

    Tushar

  • Tushar,

    If you are getting electrical noise from your motor I would expect it to show up there.  Did you remove the resistors and capacitors next to J4?  These provide pull-up and filtering to help with some of these issues.

  • Adam,

    I am wrong about J4. It is noise free.

    I am getting noise between C2000 pins and U2(level translator). and I am accessing these pins from J5 connector. I see noise directly on controller lines. 

    I did not remove RC filters components.

    I am running lab12a

    Tushar

  • Tushar,

    It sounds like the noise in your system is probably coming in from the encoder lines.  You should try to setup some sort of shielding and move the lines away from the motor phase lines.

  • Hello, Adam,

    I will continue Tushar's work now.

    The following is our motor's parameters.

    #define USER_MOTOR_TYPE MOTOR_Type_Pm

    #define USER_MOTOR_NUM_POLE_PAIRS (6)

    #define USER_MOTOR_Rr (NULL)

    #define USER_MOTOR_Rs (8.284804344)

    #define USER_MOTOR_Ls_d (0.003350858)

    #define USER_MOTOR_Ls_q (0.003350858)

    #define USER_MOTOR_RATED_FLUX (0.124141)

    #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 (3.0)

    #define USER_MOTOR_FLUX_EST_FREQ_Hz (20.0)

    #define USER_MOTOR_ENCODER_LINES (3186.0)

    #define USER_MOTOR_MAX_SPEED_KRPM (2.0)

    #define USER_SYSTEM_INERTIA (0.016667)

    #define USER_SYSTEM_FRICTION (0.042809)

    We use 12V power for PVDD and do a test on the project 12a.

    Now we can get a correct encoder count from the SPI encoder chip. As you said before, we rewrite the ENC_getElecAngle function. Its return value will vary from 0 to 1 when rotating the motor 360 degree by hand. But it does not work. After enable the run_identity variable, the motor just spins about 25 degree, then it stops. At the same time the motor is easy to rotate by hand.

     

    In ENC_Setup function of the file enc.c, the following codes will set the gain variable:

    // compute the gain which translates the mech into the elec angle

    enc->mech_angle_gain = (_iq)((((uint32_t)1)<<24)/(4*num_enc_slots));

    In ENC_calcElecAngle function, the following codes will calculate the electrical angle:

    // compute the mechanical angle

     temp = (QEP_read_posn_count(enc->qepHandle))*enc->mech_angle_gain;

     // add in calibrated offset

    temp += enc->enc_zero_offset;

    // convert to electrical angle

    temp = temp * enc->num_pole_pairs;

    // wrap around 1.0 (Q24)

    temp &= ((uint32_t) 0x00ffffff);

    // store encoder electrical angle

    enc->enc_elec_angle = (_iq)temp;

    I think both of the above code segements are based on (angle = pairs * (count * gain + offset)). But where is the red "4" from? I wonder if it should be replaced by num_pole_pairs. my motor's num_pole_pairs is not 4, is 6.

    Problem 2:

    After enable the system, when I rotate the motor by hand, the variable st_obj.vel.conv.cfg.Pos_mrev will be added about 0.2, not varies from 0 to 1. when continue rotating the motor this variable will become bigger. it can be more than 1.

    I want to know if this variable is from the Spintac position converter module. I think my problem is related with this module.

    Besides where can I find some detailed PDF file about this module? For example its input format and output format, input variable names and output variable names in the example project code.

     

    Thank you

    Fei 

     

     

     

  • Fei,

    In InstaSPIN the electrical angle should vary from 0 to 1 for each electrical cycle.  So, your electrical angle should vary from 0 to 1 for each pole pair in your motor.  It also needs to be aligned so that a 0 reading from your encoder corresponds to a 0 electrical angle on the motor.  This alignment can be done during the Rs Recalibration phase.  When the system is doing the Rs Recalibration the motor is forced into alignment on a 0 degree electrical angle.

    In the ENC_setup function the red 4 is to account for the quadrature aspect of the encoder.  In quadrature encoders for each encoder slot, that translates into 4 counts.  But it should not be used for your SPI based encoder.

    When you read a value from your encoder, does it vary from 0 to 1 for one mechanical revolution of the motor?

    If the electrical angle that you are providing as an input to SpinTAC Position Converter does not cycle between 0 and 1 for each pole pair in your motor, than I would not expect that the Pos_mrev calculation will come out correctly.  

    I think the problem is in the electrical angle generation.

    There is quite a bit more detailed information about SpinTAC Position Converter in the InstaSPIN-FOC & -MOTION User's Guide.

  • Hello, Adam

    I am not very clear for the electrical angle. If my motor's pole pairs is 6, when spinning the motor one one mechanical revolution, the electrical angle will vary from 0 to 1 by 6 times? 

    Now the variable pos_mrev can vary from 0 to 1 when rotating one mechanical revolution. If I continue to rotate another one mechanical revolution, it will vary from 1 to 2. This is correct?

    Maybe I found an error. In my project the variable erev_TO_pu_ps is 5(IQ24). But in the user guide it should be less than 0.01. It is very big.

    USER_IQ_FULL_SCALE_FREQ_Hz     200

    ST_SAMPLE_TIME      (((1) * (15)) / ((float_t)(45.0) * 1000.0 / (float_t)(3)))

    USER_PWM_FREQ_kHz        45.0

    USER_NUM_PWM_TICKS_PER_ISR_TICK        3

    USER_NUM_ISR_TICKS_PER_CTRL_TICK      1

    USER_NUM_CTRL_TICKS_PER_SPEED_TICK  15

    Which parameter should I fix to make erev_TO_pu_ps valid?

    Thank you very much

    Fei

  • Fei,

    Yes, you should have the electrical angle vary once for each pole pair in your motor.  An easy way to do this it to have the mechanical angle vary between 0 and 1 for each mechanical rotation, multiply that value by 6, and and the resultant value with 0x00FFFFFF.  If you look at the ENC function that calculates the electrical angle, this is basically what it does.

    The variable Pos_mrev will vary between -10 and 10.  When it reaches 10 it will rollover to -10.  This will also increase the PosRollOverCount variable.  When it reaches -10 it will rollover to 10 and will decrease the PosRollOverCount variable.  

    The variable erev_TO_pu_ps should be 1 / (USER_IQ_FULL_SCALE_FREQ_Hz  * ST_SAMPLE_TIME).  So for most applications we see this as being about 1 / (500 *0.001) = 2.  I don't see it being set to 5 as a big problem.  

  • Hello, Adam,

    Thank you for your response! As you told me, I reset the encoder line number again, my motor can rotate now.

    Yesterday I tested the position control project(13a and 13b) on a control system without gear, the encoder sensor is installed on the motor shaft. Everything is good.

    Today I go back a control system with gear, the encoder sensor is installed on the gear shaft.

    The gear ratio is 72:14. It means that when the motor rotates 72 revolutions the gear rotates only 14 revolutions. 

    So for this gear system my encoder lines number should be set to 97(500*14/72 = 97.22, 500 is the default encoder lines number). There is an error because 0.22 is deleted.

    Problem1: How can I eliminate the influence from this above error?

    Problem2: When project 13a is tested on this gear system, everything is good. but when project 13b is tested, there is a problem. After the specified position movement is finished, the motor gets into a vibration state. This will last for a long time. A same scale parameter(4.0) is used for the project 13a and 13b. Also I adjust this parameter. It is not helpful.

    Maybe the problem 2 is related with the problem 1. How should I fix these two problems?

    Thank you

    Fei

  • Fei,

    I'm glad you were able to get the motor under position control.  

    Problem 1:

    What you will need to do is to add in compensation to manually correct for that error in the rotation.  This eQEP module on the chip assumes and integer number of lines, and so any fractional line counts need to be handled outside of that module.

    Problem 2:

    This is the backlash issue.  Since your encoder only reads when the gears turn, your motor is free to move inbetween the teeth of the gears.  So your motor is moving without the encoder sensing this movement.  This is why it is vibrating.

    So both of these problems are related.  My advice would be to mount the encoder directly on the shaft of the motor.  This will resolve both issues.  You could also address Problem 1 by adding in the fractional line compensation I talked about above and Problem 2 could be addressed by adding deadband compensation.  Adding in this deadband compensation would be pretty difficult since it would require you to set the controller output to zero unless a sufficiently large error has been noticed.  You would also need to provide this zero value back to SpinTAC so that is doesn't have issues with the state estimation.

  • Hello, Adam,

    I am using the project 13b to test the position transition. Also I add the UART driver into this project. I want to send a position commands through the UART channel every 5ms. These command characters will be received in an interrupt function. Then they will be processed in the while loop.

    (1) When I do not enable the gMotorVars.Flag_enableSys and gMotorVars.Flag_Run_Identify, all UART commands can be received and processed correctly. But once enabling the 2 variables, some commands or some command characters are lost.

    (2) Last week I found that it will take about 100ms(according to the gMotorVars.SpinTAC.PosMoveStatus flag) to finish a 0.001 revolution transition for my motor. Of course It's 

     maximum speed (gMotorVars.MaxVel_krpm) is not very high. But this time is very long in truth.

    Can you give me some ideas to solve the above problems?

    Thank you

    Fei

  • Fei,

    1. What is most likely happening is that the mainISR that is doing the motor control is preventing your UART isr from receiving characters.  You will need to look at the F28069 Technical Reference Guide for more information about setting up your interrupts.  

    2.  When you timed that did you use the watch window or did you use the CPU timer?  Also we provide an output that will tell you how long a movement will take.  It is provided in gMotorVars.SpinTAC.PosMoveTime_ticks.  This is how many position loop samples it will take to complete the transition.  The other option is to increase the acceleration, deceleration, and jerk limits.  These limits are what sets up the profile and by increasing them the profile will complete faster.

  • Thank you, Adam,

    I set the uart interrup as the mainISR interrupt.

    For the position transition time, I tried a continuous position transition, the time frequency to send out a new position move command is set to 10HZ. At this time the motor works like continuous spin. If I increase the frequency I can detect that  sometime the gMotorVars.SpinTAC.PosMoveStatus will not be ST_MOVE_IDLE before sending out a new position command. Now the gMotorVars.SpinTAC.PosMoveTime_ticks variable is 89.

    What is the unit of gMotorVars.SpinTAC.PosMoveTime_ticks?  how many position loop samples? what means this?

    Thank you 

    Fei

  • Fei,

    So you are doing your UART processing in the mainISR?

    The unit of gMotorVars.SpinTAC.PosMoveTime_ticks is how many position loop samples.  The position loop sample time is defined by ST_SAMPLE_TIME in spintac_position.h.  This is calculated from: 

    (USER_NUM_ISR_TICKS_PER_CTRL_TICK * USER_NUM_CTRL_TICKS_PER_SPEED_TICK) / USER_ISR_FREQ_Hz

  • Adam,

    I configure the uart interrupt as a different interrupt with the mainISR. So there are 2 different interrupts, the first one is mainISR, the other one is UART RX.

    I received the uart bytes through the uart rx routine, but I will process these bytes in the while loop of the main function.

    The current ST_SAMPLE_TIME is 1ms. So the time to finish a 0.001 revolution move is 86ms.

     

    Thank you

     

    Fei

  • Hi.

    I'm taking over the project that Tushar was working on...

    However, I don't have his data or files... All I have is the history in this forum...

    When I run FOC Lab02a, the first run goes fine, apparently, but when I re-enable the Identify flag for the second run, the motor will not spin correctly. It basically just shakes a lot with very little if any spin.

    Can you please tell me what you think may be wrong?

    If you need any of my user.h params, please just let me know.

    Thanks!

    Jim

  • Sorry for the thread hijack---I'm re-posting in a new thread...

    Moderator Edit - the new thread is here: https://e2e.ti.com/support/microcontrollers/c2000/f/902/t/437591