Based on STM32CUBEMX drive low-voltage stepper motor driver STSPIN220 (2) ---- drive STSPIN220

Kit overview

The goal of this document is to provide detailed information and how-to instructions on using STM32CubeMX to drive a low-voltage stepper motor driver STSPIN220. Through this document, you will learn how to use STM32CubeMX to configure the motor driver, and how to achieve precise control and motion of the stepper motor.

I am currently taking ST courses, and those who need samples can join the group application: 615061293.
insert image description here

sample application

https://www.wjx.top/vm/PpC1kRR.aspx

video teaching

https://www.bilibili.com/video/BV1Ju4y1R7mA/

Based on STM32CUBEMX drive low-voltage stepper motor driver STSPIN220 (1) ---- drive STSPIN220

STSPIN220 Description

The STSPIN220 is a highly integrated chip designed specifically for stepper motors. Its unique features and functions allow it to combine control logic and low RDS(on) power stage in a small VFQFPN 3 x 3 x 1.0 mm package for motors. The field of control offers an excellent solution.
Integrated control logic and low RDS(on) power stage: STSPIN220 integrates efficient control logic and low RDS(on) power stage, which means it can drive stepper motors in an efficient manner, resulting in lower energy consumption and higher performance.
Micro-step resolution and PWM current control: The chip's built-in controller makes full use of the fixed off-time and up to 1/256 step micro-step resolution to achieve precise PWM current control. This means that finer stepper motor motion control can be achieved to meet the needs of different applications.
Battery-powered and zero-power modes: The STSPIN220 is designed with battery-powered scenarios in mind, and can be forced into a zero-power state to prolong battery life in battery-powered situations. This is especially useful in mobile devices and portable applications.
A full set of protection mechanisms: The chip provides a comprehensive protection mechanism, including over-current protection, over-temperature protection and short-circuit protection. These protection mechanisms can ensure the stable and safe operation of the stepper motor under various abnormal conditions, effectively protecting the reliability of the system.
To sum up, STSPIN220, as a chip specially designed for stepper motors, integrates a variety of advanced functions in a small package. It provides an efficient, precise and safe drive solution for stepper motor applications with integrated control logic, micro-stepping resolution and a full set of protection mechanisms, suitable for a variety of application fields, from industrial automation to portable equipment. Whether it's power saving, precise control or extended battery life, the STSPIN220 brings reliable performance and great results to your projects.

insert image description here

All functions of STSPIN220

As a chip specially designed for stepping motors, STSPIN220 has many excellent features and provides a highly reliable solution for the field of motor control:
Wide range of operating voltage: STSPIN220 supports a wide range of operating voltages, from 1.8V to 10V , which means it is suitable for a variety of different power supply scenarios, from low voltage to standard voltage range.
High output current capability: The maximum output current of 1.3 Arms enables the STSPIN220 to drive stepper motors with higher current demands, ensuring that the motors can move with sufficient force.
Low RDS(ON) value: The chip's high and low side current sensors and MOSFETs have a low RDS(ON) value of only 0.4Ω (typ.). This reduces power consumption and heat loss, increasing the efficiency and performance of the motor.
Fine micro-stepping control: STSPIN220 can achieve micro-stepping up to 1/256 per step, which makes the movement of stepper motors smoother and more precise, suitable for applications that require high-precision control.
Current Control Through Programmable Off-Time: The chip implements current control with programmable off-time, which can adjust the current to the motor according to the application requirements for optimum performance.
Complete Protection Mechanisms: STSPIN220 provides comprehensive protection mechanisms including non-dissipative overcurrent protection, short circuit protection and thermal shutdown. These protection mechanisms ensure that both the motor driver and the stepper motor can operate safely under abnormal conditions.
Very Low Standby Power Consumption: The chip consumes less than 80 nA in standby mode, making it ideal for applications requiring power savings and extended battery life.

In summary, STSPIN220 provides an advanced solution for stepping motor drive with its wide operating voltage range, high output current capability, micro-stepping control, current control mode, protection mechanism and low standby power consumption . Whether in terms of performance, efficiency or power management, the STSPIN220 brings outstanding performance and reliability to stepper motor applications.

insert image description here

basic configuration

For small current motors, R10 is changed to below 10K, here it is set to 5.1k
insert image description here

REF

REF is the reference voltage, the maximum range is -0.3-1V
insert image description here

current configuration

The configuration formula is shown in the figure below.
insert image description here

It can be seen that R_SNS is 0.68R. If 200mA is set, then V_REF=0.68R*200MA=136mV, which is consistent with the V_REF=136mV mentioned above.
insert image description here

subdivision configuration

STSPIN provides a maximum of 256 subdivision operations, and the specific configuration is as follows.
insert image description here

I/O configuration

Looking at the schematic diagram, there are mainly 6 IOs that need to be configured.
They are STBY, EN, MODE1, MODE2, MODE3, MODE4.
insert image description here

The IO description is as follows.
Among them, EN\FAULT is the enable pin, which needs to be configured as an open-drain output.
STSPIN220 works normally when high level is enabled.
insert image description here
insert image description here
The figure below is a schematic diagram of setting subdivision. STBY is a state in the STSPIN220 driver, which means the standby state (Standby). In standby mode, the drive may reduce power consumption and stop performing stepper operations to save energy when stepper motor motion is not required. When the drive exits from standby, the value of the MODE input is taken. It should be noted that both MODE1 and MODE2 are forced to full-step mode when they are low.
insert image description here
insert image description here

