IRL540/30N06L Dimming Headache

Hi Folks, new member here.
Ive been tinkering and learning arduino and absolutely find it a blast. The net and forums are full of good info, and the ideal for projects are almost limitless
I first begun learning arduino code, when multiwii first came out to fly multirotors.

Ive begun working on a simple project using a nano, but I have come up across a roadblock, and need some assistance from more seasoned members.

Simply put, I am controlling a 30N06L logic mosfet using a nano and a 10k pot as a "brightness" input.

I have all the coding figured out, and the code works very well, I figured how to get the serial monitor to work so I can read my A0 input value as I turn the pot.
I then have a basic code to turn the (0-1023) A0 value, into a basic Analogue write value (0-255) to pin D3

I then have D3 driving my 30N06L Mosfet in a identical schematic like this below. I am using it to drive a 12v led strip. I don't have any need for current control with this led in this application.. Just voltage 0-12v.

Heres my problem, I don't get very good transition from off to low dimming percentage.

It is nearly identical to this issue in the first post. but there was no outcome.
https://forum.arduino.cc/index.php?topic=335088.0

I have verified that my D3 PWM value is working as expected, ive connected my oscilloscope to the D3 PWM output, and I do get 0-100% duty cycle from the arduino.

The problem is I don't get a full dimming at the lower end of the command. I have the standard 10k pulldown resistor across the Gate and Source, and I have no erratic behaviour from the mosfet when it is commanded off (0%pwm, analogueWrite-0).

I get full power when commanded 100% (analogueWwrite 255), I get around 75% dimming when commanded around (Analogue Write ~175). The dimming smoothness works as expected, and I don't get any pwm flicker..

Problem is, the Jump from a Analogue write of 0 to 1.. at 1, I get about 40% dimming.. approx. 6.45v to the leds.
I wonder if this is a limitation of the mosfet, I have also tested the setup with a IRL540 and get identical results. I also added a 220Ω resistor between D3 and the Gate, but it made no difference.

I even get the same issue if I completely omit the pot input, and manually type in a "analogueWrite 1" value.

Im wondering if I have to use a different pwm technique and change the default 490hz to something else.

Any help would be greatly appreciated.
This is the only road block im having right now, and I want to sort it out before I begin to add more channels and features.

Hi, and welcome to the forum.

I think your have too high expectations of 8-bit PWM.
8-bit PWM can only give you about 20 equal brightness steps, because vision is sort of logarithmic.

If you want equal brightness steps, then you could put the right PWM values in a lookup table, and step through them. This is an example of a 32-step table.

prog_uint8_t CIEL8[] PROGMEM = {0, 1, 2, 3, 4, 5, 7, 9, 12, 15, 18, 22, 27, 32, 38, 44, 51, 58, 67, 76, 86, 96, 108, 120, 134, 148, 163, 180, 197, 216, 235, 255};

12-bit PWM is needed if you want smoother dimming (and lower brightness) at the low end.
Leo..

You can use dB as a measure for relative brightness to reflect the logarithmic nature of the eye's
response to light. (I'm surprised it isn't done more often).

So if we call analogWrite(pin, 255) as 0dB, then:

analogWrite (pin, 254) -0.017 dB
analogWrite (pin, 253) -0.034 dB
analogWrite (pin, 100) -4dB
analogWrite (pin, 30) -9dB
analogWrite (pin, 10) -14dB
analogWrite (pin, 3) -19dB
analogWrite (pin, 2) -21dB
analogWrite (pin, 1) -24dB
analogWrite (pin, 0) - infinity dB

So the last few values, 3, 2, 1 are ~3dB steps (quite noticable), then drops straight to off suddenly).

12bit ADC would make the smallest output -30dB, which is a modest improvement.

Also,you may want to look at the Timer1 library to get 0-1023 PWM.

.

timer1 is 16 bit so in theory you can get 65536 levels (at 244Hz), or 16000 (at 1kHz), ie 48dB and 42dB
dynamic ranges (assuming a 16MHz clock)

I use the 12-bit/200Hz PWM outputs of the PCA9685 for the downlights in my house.
Practically, 12-bit dims down smoothly to very low brightness.
Leo..

