當前位置:網站首頁>【STM32學習】(21)STM32實現步進電機

【STM32學習】(21)STM32實現步進電機

2022-07-23 01:29:51小材大用

實物圖:

 

實現示意圖:其實看著示意圖就可以實現步進電機轉動了。

 

四相五線的步進電機。

4線為:A B C D

該步進電機分為4拍和8拍

4拍:分為單四拍和雙四拍

單四拍:A-B-C-D-A-

雙四拍:AB-BC-CD-DA-AB-

8拍:

A-AB-B-BC-C-CD-D-DA-A-

想讓步進電機反轉,只需要將順序反轉就行。

主要代碼為:

int main(void)
{
  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
		/* 正轉  8拍 */
//	  _74HC595_Send595OneByte(0X8F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0XCF);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X4F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X6F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X2F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X3F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X1F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X9F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);

		/* 反轉 8拍 */
	  _74HC595_Send595OneByte(0X1F);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0X3F);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0X2F);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0X6F);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0X4F);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0XCF);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0X8F);
	  _74HC595_OUT();
	  HAL_Delay(1);
	  _74HC595_Send595OneByte(0X9F);
	  _74HC595_OUT();
	  HAL_Delay(1);


		/* 正轉 4拍 單四拍 */
//	  _74HC595_Send595OneByte(0X8F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X4F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X2F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X1F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
  
		/* 正轉 4拍 雙四拍 */
//	  _74HC595_Send595OneByte(0XCF);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X6F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X3F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X9F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
	  
	  /* 反轉 4拍 單四拍 */
//	  _74HC595_Send595OneByte(0X8F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X4F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X2F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);
//	  _74HC595_Send595OneByte(0X1F);
//	  _74HC595_OUT();
//	  HAL_Delay(1);

	  
	  
	  
  }
  /* USER CODE END 3 */
}

效果如下:

代碼鏈接為:

 


 

版權聲明
本文為[小材大用]所創,轉載請帶上原文鏈接,感謝
https://cht.chowdera.com/2022/204/202207221455246287.html

隨機推薦