Sterling
Sterling
DIIDevHeads IoT Integration Server
Created by Sterling on 9/27/2024 in #firmware-and-baremetal
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:
while (1)
{
if(gu32_Freq <= 200)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); // Set pin high if frequency <= 200 Hz

if(gu32_Freq > 200)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // Set pin low if frequency > 200 Hz
}
while (1)
{
if(gu32_Freq <= 200)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); // Set pin high if frequency <= 200 Hz

if(gu32_Freq > 200)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // Set pin low if frequency > 200 Hz
}
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?
4 replies