1
\$\begingroup\$

Is is possible to measure the frequency of an input analog signal with the input capture mode of Timers in STM32F4 ? If not, then what is the alternative ? Thank you in advance.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ How does your analog signal looks like in comparison to the digital signal that the timer capture pin wants to see? \$\endgroup\$
    – Turbo J
    Aug 30, 2015 at 11:15

1 Answer 1

3
\$\begingroup\$

Introduction

It seems like you are trying to build a frequency counter. You can achieve such a device with the timer module in a microcontroller. Be aware that it will have some limitations in terms of how fast of a signal it can observe.

Analog Processing

You will need to first condition the input signal. To know what is required, I would first need to know a bit more about your signal, but I will assume you are trying to measure the frequency of something that is basically a sine/square wave perhaps with some DC offset. We need to get from this general analog signal to a digital square wave that represents the same edges. We can do that with the following comparator circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

Microcontroller Configuration

Configure your microcontroller to count up until it sees a rising edge on the output of the comparator. Increase the timer frequency as high as possible to achieve the frequency resolution you require. You will also want to fire an interrupt on a capture event so you can do something with the new data.

Algorithm

When the interrupt is fired grab the value in the capture register and compute the frequency of the signal as follows:

$$f_{in} = \frac{f_{timer}}{count}$$

You may then wish to average several of these readings.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.