Hey.

Thanks for the tips.

I will look into the timer1 sequence and see if I can get it to give me a bit more of a progressive dim at the lower end.

I only really have weekends to tinker away so I wont be able to try it till then.

Honestly even though the ATmega328 is 8 bit, values between 1 and 255 dim very nicely actually, and there is barely any noticeable stepping between the values. I was planning to experiment with a sampling array to slow down the "suddenness" of the analogue input values, and give the dimmer a smooth ramp up and down.

I just find it odd that the jump from analogueWrite 0(off) to 1(lowest dim value).. is a massive jump.. 2 to 255 is nice and progressively brighter.

I can try and grab some oscilloscope screenshots for anyone to see what the mostfet is being fed.

Yes, big brightness jumps at low PWM values. They get smoother above ~5 or so.
You can see that clearly if you look at the values of "equal brightness steps" of the lookup table in post#1.

Maybe worth playing with Timer1 (post#4).
Never done this myself. Let us know how you get on.
Leo..

..I'd take a look with a scope to see if a transistor driver is needed. (gate capacitance)
In may improve a litte by reducing pwn speed to 100..150 Hz (if scops shows that turning off is slow)

http://forum.arduino.cc/index.php?topic=417166.msg2872889#msg2872889

This should work

#include <TimerOne.h>//  https://github.com/PaulStoffregen/TimerOne
const int potPin = A0;
const int outPin = 9;
void setup() {
  float freQuencyHz = 500; //Hz (any reasonable value)
  int microSec = ((1.0000 / freQuencyHz) * 1000000.0000);
  Timer1.initialize(microSec); 
}
void loop() {
  unsigned long potVal = analogRead(potPin);
  Timer1.pwm(outPin, (potVal * potVal) / 1024);
  delay(10);
}

A thought - could you use a binary rate multiplier ( ancient device ) for more resolution .... ?

Allan.

Thanks for the tips and sample code. ill get a chance to try it in a few days. Ill also get some osiliscope pics of the arduino signal to the 30N06, and the output of the mosfet.

Hey folks

I got back onto this project, and looking for some more help

To update, i tired some of the examples of the code above and was either getting the same result, or not able to get it to work at all. I dont know if this is a limitation of the nano i am using being able to do the Timer coding, or the digital output i was using to test.. D3 for example.

Im starting to suspect that i might have a hardware limitation (mosfet?)

The mosfet has a VGS(th) - max threashold for RDSon of 2.5v, so the 5v pwm from the arduino should be more then enough, the 30N06L is supposed to be logic level. i wonder if im having a gate capacitance issue? and need a lower value resistor between the gate and source(ground).
instead of 10k, a 500Ω for example?

Below is a sample of code for a single output that re-creates the issue i am having

const int potPin = A1;
const int ledoutPin = 3;
int ledbrt = 0;
                     
                         

void setup()
{
pinMode (ledoutPin, OUTPUT);
}

void loop()
{
float ledbrt = map(analogRead(A1), 0,1023,0,255); // sets the value (range from 0 to 255)
 {
  
analogWrite(ledoutPin, ledbrt);           
                          
 }  
}

i took out the serial.print code that i use to verify values of the pot analogueread , and command to the analoguewrite output pin.

I think mentioning that i am running leds with the setup confused a few above. so lets just say i can use the identical setup to run a motor, or other 12v device.. Really what im looking at is voltage control from the mosfet, and the ability (lack of ability of the system to go below 6.4v)

just to clarify again

A value of:

analogWrite (pin D3, 255) gives me 12v

analogWrite (pin D3, 1) gives me 6.4v

analogWrite (pin D3, 0) gives me 0v

i need more range between 6.4v and 0v.. and i suspect that with the arduino D3 pin duty cycle of 0.5% @ a D3 value of 1 is not enough for the mostfet? or a limitation of the internal scaling of the mosfet?

will increasing the sampling frequency give me lower duty ranges at the bottom end.?

This whole scenario seems odd, because i am sure there has been others that have driven a mosfet from a nano for basic voltage adjustment, and don't hit a 6.4-0v sudden drop issue

You cannot measure the output voltage from a PWM'd LED (or motor come to that) and
expect a linear function of duty-cycle, because it won't be. Use a resistor (linear load) to
see a linear voltage with duty-cycle response.

It may be something is wrong, in which case subtituting a 1k resistor for the LED load and
measuring the resistor voltage against analogWrite values should be linear - if not, something
is wrong (perhaps your gate resistor is too large - use 150ohms). Maybe the MOSFET is fried
(they often fail partially if the gate-oxide has been punctured by static, and they are static-sensitive
devices without any inbuilt protection)

An oscilloscope on the switching waveform would be very useful for diagnosis.

[ And looking at your circuit perhaps the gate resistor is too small (missing), so that the pin
is over-stressed? Try a different pin and 150 gate resistor ]

MarkT:
You cannot measure the output voltage from a PWM'd LED (or motor come to that) and
expect a linear function of duty-cycle, because it won't be. Use a resistor (linear load) to
see a linear voltage with duty-cycle response.

It may be something is wrong, in which case subtituting a 1k resistor for the LED load and
measuring the resistor voltage against analogWrite values should be linear - if not, something
is wrong (perhaps your gate resistor is too large - use 150ohms). Maybe the MOSFET is fried
(they often fail partially if the gate-oxide has been punctured by static, and they are static-sensitive
devices without any inbuilt protection)

An oscilloscope on the switching waveform would be very useful for diagnosis.

And looking at your circuit perhaps the gate resistor is too small (missing), so that the pin
is over-stressed? Try a different pin and 150 gate resistor

I did some testing that night, and came to some similar conclusions. It looks to be a hardware issue.
with that said I understand completely the limitations of the 0-255 8bit resolution and its "visual" limitations towards the bottom end, especially for dimming.

My code works as expected, and i can verify the pwm/duty output from the arduino using the scope, and it outputs as expected. I would of have some scope pics posted, but i was having issues trying to save the waveforms to usb the other day. Ill try agian.

This being my first project experimenting with driving large current applications using an arduino, and the first time experimenting with mosfets, i began to narrow down the issue, i did some reading on mosfet design and operational characteristics, something that really stood out were the issues around switching speed/gate capacatance/inrush gate current.

I did my testing with a fixed load across the output. large ~ 10Ω reistor, to give me around a 1.4a load on the mosfet. Then i began to test. I suspected there was a capacatance switching issue going on with the mosfet, either it wasnt shutting off completely at low duty cycle rates, or the PWM frequency was too fast for the mostfet to switch on/off completely. And with that, possibly some poor quality mosfets.

First, i changed the Gate to Source pulldown resistor from 10k to 220. A quick test, and i noticed i have significantly improved lower-end dimming performance (the mosfet is fully turning off now). However at "full brightness" "full on" command, i wasnt getting the full on voltage. I suspected the gate wasnt getting the proper voltage and was not fully saturated because the arduino output was overloaded. Sure enough, the arduino output was sagging below 4.5v when commanded on.

Soo chock that inial design as poor.

I then began to hunt down a better design, something that used higher current capable transistors to drive the gate of the mosfet to gurantee a full 5+v and 0v waveform to the mosfet, and is not overloading the arduino.

I came across this great totem-pole driver schematic. that i will give a try, and call it v2. :slight_smile:

I ordered the parts from digikey yesterday, and il build it out next week.

Parts came in today, and i was able to successfully build the "totem-pole" driver arrangement.
It worked right off the bat, and did provide some better results then just driving the mosfet directly from the arduino. It seemed to have better consistency (at lower pwm's the output voltage would slightly fluctuate, and there was a bit of excess noise on the output.

With that said, now its time to begin experimenting with some of the timer functions for the nano. With that said, it looks like i am limited to 2 outputs that can potential support 16bit output configuration (digital 9, 10) that support the timer1 function?

In the grand scheme of things, im looking to have 5-6 pwm controlled outputs from the arduino, so does that limit me to using a PCA9685 (12bit 16 output via I2C), or a ADS1115 (16 bit 4 output via I2C)?. i have yet to do any I2C interface stuff yet so that would be a new learn as well.

For bench testing, the size of the unit doesn't matter, but once i put it into a portable project, i would like to keep chip count to a minimum. Thats why i have been testing with the nano, and trying to stay within the limitations of the "nano" footprint.

Thanks :slight_smile:

The mosfet has a VGS(th) - max threashold for RDSon of 2.5v, so the 5v pwm from the arduino should be more then enough, the 30N06L is supposed to be logic level. i wonder if im having a gate capacitance issue? and need a lower value resistor between the gate and source(ground).
instead of 10k, a 500Ω for example?

You seem to be completely confusing things here.

Vgs(th) is the threshold voltage, nothing to do with being on, all to do with being off.

There are values of Vgs quoted for each Rds(on) value, these are the on voltages, and will be
completely different from Vgs(th), typical 3 times larger.

For the FQP30N06L, the device is marginally logic-level - the on resistance is quoted for 5.0V,
not for 4.5V, which means your 5V supply must be a good 5V, not drooping, otherwise the on-behaviour
may be unreliable with some devices.

That MOSFET is only just good enough to run from 5V PWM, there is no margin.

Note that when a device is run close to its limit like this switching will be unsymmetrical and you
will need to pay attention to driving the gate with a proper driver so that switching time is not over-long.

If you look at the gate charge/voltage graph you'll see the plateau is at about 3.8V (+/- manufacturing
spread of about 1V), in other words the plateau voltage for any device could be anything from 2.8 to 4.8V,
which is why they don't guarantee on performance at 4.5V.

Its not the best device to choose for PWM from 5V, basically. You need a proper MOSFET
driver chip, the bipolar circuit given above loses about 1V and won't perform adequately for
such a marginal device. My favorite drives-anything-low-side-driver chip is the MIC4422,
bags of current, works from 4.5V upto 18V, internally its MOSFETs to it drives fully to the rail.

MarkT:
That MOSFET is only just good enough to run from 5V PWM, there is no margin.

Note that when a device is run close to its limit like this switching will be unsymmetrical and you
will need to pay attention to driving the gate with a proper driver so that switching time is not over-long.

If you look at the gate charge/voltage graph you'll see the plateau is at about 3.8V (+/- manufacturing
spread of about 1V), in other words the plateau voltage for any device could be anything from 2.8 to 4.8V,
which is why they don't guarantee on performance at 4.5V.

