stm32定时器的编码器模式
</pre><pre name="code" class="objc">
</pre><pre name="code" class="objc">/**********************************************************************************
* @file: stm32定时器的编码器模式
* @date: 2015.8.2
* @author: shenhuixiang
* @version: 1.0.0
***********************************************************************************
* @description:
关于stm32定时器的编码器模式配置
**********************************************************************************/
#include "bsp_tim.h"
/***************************************************************************
Ãû ³Æ£ºTIM_Configuration()
¹¦ ÄÜ£ºTIM³õʼ»¯ÅäÖÃ
Èë¿Ú²ÎÊý£ºvoid
³ö¿Ú²ÎÊý£ºvoid
***************************************************************************/
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//开启外设时钟 tim3和GPIOA
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //选择输入上拉模式,因为我的编码器是开路输出,所以选择上拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
<pre name="code" class="objc">//陪置中断优先级
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//响应优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
</pre><pre>
</pre><pre name="code" class="objc">刚接触到32单片机,以上内容有啥错误的,还请批评指正,此部分代码均在使用编码器过程中从百度学习的,只是在我使用的时候修改了部分内容,如有啥问题的请联系我。