Circuit check: Arduino pwm via optocoupler to control geared 12v fan - Page 1
Forum section: electronics / beginners

author: tifkat
author_rank: Regular Contributor
timestamp: February 12, 2021, 02:57:25 am
content: Hello gents, ladies, cyborgs and others,I have a project in which I want to introduce some gentle convection into a heated enclosure to ensure even distribution of temperature throughout. I have purchased a 12v motor with gearing to reach a maximum 210 RPM, and I would like to have some control over the speed.My plan is to use standard Arduino PWM output (I don't believe I will need anything high speed) via an optocoupler which would drive 2x S8550 PNP transistors.The fan is rated at 0.6A continuous current, no startup current draw figures provided. I have a Fairchild 4N26 optocoupler and some S8550 transistors.Attached is a schematic I have worked out, with some descriptive text denoting why I included specific parts in the circuit.My questions are:1) How many "traps for young players" have I found myself in?2) Would a low pass filter for smoothing out the PWM into a continuous DC level be necessary, and where would the caps go? (I'm thinking on the Optocoupler side of the Voltage reduction resistors as noted in the schematic)3) Would the 2x S8550 PNP BJTs be sufficient in your opinion4) Did I get the protection diode correct?5) Does my diagram suck? :-DDisclaimer: I am using parts I have on hand, I don't have budget to change parts (right now). All parts purchased from AliExpress. Components are untested. Still waiting for my 12v supply to show up.

author: ledtester
author_rank: Super Contributor
timestamp: February 12, 2021, 05:48:36 am
content: I am certainly no design expert, but my instinct tells me that it would be preferable to use one power transistor rather than parallelizing two S8550's. Perhaps a TIP125 if you wanted to go the PNP route. Would be very interested to hear from others on this.

