高中生
最后登录1970-1-1
在线时间 小时
注册时间2022-6-22
|
static void TIM1_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
// 设置中断组为0
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// 设置中断来源
NVIC_InitStructure.NVIC_IRQChannel = TIM1_TIM_IRQn;
// 设置抢占优先级
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;
// 设置子优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//引脚初始化PA11 ch4 PA8
static void TIM1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// 输入捕获通道 GPIO 初始化
RCC_AHB1PeriphClockCmd(TIM1_measure_GPIO_CLK, ENABLE);
GPIO_PinAFConfig(TIM1_measure_GPIO_PORT,TIM1_measure_GPIO_PIN,TIM1_measure_AF);
GPIO_PinAFConfig(TIM1_measure_GPIO_PORT1,TIM1_measure_GPIO_PIN1,TIM1_measure_AF);
GPIO_InitStructure.GPIO_Pin = TIM1_measure_GPIO_PIN;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(TIM1_measure_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TIM1_measure_GPIO_PIN1;
GPIO_Init(TIM1_measure_GPIO_PORT, &GPIO_InitStructure);
}
static void TIM1_Mode_Config(void)
{
//时基配置在pwmout函数中
/*--------------------输入捕获结构体初始化-------------------*/
TIM_ICInitTypeDef TIM_ICInitStructure;
// 配置输入捕获的通道,需要根据具体的GPIO来配置
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
// 输入捕获信号的极性配置
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
// 输入通道和捕获通道的映射关系,有直连和非直连两种
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
// 输入的需要被捕获的信号的分频系数
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
// 输入的需要被捕获的信号的滤波系数
TIM_ICInitStructure.TIM_ICFilter = 0;
// 定时器输入捕获初始化
TIM_ICInit(TIM1_TIM, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
// 定时器输入捕获初始化
TIM_ICInit(TIM1_TIM, &TIM_ICInitStructure);
// 开启更新和捕获中断
TIM_ITConfig (TIM1_TIM, TIM_IT_Update | TIM_IT_CC1|TIM_IT_CC4, ENABLE );
// 清除更新和捕获中断标志位
TIM_ClearFlag(TIM1_TIM, TIM_FLAG_Update|TIM_IT_CC1|TIM_IT_CC4);
// 使能计数器
TIM_Cmd(TIM1_TIM, ENABLE);
}
大佬帮忙看看有啥问题吗,实在找不出来
|
|