0
\$\begingroup\$

I'm using an STM32F103 to measure water flow through a pipe using Hall flow sensors. My power supply is 12V DC to 5V/3.3V DC. STM works with 3.3V and Hall sensors with 5V levels. I've configured the TIM4 as Input Capture and connected it directly to the flow sensor output and I'm counting the number of ticks per second to determine the flow.

What I've noticed is that even when there is no flow, the sensor gives out random values. To the same PS I also have connected an LCD display, 2x Hall flow sensors, a 555 timer, and 2x STM32s. What I want to know is will this issue be solved by just using optocouplers on every input from Hall sensor to the GPIO pin? I'm thinking since all of these devices have a common ground there is a lot of noise in the system, but maybe the issue is something else?

\$\endgroup\$
6
  • \$\begingroup\$ Do you have level shifters between the Hall sensors and the microcontroller? You should; at low frequency a resistor voltage divider might work. Try using one Hall sensor alone and look at the output with an oscilloscope. How does it look? \$\endgroup\$ Commented Jul 3, 2019 at 11:40
  • \$\begingroup\$ Since i'm detecting rising edges with the STM , and the GPIO pins are 5V tolerant i was thinking it won't make much of a difference and i just connected it directly without any level shifters. And yes the frequency will be low. \$\endgroup\$ Commented Jul 3, 2019 at 11:46
  • \$\begingroup\$ OK, sorry, I didn't realize the inputs are 5V-tolerant. \$\endgroup\$ Commented Jul 3, 2019 at 12:01
  • 1
    \$\begingroup\$ Which flow sensor do you have, and how it wired to the STM32? What do you get if you measure the sensor output directly with a meter or oscilloscope? \$\endgroup\$ Commented Jul 3, 2019 at 15:23
  • \$\begingroup\$ Speratly both of them work when connected to a power source and measured by an osciloscope. I'm using a PCB protoboard where i've soldered male pins which are connected to the PS and the STM32. Whilst the sensor is crimped on a female connector, i've noticed that if both of them are connected they work properly, so i'm guessing it didn't work because one was connected and other was floating . I'm sorry for my late response. I guess the issue was solved by connecting both of them, the reason why is still unclear. Thank you for your responses, it was helpfull. \$\endgroup\$ Commented Jul 5, 2019 at 14:05

1 Answer 1

0
\$\begingroup\$

Should not be any problem. But you could use a Zener for possible voltage spikes (5.1V for instance). Also, you need to make sure you are using the 5V tolerant pins, as not all pins of the STM32F103 are 5V tolerant.

Regarding your noise problem, you could try to simply add a small capacitor from signal to ground to suppress some false triggering due to noise. You might also add a pull-down resistor. Using an Opto Isolator wouldn't make sense since your using the same power supply for both sides.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.