Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
AndreaB
Level 2
Level 2
First like received 5 questions asked 10 sign-ins

Hello, 

I am working with KIT_A2G_TC387_MOTORCTR board and motor manager by demo FOC control. I started from demo code but I have configured CAN communication in order to receive target speed from CAN. In my application I have also implemented a component that takes target speed from CAN and calculates reference speed for FOC using a custom, specific ramp of values. 

All it is working fine if I set a positive value of reference speed but when I set a negative one, the motor starts moving on backward side but with some spikes in which is moving forward. Since FOC software is based on demo code (I have made no changes in FOC, adc or pwm code) and it is implemented to control the motor with speeds from 0 to 6000 rpm, I would like to know which change I have to do in the demo code to allow also negative value of speed, removing the above mentioned spikes.

 

Thanks,

Andrea

1 Solution
gecmar
Employee
Employee
5 solutions authored 10 replies posted 10 sign-ins

Hello Andrea,

In function void PmsmFoc_initControlVariables(MotorControl* const motorCtrl) modifiy q-axis current PI controller settings:

Ifx_PicF32_setKpKi(&motorCtrl->pmsmFoc.piIqUSER_MOTOR_PI_IQ_KPUSER_MOTOR_PI_IQ_KI, USER_MOTOR_PI_IQ_CONTROL_PERIOD);

Modify following in PmsmFoc_Motor_Nanotec_DB42S02.h:

#define USER_MOTOR_SPEED_LOW_LIMIT_RPM (0.0f)

#define USER_MOTOR_KID_MULTI (0.001f)
#define USER_MOTOR_KIQ_MULTI (0.001f)

Change GPT12 initialization in void PmsmFoc_Gpt12_initGpt12(IfxGpt12_IncrEnc* gpt12IncrEnc):

gpt12Config.base.resolutionFactor = IfxStdIf_Pos_ResolutionFactor_fourFold;

Add following:

sint32 resolution = gpt12IncrEnc->resolution - 1;
IfxGpt12_T2_setMode(&MODULE_GPT120,IfxGpt12_Mode_reload);
IfxGpt12_T2_setTimerValue(&MODULE_GPT120,resolution);
IfxGpt12_T2_setReloadInputMode(&MODULE_GPT120,IfxGpt12_ReloadInputMode_bothEdgesTxOTL);

Remove following:

//IfxGpt12_T3_setIncrementalInterfaceInputMode(&MODULE_GPT120, IfxGpt12_IncrementalInterfaceInputMode_bothEdgesTxEUD);
//IfxGpt12_T4_setRemoteControl(&MODULE_GPT120, IfxGpt12_TimerRemoteControl_on);

In function PmsmFoc_PositionAcquisition_updatePosition(PositionAcquisition* positionAcquisition) modify position calculation:

position= ((rawPosition * (uint32)USER_MOTOR_POLE_PAIR * (uint32)COSSIN_TABLE_SIZE) / encoder->resolution) & (uint32)(COSSIN_TABLE_SIZE-1);

Best regards

View solution in original post

13 Replies
AndreaB
Level 2
Level 2
First like received 5 questions asked 10 sign-ins

Anyone could help me?

It is very important for my application.. Hope it is possible with this code..

Andrea

0 Likes
gecmar
Employee
Employee
5 solutions authored 10 replies posted 10 sign-ins

Hello Andrea

In OsTasks.c find static __attribute__((__noreturn__)) void periodicSpeedControlTask(void *arg) and remove lines with limits related to motorTargetSpeed. 

If you want to set negative speed reference using touch screen, in addition you need to remove limits in Menue_SpeedMnsSel function, which can be found in menue.c

Best regards

0 Likes
lock attach
Attachments are accessible only for community members.
AndreaB
Level 2
Level 2
First like received 5 questions asked 10 sign-ins

Hello,

thanks for your response.

I have already tried to do it but what I am seeing is that I still see some spikes (see image attached.. in which I am seeing the variable g_motorControl.pmsmFoc.speedControl.measSpeed).

if I set positive values or rpm, I get no issue.

Seems a PI controller issue.. maybe into configuration but I am not sure..

0 Likes
gecmar
Employee
Employee
5 solutions authored 10 replies posted 10 sign-ins

Hello Andrea,

In function void PmsmFoc_initControlVariables(MotorControl* const motorCtrl) modifiy q-axis current PI controller settings:

Ifx_PicF32_setKpKi(&motorCtrl->pmsmFoc.piIqUSER_MOTOR_PI_IQ_KPUSER_MOTOR_PI_IQ_KI, USER_MOTOR_PI_IQ_CONTROL_PERIOD);

Modify following in PmsmFoc_Motor_Nanotec_DB42S02.h:

#define USER_MOTOR_SPEED_LOW_LIMIT_RPM (0.0f)

#define USER_MOTOR_KID_MULTI (0.001f)
#define USER_MOTOR_KIQ_MULTI (0.001f)

