Driving 12V LED with PWM problem

I want to make a simple board for controlling some different 12v LED strips/LED and other high current things.

Here is the circuit:

Here is the finished board:

I am powering it using a 14V supply for testing:

The problem I have here is that when using PWM, AnalogWrite value of less than 150 (255 being the highest), the 12V 10W LED is barely on. I have measured the current: they are 1A @ 255; 300ma @ 200 and 1ma at 150. I am using a VND3NV04 MOSFET and attiny13A for this board. what could be the issue here? I was really expecting PWM give me a more linear output from 0-255.

Eagle and code.zip (305 KB)

What power supply are you using? Have you decoupled the LED supply directly (this is where decoupling
is most needed for switching LEDs)

What PWM frequency?

Sure its the VND2NV04 omnifet? Some such devices(*) are ultra slow compared to bare MOSFETs,
though the part you quote is supposed to be full speed.

(*) intelligent switch chips are an IC plus an integrated MOSFET, and many are totally unsuitable
for PWM with > 100us switching times. You should check you have the right part

MarkT:
What power supply are you using? Have you decoupled the LED supply directly (this is where decoupling
is most needed for switching LEDs)

What PWM frequency?

Sure its the VND2NV04 omnifet? Some such devices(*) are ultra slow compared to bare MOSFETs,
though the part you quote is supposed to be full speed.

(*) intelligent switch chips are an IC plus an integrated MOSFET, and many are totally unsuitable
for PWM with > 100us switching times. You should check you have the right part

I am using a DIY regulated power supply for testing, but I am planning to use this board on a 12v adapter for powering the LED strips. The led is directly connected to the 12V and Ground via the Mosfet. You are right. By turning down the clock frequency to 1.2Mhz, I am able to get it to work just as it should be. The main clock was 9.6Mhz, and the PWM signal was probably too fast for my Smart Mosfet? I am not sure what frequency the PWM is. I will try another MOSFET for the next board.

Can you measure your PWM frequency somehow? - that omnifet is rated to 50kHz going by the datasheet,
which is why I doubted its the same device.

You haven't really said if there is decoupling on the load - you need it for PWM really.

Pulse width with an 8-bit PWM value of 1 is ~4uSec at a PWM frequency of 1kHz.

About the same as the posistive pulse of a frequency of 125kHz.

I think you have to stay well under a PWM frequency of 1kHz if you want to dim to "1".
Leo..

MarkT:
Can you measure your PWM frequency somehow? - that omnifet is rated to 50kHz going by the datasheet,
which is why I doubted its the same device.

You haven't really said if there is decoupling on the load - you need it for PWM really.

It's 38khz @ 9.6Mhz cpu clock. The frequency doesn't change with different pwm values of 1 and 150. I don't have any decoupling on the led. It works fine now with clock speed set to 4.8mhz. (strange, Will try another fet next time)

Here is my finished code. It works fine now. thank you for the helpful comment.

/*B1,B2,B3 buttons D1-D3
 *B4 LED D4
 *B0 Mos D0
 */
byte led=4;
byte mos=0;

byte ba,bb,bc;
byte baps=1;
byte bbps=1;
byte bcps=1;

byte set=0;
byte ledstate=1;
byte pwm=75;
byte pspwm,dir=0;
int ta,tb,tc,td,tsec;
byte power=0;

void setup() {
DDRB=0b00000000;
PORTB=0b00001110;
}


void loop() {

ba=digitalRead(1);
bb=digitalRead(2);
bc=digitalRead(3);

       
//######AAA##################  
if(ba!=baps){
  delay(80);
  if(ba==0) {
    power=!power;
    if(power) { pwm=255; }
    else {pwm=0; }
  }
      baps=ba;
  }

//#####BBB###################  
if(bb!=bbps){
  delay(80);
  if(bb==0) {
    pwm-=25; 
  }
      bbps=bb;
  }

//#####CCC###################  
if(bc!=bcps){
  delay(80);
  if(bc==0) {
    pwm+=25;  
  }
      bcps=bc;
  }  

//######################## 

ta=millis();
if(ta-tb>=5){

if(set==1){  
if(dir==0)pwm++;
else pwm--;

if(pwm==220) dir=1;
if(pwm==0) dir=0;
}

tb=ta;  
  }

tc=millis();
if(tc-td>=1000){
tsec++;
ledstate=!ledstate;
td=tc;  
  }  


if(tsec>=3600 && set==0){
    pspwm=pwm;
    set=1;
    tsec=0;
  }

if(tsec>=5 && set==1){ 
  pwm=pspwm;
  set=0;
  }  


  analogWrite(mos, pwm);      
  digitalWrite(led, ledstate);   


}

flyandance:
It's 38khz @ 9.6Mhz cpu clock. The frequency doesn't change with different pwm values of 1 and 150.

The base frequency doesn't change, but the pulse width does.
If the base frequency is 38khz, and you set PWM to 1, the pulse width is 1/256 of the time of the base frequency.
You're basically trying to make the mosfet switch (with a PWM value of 1) at the MCU's clock frequency.
Leo..

Wawa:
The base frequency doesn't change, but the pulse width does.
If the base frequency is 38khz, and you set PWM to 1, the pulse width is 1/256 of the time of the base frequency.
You're basically trying to make the mosfet switch (with a PWM value of 1) at the MCU's clock frequency.
Leo..

Make sense, 38k * 255= 9.69Mhz. so I need a fet that can handle up to 10Mhz here. thank you for clarify this for me.

flyandance:
Make sense, 38k * 255= 9.69Mhz. so I need a fet that can handle up to 10Mhz here. thank you for clarify this for me.

Why.
I use a base frequency of 200Hz for the LED downlighting in my house (12-bit PWM).
Flicker would be the problem if you go too low (<50Hz), but 200Hz is not a problem.

A high base frequency could be needed for inductive loads (motors), to stop the whining noise.
But I suppose for a motor you won’t have to go that low in PWM value.
A base frequency just outside out hearing range (20kHz) is enough.
Leo…

flyandance:
Make sense, 38k * 255= 9.69Mhz. so I need a fet that can handle up to 10Mhz here. thank you for clarify this for me.

Its the gate drive that limits the switching speed, most MOSFETs can switch pretty much as fast as you can push
charge onto the gate...