STM32 external counting ETR calculation frequency

Publisher:omicron25Latest update time:2017-10-27 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

STM32 external counter ETR calculates frequency, measures 100K frequency, uses timer 2 for 250ms, and timer 3PD2 (TIM3_ETR) counts, and the calculation formula is f=n*t;

void Tim3_Configuration(void)

{  

   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

   TIM_TimeBaseStructure.TIM_Prescaler = 0x00; 

   TIM_TimeBaseStructure.TIM_Period = 0xFFFF; 

   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; 

   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 

   TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);  // Time base configuration 

      

   TIM_ETRClockMode2Config(TIM3, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);  

   TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);  

   TIM_SetCounter(TIM3, 0);    

   TIM_Cmd(TIM3, ENABLE); 

         

void Tim2_Config(void)

{

    TIM_TimeBaseInitTypeDef   TIM2_TimeBaseStructure;

    NVIC_InitTypeDef NVIC_InitStructure;  

    TIM_DeInit(TIM2);

    TIM2_TimeBaseStructure.TIM_Period =(2500-1);

    TIM2_TimeBaseStructure.TIM_Prescaler = (7200-1); 

    TIM2_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    TIM2_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM2, &TIM2_TimeBaseStructure); // Time base configuration

    TIM_ClearFlag(TIM2,TIM_FLAG_Update);

    TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE ); 

    TIM_Cmd(TIM2, ENABLE); 

    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);                

void TIM2_IRQHandler(void)   

{

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

          {

             TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

             CAPTURE=(u32)TIM_GetCounter(TIM3);        

          }

        sum+=CAPTURE;

        count++;

        if(count==4)

        {

         Frequency=sum*4; //Calculate the frequency formula F=n*t; Here we calculate the count value 4 times, which is the frequency of 1S.

       sum=0;

        count=0;

          }

        TIM_SetCounter(TIM3,0); 


Keywords:STM32 Reference address:STM32 external counting ETR calculation frequency

Previous article:STM32 timer encoder mode calculates the number of AB phase pulses of the reduction motor
Next article:Understanding of STM32 address mapping

Recommended ReadingLatest update time:2024-11-16 12:43

stm32 FSMC-External SRAM IS62WV51216
Pin Definition  FSMC configuration steps 1. Enable the corresponding pin GPIO clock  2. Configure the GPIO pin mode  3. Enable the FSMC clock  4. FSMC initialization  5. Memory block enable Example  #define Bank1_SRAM3_ADDR ((u32)(0x68000000)) //First address 0x60000000, each block 0x40000000 void SRAM_gpio_ini
[Microcontroller]
About 8 working modes of GPIO in STM32
1 Overview I/O ports are very commonly used peripherals in microcontrollers. STM32's I/O ports have 8 states. Although I have not encountered any problems in the process of using them, I have not been very clear about them. Therefore, I will make a summary here (in fact, the concept here is also the same as other mi
[Microcontroller]
STM32 uses FSMC to control NAND flash routine
Recently, the development project needs to use STM32 to drive NAND FLASH, but because the development board routines and firmware library are for small pages (512B), the FLASH I need to use is 1G bit large page (2K), which took two more days of detours. The following notes will explain how to modify the default firmwa
[Microcontroller]
assert_param function in STM32 microcontroller
When we learn STM32, the function assert_param is very likely to appear. If you search online, you will find that the assertion mechanism is generally explained online and is used during the program development and debugging stage. Next, I will talk about my views on these applications. When learning something, you sh
[Microcontroller]
assert_param function in STM32 microcontroller
Implementation issues of printf and scanf in STM32
#include "sys.h" #include "usart3.h"       #include "stdarg.h"           #include "stdio.h"           #include "string.h" #include "timer.h"  //Serial port send buffer      __align(8) u8 USART3_TX_BUF ; //Send buffer, maximum USART3_MAX_SEND_LEN bytes //Serial port receive buffer      u8 USART3_RX_BUF ; //Receive buff
[Microcontroller]
stm32 runtime measurement and interval execution
This program uses the stm32 ordinary timer to form the execution time measurement function and the interval execution function. The usage is as follows. The two functions are reused and selected by #define //#define StopWatch in execution time test mode //use: #include "Runtime.h" Runtime_init(); while(1){      
[Microcontroller]
STM32 library function USART_SendData problem and solution
1. Problems and Phenomena There is no problem in using USART_SendData() function to send single characters non-continuously; when sending characters continuously (no delay between two characters), the sending buffer will overflow. If the amount of data sent is very small, the serial port will only send the last char
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号