Using 0-5VDC with n-channel mosfet for PWM on 12VDC

Thread Starter

jnobits

Joined Mar 7, 2019
23
Hello,
I've been stumped by a project because of a lack of understanding. I need to use an Arduino (because it's controlling a lot of other related stuff and has available outputs) to do pulse width modulation on 12VDC. I looked up solid state relays and could not find anything that had a control voltage of 0-5VDC and could switch up to 15VDC. Then i looked up mosfets and found some post showing using n-channel mosfets to do PWM but on smaller voltage. I purchased some n-channel mosfets and when I generate PWM from the Arduino, i get the correct frequency and duty cycle but wrong amplitude. This is using a single mosfet with arduino to signal, 12+ to source, and drain going to +12 side of load and -12 side of load going back to -12 on power supply. I think I have it hooked up wrong, but at the same time, i think the circuit is wrong.

Here is my goal:
Use Arduino 0-5V to generate a PWM signal (done, verified with oscilloscope)
apply that signal to a SSR or circuit that will:
-send a steady +12 volts when the signal (from arduino pin x) is just on (+5VDC)
-send 0VDC when the signal (from arduino pin x) is 0VDC
-PWM on the +12VDC when the signal (from arduino pin x) is PWM (generate the same PWM)

I don't understand circuits enough and its been so many years that I don't remember my options or how to complete this after my first attempt failed. Last night I tried to make a circuit in autodesk eagle free and could not get the mosfet to map so I could simulate the signal and test.

Any ideas on how i can complete this using mosfets? Or if there is a relay I can buy that can be used to send/mirror the 0-5VDC signal on 12VDC?
 

ericgibbs

Joined Jan 29, 2010
8,861
hi jno,
Welcome to AAC.
Do you have an image of your test circuit that you could post.? [autodesk screen grab.?]
Your description sounds like a common type of project for PWM
E
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
hey ericgibbs,

i'm going to try and make one again in a few minuets and upload it. the one i tried to make last night i deleted because i couldn't map the n-channel mosfet. I should have saved it so i didn't have to start over (im new to that program too). i'll post it soon
 

MrSoftware

Joined Oct 29, 2013
1,576
Can you hand sketch your schematic and post it, including part numbers for the mosfet part of the circuit? Also is your voltage really +12 and -12, or is it +12 and 0? I suspect you mean +12 and 0, like a battery, but need to be sure as having -12 could make a difference.

