cancel
Showing results for 
Search instead for 
Did you mean: 

Reading square wave signals

SHelg.1
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Javier1
Principal

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/

we dont need to firmware by ourselves, lets talk

View solution in original post

3 REPLIES 3
S.Ma
Principal

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.

I will have to try that, thank you

Javier1
Principal

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/

we dont need to firmware by ourselves, lets talk