The startup sequence diagram is shown below, and the specific steps are as follows.

  1. Power up: First, power up the driver, i.e. connect the VS supply voltage to the driver. But keep both STBY and EN/FAULT inputs low.
  2. Set MODEx input: Set the state of the MODEx input pin according to the target step resolution (see Table 1). These pins determine the microstep motion mode of the stepper motor.
  3. Wait: Wait at least 1 microsecond (t MODEsu minimum time). This waiting time is the time to ensure that the MODEx input is set stably.
  4. Set STBY pin high: Set STBY pin to high level. This will cause the previously set MODEx configuration to be latched inside the device.
  5. Wait: wait at least 100 microseconds (t MODEho minimum time). This wait time is the time to ensure that the MODEx configuration is properly latched.
  6. Enable Power Stage: Release the EN/FAULT input to enable power stage operation. This means the drive is ready to perform a step operation.
    By following this recommended power-up sequence and setup process, you can ensure that the states of the various inputs are stable and the microstepping mode configuration is properly latched before the driver begins operating, allowing for precise control of the stepper motor. This process helps reduce potential startup issues and instability.

insert image description here

The specific configuration is as follows.

insert image description here
STSPIN220 enable, low power consumption, direction initialization are shown below.

//使能操作 1使能0失能
void STSPIN220_enable(uint8_t enable)
{
    
    
	if(enable)
		HAL_GPIO_WritePin(en_GPIO_Port, en_Pin, 1);
	else
		HAL_GPIO_WritePin(en_GPIO_Port, en_Pin, 0);

}

//方向设置 0反1正
void STSPIN220_setDirection(uint8_t direction)
{
    
    
	if(direction)
		HAL_GPIO_WritePin(mode4_GPIO_Port, mode4_Pin, 1);		
	else
		HAL_GPIO_WritePin(mode4_GPIO_Port, mode4_Pin, 0);		
}
//低功耗模式 1使能0失能
void STSPIN220_Stby(uint8_t stby)
{
    
    
	if(stby)
		HAL_GPIO_WritePin(stby_GPIO_Port, stby_Pin, 0);		
	else
		HAL_GPIO_WritePin(stby_GPIO_Port, stby_Pin, 1);	


}

Timer configuration

In STM32CUBEMX, select Timer 1 and configure it as PWM output mode. Make sure the correct timer channel (channel 4) is selected.
insert image description here

Configure the clock source and prescaler factor of Timer 1. According to the requirements of the application and the system clock frequency, select the appropriate clock source and prescaler factor to obtain the required pulse frequency. Configure the clock source and prescaler factor for Timer 1 to values ​​appropriate for your application.
The PWM frequency calculation is shown below.
insert image description here

In the above configuration, the prescale factor of Timer 1 is set to 48-1, and the auto-reload value is set to 1000-1. From these configurations, the frequency of the PWM can be calculated as 48,000,000 / ((48-1+1) * (1000-1+1)) = 1000Hz, which is 1kHz.
In timers, the "pulse" of a channel refers to a characteristic of the signal output by the timer. Each timer channel can be used to generate a pulse signal, and "pulse" usually refers to the duration of a single pulse. In this setup, we configure the pulse to have a duty cycle of 50%, so the setting is 500-1.

insert image description here

Initialize mode

Since the mode needs to be initialized, the main operation is 4 IO ports, so it is necessary to first initialize the IO of the mode3 pins to normal IO, and then switch to the TIM mode.

/* USER CODE BEGIN 4 */
void MX_GPIO_Init_mode3(void)
{
    
    

  GPIO_InitTypeDef GPIO_InitStruct = {
    
    0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(mode3_GPIO_Port, mode3_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : PAPin PAPin PAPin PAPin
                           PAPin */
  GPIO_InitStruct.Pin = mode3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

/* USER CODE END 4 */

Note that the function needs to be declared.

/* USER CODE BEGIN 0 */
void MX_GPIO_Init_mode3(void);
/* USER CODE END 0 */

At the same time, the timer initialization needs to be closed.
insert image description here

After the mode3 is initialized, en and stby settings need to be set, as shown below.

  /* USER CODE BEGIN 2 */
	MX_GPIO_Init_mode3();
	HAL_Delay(100);

	STSPIN220_SetStepMode(0);//mode1-mode4都关闭
	STSPIN220_enable(0);//使能操作 1使能0失能
	STSPIN220_Stby(1);//低功耗模式 1开启低功耗0关闭低功耗
	HAL_Delay(100);

	STSPIN220_SetStepMode(2);//细分操作
	STSPIN220_Stby(0);//低功耗模式 1开启低功耗0关闭低功耗,加载mode
	HAL_Delay(100);//等待电平稳定
	STSPIN220_setDirection(1);//0反1正
	HAL_Delay(100);//等待电平稳定
	STSPIN220_enable(1);//使能操作 1使能0失能
	HAL_Delay(100);
	
    MX_TIM1_Init();
	HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);

  /* USER CODE END 2 */

Guess you like

Origin blog.csdn.net/qq_24312945/article/details/132149124