cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474RE - Wrong Frequency Displayed when Input signal Function Generator gets disconnected

Priyam1204
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

1 REPLY 1
TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".