找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2448|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32F4 input_capture_frq

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:263845 發(fā)表于 2017-12-19 19:11 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
Input Capture Library (STM32F4)
To measure one (or more) external frequencies with the STM32F4, this library (s) can be used.
(there is also an extra LIB if the duty cycle is to be measured)

As with the PWM-Lib, I have each written a library for the four timers "TIM2, TIM3, TIM4, TIM5".

The timers are operated in input capture mode. The interrupt function is therefore called only once per Hi-edge from the external signal. After two hi-edges, the time interval between the edges is determined and stored. This value then corresponds to the period duration.

Per timer up to 4 different input signals can be measured.

The number and name of the channels to be used must be declared in the H file and assigned to the corresponding port pins in the C file.
(in the examples, I have always activated only two channels per timer)

The H-File also sets the clock frequency of the timer. This then applies to all channels and affects the resolution and the minimum frequency that can be measured.

Note: the function for reading the frequency only transfers the timer value of the period. The conversion into a frequency must be made extra if necessary. If there is no signal (or the measurement is not finished yet), the return value = 0. This means that a missing signal can be detected.

Image :


Benutzte Module der CooCox-IDE : GPIO, TIM, MISCBenutzte Librarys : keineEnumerationen (für FRQ mit TIM2) :
typedef enum {  ICFRQ_T2_PB11 = 0,  // FRQ-Messung per TIM2 an PB11  ICFRQ_T2_PA2  = 1   // FRQ-Messung per TIM2 an PA2}ICFRQ_TIM2_NAME_t;Funktionen (für FRQ mit TIM2) :
void UB_ICFRQ_TIM2_Init(void);                           // um die FRQ-Messung mit TIM2 zu initialisierenuint32_t UB_ICFRQ_TIM2_ReadFRQ(ICFRQ_TIM2_NAME_t vname); // zum auslesen der gemessenen FrequenzBeispiel :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//--------------------------------------------------------------
// File     : main.c
// Datum    : 10.07.2013
// Version  : 1.0
// Autor    : UB
// EMail    : mc-4u(@)t-online.de
// CPU      : STM32F4
// IDE      : CooCox CoIDE 1.7.0
// Module   : CMSIS_BOOT, M4_CMSIS_CORE
// Funktion : Demo der InputCapture FRQ-Library
// Hinweis  : Diese zwei Files muessen auf 8MHz stehen
//              "cmsis_boot/stm32f4xx.h"
//              "cmsis_boot/system_stm32f4xx.c"
//--------------------------------------------------------------

#include "main.h"
#include "stm32_ub_icfrq_tim2.h"

int main(void)
{
  uint32_t messwert=0,freuqenz=0;

  SystemInit(); // Quarz Einstellungen aktivieren

  // Init vom Timer2 zur FRQ-Messung
  UB_ICFRQ_TIM2_Init();

  while(1)
  {
    // gemessene FRQ an PB11 auslesen
    messwert=UB_ICFRQ_TIM2_ReadFRQ(ICFRQ_T2_PB11);
    if(messwert>0) {
      // wenn Messwert gueltig
      // frequenz ausrechnen
      freuqenz=(1000000/messwert);
    }
  }
}





全部資料51hei下載地址:
Demo_49_FRQ_IN.zip (233.79 KB, 下載次數(shù): 9)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表