# Optimizing needed pins of a full H-Bridge using logic.

#### Graylord

Joined Jan 19, 2018
4
Hi! My first post here, and I'm a bit new to electronics, and have gone from using premade, modular circuits, to making my own power supply, voltage regulators, H-Bridges for DC motors, etc, designed for my specific uses, needs, currents and voltages. But I haven't touched much on logic circuits yet and could use some help. I have programming experience though, so once I get a bit more of an understanding of my options and their uses I hopefully should be able to wrap my head around it.

I've currently set up an H bridge, it uses 3 inputs at the moment, one for deciding high or low on the left side, one for high and low for the right side and one for PWM. It is based on the schematic from "Intermediate Robot building" by David Cook.

Here's is a schematic of the bridge for reference.

Im planning to use this for 4 motors, this totals up to 12 outputs on my MCU! My programmer brain is telling me there should be some way to avoid using a lot of them by using some Mosfets (for efficiency) as simple logic conditions. Or perhaps there are some logic chips that I'm not aware of that would be a better choice, or even a chip that entirely reaches my end goal.

For instance, for 1 output on my MCU, hook it up to both an n-channel and a p-channel MOSFET. Then hook the p-channel MOSFET to the input of the driver chip of the left motor that makes it go clockwise as well as the input of the chip of right motor for counter clockwise. This results in forwards motion. When sending a 0v signal, the n-channel mosfet turns on and does the exact same process inverted, making it go backwards.

I might also be doubling up on the amounts of components needed here, I suspect I could use a single component making use of both 0v and 5v output, a comparator perhaps?

So this should reduce backwards and forwards motion, controlling 2 motors, to a single pin, right?

My bot is omnidirectional, making use of motor on the left, right, front and back. (currently replacing power and brains with a circuit made from scratch, instead of using an Arduino and modules, hence the topic)

In the end I'm thinking I'm only going to need 5 outputs from my MCU by efficiently using 0v/5v as booleans.

• 1. Forwards/Backwards (5v/0v)
• 2. Rotate left/right (5v/0v)
• 3. Strafe left/right (5v/0v)
• 4. Speed control of front & back motors (PWM)
• 5. Speed control of left & right motors (PWM)
(I've separated the 2 speed controls as I'm planning to make it controllable with an analogue stick, so the controller might want to make it go slightly diagonally forward/left for instance)

Though I admit im not certain if this will lose braking? What happens if I set PWM to 0 on both output 4 and 5? I don't need coasting. If that wouldn't work, I'm not intending to make the user able to move and rotate at once, so perhaps braking when all inputs are 0v would be viable? I could consider sacrificing a 6th output pin and just add a dedicated brake signal, giving me the opportunity for a dedicated brake button as well.

Is this a decent approach? Any issues with this setup I'm not aware of or better ways of handling it? I would also love some simple guides or examples for reference, as I am finding all the hookups and logic a bit much to wrap my head around all at once. (Perhaps there's some software I can use to plan and try out the logic even?)

I found this tutorial which touches on bridging both directions with a "not" gate so that there's a single pin for direction, it also states you can "use logic to filter the control lines so that the PWM signal is combined with the direction signals."

But it never actually goes into how to accomplish this, what exactly would I need?

Cheers and sorry for the long post!