1
\$\begingroup\$

I've experienced the following on both an STM32F4, and in my recent experiments with a Pi Pico.

(My goal, which isn't particularly relevant to the question is to create a -12V to +12V square wave using an H-bridge. To drive it I use the 2 microcontroller pins)

When one of my GPIO pins is high, the other is low. (They will feed into the INA1 and INA2 of the H-bridge)

The outputs of the microcontroller are the default Push-Pull. My understanding is that when LOW, it should be switched to GND.

Here is the output when I connect the scope to my two alternating GPIO pins enter image description here

And here is the output when connecting to 1 of my GPIO pins and actual GND enter image description here

So why all the extra noise when using a GPIO pin as a ground, and can I do anything about it?

UPDATE

In addition to the comment replies I have made, the issue is power supply related. In both examples the microcontroller (a raspberry pi pico in this case) was being powered through USB. When I removed USB power and connected a buck convertor, the output across the 2 GPIO pins becomes a nice noise-free square wave. While I can't explain the exactly why this works (I would probably need to understand the pi pico build-in power suppy), I am happy that my design will work.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Are you saying you're connecting the scope ground to the other toggling GPIO in the first trace? \$\endgroup\$ Commented May 10, 2021 at 19:05
  • \$\begingroup\$ That is correct @CristobolPolychronopolis \$\endgroup\$
    – Greg Woods
    Commented May 10, 2021 at 19:18
  • 3
    \$\begingroup\$ If you connect the scope ground to something not ground, the scope is floating. Don't do that, it will pick up random noise. Use the difference input feature of your scope instead if you want to watch differential outputs. \$\endgroup\$
    – Janka
    Commented May 10, 2021 at 19:52
  • \$\begingroup\$ @Janka I've never even used the second set of leads on scope until now, but yes, using both channels and difference shows a perfect square wave with from +3.3V to -3.3V as I was expecting. But my desired output is those 2 pins without any direct reference to gnd. Will I get this? Is the scope maths a good enough test? \$\endgroup\$
    – Greg Woods
    Commented May 10, 2021 at 20:55
  • 1
    \$\begingroup\$ If the device was grounded to Earth ground, the scope grounded to Earth ground, and two probes used with the math function, then yes, the math result is valid. \$\endgroup\$
    – rdtsc
    Commented May 10, 2021 at 21:03

3 Answers 3

8
\$\begingroup\$

I'm assuming that your STM hasn't burnt out that it is running from an isolated supply. Switching a GPIO low isn't a dead short to ground. It is a connection through a tiny gold bond wire, through a transistor to a portion of the silicon die bonded by another little gold bond wire shared by a load of other circuitry to the ground pin of the chip and from there out to the PCB and the PSU ground.

Connect your 'scope ground lead to the PSU GND and the probe to the GPIO and you will be able to measure the voltage drop across the GPIO when low. You will see some noise due to voltages induced by the other currents being switched and passed through the common ground connection.

\$\endgroup\$
3
  • \$\begingroup\$ Your remark "that it is running from an isolated supply" led me to disconnect from USB power and run from a separate buck convertor (which the final design will use anyway), so while not strictly speaking the answer, it did allow me to progress \$\endgroup\$
    – Greg Woods
    Commented May 10, 2021 at 20:58
  • 1
    \$\begingroup\$ Make sure that you understand what will happen to your scope if it has an earth connection through the mains and you connect the GND clip to a device that has a voltage offset from mains earth. A very high current may result in the scope's probe earth and damage to the scope may occur. \$\endgroup\$
    – Transistor
    Commented May 10, 2021 at 21:05
  • \$\begingroup\$ hmm... I did manage to make my scope "sing" which probably wasn't good, but all is well now :/ My lack of EE training was certainly showing. I certainly need to read up on scopes and earth! \$\endgroup\$
    – Greg Woods
    Commented May 10, 2021 at 21:13
3
\$\begingroup\$

Your scope ground is probably connected to earth ground. Now the question is whether your micro is also connected to earth ground...it probably is, because if it wasn't, you'd likely see the voltage double between the "real" ground connection and the second GPIO ground connection. This connection may be through the supply or through the grounding leads of other equipment.

Assuming it's connected and not floating, the noise you're seeing is probably due to the fact that your scope ground signal is taking a long roundabout way to the scope without a real ground connection. Your scope ground isn't providing a good current path; its only effect in that configuration is to load down the other GPIO. This can add to the apparent noise by including the remaining noise/voltage on the other pin, as well as straining the uP supply/power distribution by loading down the other pin.

If you want to see the differential voltage directly, you'll have to eliminate the other ground path. A far better approach is to attach a second probe and use the math function that will give you the difference between the two inputs, but I don't know what your probe situation is.

\$\endgroup\$
1
  • \$\begingroup\$ I disconnected USB and "fixed" the problem, and even without using the scope's maths functionality, I still got a good output. But using the scope second probe and the math difference feature was a good suggestion too, and enabled me to see what I needed even with USB connected. \$\endgroup\$
    – Greg Woods
    Commented May 10, 2021 at 21:07
1
\$\begingroup\$

Setting an output pin to logic 0 does not make it "be switched to GND". The voltage on such an output pin is guaranteed to be less than the \$V_{OL}\$ specification, but it can have any voltage below that value.

\$\endgroup\$
2
  • \$\begingroup\$ The exact voltage was never the issue, it was the noise that was the problem \$\endgroup\$
    – Greg Woods
    Commented May 10, 2021 at 20:58
  • 1
    \$\begingroup\$ The point is that you are not guaranteed any exact value. The "noise" is an allowed part of the value. \$\endgroup\$ Commented May 10, 2021 at 21:13

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.