author: Ian.M
author_rank: Super Contributor
timestamp: February 12, 2021, 06:10:56 am
content: A 0.6A DC motor (not brushless) probably draws something like 6A stall current, maybe even more. It will draw that current at every startup unless you ramp up the PWM very cautiously. If your ramp up rate is too fast, it will blow your transistors. Adding current sensing to close the loop and stay within their max. Ic rating is strongly recommended if the transistors cant survive the stall current with adequate safety margin.Personally, for simplicity I'd run it open loop with a beefy enough transistor to handle the stall current. I'd ditch the circuit above (as there's no benefit in optoisolation unless control and/or load circuit grounds must be independently floating, and several disadvantages) and use an 8A or 10A 'logic level' N-MOSFET(i.e. Vgs_threshold(min)<Logic_Vcc/2, but check Rds_on @Vgs=Vcc is low enough)on the low side of the motor, with a beefy anti-parallel Schottky diode across the motor, to allow its current to recirculate during the PWM off-time. Odds are it can be driven direct by an Arduino PWM pin, with only a 100R 'gate stopper' resistor as close as possible to the MOSFET to prevent RF oscillation during transition, However if the MOSFET has particularly high gate charge and you are using a high PWM frequency, it may need a gate driver to keep the switching time small compared to the PWM period.

author: ledtester
author_rank: Super Contributor
timestamp: February 12, 2021, 06:35:14 am
content: QuoteI don't think you want to filter your PWM signal. BJT transistors have a highly non-linear response to base voltage as you sweep it from 0V to 12V. For instance, you might see something like:base voltage between 12 and 11.5V -- PNP is offbase voltage less than 6V -- PNP is fully onbase voltage between 11.5 and 6V -- current through PNP increases exponentiallyThe actual response will be different for every transistor (even of the same make.)However, if you make the base voltage either 0V or 12V you will be sure to turn the transistor fully on or fully off, so the average current through the transistor will be proportional to the duty cycle and this sidesteps the non-linearity and individual characteristics of the transistor.

author: tifkat
author_rank: Regular Contributor
timestamp: February 12, 2021, 07:54:21 am
content: Quote from: ledtester on February 12, 2021, 06:35:14 amOf course!! I don't need to have those 2 "unsure" resistors in there, because the BJTs are PNP and flat GND is perfect... no need to reach a certain voltage... the more groundy is it, the better. That make things much easier. And being rated at 30v, the 12v side of the optocoupler shouldn't be in any danger. And current limiting probably isn't a thing because the S8550s just won't push that much through... or am I wrong on that?Here is the motor:

author: ledtester
author_rank: Super Contributor
timestamp: February 12, 2021, 08:05:21 am
content: QuoteActually it's a good idea to have those resistors. You don't want uncontrolled current through the emitter-base junction. Yes, current will be limited by the opto-coupler, but I would still include them. The will also help even out the current sharing between the two transistors.It's the same reason you have a base resistor on NPN transistors.Even with resistors you'll have no problem driving the transistors into saturation. Because of the current gain of the PNP you don't need a lot of base current.

author: tifkat
author_rank: Regular Contributor
timestamp: February 12, 2021, 08:05:57 am
content: Ian,I'll read through you reply a few more times and try to come up with something that matches what you say. The minister for war and finance may have something to say about me spending more money on beefier components, but maybe I can stretch the limits... just ONEmoretime..

author: tifkat
author_rank: Regular Contributor
timestamp: February 12, 2021, 08:10:38 am
content: Quote from: ledtester on February 12, 2021, 08:05:21 amOk... so are the values ok? Is there anything I got wrong? I tried to think of everything I have learned about transistor biasing and protection and cutoff, linear and saturation point requirements.I'd really love a discussion from someone who knows this stuff really well, how each noted part of the circuit fairs in the daily use of this kind of circuit.

author: Ian.M
author_rank: Super Contributor
timestamp: February 12, 2021, 08:43:01 am
content: The min. hFEof a S8550 @Ic=500mA is only 40, rising to 120 @150mA. I estimate the min. min. hFEcould be as low as 85, (the datasheet's typ. hFEvs Ic graph shows a typical hFEof 100 @ 300mA)You therefore need 600mA/85 base current for the pair which is 7mAThe min. CTRR of a 4N25 is only 20%, so you'd need 35mA opto-LED If to guarantee enough base drive *IF* there wasn't a 1K base pulldown on the opto's phototransistor. That's already more than an Arduino output is good for.Of course you may get lucky and get high gain transistors and a high CTRR optocoupler, but its a gamble and there is a significant risk the transistors will have insufficient base drive, and depending on the PWM duty cycle, they may overheat badly and possibly fail.

author: perieanuo
author_rank: Frequent Contributor
timestamp: February 12, 2021, 09:00:44 am
content: hi,I use some silent cooler with temperature-controlled speed in my analog power supplythe digital part (some arduino-like) shows current/voltage/temperature... on oled display and control this cooler.I didn't use opto, but look how simple it is to implement one.it works from 2018 until now when I need analog low-noise ps on prototype boardsI have to look to the code to tell you exactly the temperatures/speeds (pwm of course), but you only need pwm out to cooler guidingregards oups, cooler == Ventilator in the drawing and Q3 == 2SC3647T-TD-E, some SOT89 transistor

author: ledtester
author_rank: Super Contributor
timestamp: February 12, 2021, 09:05:24 am
content: Let me start off by saying that I agree with Ian M. in that you should use low-side switching with a N-MOSFET and drive it directly from the mcu. It's a lot simpler and easier to design.PNP transistors are current driven devices, but the 4N26 is a very poor at transmitting current. It only has a CTR of 20% (50% nominal). You are putting 15mA through the optocoupler's led. That means only 3mA is guaranteed to pass through the C-E junction of the 4N26. The S8550 has a min hFE of 85. 3ma*85 = about 250mA which is way less than you need.(Note that doubling up the S8550's doesn't actually help in this case, because there's only 3mA of base current total to go around. Have multiple S8550's would help if you can get the base current up higher.)The point is that the design is very marginal. You might get lucky with the components you happen to use, though, if you only need to build one copy.Optocouplers such as the 4N26 are really suited for transmitting serial data which doesn't require a lot of current. The white paper "Basic Characteristics and Application Circuit Design of IC couplers" on this page:https://toshiba.semicon-storage.com/ap-en/semiconductor/knowledge/application-note.html#Photocoupleris a good read for learning how to design with them.

author: tifkat
author_rank: Regular Contributor
timestamp: February 12, 2021, 09:06:37 am
content: Quote from: Ian.M on February 12, 2021, 08:43:01 amYou got it pretty much spot on according to the data sheet. 85-300.QuoteYeah that 1k was honestly a bit of a guess. I know bigger would help reduce the effect on the minimum required, but it would also mean slower turn off. A question: for an optocoupler, is such a base pull down necessary?I know 20mA is the stated "limit" for any current out of the ATMegas, but have heard plenty of times the 40mA is quite safe, of course if you're only pushing that through 1 or 2 pins.Come to think of it, while I am wanting to test this with a ATmega328, long term I actually want to use a SAM3x8e, so there goes my 5v... although 3.3vay still work. I'm not aware of mA out capabilities of the SAM family.QuoteThankyou very much for this analysis. It did clear up some very important stuff I read in the data sheet and just didn't grok. Now your post has made them all very understandable.I guess I will look at a beefier right hand side solution.Thanks Ian!

author: tifkat
author_rank: Regular Contributor
timestamp: February 12, 2021, 09:17:00 am
content: Thanks for your input also ledtester. I'll give that link a read. This was my first attempt to design anything based around an optocoupler, and no one has said my circuit is bad/wrong... just deficient for the stated purpose, so I'm prettt chuffed with that.I guess the marginality of the parts is a symptom of not knowing the parts purchased, and not purchasing them for a specific purpose. There's my trap for young players!Perieanuo,That is very simple. Where does the top pin of the fan header go off to? I assume +12v

author: perieanuo
author_rank: Frequent Contributor
timestamp: February 12, 2021, 12:08:16 pm
content: yes, it's 12V. it was just an example for you to nor overthink the diagram on optocoupler output.you noticed I haven't put reverse diode for final transistor, the spike is too small. in real production I'll populate that diode.so you can atack a classic opto like 4n35 or whatever with some 470R series resistor from microcontroller output, the opto output you can use like output Collector on +12Vdc, the series 10k or smaller one 1K on opto Emiter targeting transistor base and that's it. you overcomplicated a simple schematic, that's my pointyou can recalculate your resistors, but it's in that areai was looking in some industrial boards designed with MC56F8323, we had 330 ohm resistor series with PC357 opto diode (I think 220 was mounted also when 330 was out of stoc)as I said, the resistor is for you to tune, but industrial stuff worked with muuuuch simplier design, it was reliable in harsh environment (that was from a step motor driver with trajectory control, some 'Ready' output, but in your case it's identical)

author: tifkat
author_rank: Regular Contributor
timestamp: February 13, 2021, 12:18:43 am
content: With the new understanding I have, thanks to Ian's explanation, I went back to the data sheet, and noticed the IR LED can be driven up to 60mA (for the -M variant I have) which seemed bogus when I read it originally, but now make total sense. Driving it harder to the max 60mA would mean then that It would have 12mA to drive the transistors. Which is probably going to be sufficient. Although the capabilities of those transistors kind of defeats the purpose for driving this particular fan.I may breadboard it, just for fun.

author: WattsThat
author_rank: Frequent Contributor
timestamp: February 13, 2021, 12:51:36 am
content: Not sure where you ended up, lots of info in the thread but I have to say you’re making this way, way harder than it needs to be. An n-channel mosfet is the best overall and simplest choice, no optocoupler is required. Here’s the diagram (and more info here).There are dozens of mosfets that will work properly, it must be a “logic level” device such as:FQP30N06LRFP30N06LEIRLB8721

author: tifkat
author_rank: Regular Contributor
timestamp: February 13, 2021, 03:42:32 am
content: Quote from: WattsThat on February 13, 2021, 12:51:36 amNah!!1. It's me trying to understand the correct setup for a transistor, and a PNP BJT at that.2. (Here's the real reason) I am working withwhat I have access toas stated at the bottom of my original post. This is the biggest hand-tieing, complexity causing, mind f*****g part of my schematic.Cleary my parts aren't up to spec for this purpose... and this kind of explains why using 2 BJTs in parallel, to get more current.. over and above the spec of a single component.No one has pointed out massive theoretical issues with the schematic (with maybe my protection diode choice not being a schottky type)... apart from the circuit being marginal for the stated purpose, mostly practical issues. So it seems my understanding in this case is solid. Which is more than what I expectedSo, thanks for your addition, I kind of plan to go this route long term. But I'll probably implement my original circuit on a breadboard for the pure hands-on, possibly do some measurements, maybe pop a tranny experience!

author: tifkat
author_rank: Regular Contributor
timestamp: February 13, 2021, 04:14:40 am
content: Is the schottky part so advantageous? It's the switching speed that dictates the choice isn't it? Or is it a lower ON voltage requirement?Switching speed: perhaps this would help, with the use of a lower duty cycle PWM signal, more off time equals more reverse current time. My original plan was to lowpass-filter though, so no switching needed.Lower On Voltage: I guess this could result in better reverse current dissipation, because it would stay on longer, leaving (potentially) only 0.2v or 0.3v in the circuit when it finally turns off. But with this comes lower breakdown voltage. Since this has 12v across it, that breakdown reverse voltage may well be problematic.So I don't see the advantage in using a Schottky diode in this case.Please, please, please correct me if I'm wrong, but it would seem to me that the use of a Schottky diode shown in WattsThat's example schematic is someone trying to look clever by including something fancy, but not really being the best choice.That said, I chose a switching diode anyway... so what would I know?!

author: ledtester
author_rank: Super Contributor
timestamp: February 13, 2021, 06:02:18 am
content: Quote from: tifkat on February 13, 2021, 04:14:40 amAccording to this SE discussion:https://electronics.stackexchange.com/a/354684/95488it's the reverse recovery time that's important.Update:This video by w2aew shows what the reverse recovery times look for various diodes:https://youtu.be/SBqLOrlA7QI