void TIM3_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure .NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3 ,ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure .TIM_Period = 1000-1; //1000*1ms = 1s
TIM_TimeBaseStructure .TIM_Prescaler = 24000; //1KHz -- 1ms
TIM_TimeBaseStructure .TIM_CounterMode = TIM_CounterMode_Up ;
TIM_TimeBaseStructure .TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseInit (TIM3,&TIM_TimeBaseStructure);
TIM_ClearFlag (TIM3,TIM_FLAG_Update);
TIM_ITConfig (TIM3,TIM_IT_Update ,ENABLE);
TIM_Cmd (TIM3,ENABLE);
}
|