微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32开发板学习日记-[3] TIM定时器输出比较

STM32开发板学习日记-[3] TIM定时器输出比较

时间:11-26 来源:互联网 点击:

GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

#ifdefVECT_TAB_RAM

NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else

NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif


NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

#ifdefDEBUG

void assert_failed(u8* file, u32 line)
{

while (1)
{
}
}
#endif

中断服务:

void TIM2_IRQHandler(void)
{

if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)//检查指定的TIM中断发生与否
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1 );//清除TIMx的中断待处理位
capture = TIM_GetCapture1(TIM2);
TIM_SetCompare1(TIM2, capture + CCR1_Val );//设置TIMx自动重装载寄存器值
//将TIM2_CC1的值增加CCR1_Val,使得下一个TIM事件也需要CCR1_Val个脉冲,

}


if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
capture = TIM_GetCapture2(TIM2);
TIM_SetCompare2(TIM2, capture + CCR2_Val);
}


if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
capture = TIM_GetCapture3(TIM2);
TIM_SetCompare3(TIM2, capture + CCR3_Val);
}


if (TIM_GetITStatus(TIM2, TIM_IT_CC4) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
capture = TIM_GetCapture4(TIM2);
TIM_SetCompare4(TIM2, capture + CCR4_Val);
}
}

上一篇:arm之TFT
下一篇:TFT画出任意斜率的直线

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top