Operational Amplifier driving MOSFET - Page 1
Forum section: electronics / beginners

author: mike_mike
author_rank: Super Contributor
timestamp: April 24, 2018, 02:26:36 pm
content: Dear Forum,I just built the attached schematic and it is working.I tested the circuit using a 12V/20W light bulb (halogen) and a 27R/5W resistor, separately, connected on the LED_load connector. One test with the light bulb and one test with the resistor.When the mosfet is OFF, when I put the oscilloscope probe on the terminals of the resistor (27R/5W) on the oscilloscope screen appears the following image:. Why ?I powered the circuit using a LM317 + PNP variable power supply, set at 12V. The maximum current that can be draw from the power supply is 3A.The circuit is a switch which is turning ON the mosfet when the night comes. I added a hysterezis and two leds, with 1.5k series resistor.When I used the 12v/20W light bulb and I put the oscilloscope probe on the bulb terminals, on the oscilloscope screen appeared only noise, with 5mV amplitude.On the pin 1, pin 6, pin 7 (LM358) and on the output of the LM317 power supply, whith respect to the GND, is only noise (about 5mV).

author: schmitt trigger
author_rank: Super Contributor
timestamp: April 24, 2018, 02:43:11 pm
content: Looks like 50 Hz hum.

author: Benta
author_rank: Super Contributor
timestamp: April 24, 2018, 02:44:13 pm
content: Yep, 50 Hz. I'd suspect your 'scope probe ground connection.

author: mike_mike
author_rank: Super Contributor
timestamp: April 24, 2018, 03:19:53 pm
content: Is that 50 Hz hum dangerous for my circuit ?Or it is just a hum captured by the oscilloscope probe ?

author: Benta
author_rank: Super Contributor
timestamp: April 24, 2018, 03:50:49 pm
content: Quote from: mike_mike on April 24, 2018, 03:19:53 pmIt's only 20 mVpp, Dangerous, no, I'd say it's noise captured by the probe. Place the probe point and probe ground directly on the resistor.

author: mike_mike
author_rank: Super Contributor
timestamp: April 26, 2018, 06:29:50 am
content: Thanks for the reply.The 100 ohm gate resistor of the mosfet has a sufficient value ?The inrush current of the mosfet will not be too high for the LM358 if I use a 100 ohm gate resistor ?

author: byoungblood
author_rank: Contributor
timestamp: April 27, 2018, 03:06:42 am
content: A MOSFET is a voltage controlled device and draws very little current at its gate, datasheet says there is about 100 nano amps leakage at the gate. If anything, you may want to use a pulldown on the gate of the MOSFET (10k would be fine) to ensure noise doesn't make it conduct.

author: Zero999
author_rank: Super Contributor
timestamp: April 27, 2018, 08:19:35 am
content: It's a bad design. Use a comparator IC, such as the LM393, rather than the LM358, which is optimised for linear operation. The LM393, will need a pull-up resistor from its output to +V: 3k3 will do.

