void DRV_Tim3Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_DeInit(TIM3);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM3->PSC =0;
TIM3->ARR = (unsigned int)(12000/16);//定时16K//系统时钟120M
TIM3->DIER|=1<<0; //允许更新中断
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
BSP_IntVectSet(BSP_INT_ID_TIM3, DRV_Tim3Irq);
BSP_IntEn(BSP_INT_ID_TIM3);
}
void DRV_Tim3Irq(void)
{
unsigned char data;
static uint8 flag=0;
if(flag)
{
SetRLED();
flag=0;
}
else
{
ClrRLED();
flag=1;
}
TIM3->SR&=~(1<<0);//清除中断标志位
}
UcOs开四个任务其中一个任务是20ms执行一次,另三个挂起状态,为什么中断中红灯亮灭波形频率小于16K(大约15K) 有些大于16K,定时器会变得不准? |