cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting the L6474 motor driver to an STM32F3

DJans.1
Associate

Hi everyone,

I am trying to control the L6474 motor driver via an STM32F3 mcu. I am not using the default shield for it, but have it connected directly to the mcu. I know the connection is correct, as this has previously, and still will, work with a different project. However, in my own project, after I configured the registers of the L6474 and turn on the PWM signal, I hear the motor keep enabling itself repeatedly without moving.

The code in the main, after STM's own initialization is as follows:

MotorDriver *mc = new MotorDriver();
  mc->initMotorController(&hspi1, GPIOB, GPIO_PIN_6, GPIOA, GPIO_PIN_9, GPIOA, GPIO_PIN_8);
 
//  mc->ReleaseReset();
  mc->SendCommand(0, L6474_DISABLE);
  mc->CmdGetStatus(0);
  mc->CmdSetParam(0, L6474_TVAL, 0b1111110);
  mc->SendCommand(0, L6474_ENABLE);
  mc->SetDirectionGPIO((GPIO_PinState)1);
  uint8_t tval = mc->CmdGetParam(0, L6474_TVAL);
  volatile uint16_t status = mc->CmdGetStatus(0);
  volatile int x = tval;
 
  HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2)
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

The initMotorController looks like this:

void MotorDriver::initMotorController(SPI_HandleTypeDef *spi_HandleTypeDef, GPIO_TypeDef* motorSpiCsPort, int motorSpiCsPin,
		GPIO_TypeDef *resetPort, int resetPin, GPIO_TypeDef *directionPort, int directionPin)
{
    l6474DriverInstance = 0;
	numberOfDevices		= 1;
	SpiHandler 			= spi_HandleTypeDef;
	GPIO_SPI_CS_Port	= motorSpiCsPort;
	GPIO_SPI_CS_Pin		= motorSpiCsPin;
 
	GPIO_ResetPort		= resetPort;
	GPIO_ResetPin		= resetPin;
	GPIO_DirectionPort	= directionPort;
	GPIO_DirectionPin	= directionPin;
 
	ReleaseReset();
 
	CmdSetParam(0, L6474_TVAL, Tval_Current_to_Par(250));
	CmdSetParam(0, L6474_T_FAST,
			  (uint8_t)L6474_TOFF_FAST_8us |
			  (uint8_t)L6474_FAST_STEP_12us);
	CmdSetParam(0, L6474_TON_MIN, Tmin_Time_to_Par(3));
	CmdSetParam(0, L6474_TOFF_MIN, Tmin_Time_to_Par(21));
	CmdSetParam(0, L6474_OCD_TH, L6474_OCD_TH_750mA);
	CmdSetParam(0, L6474_STEP_MODE,
			  (uint8_t)L6474_STEP_SEL_1_16 |
			  (uint8_t)L6474_SYNC_SEL_1_2);
	CmdSetParam(0, L6474_ALARM_EN, L6474_ALARM_EN_OVERCURRENT |\
            L6474_ALARM_EN_THERMAL_SHUTDOWN |\
            L6474_ALARM_EN_THERMAL_WARNING |\
            L6474_ALARM_EN_UNDERVOLTAGE |\
            L6474_ALARM_EN_SW_TURN_ON |\
            L6474_ALARM_EN_WRONG_NPERF_CMD);
	CmdSetParam(0, L6474_CONFIG,
			  (uint16_t)L6474_CONFIG_INT_16MHZ |
			  (uint16_t)L6474_CONFIG_EN_TQREG_TVAL_USED |
			  (uint16_t)L6474_CONFIG_OC_SD_ENABLE |
			  (uint16_t)L6474_CONFIG_SR_320V_us |
			  (uint16_t)L6474_CONFIG_TOFF_044us);
 
	SendCommand(l6474DriverInstance, L6474_DISABLE);
 
    /* Get Status to clear flags after start up */
    CmdGetStatus(l6474DriverInstance);
}

I am fairly positive that the registers are being set correctly, as they all seem to contain the given value when I request the parameters.

When I debug the code, it also looks like the software keeps rebooting itself, as I keep landing on a breakpoint in the main function, outside of the loop, repeatedly.

Edit 1:

The project was generated using the STM32CubeMX software. The project runs on a STM32F303RCT. For the motor I am using a 17hs4401 stepper motor. It gets compiled using the SW4STM32 toolchain. The firmware package is STM32Cube FW_F3 V1.10.0. About the rest of the hardware, I can only generally say that it is functional and that I know I am writing to the right GPIO. It was designed in house by our hardware engineer. I hope that is sufficient extra information.

Edit 2:

The continuously restarting of the application seems to have been fixed by refreshing the watchdog in the main while loop. I've started the PWM, but it does not seem to be effective. Since I currently do not have the tools to check whether I see the PWM signal on the port, I can't say whether it is not started in the software or not used by the L6474.

Edit 3:

I almost feel stupid for saying this, but after some research I have found that elsewere in code that I reused from another project, the overcurrent threshold was set way below the torque value. Causing it to flag an over current and disable the driver. I did not see this in the status register, as I was reading this before the over current was flagged. It was a silly mistake and has been fixed now.

3 REPLIES 3
Laurent Ca...
Lead II

Dear @Daniel.Jsen​ 

Welcome to the STM32 Community

Could you give more details to the STM32 Community about your setup?

That is to say the material you use (HW and also SW): CPU(s), board(s), motor(s), tools and versions, and so on.

And more especially did you use STM32 MC tools and what version of those tools you use (such as MC_suite, STM32 MC Motor Profile, STM32 MC SDK, STM32 MC Workbench, the used example, the origin of the base of your application source code, and so on)?

Please do not forget to also indicate the compilation tools suite you use (with the version number).

Best regards

DJans.1
Associate

Dear @Laurent Ca...​ 

Thank you for your response. I have added some extra information. I hope this is sufficient!

Laurent Ca...
Lead II

Dear @Daniel.Jsen​ 

According to your edit 1, you use a stepper motor.

My team is working on the STM32 MC-SDK tools suite that is support FOC and also partially 6-steps, and not stepper motors.

Therefore I pass your question on to engineers who may be able to help you.

Otherwise I hope the STM32 community will be able to help you.

Best regards