author: 0xfede
author_rank: Regular Contributor
timestamp: April 27, 2018, 09:02:46 am
content: Hi mike_mike,you may want to add a couple of resistors (one in series with the LDR and the other in series with the trimmer) because with some combinations of light/trimmer settings the two components may be damaged.There is nothing wrong using an opamp to drive a MOSFET as long as it go to 0 volts; the LM358 has a VOL of max 20mV (page 6 of this datasheet:http://www.ti.com/lit/ds/symlink/lm158-n.pdf) so it should work.By the way as byoungblood suggested a 10K resistor between gate and ground is a good thing.Hope this helps.Best,0xfede

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 09:12:06 am
content: @0xfede What value should have those resistors ? (the resistor in series with the LDR and in series with de 10k trimmer)

author: 0xfede
author_rank: Regular Contributor
timestamp: April 27, 2018, 09:15:36 am
content: Quote from: mike_mike on April 27, 2018, 09:12:06 amWith a couple of 1K resistors you will limit the maximum current flowing thru the LDR/trimmer to 6mA and that should be safe.Best,0xfede

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 09:36:41 am
content: Although its not good design practice to use an OPAMP as a comparator, I don't think the OPAMP can get itself in any trouble driving an IRF830 MOSFET gate.* The circuit has over 4% hysteresis, which with the likely supply voltage in the 10 to 15V region, is over half a volt , so its extremely unlikely that it could ever rapidly pulse between on and off at a rate fast enough that the dissipation due to charging/discharging the gate capacitance could be significant.* The LM358 has a slew rate of about 0.5V/us and is good for about 40mA of output current (subject to dissipation constraints). The IRF 830 has 38nC worst case total gate charge, with a turn-on plateau of about 12nC. The OPAMP cant actually slew fast enough outside the plateau region to drive 40mA into the gate, and worst case, assuming entering the plateau region at 0mA output current and ramping up to 40mA at the end of the plateau charging time, gives a duration of 0.6us during which time the voltage across the gate resistor, limited by the slew rate cant exceed 0.3V. That means the resistor could be as low as 10 ohms and the peak current would still be under 40mA.* The LM358 output current is internally limited and its short-circuit tolerant, subject to dissipation constraints.* 100 ohms in series with the gate should be sufficient to prevent RF oscillation as the MOSFET passes through its linear region (though it would be advisable tp locate the resistor close to the gate pin.0xfede's suggestion to add some series resistance to the LDR+trimmer potential divider to prevent damage if the trimmer is set to minimum and the LDR is brightly illuminated is good. A total of 570 ohms would keep the LDR dissipation under 0.1W at up to 15V supply voltage. It only needs one 680R resistor in series with the pot unless you need to be able to set the switching point for very bright illumination, in which case a pair of 330R resistors one in series with the LDR and the other with the pot would be preferable. That should be safe for any ORP12 clone. If you are using a miniature LDR, consult its datasheet for actual dissipation and current limits and recalculate the minimum resistance accordingly.A 10K gate pull-down is pointless - the OPAMP has a push-pull output stage and no strobe pin so its output can never go Hi-Z.Although the IRF830 is rated for repetitive avalanche operation, it would be advisable to add a reverse biassed diode across the main load terminals to shunt the back-EMF if long cables or an inductive load are ever connected.

author: 0xfede
author_rank: Regular Contributor
timestamp: April 27, 2018, 09:44:27 am
content: Quote from: Ian.M on April 27, 2018, 09:36:41 amUsing my experience I can say that the LM358 has a much higher VOL when is not resistive loaded (especially when ambient temp is extremely low) to the ground hence the need for the 10K resistor.Best,0xfede

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 10:05:44 am
content: The LM358's Vol will be under 1V while sinking 1mA, and the IRF830's minimum Vgs threshold voltage is 2V so there's plenty of safety margin for the off state even without a gate pulldown resistor.

author: Zero999
author_rank: Super Contributor
timestamp: April 27, 2018, 10:18:39 am
content: Yes 0xfede is mistaken. The only time this could be an issue is if the LM358 is sinking current.The original poster should also consider a MOSFET more suited to 12V operation, than the IRF830, which is rated to 500V. A MOSFET rated to 50V or less will have a lower on resistance or lower gate charge, everything else being equal.

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 10:48:56 am
content: While we are optimising the existing design, the potential divider biasing in+ of the spare OPAMP in the LM358 is pointless. As its common mode input voltage range includes ground, the other half is already driving rail-to-rail, and the ON LED will be continuously drawing about 7mA, the tiny improvement in quiescent current consumption from biassing the spare OPAMP at Vcc/2 isn't worth the cost of the resistors. Even without the LED, if quiescent current consumption was critical, the spare OPAMP could be biased from the in+ of the active OPAMP, saving two resistors, with negligible effect on its operation.

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 11:15:47 am
content: Is there any relation between the ON LED and the spare opamp ?Could you please be more explicit ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 11:41:20 am
content: Only that the LED is using more than an order of magnitude more current than the spare OPAMP, so any small improvement in quiescent current by biasing the spare OPAMP at Vcc/2 will have negligible effect on the circuit's total off-state current consumption. If you needed to save power, using a high efficiency LED so you could reduce its current consumption to 1mA would be a good start.

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 11:49:58 am
content: Please confirm that the modifications to be made are:1. add two resistor, each 330 ohms, one resistor in series with the LDR and one resistor in series with the 10k trimmer.2. connect the non inverting input (pin 5) of the spare op amp to the pin 3 of the used op amp.Beginner questions:3. can I use IRF530 or IRF630 in the place of IRF830 ?4. the mosfet gate resistor should be left at 100 ohms or it should be increased ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 12:50:25 pm
content: 1. Yes, that will work. As an ORP12 in direct daylight can have a rather low resistance, if you need to distinguish between the lower light levels typical of artificial light and direct daylight, its better to add an equal resistance to the preset and the ORP12. If you are only interested in lower light levels where the ORP12 resistance >1K,, a single 680R resistor in series with the preset would be sufficient2. That would work, but it adds unnecessary complexity, to save at most a small fraction of a mA, and there's no good reason not to simply ground the spare OPAMP non-inverting input.3. *ANY* power N-MOSFET*with an adequate Vds voltage rating would work as long as its Vgs threshold voltage falls in the range 2V-6V. If lower, it might not turn off reliably. If higher, there would be insufficent gate drive to get the datasheet nominal Rds_on resistance.4. There's no benefit in increasing it, but even if you made it several K the circuit would still function.* Except modules, 'hocky pucks' and other extremely high current devices with far far too much gate capacitance vs the limited drive current available from the OPAMP

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 02:14:59 pm
content: Thanks for the reply.I modified the R4 to 1.5K if Ian.M said that it will be OK to increase the R4 value.I was advised (not on the forum) to add a capacitor (100nF) in paralel with the 10K trimmer, so I added that capacitor.I attached the modified schematic. Please have a look at the schematic and tell me if it is OK.

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 03:46:54 pm
content: C1 may give you more trouble than it prevents. Without it both the +in and -in voltages are purely dependent on the resistance ratios of their respective dividers and the instantaneous supply voltage. With it, the -in voltage is delayed, which means that if the supply voltage transiently drops more than about 1.5V as the load switches on (and that 20W bulb has a cold resistance under 1 ohm so pulls a very large current spike at turn-on), the -in will be above the + in and it will switch back off resulting in oscillation. If you *MUST* put a capacitor there , make it a lot smaller and distribute it evenly from the input pin to both supply rails e.g. 10nF to each rail from the pin.1.5K will do for the gate resistor - it slows down the switching time to the order of 10us, which will increase the dissipation in the MOSFET, but its still well within the S.O.A for any of the MOSFETs you have listed, and unless it toggles rapidly and continuously (see issue in previous paragraph) the dissipation should be low enough that it wont need heatsinking.

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 03:52:11 pm
content: Thanks for the reply.If I will remove that 100nF capacitor and I will use the circuit without it. It will be ok ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 04:39:54 pm
content: Yes, as long as you keep the photocell wiring as short as possible. If its mounted off-board use twisted pair.

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 04:42:26 pm
content: I am planning to use for the photoresistor 1 meter long wires.1. What should I do in this case ? It is sufficient to use twisted pair in this case ?2. Or should I use a capacitor between GND and pin 2 and one capacitor between +12V and pin 2 ? 10 nF is sufficient ? Please confirm if I am correct.

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 05:45:49 pm
content: Twisted pair helps to prevent it picking up EMI, which, rectified in the B-E junction of the OPAMP input, could cause incorrect operation. With a 1m cable run, I'd add the 2x 10nF caps as discussed to further shunt RF EMI away from the OPAMP input.

author: mike_mike
author_rank: Super Contributor
timestamp: April 27, 2018, 05:50:33 pm
content: I made a schematic with those capacitors.Please have a look and tell me if the schematic is ok.

author: Ian.M
author_rank: Super Contributor
timestamp: April 27, 2018, 09:35:51 pm
content: Looks O.K. Time to breadboad it, (with the MOSFET, its gate resistor, the diode and the MOSFET's supply and load connections soldered up on protoboard so no connections to/on the breadboard have to carry over 1/2A) and confirm it does what you want, then either lay out a PCB or develop a nice tight protoboard layout.

author: mike_mike
author_rank: Super Contributor
timestamp: April 28, 2018, 08:16:13 am
content: Thanks for the reply.You said in one of the previous post that LM393 (comparator)is better for this design.It will be fine if i will use LM358 or I shoud switch for LM393 ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 28, 2018, 08:33:09 am
content: Not me. You could switch to a comparator, but a LM393 isn't the best choice. Its a dual comparator with open collector outputs, and for driving a single MOSFET gate, you'd be better off with a single comparator with a push-pull output stage. However for such a slow circuit, (limited by the ORP12 and the load) there's no reason not to stick with an OPAMP.

author: Zero999
author_rank: Super Contributor
timestamp: April 28, 2018, 11:28:15 pm
content: Quote from: Ian.M on April 28, 2018, 08:33:09 amIt was me and I wouldn't recommend using a comparator to drive a MOSFET. It's probably slightly better, than the LM358, but not much.In this case, I think the MOSFET is unnecessary. The LED can be driven from the LM358 or LM393. The spare op-amp/comparator could be used to drive, the LED, which would prevent the voltage drop from interfering with the comparator circuit.I'd recommend the LM311, which can drive up to 50mA out, with a very low saturation voltage.

author: Ian.M
author_rank: Super Contributor
timestamp: April 29, 2018, 12:09:44 am
content: Errr the O.P's also driving a 12V 20W Halogen bulb, which will have a cold resistance of under one ohm!. With a >16A turn-on surge, there's no realistic way of getting rid of the MOSFET. Your buffered LM358 circuit looks nice for isolating the MOSFET gate drive from the hysterisis feedback. Drive the LED off the comparator stage, sourcing current so it doesn't affect the Vol, and the MOSFET gate off the buffer stage.

author: mike_mike
author_rank: Super Contributor
timestamp: April 29, 2018, 07:51:15 am
content: Quote from: Ian.M on April 29, 2018, 12:09:44 amCan you please be more explicit ? I did not understood this.1. Are there any modifications that I have to do ?2. Or it is ok to use the circuit as it was in the last schematic uploaded by me ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 29, 2018, 08:43:06 am
content: It should work as-is, but Hero999 has proposed a small improvement (top schematic in reply#30) If you want to adopt his improvement, as you need to drive both a LED and a MOSFET, move the connection to R4 for his output LED from pin 7 to 1 to drive it off the first (comparator) OPAMP in the chip, and drive the MOSFET gate resistor from pin 7 of the second (buffer) OPAMP.

author: mike_mike
author_rank: Super Contributor
timestamp: April 29, 2018, 09:01:18 am
content: Thanks for the reply.I tested the circuit and it is working as I expected (I tested the last schematic that I uploaded in post 26).It is OK now to make the PCB @Ian.M ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 29, 2018, 09:40:11 am
content: That's up to you. Personally I am somewhat of a perfectionist so would investigate Hero's improvement, but eventually you need to either scratch-build a prototype on matrix board, put it into service and see how it holds up or take a gamble and skip that step and go straight to laying out a PCB. If you rarely lay out PCBs, you'll probably want to post PNGs or GIFs of it here for comment (PNGs or GIFs as many users cant handle proprietary PCB design file formats, and not everyone has a Gerber viewer program installed)

author: Zero999
author_rank: Super Contributor
timestamp: April 29, 2018, 09:58:08 am
content: Quote from: Ian.M on April 29, 2018, 12:09:44 amI agree. This is the problem with not putting everything on the schematic! Although I did read the text, I had forgotten about the halogen lamp, by the time it got to this stage of the thread!Yes, the MOSFET or relay are unavoidable and the spare op-amp could be used as a buffer for the MOSFET.I think a comparator with a push-pull output, such as the LMC6762, TSX3702 or LMC7211, would be the ideal solution, but they aren't always available in DIP packages or as cheap and easy to obtain as jellybean parts such as the LM358.

author: mike_mike
author_rank: Super Contributor
timestamp: April 29, 2018, 10:17:00 am
content: Thanks for the reply @Ian.M and @Hero999.I made the top schematic from post 36 (with LM358). I just modified on the old project. It is working.It is ok to make the layout ?

author: Ian.M
author_rank: Super Contributor
timestamp: April 29, 2018, 11:16:02 am
content: Yes, it looks like time totape it out.

author: mike_mike
author_rank: Super Contributor
timestamp: April 29, 2018, 02:16:12 pm
content: I attached the layout and the schematic.The LDR will be connected to the board using wires.Please have a look and tell me if the schematic and layout are ok.

author: Ian.M
author_rank: Super Contributor
timestamp: April 29, 2018, 07:32:26 pm
content: That's fairly sucky. The power in connector, load connector, MOSFET, 1N4007 diode and 470uF cap all need to be as close as possible to each other with minimal trace length between them so the MOSFET and diode should be right next to the connectors at the board edge. The power trace *MUST* go direct from the power connector to the 470uF cap and from there one branch back to the load connector and one off to the rest of the board. Same goes for Ground if you aren't using a ground plane. All high current traces need to be beefed up - doubling their width where you can wouldn't go amiss. The 100nF cap needs to be asw close to the OPAMP as possible with minimal trace length between them. The ORP12 needs a connector in parallel for off-board mounting. Otherwise,it doesn't look *TOO* bad for a minimal jumpers single sided layout, though you could probably do better making the traces round the OPAMP apart from its power and ground pins skinny enough that you can route one between its pins.

author: mike_mike
author_rank: Super Contributor
timestamp: April 29, 2018, 08:14:24 pm
content: I uploaded new files.Please have a look and tell me if it is ok.I am not sure if I understood correctly what you said.

author: Ian.M
author_rank: Super Contributor
timestamp: April 29, 2018, 08:51:33 pm
content: I've hilighted the critical high current traces that need to be shortened and separated from the low current traces. They should be grouped in one corner of the board, with the power and load connectors next to each other, then the MOSFET beside them, then the 470uf cap. The 1N4007 diode and the gate resistor should be near the MOSFET. They can go between the MOSFET and the cap for a bit of space so the MOSFET doesn't cook the cap if its ever loaded enough to run hot. Apart from the diode, *NOTHING* I haven't hilighted should join a highlighted power or ground trace anywhere other than at the 470uF cap pins.

author: Zero999
author_rank: Super Contributor
timestamp: April 29, 2018, 09:01:18 pm
content: You don't need big, fat, traces everywhere, although it doesn't cause any harm. Only the ones which carry current, to the load, i.e. the ones from, J2, to the MOSFET's drain, source, the 470μF capacitor and J1 need to be much larger, than the other traces, which can be relatively thin. Ideally the heavy current carrying traces should be solid copper pours, if possible. I don't know what the exact scale is. The traces look thick enough for 3A, but use the calculator, linked below, to be sure. Consider the trace length, the voltage drop, as well as the temperature rise.http://www.4pcb.com/trace-width-calculator.htmlBy the way, please avoid using jpg format for drawings. It results in large files and fuzzy edges, which can make editing difficult. Please stick to PNG for schematics and PCB layouts. Look at the size of the files I posted and how sharp they are, compared to the JPGs. I also reduced the colour depth to 4-bit, to make the files size, as small as possible, but this can only be done with images which don''t contain many colours, without loss of quality: 8-bit colour will be fine for most drawings.

author: mike_mike
author_rank: Super Contributor
timestamp: April 30, 2018, 04:56:33 am
content: Quote from: Ian.M on April 29, 2018, 08:43:06 amYou said to drive the led from pin 1 of LM358. I drive it using the mosfet (like in the top schematic from reply #36). It is a mistake ?I already made the top schematic from reply #36 and it is working. Also, the layout was made for the top schematic from reply #36.It is a problem if I drive the led as shown in the top schematic from reply #36, using the mosfet ? (That led is connected at J3)

author: Ian.M
author_rank: Super Contributor
timestamp: April 30, 2018, 06:49:24 am
content: You can do it either way. Before I talked you into adding the 1N4007 diode, an inductive load would have killed the LED at turnoff if you left it in parallel to the load. I've got a mild preference for moving it to the output of the first stage OPAMP as if your load shorts and the MOSFET dies, the LED should still work (the OPAMP will survive a MOSFET failure as the 1K5 gate resistor will limit the current to under 10mA, well within the OPAMPs ratings no matter how the MOSFET shorts out as it dies or blows apart), telling you the failure to command the load is either a load problem or a blown MOSFET. If you aren't going to volume production, you may want to add a second LED on the board on the first stage OPAMP output instead of moving it as if the two LEDs don't match you know you've killed the MOSFET and its also handy for setting it up before you wire everything up as all you need to do is hook up power and the ORP 12 to test the board or set the threshold.How are you doing on rearranging the board to shorten the high current traces? One thing I forgot to mention - a fuse in the DC input would be a good idea. It wont be fast enough to save the MOSFET, unless you vastly over-spec the MOSFET, but will prevent a high current short burning traces off the board, keeping it easily repairable.

author: mike_mike
author_rank: Super Contributor
timestamp: April 30, 2018, 03:28:15 pm
content: I am sorry for the delayed response.I attached the updated schematic and layout.I tried to do my best, but I am not sure if I made them correct.All traces are 1.5mm wide.Please have a look and tell me if the schematic and layout are ok.

author: mike_mike
author_rank: Super Contributor
timestamp: May 01, 2018, 07:27:04 am
content: I am attaching a new layout.I am not sure if I made it correctly. I tried to respect the instructions.I elongated the pads to make sure that will be enough copper on the board. I will make the PCB using transfer toner method.I tried to make the power traces shorter but I don't know if they are short enough. I arranged the power traces on the top of the PCB.The power traces width is 2mm and the rest of the traces are 1.5mm.Please have a look at the schematic and at the layout and tell me if they are ok.

author: mike_mike
author_rank: Super Contributor
timestamp: May 01, 2018, 09:27:24 am
content: @Ian.M Are you still there ? Can you please respond ?

author: Zero999
author_rank: Super Contributor
timestamp: May 01, 2018, 10:21:08 am
content: Quote from: mike_mike on May 01, 2018, 09:27:24 amPeople do have other things to do, than post here you know. If no one responds within a day or two, fair enough bump the thread, but you only waited a few hours, which demonstrates lack of patience.The last layout looks better than the others, but I haven't looked in great detail.

author: mike_mike
author_rank: Super Contributor
timestamp: May 01, 2018, 10:23:37 am
content: Thanks for the reply @Hero999.I am sorry for bothering you and @Ian.M with my questions.Have you looked at the schematic ? It is OK ?

author: Zero999
author_rank: Super Contributor
timestamp: May 01, 2018, 12:24:18 pm
content: Quote from: mike_mike on May 01, 2018, 10:23:37 amI don't mind the questions, as long as you don't forget that people are not being paid for the advice they give.The schematic would be better if J9 and R8 were switched by the MOSFET, rather than being connected to the op-amp's output.

author: Ian.M
author_rank: Super Contributor
timestamp: May 02, 2018, 02:34:17 am
content: Use a Polyfuse, they are much more compact, and self-reset when the power is switched off for a few minutes.@Hero999: the whole point of the second LED connected to the first stage OPAMP output is it should *ALWAYS* match the one switched by the MOSFET. If it doesn't it means the MOSFET's blown - which is difficult to avoid in such a simple circuit if its output is shorted, without incurring excessive losses or complexity protecting the MOSFET, so its useful to have an indication that there is a fault.

author: mike_mike
author_rank: Super Contributor
timestamp: May 02, 2018, 04:52:07 am
content: Thanks for the reply.I think I will use for the moment a 5x20 mm fuse which I can find at the local electronics store.It is ok now to make the pcb, or there are any other modifications that I should do ?

author: Ian.M
author_rank: Super Contributor
timestamp: May 02, 2018, 05:20:57 am
content: Looks reasonable. I'm sure I could tidy it up a bit 'hands on', and I'd probably use a ground plane, if not for the whole board, at least for the small signal stuff from a line across the board between J1 and J6 downwards, but its not worth the time to try to talk you through the changes, as you aren't PWMing anything so it isn't going to radiate significant EMI. Worst case it may flash a bit if you get a cellphone too close to it!If you've checked the high current trace widths and copper thickness are adequate with the calculator Hero999 linked in Reply #43, it passes the schematic package ERC and DRC, and you have sorted out how you will mount it without mounting holes, then go for it. I've seen worse in commercial products!

author: mike_mike
author_rank: Super Contributor
timestamp: May 02, 2018, 05:27:49 am
content: Thanks for the reply.The last uploaded schematic (reply #47) is correct ? Sorry for asking again. I just want to be sure.

author: Zero999
author_rank: Super Contributor
timestamp: May 02, 2018, 07:55:02 am
content: Quote from: Ian.M on May 02, 2018, 02:34:17 amGood point.Quote from: mike_mike on May 02, 2018, 05:27:49 amIt looks good to me.

author: mike_mike
author_rank: Super Contributor
timestamp: May 03, 2018, 02:19:40 pm
content: I built the circuit and I tested it.Everything looked OK, but when I put the scope on pin 2, there appears an oscillation (I don't know what is it, but I suppose it is a oscillation).The first image is from pin 2 of LM358 (the probe between GND and pin 2), and the second image is from the terminals of LDR.On the pin 6 and 7 is only noise, about 2-3mV. On pin 1 is the same with pin 6 and 7 (DS0262.png).I tried to remove the two 10 nF capacitors but it behaves the same.I tried with another LDR and it behaves the same.I do not know what other details I need to show.It is normal or my circuit does not work correctly ?

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2018, 03:12:31 pm
content: So you've got 35mV of 100Hz ripple at the first OPAMP input. That could be noise on your +12V supply - try probing the +12V rail with the scope input on AC coupling and see if its worse there, or run it from a 12V battery and see if the ripple at pin 2 goes away. Alternatively it may just be the LDR responding to the room lights flickering at twice mains frequency. Test that by turning off the lights and illuminating the LDR either with natural daylight, a LED keyring torch that doesn't have any electronic controls or fancy modes, or an torch with an incandescent bulb. As the circuit has >0.5V hysterisis, 35mV of ripple isn't going to cause any problems.As for what you measured at the LDR - unless its well lit, its fairly high impedance and that looks a lot like its picking up mains hum on the wiring.

author: mike_mike
author_rank: Super Contributor
timestamp: May 03, 2018, 03:44:26 pm
content: I made some tests, with the light turned off in the room. The light of the room consist of 1 LED 230V light bulb.Natural light, load off DS0355.png.Natural light, load on DS0358.png.Output of the 12V power supply: DS0356.png.The probe on the LDR with the circuit turned off and the LDR connected directly to the PCB: DS0360.png.Please have a look at the measurement images and tell me what you think.

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2018, 03:52:33 pm
content: That proves the 100Hz ripple at pin 2 was from the room lighting. However there's still something odd about the 50Hz mains hum you are getting at the LDR. Exactly what point on the above schematic are you probing, and where's the scope ground clip connected to?

author: mike_mike
author_rank: Super Contributor
timestamp: May 03, 2018, 03:55:49 pm
content: The oscilloscope probe is connected on the terminal block marked with arrows. The ground clip is on the upper arrow.And I am using the crocodile clip of the probe.That 50 Hz sine wave (or approximate sine wave) as in the DS0360.png is present on the LDR even if the power of the circuit is off.

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2018, 04:27:12 pm
content: You can't do that unless you are using a self-contained battery powered scopemeter. You are lucky not to have blown the OPAMP, and if you'd put the ground clip on the other end of R3, if the PSU had a grounded output it would have damaged your scope. As you are using a mains PSU, even if its fully isolated, the scope ground clip *MUST* go on the 0V (circuit Gnd) rail as otherwise anything you are trying to measure will be swamped by the line frequency leakage current through the PSU's pri-sec class Y EMI suppression capacitor.The only way of making differential measurements safely with a conventional mains powered DSO is to either use two channels and use waveform arithmetic to display the difference (low accuracy if the common mode signal is large with respect to the difference signal, and no good at HF) or to use a differential probe.Forum topic:https://www.eevblog.com/forum/blog/eevblog-279-how-not-to-blow-up-your-oscilloscope!/

author: mike_mike
author_rank: Super Contributor
timestamp: May 03, 2018, 04:43:38 pm
content: Thanks for the link, it is giving 404 error.I measured again, with the ground clip on the gnd of the circuit and the probe on pin 1 and pin 2 of the J4 connector.On pin 1, it gives me the following results:DS0363 in completely darknessDS0364 in direct natural lightOn pin 2:DS0366 in completely darknessDS0365 in direct natural lightPlease have a look and tell me what you think.

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2018, 06:03:54 pm
content: Yep. I was right. Mains hum due to incorrect probe ground connection.I've fixed the links above. You *SHOULD* watch the video above . . .

author: mike_mike
author_rank: Super Contributor
timestamp: May 03, 2018, 06:07:41 pm
content: Thanks for the reply.The circuit is OK now ?And sorry for bothering you with my beginner questions.

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2018, 07:06:27 pm
content: If it works the way you want, its O.K. We eliminated all the major problems earlier.

author: mike_mike
author_rank: Super Contributor
timestamp: May 06, 2018, 11:45:46 am
content: Thanks for the reply @Ian.M.The 1.5K ohms (R4) gate resistor is having a sufficient value to avoid ringing and oscillations ?

author: Ian.M
author_rank: Super Contributor
timestamp: May 06, 2018, 12:35:37 pm
content: Plenty. Even 100R would stop it oscillating as long as its close to the gate pin. The advantage of 1.5K is it limits the maximum gate current (even if the MOSFET fails shorted) to under 10mA, which the OPAMP can easily handle. If you put a 100R one there, if you short the load and blow the MOSFET, there's a significant risk of it taking out the OPAMP as well. Series gate resistors always need to be as close to the MOSFET as possible - if you put them too far away, you risk the track between them and the gate acting as an antennae coupled to the load circuit, possibly turning the MOSFET into a power oscillator.

author: mike_mike
author_rank: Super Contributor
timestamp: May 06, 2018, 12:53:01 pm
content: Thanks for the reply.You said about distance between the resistor (R4) and mosfet.On my layout, that distance is about 200 mils and the trace is about 2mm wide. It is sufficiently short ?

author: Ian.M
author_rank: Super Contributor
timestamp: May 06, 2018, 01:51:10 pm
content: That should be fine for any normal power MOSFET. Typically one sees problems if the gate track snakes around larger boards, or if the gate is directly driven by a low impedance and there is significant reactive impedance in both the drain and source circuits.IMHO its time to just <expletive> build it!I'll probably be ignoring further posts in this thread unless you post a photo of the actual build.

author: mike_mike
author_rank: Super Contributor
timestamp: May 06, 2018, 02:24:43 pm
content: @Ian.M you can find the photos in the following link:https://imgur.com/a/9BpcbhiI am sorry about the quality of the photos. I do not have a camera. I used my smartphone.I used the toner transfer method for the PCB. I put solder on all traces to prevent the oxidation.