u16 capture=0;
u16 CCR1_Val=1000;
u16 CCR2_Val=5000;
u16 CCR3_Val=10000;
u16 CCR4_Val=20000;
TIM_TimeBaseStructure.TIM_Period=65535;
TIM_TimeBaseStructure.TIM_Prescaler=7200-1;
TIM_TimeBaseStructure.TIM_ClockDivision=0x0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//向上计数
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
void TIM2_IRQHandler(void)
{
/*TIM2_CH1*/
if(TIM_GetITStatus(TIM2,TIM_IT_CC1)!=RESET)
{
TIM_ClearITPendingBit(TIM2,TIM_IT_CC1);
/*PC.1引脚的翻转频率为 Hz*/
GPIO_WriteBit(GPIOC,GPIO_Pin_1,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_1)));
capture=TIM_GetCapture1(TIM2);
TIM_SetCompare1(TIM2,capture+CCR1_Val);
//GPIO_ResetBits(GPIOC,GPIO_Pin_All);
}
/*TIM2_CH2*/
if(TIM_GetITStatus(TIM2,TIM_IT_CC2)!=RESET)
{
GPIO_WriteBit(GPIOC,GPIO_Pin_2,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_2)));
TIM_ClearITPendingBit(TIM2,TIM_IT_CC2);
capture=TIM_GetCapture2(TIM2);
TIM_SetCompare2(TIM2,capture+CCR2_Val);
//GPIO_SetBits(GPIOC,GPIO_Pin_All);
}
}
请问这个定时时间怎么算啊?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
让通用定时器的4个通道分别产生不同的定时时间
一周热门 更多>