Trouble with a MOSFET

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to use an AVR ATiny85 to control some high power LEDs (13W worth) using a International Rectifier's HEXFET Power MOSFET (datasheet attached). I assembled a test circuit and am trying to control the LEDs throught the MOSFET by using the Tiny's fast PWM to adjust the brightness of the LEDs.

When I connect the circuit after programming the Tiny, the LEDs do not turn on unless I come into contact with the gate pin, in which case they flicker (at first I thought the flickering was the system working so I adjusted the PWM frequency to get rid of the flicker but it remained at the same frequency indicating it is not).

I have the output pin from the Tiny hooked up directly to the gate pin on the MOSFET. Is this the configuration it should be in? do I need a pull up/ pull down resistor? is there some configuration I am missing in the Tiny? (code at the bottom)

From the datasheet of the transistor I thought it would work but I am no expert in these matters.

Please help

******************************************
Code
******************************************

.def Temp = R16
.def Temp2 = R23
.def Level = R17

.CSEG
.ORG $0000
rjmp RESET
reti
reti
reti
rjmp increment
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti

RESET:

ldi Temp,(1<<DDB0)|(0<<DDB1)|(0<<DDB2)|(0<<DDB3)|(0<<DDB4)|(0<<DDB5)
out DDRB,Temp
ldi Temp, (1<<PORTB4)|(1<<PORTB0)
out PORTB, Temp
SEI
ldi temp, HIGH(RAMEND) ; Init MSB stack
out SPH,temp
ldi temp, LOW(RAMEND) ; Init LSB stack
out SPL,temp
ldi Temp, (1<<TSM)|(1<<PSR0)
out GTCCR, Temp
ldi Temp, (0<<CS02)|(1<<CS01)|(1<<CS00)
out TCCR0B, Temp
ldi Temp, 0x00
out GTCCR, Temp
ldi Temp, (1<<WGM00)|(1<<WGM01)|(1<<COM0A1)
out TCCR0A, Temp
ldi Level, 0
out OCR0A, Level
ldi Temp, (1<<CS13)|(1<<CS12)|(1<<CS11)|(1<<CS10)
out TCCR1, Temp
ldi Temp, (1<<TOIE1)
out TIMSK, Temp

MAIN:
nop
rjmp MAIN

increment:
inc Level
out OCR0A, Level
reti

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is a copy of the basic circuit atm.[/img]

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have a scope to verify what is arriving at the mosfet gate ?

As short test you could connect a small LED over 330 Ohm to the tiny output. You should be able to vary its brightness with the PWM.

Other remark: You should separate the power supply of the LED and the tiny. At least using inductor or resistor and a capacitor. You attempt to switch a couple of amps and there might be enough ripple on the power supply to disturb the tiny. Do you have a bypass capacitor ?

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think the AVR is capable of driving the MOSFET in your application. Although the MOSFET is a voltage-controlled device it has a large gate capacitance that you have to overcome when you switch it on and off. You will need some form of gate driver IC or maybe rig up an NPN/PNP push-pull to drive the gate. Also it good to have a pull-down resistor on the gate so that its in a known state when you power up your circuit.

-=mike=-

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is your PWM frequency ?

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you absolutely have to use a transistor, go for an NPN (2N2222) instead of a MOSFET.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a logic level mosfet. Something like an IRLZ24.

It all starts with a mental vision.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With 1.0 Volt as threshold voltage the MOSFET you have
chosen is a logic - level type, so it should work.
If your PWM frequency is low enough (below 1 kHz)
the circuit should work. I have done similar
with similar MOSFETs.

A check of the gate-voltage with a scope would be
interesting.

A 2N2222 is much to small as switch in this
application !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mosfets are prone to damage from static while not connected to the circuit...

Test your code as per Markus's suggestion and then the mosfet circuit...

Divide and conquer...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not set the port pin high in software as a test and see if the LEDs shine bright? Instead of all the bit shifting code and timer code you can just test your switch by setting the pin high.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Systematically performing the following tests:

Set PB0 to high and connect to an indicator LED -->
discovered the chip I was using was messed up -->
replaced it and retried with success.

Set PB0 to high and connected it to my transistor -->
High powered LEDs Lit up! YAY

