STM32 (HAL) impulsa la rotación hacia adelante y hacia atrás del motor paso a paso a través del chip UN2003

Tabla de contenido

1. Introducción

2. Configuración Cubemax

2.1 Configuración del RCC

 2.2 Configuración del sistema

 2.3 Configuración GPIO

 2.4 Generar archivos

 3. Conexión de hardware

4. Integración del código Keil

4.1 Definición de macros

4.2 agregar fun.c func.h


1. Introducción

La microcomputadora de un solo chip STM32F103C8T6 (modo de biblioteca HAL) controla la rotación positiva y negativa del motor paso a paso a través del chip UN2003.

2. Configuración Cubemax

2.1 Configuración del RCC

 2.2 Configuración del sistema

 2.3 Configuración GPIO

 2.4 Generar archivos

 3. Conexión de hardware

EN1---PB15

IN2---PB14

IN3 --- PB13

IN4----PB12

+5V---5V

TIERRA --- TIERRA

4. Integración del código Keil

4.1 Definición de macros

#define LD_ON HAL_GPIO_WritePin(LD_GPIO_Port, LD_Pin, GPIO_PIN_SET)
#define LD_OFF HAL_GPIO_WritePin(LD_GPIO_Port, LD_Pin, GPIO_PIN_RESET)
#define LC_ON HAL_GPIO_WritePin(LC_GPIO_Port, LC_Pin, GPIO_PIN_SET)
#define LC_OFF HAL_GPIO_WritePin(LC_GPIO_Port, LC_Pin, GPIO_PIN_RESET)
#define LB_ON HAL_GPIO_WritePin(LB_GPIO_Port, LB_Pin, GPIO_PIN_SET)
#define LB_OFF HAL_GPIO_WritePin(LB_GPIO_Port, LB_Pin, GPIO_PIN_RESET)
#define LA_ON HAL_GPIO_WritePin(LA_GPIO_Port, LA_Pin, GPIO_PIN_SET)
#define LA_OFF HAL_GPIO_WritePin(LA_GPIO_Port, LA_Pin, GPIO_PIN_RESET)

4.2 agregar fun.c func.h

función.h

#ifndef FUNC_FUNC_H_
#define FUNC_FUNC_H_

#include "main.h"

#define time 24000
void anticlockwise(void);
void clockwise(void);

#endif /* FUNC_FUNC_H_ */

func.c

#include "func.h"
uint32_t free_time_delay;
void anticlockwise()
{
	 //D4-LD
		//D5-LC
		//D6-LB
		//D7-LA
		
	LD_ON;
  //1
  free_time_delay = time; while(--free_time_delay>0);
  LC_ON;
  //2
  free_time_delay = time; while(--free_time_delay>0);
  LD_OFF;
  //3
  free_time_delay = time; while(--free_time_delay>0);
  LB_ON;
  //4
  free_time_delay = time; while(--free_time_delay>0);
  LC_OFF;
  //5
  free_time_delay = time; while(--free_time_delay>0);
  LA_ON;;
  //6
  free_time_delay = time; while(--free_time_delay>0);
  LB_OFF;
  //7
  free_time_delay = time; while(--free_time_delay>0);
  LD_ON;
  //8
  free_time_delay = time; while(--free_time_delay>0);
  LA_OFF;

}

void clockwise()
{
	 LA_ON;
  //1
  free_time_delay = time; while(--free_time_delay>0);
  LB_ON;
  //2
  free_time_delay = time; while(--free_time_delay>0);
  LA_OFF;
  //3
  free_time_delay = time; while(--free_time_delay>0);
  LC_ON;
  //4
  free_time_delay = time; while(--free_time_delay>0);
  LB_OFF;
  //5
  free_time_delay = time; while(--free_time_delay>0);
  LD_ON;;
  //6
  free_time_delay = time; while(--free_time_delay>0);
  LC_OFF;
  //7
  free_time_delay = time; while(--free_time_delay>0);
  LA_ON;
  //8
  free_time_delay = time; while(--free_time_delay>0);
  LD_OFF;
}

C Principal

while (1)
  {
		clockwise();//正
		HAL_Delay(5000);
		
		anticlockwise();//反
		HAL_Delay(5000);
    /* USER CODE END WHILE */

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

Supongo que te gusta

Origin blog.csdn.net/weixin_44597885/article/details/130198920
Recomendado
Clasificación