久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標(biāo)題: 用中密度stm32f103xx微控制器驅(qū)動(dòng)an2820雙極步進(jìn)電機(jī) [打印本頁]

作者: qi12z3    時(shí)間: 2019-10-23 15:38
標(biāo)題: 用中密度stm32f103xx微控制器驅(qū)動(dòng)an2820雙極步進(jìn)電機(jī)
#include "stm32f10x.h"
#include "StepperMotor.h"

GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
DMA_InitTypeDef DMA_InitStructure;


uint16_t SRC_Buffer_DEC[20] ={15000,15000,20000,20000,25000,25000,30000,30000,35000,35000,
                          40000,40000,45000,45000,50000,50000,55000,55000,60000,60000};

uint16_t SRC_Buffer_INC[20] ={60000,60000,55000,55000,50000,50000,45000,45000,40000,40000,
                          35000,35000,30000,30000,25000,25000,20000,20000,15000,15000};
                          
                                          
/**
   * @brief  Configures the driver control pin
   * @param  None
   * @retval : None
   */

void Stepper_PinControlConfig(void)
{
    /* Configure PC.04, PC.05, PC.06, PC.07, PC.08, PC.09 as output push pull*/
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7
                                 | GPIO_Pin_8 | GPIO_Pin_9;
                                 
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_Init(GPIOC, &GPIO_InitStructure);  
}


/**
   * @brief  Starts or Stops the stepper motor
   * @param NewState: This parameter can be ENABLE or DISABLE.
   * @retval : None
   */
void Stepper_Start(FunctionalState NewState)
{   
   if(NewState == ENABLE)
   {
      /* Set the C.09 pin */
     GPIO_SetBits(GPIOC, GPIO_Pin_9);
   }
   else
   {   
     /* Reset the C.09 pin */
     GPIO_ResetBits(GPIOC, GPIO_Pin_9);
   }
}


/**
   * @brief  Disables the initialization of the driver to its default reset value
   * @param  None
   * @retval : None
   */
void Stepper_ResetDisable(void)
{   
   /* Set the C.05pin */
   GPIO_SetBits(GPIOC, GPIO_Pin_5);
}



/**
   * @brief  Selects the direction of the rotation
   * @param Stepper_RotationDirection: Specifies the rotation direction
   *   This parameter can be one of the following values:
   * @arg Stepper_RotationDirection_CW : sets clockwise direction
   * @arg Stepper_RotationDirection_CCW: sets counterclockwise direction
   *   
   * @retval : None
   */
void Stepper_SetRotationDirection(uint16_t Stepper_RotationDirection)
{
     if(Stepper_RotationDirection == Stepper_RotationDirection_CW )
   {
     /* Set the C.06 pin */
     GPIO_SetBits(GPIOC, GPIO_Pin_6);
   }
   else
   {   
     /* Reset the C.06 pin */
     GPIO_ResetBits(GPIOC, GPIO_Pin_6);
   }
}



/**
   * @brief  Selects the step mode  
   * @param Stepper_Mode: Specifies the Step Mode
   *   This parameter can be one of the following values:
   * @param Stepper_Full : Sets FULL STEP Mode
   * @param Stepper_Half : Sets HALF STEP Mode
   *   
   * @retval : None
   */
void Stepper_SelectMode(uint16_t Stepper_Mode)
{
   if(Stepper_Mode ==  Stepper_Full)
   {
      /* Reset the C.07 pin */
    GPIO_ResetBits(GPIOC, GPIO_Pin_7);
   }
   else
   {   
     /* Set the C.07 pin */
    GPIO_SetBits(GPIOC, GPIO_Pin_7);
   }
}



/**
   * @brief  Selects the decay mode  
   * @param StepperControlMode: Specifies the Decay Mode
   *   This parameter can be one of the following values:
   * @param Stepper_ControlFast : Sets FAST DECAY Mode
   * @param Stepper_ControlSlow : Sets SLOW DECAY Mode
   *   
   * @retval : None
   */
void Stepper_SetControlMode(uint16_t Stepper_ControlMode)
{
    if(Stepper_ControlMode ==  Stepper_ControlFast)
   {
     /* Reset the C.08 pin */
     GPIO_ResetBits(GPIOC, GPIO_Pin_8);
   }
   else
   {   
    /* Set the C.08 pin */
    GPIO_SetBits(GPIOC, GPIO_Pin_8);
   }

}


