2025-06-02 5:58 AM
Hello Everyone,
I'm using a Nucleo-G474RE board with TIM20 configured in input capture mode on channels 1–3 to measure PWM frequency from a function generator. Everything works fine when the signal is active, but when I turn off or disconnect the input, the code starts reporting a consistent 50 Hz frequency on the channel that gets disconnected—even though there is no signal. I'm using HAL, and the input pins (PB2, PC2, PC8) are configured without any pull-up/down resistors. I suspect it's retaining old capture values because when I was developing the code I was testing one timer channel with constant 50hz signal. Or Maybe it is caused by some electronic noise . How can I make sure the timer detects that the signal is lost and reports 0 Hz instead of a false frequency?
Solved! Go to Solution.
2025-06-02 6:01 AM
50 Hz is probably the signal from the electrical lines. Are you in a country with 50 Hz mains?
If the signal is floating or not connected, it is free to pick up noise from any source. Use an internal or external pull resistor to set the pin to a known state when there is nothing else driving it.
2025-06-02 6:01 AM
50 Hz is probably the signal from the electrical lines. Are you in a country with 50 Hz mains?
If the signal is floating or not connected, it is free to pick up noise from any source. Use an internal or external pull resistor to set the pin to a known state when there is nothing else driving it.