Change the Pwm frequency according to delay on time of the mosfet ?

HI, i'm switching a incandescent bulb (12V, 40W) using this scheme:
I'm using Arduino Mega on pin 13

The problem is that even with analogWrite(13, 50) the bulbs are at full brightness i think

The Mosfet IRF5305PbF have the following times:

and the Photocoupler TLP521:

Do i need to change the frequency of the arduino in order to make my mosfet turn on/off as it should compared to the output duty of my arduino ?

We see no current limiting resistors any where.

How long does the light bulb have to be off before your eyes will notice it? Once you know that, then you will have the answer to your question.

Paul

larryd:
We see no current limiting resistors any where.

Fixed the schematic, tnx

Paul_KD7HB:
How long does the light bulb have to be off before your eyes will notice it? Once you know that, then you will have the answer to your question.

Paul

And how i can know this ?
i had a look on the internet but here is no datasheet or code of this bulb

I would suggest using a proper MOS FET driver.
Google for some common types.

.

larryd:
I would suggest using a proper MOS FET driver.
Google for some common types.

.

I tried but ... fried two tc4426A drivers

prologikus:
Fixed the schematic, tnx

And how i can know this ?
i had a look on the internet but here is no datasheet or code of this bulb

Does the light in your room use incandescent light bulbs? If so, turn the switch off and see how much time elapses before you notice the bulb had dimmed. Perhaps 1/4 second? Try that for your program and work from there.

Paul

Paul_KD7HB:
Does the light in your room use incandescent light bulbs? If so, turn the switch off and see how much time elapses before you notice the bulb had dimmed. Perhaps 1/4 second? Try that for your program and work from there.

Paul

For my eye it seems like it dimmed instantly
but let's say a random value of about 100ms fall time , what i'm gonna do with it ?

Why make a complicated driver like that? 40W@ 12V is some amps but nothing a (logic level) mosfet can't drive directly.

And have you tried different values? And off? Where is the code so we know you didn't mess up there :wink:

And do note we don't see light linear. So 50 out of 255 does NOT result in 1/5th brightness for our eyes.

And now I think about it, you might have already fried the opto's... When pin 13 is floating you just have 2 leds in series without current limiting resistors. And the combined ax forward voltage of both is lower then 3,3V (2x 1,3V = 2,6V) so current WILL flow freely.

Throw both opto's in the bin, grab a new one, connect the LED with a resistor between pin 13 and GND. And on the output, connect the emitter to GND, collector to the mosfet gate and add a resistor of +-1k between mosfet gate and 12V to turn it off. And of course mosfet source to 12V and drain to the load.

septillion:
And now I think about it, you might have already fried the opto's... When pin 13 is floating you just have 2 leds in series without current limiting resistors. And the combined ax forward voltage of both is lower then 3,3V (2x 1,3V = 2,6V) so current WILL flow freely.

Throw both opto's in the bin, grab a new one, connect the LED with a resistor between pin 13 and GND. And on the output, connect the emitter to GND, collector to the mosfet gate and add a resistor of +-1k between mosfet gate and 12V to turn it off. And of course mosfet source to 12V and drain to the load.

 if (ledu_status == 2) { //TURNING ON ~~~~~~~~~
      if (ledu_dim != 40) {
        ledu_dim = ledu_dim + 1;
        analogWrite(usaOutPin, ledu_dim);
      }
      else {
        ledu_status = 3;
      }
    }

    if (ledu_status == 1) { //TURING OFF ~~~~~~~~~~
      if (ledu_dim != 0) { 
        ledu_dim = ledu_dim - 1;
        analogWrite(usaOutPin, ledu_dim);
      }
      else {
        ledu_status = 0;
      }
    }

septillion:
And now I think about it, you might have already fried the opto's... When pin 13 is floating you just have 2 leds in series without current limiting resistors. And the combined ax forward voltage of both is lower then 3,3V (2x 1,3V = 2,6V) so current WILL flow freely.

Throw both opto's in the bin, grab a new one, connect the LED with a resistor between pin 13 and GND. And on the output, connect the emitter to GND, collector to the mosfet gate and add a resistor of +-1k between mosfet gate and 12V to turn it off. And of course mosfet source to 12V and drain to the load.

they had the resistor, i just forget to draw it
i checked the pin 13 with my multimeter and it works like it should !

NEWS:
If i'm adding a 50k resistor between 3.2v and photocouper the led turn off after 3 seconds that when it should (400ms fall time from my eye)

removing the resistor the leds won't turn off anymore and the photocouplers ar getting way too hot to keep the circuit pluged

We're not Snippers R Us aka all code in a compilable manner.

