我同时开了TIM2和TIM3,TIM2定1ms,TIM3定0.1ms
static void Tim3_Init(void)
{
asm("sim"); //禁止中断
//禁止中断
TIM3_ITConfig(TIM3_IT_UPDATE, DISABLE);
//分频(2^3分频) 16M / 8 = 2Mhz-->0.5us,允许产生更新标志
TIM3_PrescalerConfig(TIM3_PRESCALER_8, TIM3_PSCRELOADMODE_IMMEDIATE);
//400U --> 400U * 0.5us = 0.2ms //0.2ms 复位一次
TIM3_SetAutoreload(200);
//初值 0
TIM3_SetCounter(0U);
//开定时器
TIM3_ARRPreloadConfig(ENABLE);
TIM3_Cmd(ENABLE);
//允许中断
TIM3_ITConfig(TIM3_IT_UPDATE, ENABLE);
//使能中断
asm("rim");
}
static void Tim2_Init(void)
{
asm("sim"); //禁止中断
//禁止中断
TIM2_ITConfig(TIM2_IT_UPDATE, DISABLE);
//分频(2^3分频) 16M / 8 = 2Mhz-->0.5us,允许产生更新标志
TIM2_PrescalerConfig(TIM2_PRESCALER_8, TIM2_PSCRELOADMODE_IMMEDIATE);
//2000 * 0.5us = 1ms //1ms 复位一次
TIM2_SetAutoreload(2000U);
//初值 0
TIM2_SetCounter(0U);
//开定时器
TIM2_ARRPreloadConfig(ENABLE);
TIM2_Cmd(ENABLE);
//允许中断
TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
//使能中断
asm("rim");
}
void Tim_Init(void)
{
Tim3_Init();
Tim2_Init();
}
void Task_TimeRun(void)
{
Task_4msCounterA++;
Task_4msCounterB++;
Task_8msCounter++;
Task_16msCounter++; /*1ms时基*/
// Led_MainFunction();
}
void Task_AD_Run(void)
{
if(u == 0)
{
GPIO_WriteHigh(GPIOA, GPIO_PIN_2);
u = 1;
}
else
{
GPIO_WriteLow(GPIOA, GPIO_PIN_2);
u= 0;
}
if(0U == ADSample_GetFlag())
{
ADSample_MainFunction();
}
}
INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
Task_AD_Run();
TIM3_ClearFlag(TIM3_FLAG_UPDATE);
}
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
Task_TimeRun();
TIM2_ClearFlag(TIM2_FLAG_UPDATE);
}
TIM3的中断应该0.1ms进入一次,但是通过io电平翻转,发现有跳动,TIM2不进行初始化,就不会跳动,怎么回事?
|