PWM IRF9540N Arduino

Thread Starter

sharanvshnu

Joined Dec 13, 2020
7
Here I'm trying to build a PWM high side driver using IRF9540N with the control of Arduino.I used a power 12V 3W LED (~280mA) as the load.When I directly connected the LED to a battery, my current consumption was 280mA and while I try the high side circuit, it's consumption is ~190mA. I tried changing the resistor values of R1, R2 & R3.
My problem is that on PWM action or ON/OFF action my current consumption is being scaled to 0 to 190mA,whereas it should be scaled from 0 to 280mA.

I have tried different circuits it's the same result.

Please help me find the solution. It's an urgent project.
PWM.PNG
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,767
hi,
You are using a P MOSFET, check the voltage polarity for the Drain of the device as wired in the circuit, also that MOS has an inbuilt diode which is forward biased in that configuration,.
E
AAA 1109 08.40.gif
 

Attachments

PRASS

Joined Feb 22, 2018
31
This just means your PWM signal is running at 64.28 % of it's duty cycle.

Turn up your duty cycle to get more mA.
word-image.jpgHere's how.

If you had proper equitment you would see that it actually goes up to 280mA, but it happens so quickly you can't measure it without an ocilloscope.
 

ericgibbs

Joined Jan 29, 2010
18,767
hi PRASS,
The MOS is a P type , it is wired upside down.
E
Corrected the circuit, improved sim.
AAA 1111 10.20.gif
 
Last edited:

Thread Starter

sharanvshnu

Joined Dec 13, 2020
7
this was my actual circuit.
This just means your PWM signal is running at 64.28 % of it's duty cycle.

Turn up your duty cycle to get more mA.
View attachment 229061Here's how.

If you had proper equitment you would see that it actually goes up to 280mA, but it happens so quickly you can't measure it without an ocilloscope.
do you mean by changing the resistor values?
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,767
hi shar,
Your MOS FET was upside down, didn't you read my posts.:) post #4.
It works fine as the post shows.
E
Remove that 1uF capacitor
 

PRASS

Joined Feb 22, 2018
31
this was my actual circuit.

do you mean by changing the resistor values?
Somewhere in your Arduino code you will find a piece saying analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

If you would like just put your code here as a comment & I will find it for you
 

Thread Starter

sharanvshnu

Joined Dec 13, 2020
7
Somewhere in your Arduino code you will find a piece saying analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

If you would like just put your code here as a comment & I will find it for you
int z = 0;
void setup() {
pinMode(3, OUTPUT);
pinMode(A5, INPUT);
Serial.begin(9600);
}

void loop() {
int v = analogRead(A5);
float volt = v * (5.0 / 1024);
float batt = (volt * 12200) / 2200;
analogWrite(3, z);
if (z < 241)
{ z = z + 10;
delay(2300);
} else if (z > 240 && z < 256)
{
z++;
delay(1200);
}
else if (z > 255)
{
z = 0;
}
Serial.println(v);
Serial.print("Batt:- ");
Serial.println(batt);
}
 

PRASS

Joined Feb 22, 2018
31
/*
Here try out this code.
I got rid of bundles of unnecessary code for you.
I highlighted the easy way to change the PWM in red.
It is set at 100 % duty cycle now but if you change the 255 number to anything below 255 it will decrease the duty cycle also.
eg; 127 will give you 50 % duty cycle & 63 will give you 25 % etc etc.

I will also drop a 2 pictures of a much easier way to create your circuit.
Because it's ok to run an Arduino from 7 to 12 volts.
*/



void setup() {
pinMode(3, OUTPUT);
pinMode(A5, INPUT);
Serial.begin(9600);
}
void loop() {
int v = analogRead(A5);
float volt = v * (5.0 / 1024);
float batt = (volt * 12200) / 2200;


analogWrite(3, 255);

Serial.println(v);
Serial.print("Batt:- ");
Serial.println(batt);
}


Untitled 2.png Untitled.png
 

djsfantasi

Joined Apr 11, 2010
9,156
/*
Here try out this code.
I got rid of bundles of unnecessary code for you.
I highlighted the easy way to change the PWM in red.
It is set at 100 % duty cycle now but if you change the 255 number to anything below 255 it will decrease the duty cycle also.
eg; 127 will give you 50 % duty cycle & 63 will give you 25 % etc etc.

I will also drop a 2 pictures of a much easier way to create your circuit.
Because it's ok to run an Arduino from 7 to 12 volts.
*/



void setup() {
pinMode(3, OUTPUT);
pinMode(A5, INPUT);
Serial.begin(9600);
}
void loop() {
int v = analogRead(A5);
float volt = v * (5.0 / 1024);
float batt = (volt * 12200) / 2200;


analogWrite(3, 255);

Serial.println(v);
Serial.print("Batt:- ");
Serial.println(batt);
}


View attachment 229099 View attachment 229100
The MOSFET shown in your second picture is a P channel MOSFET which usually is used to switch the high side. You have it on the low side. It also must be a logic level MOSFET as the Arduino GPIO can only provide 5V (at most). Just because you can power the Arduino with 12V doesn’t mean you can connect 12V devices to it (without driver circuitry). The 12V input goes through an onboard voltage regulator, bringing the MCU voltage down to 5V. Your diagram is missing a lot of information and likely won’t work.
 
Top