/**
   * @brief  Activates or Desactivates the driver
   * @param NewState: This parameter can be ENABLE or DISABLE.
   * @retval : None
   */
void Stepper_Cmd(FunctionalState NewState)
{   
     if(NewState == ENABLE)
   {
     /* TIM2 clock enable */
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
      /* GPIOA clock enable */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
     /* GPIOC clock enable */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
     /* Enable DMA1 clock */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
     
   }
   else
   {   
     /* TIM2 clock disable */
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, DISABLE);
      /* GPIOA clock disable */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
     /* GPIOC clock disable */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, DISABLE);
     /* Disable DMA1 clock */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, DISABLE);
   
   }
}



/**
   * @brief  Configures the peripherals used to control the stepper motor
   * @param  None
   * @retval : None
   */
void Stepper_Init(void)
{
   GPIO_InitTypeDef GPIO_InitStructure;
   /* GPIOA Configuration:TIM2 Channel1 in Output */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

   GPIO_Init(GPIOA, &GPIO_InitStructure);

   /* ---------------------------------------------------------------
   TIM2 Configuration: Output Compare Toggle Mode:
   --------------------------------------------------------------- */
    /* Time base configuration */
   TIM_TimeBaseStructure.TIM_Period =60000;
   TIM_TimeBaseStructure.TIM_Prescaler = 2;
   TIM_OCInitStructure.TIM_Pulse = 0;  
   TIM_TimeBaseStructure.TIM_ClockDivision = 0;
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
   
   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
   /* Output Compare Toggle Mode configuration: Channel1 */
   TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_Toggle;  
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
   TIM_OC1Init(TIM2, &TIM_OCInitStructure);
  
   TIM_ARRPreloadConfig(TIM2, ENABLE);
   
   /* TIM enable counter */
   TIM_Cmd(TIM2, ENABLE);
   
   /* -------------------------------------------------------------------
   DMA1 configuration
   ---------------------------------------------------------------------- */
   
   /* DMA1 channel2 configuration ----------------------------------*/
   DMA_DeInit(DMA1_Channel2);
   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM2_ARR_Address;
   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SRC_Buffer_INC;
   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
   DMA_InitStructure.DMA_BufferSize = BufferSize;
   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
   DMA_Init(DMA1_Channel2, &DMA_InitStructure);
   
/* Enable DMA1 Channel2 Transfer Complete interrupt */
   DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE);
   
   /* Enable DMA1 Channel2 */
   DMA_Cmd(DMA1_Channel2, ENABLE);
   
   /* Enable TIM2 DMA update request */
   TIM_DMACmd(TIM2,TIM_DMA_Update, ENABLE);
     
}

/**
   * @}
   */

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

stm32f10x_an2820_fw.chm

675.52 KB, 下載次數(shù): 3, 下載積分: 黑幣 -5

用中密度stm32f103xx微控制器驅(qū)動(dòng)an2820雙極步進(jìn)電機(jī)詳解






歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 欧美成人一区二免费视频软件 | 国产不卡在线播放 | 亚洲成色777777在线观看影院 | 国产伦精品一区二区 | 91精品久久久久久久久久入口 | 一区二区三区四区av | 精品一区在线看 | 日韩不卡三区 | 伊人久久精品一区二区三区 | 国产乱码精品一区二区三区中文 | 国产精品成人一区二区三区 | 亚洲国产一区二区三区 | 欧美黑人一级爽快片淫片高清 | 久久精品一区二区三区四区 | 久久国产精品一区二区 | 欧美一区二区成人 | 波多野结衣先锋影音 | 日韩在线免费 | 隔壁老王国产在线精品 | 亚洲电影第三页 | 黑人巨大精品欧美黑白配亚洲 | 日韩精品久久久 | 欧美成人一区二区 | 成人小视频在线观看 | www.黄色在线观看 | 91精品国产高清一区二区三区 | 中文字幕一区二区三区乱码在线 | 国产精品欧美一区喷水 | 国产精品久久久久久妇女6080 | a级黄色片在线观看 | 亚洲精品一区国语对白 | a天堂在线| 超碰520 | 99久久亚洲 | 精品日韩在线 | av一区二区三区四区 | 黄色在线免费观看视频 | 亚洲综合色 | 91伊人网 | 精品久久久久久久久久久 | 国产成人免费 |