Showing results for 
Search instead 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!



a) if your logic level is not really 3V3 CMOS (where high level is above the limit to see a high, e.g. 2.4V) or the inputs use a Schmitt Trigger (with a hysteresis) - you might not see all pulses properly:

b) Nyquist or Shannon Theorem:
    You need 2xFs in order to realize a sine wave (doubled sampling frequency compared to the frequency of the signal)
    for 1.24 MHz sine wave expected (or able to see) - you have to sample (at least) with 2.48 MHz

Associate III

Using DMA instead of interrupts fixed it. I guess I really shouldn't have used them in the first place.

I am now executing two 'HAL_TIM_IC_Start_DMA' back to back with different variables. I am not entirely certain how they behave when used like that but I think it should start the first one and then immediately start the second one when it finished, like with circular.