STM32 timer timing calculation

Publisher:TapirLatest update time:2015-08-12 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Assuming the system clock is 72Mhz, TIM1 is obtained from PCLK2 (72MHz), and TIM2-7 is obtained from PCLK1.
The key is to set the clock pre-division number and the value of the automatic reload register period.


Basic settings of the timer
   1.    TIM_TimeBaseStructure.TIM_Prescaler = 7199; //Clock pre-division number    For example:
clock frequency = 72/(clock pre-division + 1)   
   2. TIM_TimeBaseStructure.TIM_Period = 9999; //The value of the automatic reload register period (timing
time)      accumulates 0xFFFF frequencies and generates an update or interrupt (that is, the timing time is up)
   3.   TIM_TimeBaseStructure.TIM_CounterMode =   TIM1_CounterMode_Up; //Timer
mode   counts up   
    
     4. TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //Time division value   
     5. TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);//Initialize timer 2
     6. TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);   //Enable interrupt    overflow interrupt   
     7. TIM_Cmd(TIM2, ENABLE);//Enable timer

Or:
TIM_TimeBaseStructure.TIM_Prescaler = 35999;//Division frequency 35999       72M/
(35999+1)/2=1Hz   Interrupt overflow once per second
TIM_TimeBaseStructure.TIM_Period = 2000; //Count value 2000   

((1+TIM_Prescaler )/72M)*(1+TIM_Period )=((1+35999)/72M)*(1+2000)=1 second*/    
Keywords:STM32 Reference address:STM32 timer timing calculation

Previous article:STM32 Development Board Getting Started Tutorial (I) GPIO
Next article:STM32 interrupts and nested NVIC quick start

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号