cancel
Showing results for
Did you mean:

# Input capture not detecting square wave

Associate III

I have built a sine wave to square wave circuit and now want to measure its frequency with the STM. I can see on the oscilloscope that the circuit works, however I can detect neither a rising nor a falling edge with the chip. It is not a problem with the code as I can detect both when they are generated by the chip with PWM or externally with a generator (which is old and its square wave really isn't that square) but also they are much slower.

The frequency of the wave is 1.24MHz, measured with the oscilloscope. I don't think that this is too fast, the timer runs at 96Mhz, but maybe using interrupts at this speed is too much?

The minimum voltage of the wave is 0.6V. I am suspecting that might be too high to be considered a logical 0 but I can't find documentation.

I would appreciate any input and also if you could point me to documentation that would be nice!

1 ACCEPTED SOLUTION

Accepted Solutions
Guru

> The frequency of the wave is 1.24MHz, measured with the oscilloscope. I don't think that this is too fast, the timer runs at 96Mhz, but maybe using interrupts at this speed is too much?

Using interrupts at 1.24 MHz is not realistic. You should expect to be limited to tens of kHz in general.

You can use DMA to capture frequencies at this rate. Capture IC to a DMA buffer and process it at the half- and/or full-complete interrupts.

11 REPLIES 11
Chief

>point me to documentation

See ds and rm from your chip (on STM website )

+

To count frequency, need to use external clk input for timer .

This from F407 ds , you didnt tell your device.

Associate III

I am using the STM32F411CEU6.
In its datasheet it says "1.7V<=V_DD<=3.6V". I am correct to then say that my 0.6V should get read as a logical low, right?

Using a HSE clock, TIM2; PCLK1 runs at 48MHz,  PCLK2 runs at 96MHz. I am using Input capture direct mode, if that matters.
I don't really know why it doesn't work then, if voltage isn't the problem and TIM2 runs fast enough to be able to detect edges.

Guru

Hardware error? Bug in the software?

Write a simple experimental program, which sets that input pin as GPIO input and some other pin as GPIO output; and the program does nothing else in main loop just reads the state of input and writes the output accordingly. If you avoid Cube and set reasonable optimization, this should be fast enough so that on output you'll see "copy" of the input (you can try also with some slower input signal source first).

JW

Guru

> The frequency of the wave is 1.24MHz, measured with the oscilloscope. I don't think that this is too fast, the timer runs at 96Mhz, but maybe using interrupts at this speed is too much?

Using interrupts at 1.24 MHz is not realistic. You should expect to be limited to tens of kHz in general.

You can use DMA to capture frequencies at this rate. Capture IC to a DMA buffer and process it at the half- and/or full-complete interrupts.

Guru

> Using interrupts at 1.24 MHz is not realistic.

True (especially so if Cube/HAL is involved), but how does that explain

>> I can detect neither a rising nor a falling edge with the chip

?

By interrupt flooding, and "detect" relying on some software output, without actually looking at the TIMx_CCRx registers in debugger?

JW

You didnt understand, what i tried to say :

you should not use "capture mode" or so, but external clk input + gating the timer for (typical 0,1 ...1 sec);

then you see in counter the counted pulses, in 1 sec gating -> 1,2 mio pulses (only with TIM2 , 32bit possible),

otherwise 16bit counter would overflow.

TIMx_ETR is the input for counting external frequency . So you get max. resolution .

Associate III

For my application it is beneficial to get the measurement in the shortest amount of time, which is the length of one period. (Even if there is some small error to it)

I will try DMA first and see if that helps. If it doesn't I will use your suggestion.

Ok - but even if you make the gating time only 1 ms , still you get much better resolution , than checking only 1 input pulse.

1,24 MHz -> 806 ns ;

with 96 M counter you get 77 +/- 1 counts ;

with 1ms gate, you get 1240 +/-1 counts ;

Depends, whether you can live with 2% tolerance, or want 0,1% or better .