中级会员
 
- 积分
- 253
- 金钱
- 253
- 注册时间
- 2015-4-29
- 在线时间
- 38 小时
|

楼主 |
发表于 2018-9-19 11:23:03
|
显示全部楼层
麻烦帮我看一下我的配置哪里不对?
void TIM10_Configuration(void) //只用一个外部脉冲端口
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure ;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
//配置TIMER作为计数器
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //50M时钟速度
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推完输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM10);
TIM_TimeBaseStructure.TIM_Period = 0xFFFF ;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00 ;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up ;
TIM_TimeBaseInit(TIM10, &TIM_TimeBaseStructure); // Time base configuration
TIM_CounterModeConfig(TIM10,TIM_CounterMode_Up);//计数模式
//TIM_ITRxExternalClockConfig(TIM10,TIM_TS_ETRF); //我测试中一直不能用的原因是缺少外部时钟模式
// TIM_TIxExternalClockConfig(TIM10, TIM_TIxExternalCLK1Source_TI1,TIM_ICPolarity_Rising, 0);//设置TIMx触发为外部时钟
TIM_ETRClockMode2Config(TIM10, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);//该参数取值在0x0和0xF之间。
//TIM_ExtTRGPolarity_NonInverted//TIM外部触发极性非翻转:高电平或上升沿有效
TIM_SetCounter(TIM10, 0); //TIM_ExtTRGPSC_OFFTIM; ETRP 预分频 OFF
// TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM10, ENABLE);
}
|
|