Hardware Timer as a Microphone

Anything can happen in the field of electronics development. Who would have thought that a timer could be a microphone. However, it is true to some extent.

In the development of electronics that include a sound emitter, sometimes it is necessary to do a binary test for the presence of sound. In this text, I will show one of the simplest ways to do such a test.

Statement of the problem

It is necessary to determine the fact of the presence of sound in the microphone wire. It is not necessary to determine the frequency, it is not necessary to determine the spectrum. It is not necessary to recognize the signal. It is necessary to simply say whether there is sound or not.

What's the plan?

Apply sound to the microcontroller hardware timer and count positive drops. If the counter has increased, then there is sound. If it has not increased, then there is no sound.

Implementation

On my at32f435zm microcontroller, a wire from a differential pair, which comes from an analog microphone, is laid to GPIO PB5. In the microcontroller, on pin PB5, I activated the input channel, which clocks hardware timer #3 on the second channel.

This mode is called Input Capture. GPIO pin PB5 must be configured to enter the alternative function mode Timer 3 channel 2 (TMR3_CH2). This function corresponds to the PIN_MUX value equal to 2.

As soon as a positive difference is received, the counter should be increased by 1. In this way, the hardware timer will count the pulses from the microphone. A small comment on setting up the register map of timer 3. The timer should be switched to the mode External clock mode A.

Here are the key settings in the register map:

Register

bit field

meaning

explanation

TMRx_CTRL1

TMREN

1

Turn on timer

TMRx_STCTRL

SMSEL

7

External clock mode A — Rising edge of the TRGIN input clocks the counter

TMRx_STCTRL

STIS

6

Filtered input 2 (C1IF2)

TMRx_STCTRL

ESP

0

rising edge

TMRx_CM1

c2c

1

Input, C2IN is mapped on C2IFP2

TMRx_PR

PR

65535

maximum account limit

TMRx_CCTRL

c2en

1

Channel 2 enable

The remaining fields can be left unchanged, since when resetting they will be set to the desired values ​​by themselves.

This is the path that the clock signal should take from the microphone to the timer.

impulse path

impulse path

Debugging

I have UART CLI in my firmware. Therefore, I can debug the functionality separately, in parts. Here in the boot log, a text appeared about the channel being configured.

You can see that the GPIO has indeed switched to timer #3 channel 2.

Timer 3 configuration is entirely determined by its registers. Here is a valid config.

Timra 3

Timra 3

There was no sound yet, so the counter was expected to be at zero.

input_capture_diag

input_capture_diag

Now let's turn on the melody. This is what a fragment of the signal looks like on the oscilloscope.

analog signal on microphone

analog signal on microphone

After the melody has played, you can see that the hardware counter value has increased by 286.

input_capture_diag

input_capture_diag

It turns out that the sound sensor is working.

Advantages

++ This is a kind of ersatz technology for those who, for various reasons, cannot use audio codec chips.

++ Simplicity and crudeness. Nothing to break. Such an improvised sensor can be made even on discrete logic.

++ No calculations. No load on the microprocessor. Everything happens completely in hardware. The sound is clocked by a hardware timer.

++ This is a sanction-resistant method of sound testing.

Flaws

–It is impossible to understand the spectral component of sound.

–It is impossible to understand the meaning of the melody that was played.

Results

It was possible to make automatic sound detection using a regular hardware timer.

Dictionary

Acronym

Transcript

CMOS

Complementary Metal-Oxide-Semiconductor

CMOS

Complementary metal–oxide–semiconductor

Links

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *