MOSFET as a PWM switch

Hi,

my project uses a bunch of Adafruit DRV8871 PWM motor drivers. My problem is the I'm short of PWM ports, so I can't just give a PWM port to IN1 and an other one for IN2.

My idea is what I saw at other drivers: to have a regular port called DIR which
-connects the PWM to IN1 if it's LOW
-connects the PWM to IN2 when it's HIGH

As far as I understood, I need a dual channel MOSFET, where one is P and the other is N channel. This would function as a switch.

My problem is that I'm not sure if I'm right and I'm not sure if what I found is the right on (yes, it's 4 a channel MOSFET, I want to save some space):

Could you please check it?
Thanks.

yes, it's 4 a channel MOSFET, I want to save some space

No it is not, it is a H-bridge.

My idea is what I saw at other drivers: to have a regular port called DIR which
-connects the PWM to IN1 if it's LOW
-connects the PWM to IN2 when it's HIGH

Yes that is what everyone does.
Putting a PWM signal on both inputs will not work.

Grumpy_Mike:
Yes that is what everyone does.
Putting a PWM signal on both inputs will not work.

So is using an N channel MOSFET connected to IN1 and a P channel channel MOSFET connected to IN2, using the same PWM port and one digital port as gate would function as a switch?

So is using an N channel MOSFET connected to IN1 and a P channel channel MOSFET connected to IN2, using the same PWM port and one digital port as gate would function as a switch?

No. You need a H-bridge, like the two things you posted.

hunelpaso:
my project uses a bunch of Adafruit DRV8871 PWM motor drivers. My problem is the I'm short of PWM ports, so I can't just give a PWM port to IN1 and an other one for IN2.

My idea is what I saw at other drivers: to have a regular port called DIR which
-connects the PWM to IN1 if it's LOW
-connects the PWM to IN2 when it's HIGH

If I understand this correctly you want a system that allows you to direct a single Arduino PWM signal to either of the two inputs on your Adafruit H-bridge.

You don't need a MOSFET for that. You need a suitable logic chip - perhaps a 74HC00 quad NAND gate. Feed the PWM signal into two different gates (and out to the two different H-bridge inputs) and use any other I/O pin to determine which gate is active. You will also need to ensure that the other H-bridge input is low - maybe that could be done with a suitable pull-down resistor.

(By the way I'm not certain that a NAND gate is the correct choice, but it should get you thinking in the right direction)

...R

Robin2:
If I understand this correctly you want a system that allows you to direct a single Arduino PWM signal to either of the two inputs on your Adafruit H-bridge.

You don't need a MOSFET for that. You need a suitable logic chip - perhaps a 74HC00 quad NAND gate. Feed the PWM signal into two different gates (and out to the two different H-bridge inputs) and use any other I/O pin to determine which gate is active. You will also need to ensure that the other H-bridge input is low - maybe that could be done with a suitable pull-down resistor.

(By the way I'm not certain that a NAND gate is the correct choice, but it should get you thinking in the right direction)

...R

Thank you!!! :slight_smile:

"a bunch of" is more than six?
You ofcourse only need ONE PWM pin per motor driver, not two.
Leo..

Wawa:
You ofcourse only need ONE PWM pin per motor driver, not two.

Depends on the motor driver. Many of them have no Direction pin and the direction is determined by whichever input pin is fed with the PWM signal - hence you need 2 Arduino PWM pins (one for FWD and one for REV) or external "steering" hardware..

,,,R

Hi,

  • What is the application?
  • Do you need to control speed and change direction?
  • Do you need indepedant control of each motor.
  • How many is heaps?
  • What model Arduino are you using?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Robin2:
Depends on the motor driver. Many of them have no Direction pin and the direction is determined by whichever input pin is fed with the PWM signal - hence you need 2 Arduino PWM pins (one for FWD and one for REV) or external "steering" hardware..

So input#1 LOW, and input#2 PWM 0-255,
or
input#1 HIGH, and input#2 PWM 255-0,
wouldn't work for speed control in two directions?

Might need a bit of extra code to take care of braking/coasting modes of the DRV8871.
Leo..

So last night I figured it out based on your comments. To implement the DIR swich, I need a NAND gate and two N-channel mosfets.

The DIR line comes from a digital output pin and goes to two places:
-to the gate of one N-channel MOSFET
-to both inputs of the NAND gate (which makes it a NOT gate)
-this will be wired to the gate of the other N-channel MOSFET

The PWM signal will be connected to the sources of the two N-channel MOSFETs.

As a result one MOSFET will be always turned on and one will be always turned off depending on if DIR high or low, and the PWM signal will remain untouched.

Wawa:
So input#1 LOW, and input#2 PWM 0-255,
or
input#1 HIGH, and input#2 PWM 255-0,
wouldn't work for speed control in two directions?

Might need a bit of extra code to take care of braking/coasting modes of the DRV8871.

I had not thought of that. I think the h-bridges I have treat a pair of HIGHs differently from a pair of LOWs

...R

Robin2:
I think the h-bridges I have treat a pair of HIGHs differently from a pair of LOWs

Yep. This DRV8871 driver does.

00 = high impedance (coast)
01 = reverse
10 = forward
11 = brake

Should be able to get all four states with code.
Should try some day.
Leo..

Wawa:
Yep. This DRV8871 driver does.

00 = high impedance (coast)
01 = reverse
10 = forward
11 = brake

Should be able to get all four states with code..

Of course you can - just use one Arduino PWM pin for reverse and another for forward.

...R

Robin2:
Of course you can - just use one Arduino PWM pin for reverse and another for forward.

...R

which leads back to the problem that I have one PWM :stuck_out_tongue: But As I wrote before, I can implement the switch with logic gates and mosfets:
IMG_0020.jpg

IMG_0020.jpg

hunelpaso:
But As I wrote before, I can implement the switch with logic gates and mosfets:

But you don't need mosfets because you are not switching power in that part of the process. Just use logic gates in place of the mosfets.

Think about ... all the stuff that is going on inside the Arduino is being done by logic gates, so a few more will be fine.

...R

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Please draw proper NOT and MOSFET symbols and label gate, drain and source.
Include power supplies and gnd circuitry.

Your diagram makes no sense, you show a MOSFET with 2 inputs. I know they exist but are very rare these days.
There is no gnd circuit or how you are going to supply power the components.

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks… Tom… :slight_smile:

Robin2:
But you don't need mosfets because you are not switching power in that part of the process. Just use logic gates in place of the mosfets.

Think about ... all the stuff that is going on inside the Arduino is being done by logic gates, so a few more will be fine.

...R

My problem is the PWM, it's not HIGH or LOW. If we consider LOW as 0 and HIGH as 255 on a digital port then what happens on an AND gate when it gets:
-HIGH(255) + 20 from the PWM?
-LOW(0) + 188 from a PWM?
-LOW(0) + 33?
etc?

Where is the threshold? What is the result of combining a PWM signal on a gate with a Digital signal?

TomGeorge:
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Please draw proper NOT and MOSFET symbols and label gate, drain and source.
Include power supplies and gnd circuitry.

Your diagram makes no sense, you show a MOSFET with 2 inputs. I know they exist but are very rare these days.
There is no gnd circuit or how you are going to supply power the components.

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

It just came to my mind that I was thinking about mosfets as relays... I need to sleep a little, sorry.

PWM from analogWrite() is a sequence of HIGHs and LOWs (5v or 0v) there is nothing in between.

The amount of power eventually passed to the motor by the motor driver depends on the percentage of time that the pulse is HIGH.

If one input of an AND gate is held HIGH and the PWM applied to the other input then the output will faithfully replicate the HIGHs and LOWs of the PWM signal. If the first input is LOW then the output will always be LOW.

...R