My first guess is the mosfet isn't turning all the way on. Double check the schematic to be sure it's wired correctly (or post your sketch here and we'll help). Also check the datasheet and see what voltage is required for the mosfet to turn all the way on, some require more than others. You need a logic level enhancement mode mosfet for your use case. If you have a scope, then scope the gate pin on the mosfet and be sure it's reaching that voltage, and quickly. If the picture on the scope looks more like a curve and less like a square wave, then it's possible the arduino pin can't move enough current to overcome the gate capacitance, in which case the fix would be either a mosfet with lower gate capacitance, or add some gate driver parts to your circuit.

Edit --> There are a number of simulators around, but I personally find the free online Multisim (https://www.multisim.com/) to be really easy to use, and you can save your circuits.
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
@btebo, thanks for that post. I have no idea what I'm doing. from my bad sketch you can see i'm missing a lot of stuff.

@MrSoftware, thank for the software recommendation. I will try them today.

Ok, here is a bad sketch, still trying to learn that program so i just sketched on paper what is hooked up and not working. One of my mosfets is bad but i have a few left. I'm sure i'm way off but not sure what/why/how lol.
 

Attachments

btebo

Joined Jul 7, 2017
89
@btebo, thanks for that post. I have no idea what I'm doing. from my bad sketch you can see i'm missing a lot of stuff.

@MrSoftware, thank for the software recommendation. I will try them today.

Ok, here is a bad sketch, still trying to learn that program so i just sketched on paper what is hooked up and not working. One of my mosfets is bad but i have a few left. I'm sure i'm way off but not sure what/why/how lol.
Looks like your MOSFET is wired incorrectly. My diagram should be good.

The "extra" components in my diagram perform the following functions:
The 10k resistor keeps the MOSFET from false triggering when there is no output from the Arduino.
The diode across the motor is call a flyback diode - when motors (and other inductive devices like a relay) turn off, they can generate voltage spikes that can damage the MOSFET. The diode must be installed properly or you will create a short.
 

MrSoftware

Joined Oct 29, 2013
1,576
You've got your mosfet connected incorrectly. Compare against the circuit posted by @btebo above. It needs to go on the - side of the circuit, connected as shown in his circuit.

Is your load a light? If yes, then that would be a low or no inductance load an the diode (shown across his motor) would not be necessary. If your load is a motor or something else with a coil then that would be an inductive load and you would need the diode to protect the rest of the circuit against big voltage spikes that can happen when current is suddenly turned off to an inductive load.
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
Thanks guys! That helps a lot. Just to make sure i understand the diagram correctly.

The load (12v light in this case) + on the light goes to power supply (VCC), the - on the light goes to D (Drain), and the cathode (-) part of diode gets connected (even though optional since its a light) to +12 volt supply (VCC) and the anode (+) part of the diode gets connected to D (drain). Does that sound correct?
 

btebo

Joined Jul 7, 2017
89
Thanks guys! That helps a lot. Just to make sure i understand the diagram correctly.

The load (12v light in this case) + on the light goes to power supply (VCC), the - on the light goes to D (Drain), and the cathode (-) part of diode gets connected (even though optional since its a light) to +12 volt supply (VCC) and the anode (+) part of the diode gets connected to D (drain). Does that sound correct?
Sounds good. You don't need the diode if you are only using a light bulb. If your lightbulb is an LED, you will need a current limiting resistor....
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
Is there a way to make the amplitude higher in the mosfet output? Maybe i'm going about this the wrong way.

I'm trying to reverse-engineer an old custom made component. When i measure the output of that part, it has the same frequency and duty cycle of what I'm generating with my circuit. But the amplitude is much higher on the old component. Both components have a 12VDC power source but I don't know/understand all the electronics inside the old part. I can only confirm the old part is:
  • being powered by 12VDC supply
  • when I measure the output voltage on the old part i get 1.445VDC when it's in PWM mode. Waveform attached as pic
  • when i measure the output voltage on the old part i get 11.38VDC when on and not in PWM mode (not outputting PWM).
Oscilloscope (yes its 20+ years old :)) is set to 2ms and 5V div. The one with the high amplitude is the output i'm trying to duplicate. The one with the low amplitude is from my circuit. With the current setup (modified to match schematic), i'm measuring 7.27VDC output when I'm generating the lower amplitude (if that's the right word) waveform.
 

Attachments

btebo

Joined Jul 7, 2017
89
Is there a way to make the amplitude higher in the mosfet output? Maybe i'm going about this the wrong way.

I'm trying to reverse-engineer an old custom made component. When i measure the output of that part, it has the same frequency and duty cycle of what I'm generating with my circuit. But the amplitude is much higher on the old component. Both components have a 12VDC power source but I don't know/understand all the electronics inside the old part. I can only confirm the old part is:
  • being powered by 12VDC supply
  • when I measure the output voltage on the old part i get 1.445VDC when it's in PWM mode. Waveform attached as pic
  • when i measure the output voltage on the old part i get 11.38VDC when on and not in PWM mode (not outputting PWM).
Oscilloscope (yes its 20+ years old :)) is set to 2ms and 5V div. The one with the high amplitude is the output i'm trying to duplicate. The one with the low amplitude is from my circuit. With the current setup (modified to match schematic), i'm measuring 7.27VDC output when I'm generating the lower amplitude (if that's the right word) waveform.
Could be that the current model MOSFET you are using isn't turning on all the way... when operating correctly with 12V powering the MOSFET, the peak should be close to 12V, and the minimum would of course be 0V. That's why we recommended a logic level MOSFET. The 5V signal from the Arduino may not be enough to fully turn on the gate of MOSFET - therefore you wouldn't have full conduction of 12V.
 

