cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030C8T6 定时器中断�?能准确定时,主频率是48MHz

振林.1
Associate

下�?�是我的代�?

void TimerInit()

{

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

TIM_DeInit(TIM3);

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

TIM_TimeBaseStructure.TIM_Prescaler = 47;

 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

 TIM_TimeBaseStructure.TIM_Period = 999;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

TIM_ARRPreloadConfig(TIM3, ENABLE);

TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);

TIM_Cmd(TIM3,ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; 

NVIC_InitStructure.NVIC_IRQChannelPriority = 1; 

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 

NVIC_Init(&NVIC_InitStructure); 

}​

void TIM3_IRQHandler(void)

{

static uint8 Time2msCnt=0;

static uint8 Time5msCnt=0;

if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET)

{    

TIM_ClearITPendingBit(TIM3,TIM_IT_Update);

Time2msCnt++;

Time5msCnt++;

Timer1msFlag=1;

if(Time2msCnt==2)

{

Time2msCnt=0;

Timer2msFlag=1;

}

if(Time5msCnt==5)

{

Time5msCnt=0;

Timer5msFlag=1;

}

while (1)

 {

if(Timer1msFlag)

{

Timer1msFlag=0;

}

if(Timer2msFlag)

{

Timer2msFlag=0;

}

if(Timer5msFlag)

{

Timer5msFlag=0;

}

 }

但是都�?准确 ​

0 REPLIES 0