cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing Quadrature Encoder with Motor Workbench

msalazar
Associate II

Hi,

I am currently utilizing the MC Workbench (6.4.2) with an B-G431-ESC1 to drive a custom DC brushless motor. I've been able to successfully to control the motor and generate a motor profile when using the sensor-less option for speed control but when I select Quadrature and generate a package I can't seem to get the motor spin.

I realize that there is lot of information that is needed to debug this problem so let's start simple, is there a guide or what steps can I take to successfully generate code from with sensor option being selected, is the bring-up for getting the motor to spin just as simple? Typically something along the lines of is sufficient if the motor does not fault:

MC_ProgramSpeedRampMotor1(1500, 1000);
MC_StartMotor1();


I can provide the entire project if needed but I am not to sure if this is a firmware or hardware problem. From reading logs generated by the uC's UART channel I can see that M1_ENCODER_Z is behaving correctly and I believe the same is true for M1_ENCODER_(A/B).

Note that the "Encoder" log in the PuTTy screenshot is updated if the motor is rotated physically without the coils being energized i.e. device is only powered through the Micro-USB port.

while (1)
  {
    if (!initMotor)
    {
        HAL_UART_Transmit(
            &huart2,
            (uint8_t*)msg,
            strlen(msg),
            100
        );

        MC_ProgramSpeedRampMotor1(1500, 1000);
        MC_StartMotor1();

        initMotor = 1;
    }

    static uint32_t lastPrint = 0;

    if (HAL_GPIO_ReadPin(M1_ENCODER_Z_GPIO_Port, M1_ENCODER_Z_Pin))
    {
       HAL_UART_Transmit(
            &huart2,
            (uint8_t*)z_msg,
            strlen(z_msg),
            100
        );
    }

    if ((HAL_GetTick() - lastPrint) >= 1000)
    {
        lastPrint = HAL_GetTick();

        char debugMsg[128];

        sprintf(
            debugMsg,
            "State=%d Fault=0x%04X Encoder=%ld\r\n",
            MC_GetSTMStateMotor1(),
            MC_GetCurrentFaultsMotor1(),
            (int32_t)__HAL_TIM_GET_COUNTER(&htim4)
        );

        HAL_UART_Transmit(
            &huart2,
            (uint8_t*)debugMsg,
            strlen(debugMsg),
            100
        );
    }

    /* USER CODE END WHILE */
    
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}



msalazar_0-1780442236291.png

 




0 REPLIES 0