Main Menu

Driving mosfet

Started by anton, December 11, 2014, 08:04:41 PM

anton

Hello all, i'm new with moteino, but have a little experience with arduino and jeenode.

I get a strange probleme.
I got a board with IRL540N Mosfet who is drived in pwm to control 12V lamp.
The output from the moteino is simply connected to the gate of the mosfet, my lamp connected to the drain and to +12V, and the source connected to a common ground with a 1k resistor connected betwen the gate and the source.

When i test my board with an arduino or a jeenode, it's work well and dimm my lamps without problem.
Whenn i plug a moteino instead of the jeenode with the same sketch inside, i get a strange beavior.
With nothing plug in the output of the Mosfet (no lamp), i can see with a voltmeter that my out dimm well.
But since i plug a lamp, i get 0V at the output and i can't turn it on.

Someone know from where the problem could came from?
What i did'nt understand it's that the same sketch and board work well with a jeenode.
They should be no difference between them.
I test the blink sketch, so it must be an electronical problem.

Thanks for all and sorry for my poor english.

TomWS

What Moteino pin did you use to drive the gate???


anton

I use the pins 3,4,5,6,7 and 9.
It's works well to drive some Leds, but not the mosfet.

TomWS

Other than pin 9, which Moteino uses to drive its own LED, the other pins should be ok to use and should drive that MOSFET for at least a 1-2 Amp load.  What is your power source for the Moteino?  If powered from 3.7-> 14V, the Moteino will have 3.3V outputs.  Standard Arduino boards would have 5Volt outputs, but I wouldn't expect this MOSFET to be too concerned about that. Vgs should be about 2.5V for a 1-2A load.

I have to ask, you are setting the pinMode(pin, OUTPUT), correct?

Tom

anton

yes of course, i set pinMode correctly.
The Mosfet drive 4-5A for a 12V lamp(50W).
The moteino has a +5v as power source from a 7805.
What i did'nt understand is, that i just test right know with a jeenode(exactly same stuff, 3,3v ATmega328) with the blink sketch and it's work. With the same sketch and same configuration on the moteino, it did'nt.
The only differences i could see, is the max current for pinout is 30mA on the moteino, i dont know the max current for the jeenode, and that the moteino as an atmega smd and the jeenode an atmega dip package.
Maybe a minimal current to drive the mosfet?
Does the moteino have a special pwm frequency?
I will test with a darlington array to up the current to see if i get a difference.
Very weard.

Felix

See the used pins in the diagrams here: http://lowpowerlab.com/moteino/#pinout
Stay away from pins 2,9-13 if you have the radio installed. Pin 9 is the onboard LED. Pin 8 is SPI CS for the FLASH chip if you have that installed.
A mosfet is logic driven not current driven like BJTs meaning you don't need significant amount of current to turn the gate ON.
The Jeenode has the same atmega328 and works at the same 9V but has no FLASH CS and no LED onboard.

ieris

Quote from: anton on December 12, 2014, 09:46:23 AM
yes of course, i set pinMode correctly.
The Mosfet drive 4-5A for a 12V lamp(50W).
The moteino has a +5v as power source from a 7805.
What i did'nt understand is, that i just test right know with a jeenode(exactly same stuff, 3,3v ATmega328) with the blink sketch and it's work. With the same sketch and same configuration on the moteino, it did'nt.
The only differences i could see, is the max current for pinout is 30mA on the moteino, i dont know the max current for the jeenode, and that the moteino as an atmega smd and the jeenode an atmega dip package.
Maybe a minimal current to drive the mosfet?
Does the moteino have a special pwm frequency?
I will test with a darlington array to up the current to see if i get a difference.
Very weard.
Most probably you need to modify a sketch as they have different pins. Are you testing physical pins (chip legs) or leg number?
I will bet for 99% that you are not measuring right pinout. ;)

TomWS

Quote from: anton on December 12, 2014, 09:46:23 AM
yes of course, i set pinMode correctly.
Sorry, don't be offended.  I had to ask.
Quote from: anton on December 12, 2014, 09:46:23 AM
The Mosfet drive 4-5A for a 12V lamp(50W).
The moteino has a +5v as power source from a 7805.
What i did'nt understand is, that i just test right know with a jeenode(exactly same stuff, 3,3v ATmega328) with the blink sketch and it's work. With the same sketch and same configuration on the moteino, it did'nt.
The only differences i could see, is the max current for pinout is 30mA on the moteino, i dont know the max current for the jeenode, and that the moteino as an atmega smd and the jeenode an atmega dip package.
Maybe a minimal current to drive the mosfet?
Doubt it, FETs are voltage controlled, not current controlled.  This would be a factor if very high speed switching but Arduino PWM is definitely NOT this.
Quote from: anton on December 12, 2014, 09:46:23 AM
Does the moteino have a special pwm frequency?
Nope.  Same ol', same ol'...
Quote from: anton on December 12, 2014, 09:46:23 AM

