cancel
Showing results for 
Search instead for 
Did you mean: 

Why he motor start with MC_OVER_CURR error?

Junde
Senior III

Hi there,

I have a DIY board similar to EVSPIN32G4. Below is the three-shunt sensing circuit(In internal OpAmps, differential, external gain mode)

Junde_0-1764138125903.png

Because the STSPING4 doesn't support internal OpAmps, differential, external gain mode, I just use the below config to generate the project(seems differential or single-end does not influence the code, yes?), see the project in the attachment:

Junde_1-1764138515887.png  Junde_2-1764138530032.png

And because the EVSPIN32G4 project's encoder and hall sensor use the same GPIO, I only enable the encoder in the MCSDK project.

After generating the code, I added the hall signal pin in STM32CubeMx and then compiled the MDK project successfully.

I added some code trying to find out why the motor isn't working:

uint8_t MC_GetHallValM1(void)
{
    uint8_t M_Hall_val;
    M_Hall_val = (M_Hall_val & 0xFE) | HAL_GPIO_ReadPin(M_HALL_U_GPIO_Port, M_HALL_U_Pin);
    M_Hall_val = (M_Hall_val & 0xFD) | (HAL_GPIO_ReadPin(M_HALL_V_GPIO_Port, M_HALL_V_Pin) << 1);
    M_Hall_val = (M_Hall_val & 0xFB) | (HAL_GPIO_ReadPin(M_HALL_W_GPIO_Port, M_HALL_W_Pin) << 2);
    return M_Hall_val;
}
uint8_t get_hal_val(void)
{
    static uint8_t M_Hall_val_pre = 0;
    uint8_t M_Hall_val = MC_GetHallValM1();
    if(M_Hall_val != M_Hall_val_pre) {
        M_Hall_val_pre = M_Hall_val;
        LOG_DBG("HALL[%d], elAngle[%d]\n", M_Hall_val, MC_GetElAngledppMotor1());
    }
    return M_Hall_val;
}

void check_state(void)
{
    static MCI_State_t pre_state = IDLE;
    static uint16_t pre_occFault = MC_NO_ERROR, pre_curFault = MC_NO_ERROR;
    static MCI_CommandState_t pre_cmdState = MCI_BUFFER_EMPTY;
    
    MCI_State_t state;
    uint16_t occFault, curFault;
    MCI_CommandState_t cmdState;
    
    state = MC_GetSTMStateMotor1();
    occFault = MC_GetOccurredFaultsMotor1();
    curFault = MC_GetCurrentFaultsMotor1();
    cmdState = MC_GetCommandStateMotor1();
    if((pre_state != state) || (pre_occFault != occFault) || (pre_curFault != curFault) || (pre_cmdState != cmdState)) {
        LOG_DBG("%4dms, sta[%2d], occF[0x%02X], curF[0x%02X], cmdSta[%d]\n", HAL_GetTick(), state, occFault, curFault, cmdState);
        pre_state = state;
        pre_occFault = occFault;
        pre_curFault = curFault;
        pre_cmdState = cmdState;
    }
}

void debug_motor_err(void)
{
    bool sta_StartM1;
    
    get_hal_val();
    check_state();
    
    sta_StartM1 = MC_StartMotor1();
    LOG_DBG("MC_StartMotor1[%s]\n", sta_StartM1==true?"true":"false");
    
    check_state();
    
    while(1) {
        get_hal_val();
        check_state();
    }
}

I call the debug_motor_err() after MX_NVIC_Init();

And then this code outputs the following LOG:

00> HALL[2], elAngle[0]
00>    4ms, sta[ 0], occF[0x00], curF[0x00], cmdSta[1]
00> MC_StartMotor1[true]
00>    4ms, sta[16], occF[0x00], curF[0x00], cmdSta[1]
00>   14ms, sta[ 0], occF[0x00], curF[0x00], cmdSta[1]
00>   16ms, sta[17], occF[0x00], curF[0x00], cmdSta[1]
00>   16ms, sta[16], occF[0x00], curF[0x00], cmdSta[1]
00>   26ms, sta[ 2], occF[0x00], curF[0x00], cmdSta[1]
00> HALL[6], elAngle[16384]
00> HALL[4], elAngle[16384]
00> HALL[5], elAngle[16384]
00>  727ms, sta[20], occF[0x00], curF[0x00], cmdSta[1]
00> 1127ms, sta[ 6], occF[0x00], curF[0x00], cmdSta[2]
00> 1127ms, sta[ 6], occF[0x00], curF[0x00], cmdSta[0]
00> 1127ms, sta[ 6], occF[0x40], curF[0x40], cmdSta[0]
00> 1128ms, sta[10], occF[0x40], curF[0x00], cmdSta[0]
00> 1129ms, sta[11], occF[0x40], curF[0x00], cmdSta[0]

From the LOG, we can see that the hall valve has been changed (the motor is always stopped at a special position where the hall value is 5), and finally it stops.

What's the reason for the error MC_OVER_CURR? How can I resolve it?

BTW, if I change ".DAC_OCP_Threshold = 7427," to ".DAC_OCP_Threshold = 9000,", the motor will be shocked after start. Where does the value 7427 come from?

I am a newbie in motor control. If anything isn't clear, please inform me.

Thank you very much for your help!

 

 

 

 

0 REPLIES 0