找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2448|回复: 0
打印 上一主题 下一主题
收起左侧

STM32F4 input_capture_frq

[复制链接]
跳转到指定楼层
楼主
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, 下载次数: 9)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表