首先,我用通用定时器实现了输入捕获,仅仅捕获一个脉冲时序,但是需要同时捕获四路信号。
然后因为IO口的关系,我用高级定时器8,就把定时器4换成了定时器8,时钟改好,设置中断向量表,修改中断函数为TIM8——CC——IRQHander完了,结果任何结果都没有,其他的连按键都没用了;
首先我通过一个LED灯调试到能进while(1),我的while1里面就只有一个按键程序,然后通过按键来控制这个LED灯就不行了,然后我去掉TIM8的配置程序,按键又能控制LED灯了,所以,认为是TIM8的配置程序出了问题,我自习对比了手册中高级定时器和通用定时器的区别(关于输入捕获部分和时基部分),找到了1:高级定时器就多了一个重复计数器,1:时钟是APB2控制
现在就卡在这里了,不知道是不是高级定时器的配置出了问题?求教高手指点。
---------------------------------
我也想知道 是怎么解决的
原子哥 有历程吗 输入捕获的TIM1和8的程序
```c
void InitTimer8(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
​ NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
//使能时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8|RCC_APB2Periph_AFIO,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
//配置捕获引脚,配置PC6为AF输入模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//配置捕获引脚,配置PA11为AF输入模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//定时器时钟配置
​ TIM_TimeBaseInitStructure.TIM_Prescaler=719; //定时器分频100K;//
​ TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
​ TIM_TimeBaseInitStructure.TIM_Period=0XFFFF; //自动重装载值
​ TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; //无需关注,和输入捕获
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;//这个参数最对TIM1和TIM8有效,用于产生PWM
​ TIM_TimeBaseInit(TIM8,&TIM_TimeBaseInitStructure);
​ //设置通道
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; //通道1和通道4
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1 上
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM8, &TIM_ICInitStructure);
//设置通道
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; //通道1和通道4
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1 上
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM8, &TIM_ICInitStructure);
/* DMA2_Channel3 用于定时器8通道1上升沿捕获 **************************************/
DMA_DeInit(DMA2_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&TIM8->CCR1;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)(timer8_capture_value);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 21; //计算20次求平均值
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_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel3, &DMA_InitStructure);
/* DMA2_Channel2 用于定时器8通道4 */
DMA_DeInit(DMA2_Channel2);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&TIM8->CCR4;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)(timer5_capture_value);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 21; //计算20次求平均值
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_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel2, &DMA_InitStructure);
/* DMA1 Channel2 enable */
DMA_Cmd(DMA2_Channel3, ENABLE);
DMA_Cmd(DMA2_Channel2, ENABLE);
TIM_DMACmd(TIM8,TIM_DMA_CC1,ENABLE); //捕获比较DMA请求使能
TIM_DMACmd(TIM8,TIM_DMA_CC4,ENABLE);
//设置中断优先级
NVIC_InitStructure.NVIC_IRQChannel=DMA2_Channel3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x05; //抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=DMA2_Channel2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x06; //抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* DMA传输完成中断使能 */
DMA_ITConfig(DMA2_Channel2,DMA_IT_TC,ENABLE);
DMA_ITConfig(DMA2_Channel3,DMA_IT_TC,ENABLE);
TIM_ClearITPendingBit(TIM8,TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4);
TIM_Cmd(TIM8,ENABLE); //使能定时器计数
}
```
一周热门 更多>