Set a 50% duty cycle on Timer 0 and hooked it up to indicator LEDs (prescaler set to 011)-->
LEDs lit up (can't tell too well if they are dimmer but they seem to be. No visible flicker as freq is at least 60hz)

Set a 25% duty cycle and decreased freq (prescaler set to 101)-->
Visible flicker (freq estimated at 32 Hz)

set duty cycle to 31/255, prescaler to 100 -->
no visible flicker, dimmer (tested vs straight 5v)
(freq estimated at 64 Hz)

DC 31/255, PS 100 hooked up to transistor-->
LEDs strobed like crazy...Headache >.<

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tested whether it was the high power LEDs I was using or the transistor which was making the system strobe by attaching indicator LEDs to the transistor rather than the high power LEDs. No blinking at all. Is the high power causing an issue? what can I do to isolate the chip from the transistor? I am still rather new to digital circuits so I don't know how to institute a bypass capacitor.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read up on what a bypass cap is and added one. Doesn't seem to make any appreciable difference. Not sure if I am using a high enough capacitance though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read up some more on bypass capacitors and added even more of varying capacitances. Flickering evened out a bit so that does seem to be part of the problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alright >.< I have no idea what I am doing. Now the flashing has gotten slower and more pronounced.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the 5V power source you are using?

Please draw your circuit more tidily showing everything. (I suggest LTSpice if you want to draw schematics).

You seem to be wildly jumping all over the place looking for an answer.

oddbudman

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You seem to make goot progress, even if it is frustrating.

It sounds like you are building your circuit on a breadboard. As you are working with high power and switching (several amps) this can be part of the problem. You might want to move to a soldered prototype, also making sure that you are using thick traces/wires for the power yielding parts (power supply - led - mosfet - ground).

As you have seen, the bypass cap already makes a difference. I'd try to use a completely separate power supply for the AVR. The source can be a regulated wall-wart or even the 5V available on the USB port of a PC. (Attention, risk of frying the PC !)

Switching large amounts of current (amps) is not trivial.

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah the joys of trial and error. Tried another one of the power supplies I have (I am using a TDK-Lambda DSP 60-5) as I have more than one. Strangely enough this one behaved differently from the first one. The wires I used to connect it to the circuit are different so this may be the issue? (solid wrapping wire on one, speaker wire on the other)

The power supplies have two VCC and two ground connectors and I tried hooking one of the VCC connectors directly to the uC, but this had no effect.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I used a separate power supply for the power for the uC (shared ground) there was no flickering, even sans bypass caps. So that is apparently the issue. How do I calculate what value of bypass cap I will need?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is a recent paper I found on techonline:
[url]
http://www.techonline.com/learni...
[/url]

I haven't read it yet but may be worth a look.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the AVR you could use 10 ufd bulk and .1 ufd at each and all vcc pins on the avr. You can use either tantalum or ceramic for the 10ufd and ceramic for the .1 ufd. That should be fine. Then you may want one larger bulk cap on VCC where power comes into the board. For a reference you can look at the STK500 schematics and see how they bypassed the power supplies at the AVR sockets.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It sounds to me like the Hi power LED is drawing too much current and/or causing to much ripple on the supply...

When this happens, the AVR will reset...
The bypass cap's purpose is to smooth the ripple...
If the current draw is too high, then the supply voltage will drop ...

I had a simliar problem with a 3 axis DC servo system, as motion was commanded the controlling boards would reset...
There was no way to isolate the motor voltage from the controllers as power was fed through a pair of linear guides... (control was RF, there were no visible wires)...

I ended up adding some bulk caps (~1500uF IIRC) to the controller and putting a diode upstream of the caps...
When the motors initiated the diodes kept the controller from losing power (preventing reverse drain on the caps)...

So... you prolly want to add some bulk capacitance to the AVR supply...
In your case, a diode wouldn't help as the LED will be drawing continuously (not intermittently as my servo's were during acceleration)...

The other option would be to use separate supplies...
One for the AVR and one for the LED...
If you choose this route, tie the grounds of both supplies together and make sure the LED supply is (over) rated for the current it will draw...
The AVR supply will not require much current as per the first page of the datasheet...

A cheap source of 5v is a PC power supply, but care must be taken as they can deliver in excess of 20 Amps...
Always use an inline fuse when using a pc power supply as they can fry your ciruit (and you) pretty quickly...

Have fun!
Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any recommendations for cheap low power 5V power supplies? Especially if they are easily available

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is a mockup of the circuit as it stands now. I will need to replace the power supply for the ICs with something less beefy or set up a proper bypass capacitor to allow use of only one power supply, but atm I don't have the proper parts for that. Will test it and let you know how it works out.

edit: just realized I forgot to connect a shared ground >.<

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does the circuit works fine/as expected with the separate power supplies ?

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've got your LED power connected to positive only?? lolz

Also... you shouldn't have the LEDs in parallel with a single current limiting resistor...
You should have 3 resistors, one for each LED, otherwise one LED might drawn more and let the magic smoke out...

Looking at the data sheet for your LED, it seems you might be driving them a bit hard...
It does say they a have a max current 700mA but @ 350mA they are being driven at 100% of their rated light output (datasheet, page 6)...

The calculator here is handy... http://led.linear1.org/led.wiz ...

Have fun...
Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting LEDs, I was just looking at them on Ebay...

It seems that each quadrant in a single LED can be driven individually...
To drive them all at the same time you would either want them in series with a single current limiting resistor...
Or all 4 in parallel but with a resister for each one...

You really never want to drive them directly in parallel without some kind of individual current limiting...

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am still pretty new to circuits. This is a school project and while it is supposed to be a team effort, I ended up being the only one really working on it.

I definitely will be redoing the whole thing, probably putting the LEDs in series rather than in parallel for the second iteration, although individual current limiting resistors may be an option as well. One of the goals of the whole project is efficiency though so the less power wasting resistors I can put into the system the better I believe, but on the other hand it's not exactly cheap to replace the LEDs so...we will see.

Thank you all for the valuable input. I am really glad I came here for help.

note: yah I noticed the power was connected to positive only for the LEDs >.< fixed that on the final draft of that diagram

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A simpler way is just to isolate your logic VCC from the LED supply with a diode. That way, if the current puts a transient spike on the main supply, it can't pull VCC down to reset the processor. Use a small schottky diode like BAT54, or a 1N914 if the voltage drop is not a problem, and don't forget the decoupling capacitor. It's more of a reservoir in this case and should be big enough to hold VCC up for a few milliseconds. The relevant formula is:

voltage drop = millisec.milliamp/C(uF)

So a 10uF cap will drop 1 volt if it supplies 10mA for 1ms. That should do it.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You also might want to enable the BOD (brown out detection) fuse...