找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4020|回复: 2
打印 上一主题 下一主题
收起左侧

STM32F103xx微控制器驱动步进电机源码

[复制链接]
跳转到指定楼层
楼主
官方库文件--使用中容量STM32F103xx微控制器驱动步进电机



单片机源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file FullHalfStepMode/src/main.c
  4.   * @author  MCD Application Team
  5.   * @version  V2.0.0
  6.   * @date  04/27/2009
  7.   * @brief  Main program body
  8.   ******************************************************************************
  9.   * @copy
  10.   *
  11.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13.   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14.   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15.   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16.   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17.   *
  18.   * <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2>
  19.   */

  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x.h"
  22. #include "StepperMotor.h"
  23. #include <stdio.h>



  24. /** @addtogroup FullHalfStepMode
  25.   * @{
  26.   */


  27. /* Private typedef -----------------------------------------------------------*/
  28.   /* Private define ------------------------------------------------------------*/
  29. /* -------------------- Stepper modes entering function ---------------- */
  30. /******* Define the Rotation Direction *******/
  31. #define RotationDirection_CW
  32. //#define RotationDirection_CCW

  33. /******* Define the Step Mode *********/
  34. #define Half_Step
  35. //#define Full_Step

  36. /******* Define the Decay Mode ********/
  37. //#define ControlSlow_Current
  38. #define ControlFast_Current

  39. /* Private macro -------------------------------------------------------------*/
  40. /* Private variables ---------------------------------------------------------*/

  41. ErrorStatus HSEStartUpStatus;

  42. /* Private function prototypes -----------------------------------------------*/
  43. void RCC_Configuration(void);
  44. void NVIC_Configuration(void);
  45.    
  46. /* Private functions ---------------------------------------------------------*/



  47. /**
  48.   * @brief  Main program
  49.   * @param  None
  50.   * @retval : None
  51.   */
  52. int main(void)
  53. {

  54.   /* System Clocks Configuration */
  55.   RCC_Configuration();
  56.   
  57.   /* NVIC Configuration */
  58.   NVIC_Configuration();
  59.   
  60.   /* Activate the driver */
  61.   Stepper_Cmd(ENABLE);
  62.   
  63.   /* Driver control pin configuration */
  64.   Stepper_PinControlConfig();
  65.   
  66.   /* Disable the initialization of the driver */
  67.   Stepper_ResetDisable();
  68.       
  69.   /* -----------Modes selection: Rotation direction, Step mode, Decay mode---------------*/
  70. #ifdef RotationDirection_CW
  71.   Stepper_SetRotationDirection(Stepper_RotationDirection_CW);
  72. #endif /* RotationDirection_CW */

  73. #ifdef RotationDirection_CCW
  74.   Stepper_SetRotationDirection(Stepper_RotationDirection_CCW);
  75. #endif /* RotationDirection_CCW */
  76.   
  77. #ifdef Half_Step
  78.   Stepper_SelectMode(Stepper_Half);
  79. #endif  /* Half_Step */
  80.   
  81. #ifdef Full_Step
  82.   Stepper_SelectMode(Stepper_Full);
  83. #endif  /* Full_Step */

  84. #ifdef ControlSlow_Current
  85.   Stepper_SetControlMode(Stepper_ControlSlow);
  86. #endif  /* ControlSlow_Current */  

  87. #ifdef ControlFast_Current
  88.   Stepper_SetControlMode(Stepper_ControlFast);
  89. #endif   /* ControlFast_Current */
  90.   
  91.   
  92.   /* Start the stepper motor */   
  93.   Stepper_Start(ENABLE);
  94.   
  95.   /* Peripherals configuration */
  96.   Stepper_Init();
  97.   
  98.   while (1)
  99.   {
  100.   }   
  101. }



  102. /**
  103.   * @brief  Configures the different system clocks.
  104.   * @param  None
  105.   * @retval : None
  106.   */
  107. void RCC_Configuration(void)
  108. {   
  109.   /* RCC system reset(for debug purpose) */
  110.   RCC_DeInit();

  111.   /* Enable HSE */
  112.   RCC_HSEConfig(RCC_HSE_ON);

  113.   /* Wait till HSE is ready */
  114.   HSEStartUpStatus = RCC_WaitForHSEStartUp();

  115.   if(HSEStartUpStatus == SUCCESS)
  116.   {
  117.     /* Enable Prefetch Buffer */
  118.     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

  119.     /* Flash 2 wait state */
  120.     FLASH_SetLatency(FLASH_Latency_2);

  121.     /* HCLK = SYSCLK */
  122.     RCC_HCLKConfig(RCC_SYSCLK_Div1);
  123.   
  124.     /* PCLK2 = HCLK */
  125.     RCC_PCLK2Config(RCC_HCLK_Div1);

  126.     /* PCLK1 = HCLK/2 */
  127.     RCC_PCLK1Config(RCC_HCLK_Div2);

  128.     /* PLLCLK = 8MHz * 9 = 72 MHz */
  129.     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

  130.     /* Enable PLL */
  131.     RCC_PLLCmd(ENABLE);

  132.     /* Wait till PLL is ready */
  133.     while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  134.     {
  135.     }
  136.    
  137.     /* Select PLL as system clock source */
  138.     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  139.     /* Wait till PLL is used as system clock source */
  140.     while(RCC_GetSYSCLKSource() != 0x08)
  141.     {
  142.     }
  143.   }

  144. }

  145. /**
  146.   * @brief  Configure the nested vectored interrupt controller.
  147.   * @param  None
  148.   * @retval : None
  149.   */
  150. void NVIC_Configuration(void)
  151. {


  152.   NVIC_SetPriorityGrouping(7); /* 0 bits for pre-emption priority 4 bits for
  153. subpriority*/
  154.   NVIC_SetPriority(DMA1_Channel2_IRQn, 0x01); /* 0x01 = 0x0 << 3 | (0x1 & 0x7), prority
  155. is 0x01 << 4 */
  156. NVIC_EnableIRQ(DMA1_Channel2_IRQn);

  157.   
  158. }

  159. #ifdef  USE_FULL_ASSERT


  160. ……………………

  161. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
官方库文件--使用中容量STM32F103xx微控制器驱动步进电机.zip (1.21 MB, 下载次数: 66)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:436417 发表于 2018-12-3 14:41 | 只看该作者
收藏
回复

使用道具 举报

板凳
ID:110942 发表于 2018-12-3 21:02 | 只看该作者
好,不错收藏了!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表