A method of using always the timing delay is implemented STM32 based

  Traditionally we used the delay function delay, however, this approach has a lot of drawbacks that need to occupy a considerable part of the clock cycle, when the original is used to calculate all kinds of complex algorithms compute kernel as the system must be stopped together down, the economy is very likely to cause problems deal with the consequences of not timely.

  In fact, we only need to use the clock interrupt mode, use a global variable as a flag to the specific procedures are as follows:

 

time3_tmp = U8 0 ; // clock marks 
U8 fun_flag; // service function flag 
void   Timer3_Config ( void ) // configuration 
{ 
TIM_TimeBaseInitTypeDef TIM_TimeBaseStruture;              ////// // re-definition of the structure 
TIM_DeInit (TIM3);                                          //// ///// initialization is resumed 
TIM_TimeBaseStruture.TIM_Period = ( 60 - . 1 );                    ////// TIM_ARR a value of 30 millisecond interrupt 
TIM_TimeBaseStruture.TIM_Prescaler = ( 36000 - . 1 );              ///////// / clock divide
= TIM_CKD_DIV1 TIM_TimeBaseStruture.TIM_ClockDivision;        ///////// sampling frequency, regardless of the frequency is 1 
TIM_TimeBaseStruture.TIM_CounterMode = TIM_CounterMode_Up;    ////// counting up 
TIM_TimeBaseStruture.TIM_RepetitionCounter = 0 ; 
TIM_TimeBaseInit (TIM3, & TIM_TimeBaseStruture) ;               ////// / set value TIM2 
TIM_CleaRFlag (TIM3, TIM_FLAG_Update);                         ////// / clear overflow flag 
TIM_ITConfig (TIM3, TIM_IT_Update, the eNABLE);                    ////// enable overflow interrupt 
}   

void   TIM3_IRQHandler ( void ) 
{ 
        
TIM_ClearITPendingBit (TIM3, TIM_IT_Update);         

The IF (time3_tmp == . 1 ) 
{ 
           fun_flag = 0 ; 
          time3_tmp = 0 ; 
          GPIO_ResetBits (GPIOB, GPIO_Pin_1); 
} 
IF (fun_flag == . 1 )                                                         ////// USART3 delay error 
    { 
                time3_tmp = . 1 ; 
          } 
TIM_Cmd (TIM3 , the DISABLE);   ////// / off timer. 3 
} 

void Fun ( void ) 
{ 
/ * trigger some event change fun_flag * / 
fun_flag=~fun_flag;
}

 

 

Like to share some information for learning hope useful reference

(Timer)
http://www.makeru.com.cn/live/1392_1199.html?s=45051
(system clock)
http://www.makeru.com.cn/live/1392_1082.html?s=45051
STM32 system interrupt
http://www.makeru.com.cn/live/3523_1745.html?s=45051

Guess you like

Origin www.cnblogs.com/QianD/p/11289724.html