prologikus:
they had the resistor, i just forget to draw it

Then you're still forgetting it because it's still not there...

septillion:
We're not Snippers R Us aka all code in a compilable manner.
Then you're still forgetting it because it's still not there...

There is a 220ohm resistor between the arduino and the circuit and it always been there, i only forget to draw it in the first photo, after the first post i edited the photo and added the resistor in the schematic too

Mmm... A 50k resistor in the optocoupler line makes them dark at all times. That you see the light on for a few seconds is most likely due to the gate capacitance of the MOSFET.

Two optos in series with 3.3V on one side and GND on the other will also cause problems, and not only when your pin is in INPUT mode. Current flows through the two LEDs, no resistor in that path means effectively a short.

A more serious problem when doing PWM with optocouplers is that the optos are quite slow: they take 3 us to switch. This may be a problem.

If you must use this P-channel, high-end switch: replace the second opto with a pull-down resistor. One opto is enough to switch the gate between 12V and GND.

Better: get a logic level N-channel MOSFET such as the PMV16UN which can handle the current just fine, and which switches fully on at 3.3V gate. Beware, these things are tiny: SOT-23 packings, the size of a grain of rice. Then you can wire it as low-side switch. Small resistor to the pin (current limiting), 10k or so pull-down.

wvmarle:
Mmm… A 50k resistor in the optocoupler line makes them dark at all times. That you see the light on for a few seconds is most likely due to the gate capacitance of the MOSFET.

Two optos in series with 3.3V on one side and GND on the other will also cause problems, and not only when your pin is in INPUT mode. Current flows through the two LEDs, no resistor in that path means effectively a short.

A more serious problem when doing PWM with optocouplers is that the optos are quite slow: they take 3 us to switch. This may be a problem.

If you must use this P-channel, high-end switch: replace the second opto with a pull-down resistor. One opto is enough to switch the gate between 12V and GND.

Better: get a logic level N-channel MOSFET such as the PMV16UN which can handle the current just fine, and which switches fully on at 3.3V gate. Beware, these things are tiny: SOT-23 packings, the size of a grain of rice. Then you can wire it as low-side switch. Small resistor to the pin (current limiting), 10k or so pull-down.

“no resistor in that path” What path ? there is a 220 resistor in any path of the led photocoupler

“then you can wire it as low-side switch.” The surrounding(situation) doesn’t let me use the low side…

prologikus:
There is a 220ohm resistor between the arduino and the circuit and it always been there, i only forget to draw it in the first photo, after the first post i edited the photo and added the resistor in the schematic too

Yes, but that will NOT stop/limit the current in any way between the 3,3V and GND through the two opto’s :wink: In THAT path there is no limiting.

septillion:
Yes, but that will NOT stop/limit the current in any way between the 3,3V and GND through the two opto's :wink: In THAT path there is no limiting.

Ye but imagine that if my Pin is LOW that become the ground of the first opto
And if the pin is HIGH the first opto won't be turned on because it have no ground
(i think)

This circuit in inspired by this video:

Thanks for your answers so far, take at look at this video if you can.

prologikus:
(i think)

You think wrong :wink: Because the way through the second opto is easier so the opto’s will do that :slight_smile:

prologikus:
This circuit in inspired by this video:

Ahh, yeah, Julian :slight_smile: But did you actually watch it? He didn’t add those two leds in line just for fun :wink: Add those as well and switch to the 5V (which would make more sense on a 5V micro).

But that design is pretty complex for what you want. Just find a (logic level) N-channel mosfet and you’re done.

septillion:
You think wrong :wink: Because the way through the second opto is easier so the opto's will do that :slight_smile:
Ahh, yeah, Julian :slight_smile: But did you actually watch it? He didn't add those two leds in line just for fun :wink: Add those as well and switch to the 5V (which would make more sense on a 5V micro).

But that design is pretty complex for what you want. Just find a (logic level) N-channel mosfet and you're done.

I can't use low side, only high side

Can you explain how i can do julian circuit working with my 3.2V? He said with that circuit you can control p channel mosfets too

prologikus:
“no resistor in that path” What path ? there is a 220 resistor in any path of the led photocoupler

Where is the resistor in the path 3.3V - optocoupler - optocoupler - GND?

You need 3.3V - optocoupler - resistor - (link to IO pin without resistor) - optocoupler - resistor - GND.

But even when you have that, strange things may still happen when your Arduino switches on with pins in INPUT mode, and both optos are (partly) on.

The schematic on the left is how you should wire the current limiting resistors. The schematic on the right is a vastly improved version, only one optocoupler. Load is off when pin is LOW or INPUT.
schematic.png