You hit the nail on the head. One thing i didnt mention yet, was as time went on, and i got a few hours of playng around on my test circut, i was begining to see some inconsistancies with the mosfet output. I still havent been able to get my scope to save pictures yet, but to make things simple. lets say, i was doing my inital testing with some "questionable quality" cheap 30N06L chips; or thats what they were labled as, from fleebay a few years ago. No longer will i make that mistake.
Because im not in the US, i need to have a decent sized order to make getting parts from Digikey worth while. On my parts order last week, i threw in some quality 30N06L, and some other testing parts such as IRL540, and IRF540 for example... Low and behold, after making a simple loop dimming sketch to cycle the brightness, and letting it run for the day. the "new" 30N06L is working as expected. The old chip began to randomly flicker and was intermittent with the dimming %. Garbage parts can make for grabage results, and you chase your tail.

I will order some MIC4422 drivers on my next order, and update the layout im using.

Ok.. so now it seems like i will need 12 or 16 bit output to get better precision at lower duty cycle values.
After reading up on these DAC chips. ADS1015 ; ADS1115 for example. If i go with a 12bit, i can have a faster sampling rate, then vs a 16bit. Assuming due to added processing requirements for higher resolutions. With all the fluff put aside,

Is it possible, with a nano, to run a pair of 4ch each ADS1015 12bit (8 channels total), at a 3300sample/sec pwm rate? Is the ATmega328 even cabpable of such a processing requirement? Understnad, that i havent done any I2C programs yet so any limitations are new to me.

Thanks agian for the suggestions

You could use two mosfets - one driving the LED chain directly for the high power part , and one via a resistor for the the lower power range. By careful choice of resistor you could in principle get up to 16-bit resolution.

This low-power extension need not use a high power mosfet - pehaps a 2N7000 or even a BC337 would do. And the resistor need not be of high wattage. It needs to be chosen such that when the low power device is 'on' it allows 1/256 of the full-power current to flow.

Allan