研究生
最后登录1970-1-1
在线时间 小时
注册时间2015-7-28
|
楼主 |
发表于 2015-10-21 19:19:17
|
显示全部楼层
大神能不能帮我看看,我这捕获程序那出错了,怎么捕获不到值啊????????
有没有什么可以查看是程序有问题还是硬件有问题啊?????
#include "bsp_TiMbase.h"
static void TIM2_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void TIM2_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM2_Cap_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
// TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Prescaler= (uint16_t)(72000000/2000000)-1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=65535;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
// TIM_TimeBaseStructure.TIM_RepetitionCounter= 0x00;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICSelection=TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICFilter = 0x00;
/*TIM2μÄí¨μàËÄéèÖÃÎa êäèë2¶»ñ Ä£ê½ */
TIM_ICInitStructure.TIM_Channel=TIM_Channel_1;
TIM_ICInit(TIM2,&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel=TIM_Channel_2;
TIM_ICInit(TIM2,&TIM_ICInitStructure);
TIM_ITConfig(TIM2,TIM_IT_CC1,ENABLE);
TIM_ITConfig(TIM2,TIM_IT_CC2,ENABLE);
TIM_ClearFlag(TIM2, TIM_FLAG_Update); ////////////////////////
TIM_ITConfig( TIM2,TIM_IT_Update|(TIM_IT_CC1,TIM_IT_CC2),ENABLE); /////////
TIM_Cmd(TIM2, ENABLE);
}
void TIM2_ANG_Init(void)
{
TIM2_GPIO_Config();
TIM2_Cap_Config();
TIM2_NVIC_Config();
} |
|