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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1781|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

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

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:628815 發(fā)表于 2019-10-23 15:38 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#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ī)詳解

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 午夜性视频 | 色久伊人 | 免费看片在线播放 | 亚洲视频一区在线观看 | 毛片a| 麻豆av免费观看 | 精品粉嫩aⅴ一区二区三区四区 | 亚洲成人精品视频 | 欧美色图另类 | 一区二区三区在线 | 欧 | 欧美a∨| 一区二区三区高清在线观看 | 91资源在线 | 免费av直接看 | 日本一道本视频 | 九九导航 | 人成在线 | 成人免费视频在线观看 | 四虎成人免费电影 | av电影一区二区 | 亚洲精品www久久久 www.蜜桃av | 国产欧美日韩精品一区二区三区 | 国产一区视频在线 | 精品国产一区二区国模嫣然 | 国产精品成人品 | 亚洲精选一区二区 | av黄色网 | 色精品视频| 亚洲成人综合社区 | 国产乱码精品一区二区三区忘忧草 | 久www| 男人天堂网址 | 久久久久国产视频 | 日韩中文字幕一区二区 | 成人久久视频 | 一级毛片观看 | 欧美一区二区三区的 | 国产电影一区二区在线观看 | 亚洲va中文字幕 | 亚洲国产精品一区二区久久 | 手机日韩|