Change GPT12 initialization in void PmsmFoc_Gpt12_initGpt12(IfxGpt12_IncrEnc* gpt12IncrEnc):

gpt12Config.base.resolutionFactor = IfxStdIf_Pos_ResolutionFactor_fourFold;

Add following:

sint32 resolution = gpt12IncrEnc->resolution - 1;
IfxGpt12_T2_setMode(&MODULE_GPT120,IfxGpt12_Mode_reload);
IfxGpt12_T2_setTimerValue(&MODULE_GPT120,resolution);
IfxGpt12_T2_setReloadInputMode(&MODULE_GPT120,IfxGpt12_ReloadInputMode_bothEdgesTxOTL);

Remove following:

//IfxGpt12_T3_setIncrementalInterfaceInputMode(&MODULE_GPT120, IfxGpt12_IncrementalInterfaceInputMode_bothEdgesTxEUD);
//IfxGpt12_T4_setRemoteControl(&MODULE_GPT120, IfxGpt12_TimerRemoteControl_on);

In function PmsmFoc_PositionAcquisition_updatePosition(PositionAcquisition* positionAcquisition) modify position calculation:

position= ((rawPosition * (uint32)USER_MOTOR_POLE_PAIR * (uint32)COSSIN_TABLE_SIZE) / encoder->resolution) & (uint32)(COSSIN_TABLE_SIZE-1);

Best regards

AndreaB
Level 2
Level 2
First like received 5 questions asked 10 sign-ins

Many thanks! it is working fine now.

could you please explain me the meaning of these changes?

Thanks a lot!

0 Likes
gecmar
Employee
Employee
5 solutions authored 10 replies posted 10 sign-ins

Hello Andrea,

  • In BIFACES project you have, in readme.txt it's written that software is tested only with positive speed reference. Now, we removed limits. The limit of 6000rpm comes from increment encoder maximum speed.
  • The q-axis PI controller settings has typo in original source
  • By selecting IfxStdIf_Pos_ResolutionFactor_fourFold we have increased resolution. More information about GPT12 incremental interface mode and T2 reload mode one can find in GPT12 chapter in User Manual. 
  • Size of the cosine & sine lookup table is defined by COSSIN_TABLE_SIZE and we need to scale rawPosition from incremental encoder software driver. Scaled position is used in Park and Inverse Park calculations

Best regards

0 Likes
AndreaB
Level 2
Level 2
First like received 5 questions asked 10 sign-ins

Thanks for the explanation.

Some additional point, if possible:

  1. I have seen that the variable g_motorControl.inverter.highSideCurrentSense.input.value contains the value of the current absorption of the board. From the code seems that INA gain and shurt resistor value are already considered in calculation so I am expecting that the value in that structure is in Ampere but it is not actually the value measured putting an amperometer in series to 12V power supply
  2. how can I have an average value of the current?

Thanks,

Andrea

0 Likes
gecmar
Employee
Employee
5 solutions authored 10 replies posted 10 sign-ins

Hello Andrea,

Please, check the power board schematic in AP32541_AURIX_TC3xx_Motor_Control_Power_Board_v1.0.1. 

The TC387 Application Kit with TFT is also supplied from power board, that could be the reason for difference in your and measurement by using high-side DC-link shunt .

Best regards

0 Likes
AndreaB
Level 2
Level 2
First like received 5 questions asked 10 sign-ins

Hello,

thanks for the answer.

So is there a way to get the overall current consumption of the board? Is it measured?

Thanks,

0 Likes
NamDo
Level 2
Level 2
First like received 10 likes given 10 sign-ins

Hi gecmar, 

I've tried to comment out the lines in OsTask.c find static_attribute__((__noreturn__)) void periodicSpeedControlTask(void *arg) for the motorTargetSpeed already. However, I'm not sure what limits should I remove in Menue_SpeedMnSel function. Should I remove refSpeed limit? Can you please advise? 

NamDo_1-1664452253218.png

 

 

 

 

0 Likes
gecmar
Employee
Employee
5 solutions authored 10 replies posted 10 sign-ins

Hello NamDo,

you can comment lines as shown below or make your own limits.

//if(refSpeed > 0.0f)

refSpeed = refSpeed - 100.0;

//else

//refSpeed = 0;

 

Best regards,

Gecmar

NamDo
Level 2
Level 2
First like received 10 likes given 10 sign-ins

Hi gecmar, thank you and I appreciate your prompt response!

The current problem I have is that: when I decrease ref speed to 0 rpm by using the "speed decrease" button on the screen. If I continue to hit the same button, the ref speed increase to a positive number instead of decreasing lower than 0. 

Could there be another place where refSpeed limit is define that I might've missed? 

0 Likes
NamDo
Level 2
Level 2
First like received 10 likes given 10 sign-ins

Hi AndreaB, I saw your post and I am very interested in your work, I'm curious how did you set up CAN communication so that the motor can receive target speed from CAN?