I will test with a darlington array to up the current to see if i get a difference.
Very weard.
Quote from: ieris on December 12, 2014, 03:07:36 PM
Most probably you need to modify a sketch as they have different pins. Are you testing physical pins (chip legs) or leg number?
I will bet for 99% that you are not measuring right pinout. ;)
I think ieris may be on to something (or 'on' something, can't tell which).  But, rather than trying darlington or other driver, try  something simple like 470 ohm resistor and an LED.  Turn it on and off first and then control with PWM to dim it... 

Tom

kiwisincebirth

I think the 3.3V is not enough voltage to turn the mosfet on. I tested your circuit (as you described in OP). With V1 set to 5V the mostfet was turned on

https://www.circuitlab.com/circuit/btsu2r/screenshot/540x405/

If I adjusted V1 to 3.3V the Mosfet was turned off. My only suggestion would be to replace R1 with a pull-up (to 12V) resistor. If you want to play with the circuit this link might help.

https://www.circuitlab.com/circuit/btsu2r/testmosfet/

anton

Thanks kiwisincenirth,
what do you mean by replace R1 with a pull up to 12v resistor?
do you mean plug the resistance between the gate and +12v instead of between the gate and the ground? The shematic from circuitlab is exactly the same as mine.

@ieris: i don't think there is a pin number problem. i test with only a blink sketch on pin 4.
With a jeenode plug on port1 DIO(pin 4) the mosfet turn on. With a moteino and a Led pluged on pin 4 it's work Well, with the moteino and the mosfet plug on pin 4 it's work if i test with a voltmeter but stay closed if i plug a lamp instead of the voltmeter (0v tested). The lamp work alone, i test it as well.

I think kiwisincebirth is more close, the 3,3v voltage is not enough, but why does it work with jeenode? it is a 3,3v board as well.

kiwisincebirth

Quote from: anton on December 13, 2014, 05:05:39 AM
Thanks kiwisincenirth,
what do you mean by replace R1 with a pull up to 12v resistor?
do you mean plug the resistance between the gate and +12v instead of between the gate and the ground? The shematic from circuitlab is exactly the same as mine.

I think kiwisincebirth is more close, the 3,3v voltage is not enough, but why does it work with jeenode? it is a 3,3v board as well.
Yes that is what I mean, but on reflection, and a bit more thought here is a better solution. See Attachment

The problem is that the mosfet you are using has a threshold voltage of 2-4 volts, in the simulator it required 3.5 volts to turn on, thus why triggering it is problematic. The circuit (attached) solves this by holding the mostfet in an ON state via pull up resistor (R1) and using an NPN transistor (Q1) which when switched on will pull the gate of the mosfet down to GND. The only issue this creates is that it is now an inverting circuit, a 0V input will turn the LAMP on, a high input will turn the lamp off. To counter this R2 and R3 form a voltage divider which provide a 3.3 Input to the base of the NPN Transistor. Thus the lamp will remain off, until you output 0V on your Motino Pin.

Of course this does add extra components, but should eliminate all issues driving the MOSFET. However have you considered alternates to using a MOSFET, e.g. Relay?

Kiwi





TomWS

#11
Good catch on the insufficient voltage on the MOSFET gate.  I looked at the datasheet and the Vgsth should be able to drive this load without an issue.  Seems like a marginal FET to me...

A couple of observations about this circuit:
R2 is potentially dangerous (will blow out the AtMega328P if the 2N3904 is removed for any reason) and should be referenced to the AtMega328P supply voltage, not 12V.
Also, the AtMega328P shouldn't drive the base of the 2N3904 directly, there should be a series resistor UNLESS the Moteino output pin is configured to be an open drain circuit.
Since R3 is unnecessary (the Moteino will sink the base solidly to ground), it can be used as the series resistor from a conventional output from the Moteino.

Tom
UPDATE: also, move R2 to the Moteino end of the series resistor rather than the base of the 2N3904.

kiwisincebirth

I would agree with TomWS suggestions.

Anon: Has this helped, have you progressed ?