Skip to main content
Explorer
March 8, 2023
Solved

Reading square wave signals

  • March 8, 2023
  • 2 replies
  • 4875 views

I am trying to read a square wave, or rather I am trying to detect when a square wave is falling using the Nucleo-F746ZG board. Using CMSIS v2, using STMCubeIDE 10.1

The square wave comes from a flow sensor, and every time it goes from high to low an interrupt is supposed to increment a value within the program.

in the .ioc file I have set up a pin and an interrupt, the pin is called FLOW_SENSOR_Pin, and the interrupt is called FLOW_SENSOR_EXTI_IRQn. For reference the pin is the PG3 pin. I have checked the signal with an oscilloscope and the sensor works as intended.

The code compiles and is downloaded to the board without problems, though the interrupt never seems to trigger.

I have attached the relevant files for the problem.

Below is the init function for the flow sensor thread.

GPIO_InitTypeDef GPIO_InitStruct = {0};

  GPIO_InitStruct.Pin = FLOW_SENSOR_Pin;

  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  HAL_GPIO_Init(FLOW_SENSOR_GPIO_Port, &GPIO_InitStruct);

  // Enable the interrupt for the input pin

  HAL_NVIC_SetPriority(FLOW_SENSOR_EXTI_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(FLOW_SENSOR_EXTI_IRQn);

Am I using a suitable pin for this application?

Or does the lack of interrupt triggers come from something else I have done?

    This topic has been closed for replies.
    Best answer by Javier1

    as @S.Ma​ said, there is many ways of counting pulses but the nicest one is to use a timer in counter configuration.

    https://deepbluembedded.com/stm32-counter-mode-example-frequency-counter-timer-in-counter-mode/

    2 replies

    Visitor II
    March 8, 2023

    Why not using a timer using the input signal as clock to increment it as edge counter? ETR or CH1 or CH2 are typical candidates.

    SHelg.1Author
    Explorer
    March 8, 2023

    I will have to try that, thank you

    Javier1Answer
    Graduate II
    March 8, 2023

    as @S.Ma​ said, there is many ways of counting pulses but the nicest one is to use a timer in counter configuration.

    https://deepbluembedded.com/stm32-counter-mode-example-frequency-counter-timer-in-counter-mode/