STM32 using TIMX_CH1 as tx1f_ed counter clock

Source: Internet
Author: User

Environment: IAR ARM 5.3

Stm32f103vbt6

Use the pa.8 external input 10Mhz square wave. Data 4 can be obtained from Systick interrupts.

4x5000 (prescaler value) x1000 (tick interrupt Time) =20mhz

Belonging to the bilateral edge detection, a pa.8 pulse has 2 edges, so the clock doubles.

Due to the use of ti1f_ed it is structured as follows:

voidRcc_configuration (void ){  /*Setup STM32 System (Clock, PLL and Flash configuration)*/Systeminit (); /*Enable Gpioa, GPIOC and USART1 clock*/Rcc_apb2periphclockcmd (Rcc_apb2periph_gpioa| RCC_APB2PERIPH_GPIOC |rcc_apb2periph_tim1, ENABLE);} Gpio_initstructure.gpio_pin=Gpio_pin_8; Gpio_initstructure.gpio_mode=gpio_mode_in_floating; Gpio_initstructure.gpio_speed=Gpio_speed_50mhz; Gpio_init (Gpioa,&gpio_initstructure);voidTim1_init (void) {tim_timebaseinittypedef tim_timebasestructure; Tim_timebasestructure.tim_period=65535; Tim_timebasestructure.tim_prescaler= the; Tim_timebasestructure.tim_clockdivision=Tim_ckd_div1; Tim_timebasestructure.tim_countermode=tim_countermode_up; Tim_timebaseinit (TIM1,&tim_timebasestructure); Tim_tixexternalclockconfig (TIM1, tim_tixexternalclk1source_ti1ed, tim_icpolarity_rising,0 );  Tim_cmd (TIM1, ENABLE); }intMainvoid) {rcc_configuration ();  Gpio_config ();  Tim1_init (); /*Setup SysTick Timer for 1 msec interrupts*/  if(Systick_config (Systemfrequency/ + ) )  {    /*Capture Error*/     while(1 )      ; }     while(1 )  {  }}voidSystick_handler (void ){  StaticU32 i =0; if(i = =0) {i=1; Gusdata=0; Tim_setcounter (TIM1,0 ); }  Else{i=0; Gusdata=Tim_getcounter (TIM1); }  }

STM32 using TIMX_CH1 as tx1f_ed counter clock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.