Why doesn't my GPIO pin stay high below 200 Hz in my frequency counter code?
I'm using a frequency counter code from Deep Blue Embedded to monitor RPM via a tachometer and trigger a relay when the frequency drops below 200 Hz. However, the output on pin PB14 doesn't stay high at low frequencies (tested between 100 Hz and 500 Hz). The signal on the oscilloscope fluctuates instead of staying steady. Here's the relevant portion of the code I'm working with:
Even when the frequency drops below 200 Hz, the pin doesn’t stay high as expected. Could the leftover UART code (without a connected hardware) be causing this? Also, I tried using PA0, but it didn’t work either. How can I safely remove the UART code without breaking the program?
Solution:Jump to solution
The frequency counter might not be reading consistently at lower frequencies.add a small debounce delay or hysteresis to stabilize the pin state. The UART code likely isn't affecting this, but if unused, you can comment it out or disable UART in the initialization code to avoid resource conflicts. For PA0 not working, ensure it's not reserved for other functions, like input capture.
2 Replies
Solution
The frequency counter might not be reading consistently at lower frequencies.add a small debounce delay or hysteresis to stabilize the pin state. The UART code likely isn't affecting this, but if unused, you can comment it out or disable UART in the initialization code to avoid resource conflicts. For PA0 not working, ensure it's not reserved for other functions, like input capture.
Hi @wafa_ath This was really helpful, I added a small debounce delay and some hysteresis, which stabilized the pin state, and now the output behaves as expected at lower frequencies. I also commented out the UART code as suggested, and it didn’t seem to affect anything negatively.
As for PA0, I realized it was reserved for input capture, so that explained why it wasn’t working for this case. Everything is working smoothly now! Thanks again!