MrSoftware

Joined Oct 29, 2013
1,576
What is the part number (model number) of the mosfet you're using? Also where are you placing the scope probe?

Also the mosfet will not work properly where it is in your schematic, did you correct that before taking your scope screen shots?
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
Mosfet model number is IRLB8721 (IRLB8721PbF) from adafruit, spec sheet here.

When placing the scope probe, the positive is on the + output of the old part and the - probe is on the negative of the old part. One thing that is strange, if I don't have the negative probe of the scope connected to the negative on the old part, the waveform is crazy looking...all over the place like interference. However, when testing my circuit, the + probe is on the + of the power supply. Either there or at the Arduino output generates a good waveform without connecting negative to anything. I don't know why.
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
Mosfet model number is IRLB8721 (IRLB8721PbF) from adafruit, spec sheet here.

When placing the scope probe, the positive is on the + output of the old part and the - probe is on the negative of the old part. One thing that is strange, if I don't have the negative probe of the scope connected to the negative on the old part, the waveform is crazy looking...all over the place like interference. However, when testing my circuit, the + probe is on the + of the power supply. Either there or at the Arduino output generates a good waveform without connecting negative to anything. I don't know why.
Edit, yes the pictures are from after changing the layout of the circuit.
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
Could be that the current model MOSFET you are using isn't turning on all the way... when operating correctly with 12V powering the MOSFET, the peak should be close to 12V, and the minimum would of course be 0V. That's why we recommended a logic level MOSFET. The 5V signal from the Arduino may not be enough to fully turn on the gate of MOSFET - therefore you wouldn't have full conduction of 12V.
@btebo It's the same one from your post and same vendor (Adafruit, Product ID 355). How can I tell from the spec sheet if the 5v (which i think is reduced during PWM) is enough? Would it be the Gate Threshold Voltage Vgs(th) (min 1.35, max 2.35)?
 

ericgibbs

Joined Jan 29, 2010
8,861
hi jno,
That MOSFET d/s shows the Vgs threshold is OK for +5V.
E
BTW: During the PWM the On state will not be reduced from +5V, only the On period.
AA1 07-Mar-19 18.54.gif
 

MrSoftware

Joined Oct 29, 2013
1,576
At first glance, the spec says "Very Low RDS(on) at 4.5V VGS", which tells me the gate needs at least 4.5v to be considered fully-on. Some arduinos are 3.3v output and some 5v, are you sure yours is 5V?

Voltage is relative, so your scope ground must be connected to what you consider to be 0V for your circuit, such as - on your power supply. Else your readings will be meaningless. Put the probe on the drain of your mosfet. You're looking for the voltage at the drain to be 12v when the mosfet is off, and near 0v when the mosfet is fully on. If you see almost 0V when the mosfet is on, then that means it's fully on and working properly. You can put your second probe (other scope channel) on the mosfet gate to see both signals at once.

While in some cases it may be possible to connect the ground clip and probe across the load to measure voltage across the load, you have to be very careful about where you attach the scope ground clip. If your power supply is not isolated from the oscilloscope ground (wall outlet) then clipping the ground clip to a non-0V location would cause a direct short to ground through your oscilloscope ground, which rarely ends well.

Edit --> To answer your Vgth question; the threshold voltage is the gate voltage where it just begins to conduct, usually specified when there is a very tiny current through the mosfet. It does not tell you where the fet is fully-on.
 

Thread Starter

jnobits

Joined Mar 7, 2019
23
Thanks @ericgibbs, I have a alternate game plan now since I've been fighting this for a few days. If i buy a signal generator I can duplicate my goal but it would require the ability to change the voltage source for the light based on switching. For example:

  1. A) When pin x from arduino is HIGH, Light receives voltage from PWM board.
  2. B) When pin x from arduino is LOW, Light receives voltage straight from power supply
Given A and B share a common negative, is there a type of switch I could use to do this safely? Im my head i'm thinking (of course...it's abc!) But I can't remember what or maybe i'm thinking too simply.
 
Top