Fan controller circuit (originally with an Op Amp, now with a µcontroller) - Page 1
Forum section: electronics / beginners

author: BGE
author_rank: Contributor
timestamp: June 01, 2020, 03:41:32 pm
content: Hi all,I'm new here. I have designed a fan controller circuit based on the MIC 502 fan management IC:First let me explain what I want this to do:- The potentiometer should be used to set a base duty cycle (aka minimum fan speed). The fan speed should then rise as the thermistor TH1 heats up. The transistor switches the fan's ground to on/off based on the duty cycle.- The box on the bottom is meant to drive a LED. If the thermistor value drops down to 1.2K (temperature is above 80°C), I want the LED on.I have a couple of issues:1/ I've been told the LM358 is not a great option as a voltage comparator. Should I use something else? For example a LM393? All I want is a voltage comparator circuit in a PDIP package capable of running a LED.2/ Is my comparator setup correct? I'm having doubts. The trigger for this circuit should be the thermistor reaching 80°C (or 1.2kOhm). I created IN2- as an image of IN2+ except the thermistor is replaced by a resistor representing the state of the thermistor at 80°c. I also did away with the potentiometer because I don't want it to affect the comparator circuit.But now that I look at it, my voltage at R8 IS going to be affected by the value of the potentiometer, no (it's basically a voltage divider isn't it)?Thanks in advance for your help!!

author: Vovk_Z
author_rank: Super Contributor
timestamp: June 01, 2020, 06:58:03 pm
content: Quote from: BGE on June 01, 2020, 03:41:32 pmIf you need a comparator then LM393 (LM2903) is a better choice of cause. Its input common-mode voltage range includes the negative rail as it is in LM358.

author: fragile
author_rank: Contributor
timestamp: June 01, 2020, 08:23:33 pm
content: You know what would go great with this? If you used a 100k ntc and put a pot in parallel with it. Then you could control the amount of change in resistance in the ntc per degree, because by turning the pot down it would make the 100k ntc become less than 100k, and even less thqn 10k, if you turned it down far enough.But you don't relly need a pot, you just need a variable resistor. I'm just thinking of if it (the system) oscillates. But the ic probwbly maybe prevents that somehow. I just don't want to sound stupid. Sorry if I'm wrong.

author: Vovk_Z
author_rank: Super Contributor
timestamp: June 01, 2020, 10:37:33 pm
content: Quote from: BGE on June 01, 2020, 03:41:32 pmAs for R5/R6 comparator divider - it is too high (11.1V ?). "Usual" opamps (I mean non-rail-to-rail input) don't like voltages close to V+ power supply.Look at "Input Common Mode Voltage Range" for LM393. It is "V+ minus 1.5V". For 12 VDC power supply it means 10.5VDC max at the opamp input.

author: Agalien
author_rank: Newbie
timestamp: June 03, 2020, 04:57:33 pm
content: Why not use the over temperature detection output (/OTF - pin 6) to control the led? This output is already monitored by a comparator.Otherwise, do you have the R/T characteristics of the NTC thermistor and the different temperature levels that you need to manage such as (i.e. Temp = 25° PWM 0% - Temp = 60° PWM 100% - Temp > 80° OTF activated)

author: madires
author_rank: Super Contributor
timestamp: June 03, 2020, 05:36:19 pm
content: Why have you selected a BUL58D as switching transistor? It's a high voltage type, usually used in old CRT TVs. BTW, it has a freewheeling diode integrated.

author: ender4171
author_rank: Contributor
timestamp: June 03, 2020, 05:36:28 pm
content: No comments on your questions (though I built a similar project using just a 555, some passives, a variable resistor, and a bi-metal thermal switch. Crude (and the duty cycle is static), but it works just fine), but your schematic just gave me a "Jesus, I've been doing this all wrong!" moment. Never thought to just duplicate the positive rail in order to make a better schematic layout. I've always just had one "rail" and tried to force everything to fit, lol.

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 10:35:16 am
content: Sorry for the lack of replies everyone, I just don't have time on week days for my hobbies...@Vovk_Z (pt1): I'll go with the 393 then!@fragile: "Then you could control the amount of change in resistance in the ntc per degree." I'm not interested in changing this characteristic... Ideally I'd like to get the exact voltage drop caused by the NTC (ie not influenced by the pot) in oder to get a temperature reading for the LED control part of this circuit.@Vovk_Z (pt2): I don't have much experience with op Amps so I didn't know this. Thanks for letting me know! I've got 11.1V because the value of the NTC at 80°C is 1.2k and this is the temperature at which I'd like the LED to come on. So if I want to work with voltages above 10.5V, I need a rail to rail op amp? Do rail to rail 393s exist in PDIP packages?@Agalien: As far as I know, this /OTF output can't be switch on/off at a specific temperature (in my case, I'd like the switch to occur at 80°C).I don't have the R/T characteristics of the thermistor yet.I haven't chosen one yet and based my calculations on a random spec sheet (http://2avrmz2nom8p47cc28p2743e-wpengine.netdna-ssl.com/wp-content/uploads/2010/11/Thermistor_10K-2.pdf) I found on the internet.I want the fan to run at whichever speed/PWM defined by the potentiometer. As the NTC's resistance goes lower, the PWM duty cycle shall increase (MIC502 should manage this). If the NTC reaches 80°C (1.2K), the LED should light up.@madires: I found this BUL58D randomly while searching on Arrow.com. The original schematic had a TIP122. Would the latter be better?@ender4171: That's what I wanted to do initially but I thought I might as well incorporate a temperature controlled circuit while I'm at it.

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 10:56:54 am
content: @Vovk_Z: If I change R8 and R5 to 6.8k (see below), now the voltage won't won't exceed 10.5V. Is this now better (as an "Input Voltage Range" perspective)? The rest of my circuit (VT1 of the MIC502) shouldn't be altered, right?As is (now), I should have the following voltages at pin 5 of the op amp (if this is correct...):10k NTC (cold): 4.8V5k NTC: 6.9V1.2k NTC (80°C): 10.2V1k NTC (worst case scenario, >80°C should never happen): 10.4V.My main concern at the moment is that I don't know if the voltage at pin 5 of the op amp (I haven't switched to a 393 yet) will vary if I turn the potentiometer RV1.I know this is probably a stupid question... but I can't figure this one out by myself...

author: madires
author_rank: Super Contributor
timestamp: June 07, 2020, 11:38:32 am
content: Quote from: BGE on June 07, 2020, 10:35:16 amTIP122 is an NPN Darlington with a collector current of 5A. How much current does the fan need? Have you though about using a MOSFET?

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 12:31:22 pm
content: Hi madiresI'm trying to design this so that any 120mm case fan will work. I have an old one (1992) that can draw up to 6W (12v @ 0.5A) so let's say 12W to be extra sure (I don't think there are many 120mm fans that draw more than 1A). The BUL58D and the TIP122 are both overkill for this application. Is it worth changing? The BUL58D is still manufactured and is still cheap ($0.55)...

author: madires
author_rank: Super Contributor
timestamp: June 07, 2020, 12:45:19 pm
content: Are you aware that the BUL58D has a low hFE of around 40 (minimum is 5)? And what about the C-E voltage drop?

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 12:56:37 pm
content: I was not and I'm afraid I don't know what are the important criteria are when choosing transistors (that's one of the reasons I created this thread under Beginners...)Based on what I want to do, which one would you use?

author: mikerj
author_rank: Super Contributor
timestamp: June 07, 2020, 01:19:25 pm
content: Quote from: BGE on June 07, 2020, 10:56:54 amProvided the current flowing into or out of the VT1 pin is negligible compared to your thermistor current then the position of RV1 will not change the voltage on pin 5 of your op-amp. The datasheet says this current could range from -2.5uA to +1uA, so you can work this out.

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 01:36:30 pm
content: Thanks mikerj for clarifying this. I completely forgot that current was going to play a role here. And as you pointed out, since the current flowing through VT1 of the MIC502 is really negligible, the potentiometer (connected in series to VT1)won't affect my temperature readings/voltage on the other side.

author: Zero999
author_rank: Super Contributor
timestamp: June 07, 2020, 01:39:00 pm
content: D2 is in the wrong place. It should be in parallel with the motor, not the transistor.

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 01:44:06 pm
content: Hi Zero999,I basically copied the top schematic from this site:https://bit-tech.net/reviews/modding/pwm_fan_controller/1/and here is why the author added a diode there (it's D1 in his schematic):QuoteDoes this make sense?

author: madires
author_rank: Super Contributor
timestamp: June 07, 2020, 01:52:22 pm
content: Quote from: BGE on June 07, 2020, 12:56:37 pmWhen you use a BJT as a switch it needs to be driven into saturation (turning it fully on). The maximum output current of the MIC502 is 25mA. That's not enough for the BUL58D with a hFE of 40.Quote from: BGE on June 07, 2020, 12:56:37 pmI'd try a logic-level MOSFET. MIC502's V_OH is 3.2V for a Vcc around 12V, but a graph shows about 3.75V at I_OH of 10mA and 12V Vcc.

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 02:18:10 pm
content: OK, let's recap everything that has been done:Here's the current schematic- BUL58D was replaced by a TIP122 (if there's a better one, I'll update the schematic)- Voltage drop at pin 6 of comparator caused by potentiometer/MIC502 (used to be pin 5 before Schmitt trigger) has been deemed negligible.Voltage at R8/RV1 pin 1 represents the temperature of the NTC thermistor and isn't influenced by anything but it.- LM358 was replaced by an LM393 comparator (rail to rail)- Comparator input voltages tweaked so that they fall within spec (6.8k resistor).- Added Schmitt trigger circuit. LED shall turn on when High Threshold is reached (when NTC behaves like a 1.1k resistor, ie when temperature is around 84°C ->10.32V) and shall turn off when voltage falls below the Low Threshold (when NTC behaves like a 1.3k resistor, ie when temperature is around 79°C ->10.07V). Resistor values calculated using thiswebsite(Low Threshold: 10.07V, High Threshold: 10.32V, V_Ref: 12V, Output Voltage High: 12V, Output Voltage Low: 0V). Here's theoutput.Apart from the transistor, it should be pretty much ready to go?What do you think?

author: madires
author_rank: Super Contributor
timestamp: June 07, 2020, 02:35:07 pm
content: The LM393 has an open collector output. So you need to power the LED via Vcc.

author: Zero999
author_rank: Super Contributor
timestamp: June 07, 2020, 02:44:14 pm
content: Quote from: BGE on June 07, 2020, 01:44:06 pmNo, it's nonsense. The transistor is not subjected to reverse voltages, when it turns off. It will be subjected to high positive voltages, in excess of the power supply voltage, when it turns off.The correct place for the diode is across the motor.https://learn.sparkfun.com/tutorials/diodes/

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 03:21:49 pm
content: Updated the schematic after reading madires and Zero999's comments.@madires: Is the LED setup correct now or do I need a pull up resistor? (In the low state, the LED should be off).

author: madires
author_rank: Super Contributor
timestamp: June 07, 2020, 04:03:54 pm
content: It's a little bit more complicated. IIRC, the output transistor switches the collector to ground if the voltage at the inverting input is higher than at the non-inverting one. Therefore one would add a pull-up resistor at the the output for positive logic, also because Out1 is fed back into In1-. To drive the LED there are two ways. One is to reverse the logic of the comparator and let the open collector output drive the LED (LED on when the voltage at the inverting input is higher). The other is to add a small transistor to switch the LED.

author: Zero999
author_rank: Super Contributor
timestamp: June 07, 2020, 04:15:15 pm
content: The first comparator in the LM393 package is configured as a linear non-inverting amplifier, which will just oscillate.Connect the LED directly between the output of the comparator and +V. 470R is also a bit lower value for the LED, which will give around 20mA and the LM393 can't sink that much current. Modern LEDs should be bright enough with 2k2, which will give 5mA.R11 appears to be a bit on the high side for a hysteresis resistor.

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 04:35:01 pm
content: Thank you both for your replies.So, if I want to sink more current, I need an additional transistor (madires' second method)... The LED I had selected worked at 20mA... I'll try to find another LED.About the Schmitt Trigger resistor values, I agree that R11 was probably a bit low (I re-ran the calculator and got 1.2M), but now that I think of it, this calculator doesn't take into account open collector outputs... I set the output voltage (High) to 12V when I did my calculations. That probably means my values are wrong aren't they?

author: Zero999
author_rank: Super Contributor
timestamp: June 07, 2020, 05:21:10 pm
content: Quote from: BGE on June 07, 2020, 04:35:01 pmWhy? The current listed on the data sheet is typically not far from the maximum rating, which is often too bright.QuoteYou're using a potential divider, so there's no need to calculate the voltages. The ratios of the resistors are all that matter. I showed how to calculate the values in another thread.https://www.eevblog.com/forum/beginners/how-should-a-beginner-balance-theory-and-practical-ldr-project/msg3047206/#msg3047206

author: BGE
author_rank: Contributor
timestamp: June 07, 2020, 05:56:00 pm
content: Here's the LED I planned on using:https://www.arrow.com/en/products/qbl8r15c/qt-brightek-corporationBut if I still want to go the transistor route (like in the thread you mentioned about the Schmitt Trigger...), this schematic should be ok, correct?I need to read more about the Schmitt Trigger in oder to understand how to determine the ratios for this application...

author: madires
author_rank: Super Contributor
timestamp: June 07, 2020, 06:01:18 pm
content: Poor little fellow! The BC557 won't be happy without a proper base resistor.

author: Zero999
author_rank: Super Contributor
timestamp: June 07, 2020, 06:02:53 pm
content: Quote from: BGE on June 07, 2020, 05:56:00 pmThere should be a pull-up resistor between the output and +12V: 10k should do.I'll make another post, going into more detail about the ratios later. Meanwhile, please refer to the thread I linked to previously for more information.Quote from: madires on June 07, 2020, 06:01:18 pmWhy not? It's an emitter follower, so the base current is self-limiting. No base resistor is required.

author: Renate
author_rank: Super Contributor
timestamp: June 09, 2020, 01:11:22 pm
content: I'm late to the party, but how about just using an ATTiny85 uP?You only need the NTC, MOSFET, 2 resistors and a LED.You can have the duty cycle curve fit however you like, have the overheat LED with hysterisis and well-defined points.Hey! I just realized I've got some I2C temp sensors on hand, even easier, no calibration.

author: Zero999
author_rank: Super Contributor
timestamp: June 10, 2020, 10:19:10 pm
content: Quote from: Renate on June 09, 2020, 01:11:22 pmA microcontroller is a reasonable enough suggestion. It will require a 5V power supply, but the LM78L05 will do the job.

author: BGE
author_rank: Contributor
timestamp: June 11, 2020, 12:02:26 pm
content: Quote from: Renate on June 09, 2020, 01:11:22 pmIt's a microcontroller, so I'd have to flash it which (for me) makes it way more complex... Plus I'd have to start from scratch again (which I already did twice before posting here). This fan control circuit is not the main feature of this PCB (I'm doing anATX mod to a Macintosh Quadra 950), and spending this much time just on the fan controller itself is already pretty inefficient, but at least I learned something along the way.I initially created a dumb controller with just a potentiometer, then realized that this limited me to 2W fans, which led me to design a (flawed) comparator circuit to compare the original ATX PSU fan signal to an Analog-converted PWM lower threshold fan signal (set using that potentiometer). I then realized that it would be impossible to compare (and convert to analog for the comparison) the original ATX PSU fan signal (if it's PWM controlled, the frequency isn't standardized, unlike ATX "motherboard" fan signals which typically work at 20-25kHz). This led me to design a brand new temperature controlled fan PWM controller (the one we're talking about in this thread) which basically "doubles" the level of security (compared to my very first design, see above). The ATX PSU should still have a working overheating protection (I won't remove its thermistor) but because of this mod, it looses its fan control... so I needed to add it back in. And the LED circuit is only meant to warn the user of a problem... It should never light up...After this small interlude/explanation, let's go back to the matter at hand:I found this website which IMO explains really well how to design Schmitt trigger circuits (it's in German. I live there so I understand it no problem, YMMV)http://www.krucker.ch/DiverseDok/Schmitt%20Trigger.pdfExample/Beispiel 3 is exactly what I've been trying to design. Using Excel, I was able to create a basic yet effective calculator.NB: Usatp/tn are the high/low output voltages, Utp/tn are the upper/lower thresholds.In my case, I'll just change R2 to 1M (instead of 100k), Utp= 10.32V and Utn= 10.07V (I still need to recheck those values with the NTC of my choosing.) I left the value of the pull up resistor at 10k as it just needs to be of a high enough value...Here is the new schematic (I also changed the position of the LED, from what I've read, it should be after the PNP transistor, right?):NB: The blue Resistor text corresponds to the resistor ID on the tutorial schematic (first picture).What do you think? Will this work now?

author: Renate
author_rank: Super Contributor
timestamp: June 12, 2020, 01:41:06 pm
content: Well, here's a handful of comments:1) If you're not using the other half of the op amp, I'd ground +in, connect output to -in.Note that this is an easy PCB trace change.This is pretty trivial, but you may sleep better knowing that the op amp isn't driven to the rails (even though the op amp could care less).2) There's no reason to have the op amp input so near the rails.Get rid of R8 (or keep it), take your overheat sense from R7/RV1.This will drop your operating point to about the middle and you can change R3 & R4.3) The overheat LED is going to be on all the time and it's clamping the op amp output.You need a resistor between the op amp and the base.

author: BGE
author_rank: Contributor
timestamp: June 12, 2020, 04:31:52 pm
content: Thank you Renate for your comments1) I followed Zero999's recommendations in his earlier post here:https://www.eevblog.com/forum/beginners/fan-controller-circuit-with-an-op-amp-and-a-led/msg3090461/#msg3090461I can't tell which one is better. Can't I simply ground everything?2) If I place In2- between RV1 (pin 3) and R7, this would equate to having one variable resistor (thermistor value + fixed 10k from pot) and one fixed resistor R7. If the thermistor is cold, that'll translate to 20k (TH1+RV1) and 15k from R7 and the voltage at pin 3 of pot/R7 should be 5.1V. When the thermistor is hot (84°C), that'll translate to a 11.1K resistor (1.1K thermistor + 10k pot) and the 15k from R7 which means the voltage at pin 3 of pot/R7 should be 6.9V.Are my calculations correct? If so I'll go ahead and do that as well as update R3/4.3) I thought the PNP transistor would be enough to invert the logic... but I was apparently wrong (see last post ofthis thread)Should I be using a MOSFET + a resistor between gate and the LM393's output instead? In the thread linked above, Bimpelrekkie said that this would also reverse the output. But this is exactly what I want here.If so, which MOSFET would you recommend using?Edit: MOSFETs don't have bases, they have gates.

author: madires
author_rank: Super Contributor
timestamp: June 12, 2020, 04:32:59 pm
content: LM393 is a comparator, not a OPamp.

author: Renate
author_rank: Super Contributor
timestamp: June 12, 2020, 06:13:30 pm
content: Quote from: madires on June 12, 2020, 04:32:59 pmOops, quilty as charged.

author: BGE
author_rank: Contributor
timestamp: June 13, 2020, 10:26:50 am
content: Now that I think of it, why don't I simply use an LM358 in a non-inverting Schmitt trigger configuration?Would it be THAT bad to use an op amp for this purpose compared to a "proper" comparator like the LM393? I've seen quite a few people use them to control LEDs etc... and this would make the circuit a lot easier since I don't need to invert what I didn't need to invert in the first place...

author: madires
author_rank: Super Contributor
timestamp: June 13, 2020, 12:14:18 pm
content: No, an OPamp is fine for a simple LED indicator. And most electronic enthusiasts have more likely a jelly bean OPamp in their parts box than a comparator.

author: BGE
author_rank: Contributor
timestamp: August 07, 2020, 07:03:43 am
content: Sorry for the lack of replies. I have completely changed my circuit and am now using a microcontroller (ATtiny85) as Renate suggested earlier. The circuit now works as intended (I built it on a breadboard) so that's at least something.But now I have another (albeit small) problem regarding interferences/noise.PB0 is pulsing at 31kHz (for acoustic reasons) and controls an FQP30N06L MOSFET (it switches the fan's ground on and off to modulate its speed). The main ground will be shared with the computer's motherboard. A friend of mine told me to add a snubber network, but of which type? RC, RCD, RC with inductor? Also, can I find the component values without experimentation (I don't have an oscilloscope)?Thanks in advance for your input on this.NB: There is a diode (although not shown here) between the fan+ and the fan- terminals.

author: Renate
author_rank: Super Contributor
timestamp: August 07, 2020, 01:15:27 pm
content: It may not be what you want, but if you use a PC 4 wire PWM fan then you don't need to have that power MOSFET.Just feed your 5V PWM signal to the fan.The advantage of 4 wire is that you don't have 2 MOSFETs in series (the pass one and the driver one).I would think that the interference would be less also.The disadvantage is that you are using a more specific fan.

author: Dabbot
author_rank: Regular Contributor
timestamp: August 07, 2020, 01:32:47 pm
content: Quote from: Renate on August 07, 2020, 01:15:27 pm+1 for this advice.I programmed a PIC10F322 to run a Noctua fan for some quiet breeze. It's great in the summertime.https://noctua.at/pub/media/wysiwyg/Noctua_PWM_specifications_white_paper.pdfQuote from: Renate on August 07, 2020, 01:15:27 pmThese things are all over the place and come in all sorts of sizes / power / speed etc. Barely a disadvantage.

author: BGE
author_rank: Contributor
timestamp: August 07, 2020, 01:54:56 pm
content: Thanks Renate for your message.Unfortunately I really need to make this compatible with 2 pin fans... Would it be possible to re-create the setup used on 4 pin fans on my PCB?Also, do you think that interference is really going to be a problem in this application? In other words, can a switching 500mA current draw from a PC fan disturb the other electronics (given that 20 year old hard drives will also be running at the same time etc...)?

author: DrG
author_rank: Super Contributor
timestamp: August 07, 2020, 02:00:47 pm
content: Quote from: Dabbot on August 07, 2020, 01:32:47 pmFWIW I happened to be using one for a food dehydrator project that I slopped together recently (it is running as I type).I used this one: bGears90https://www.bgears.com/b-pwm/Works like a charm using a GPIO from a 5V uc (all on or PWM). But, I found that I can't get the fan completely off using the PWM pin. Even attaching it to GND, the fan will still rotate, but only at a very low RPM. I know I could have put it on a MOSFET or relay to turn it off completely, but in my case, it was no problem since I always want the fan on at some level. Still, it surprised me to see this. I don't know if it is specific to my unit or more general with 4-pin fans meant for PC cooling.

author: Dabbot
author_rank: Regular Contributor
timestamp: August 07, 2020, 02:12:58 pm
content: Quote from: DrG on August 07, 2020, 02:00:47 pmThe specifications for 4-wire fans are more like guidelines. Different brands / models behave differently, but I would have thought grounding the PWM pin would stop the fan. Not that it really matters at a very low speed.Edit: This behavior is described in the specification under "Operation below Minimum RPM": Type A OperationFor my implementation, the chip reads a value from a pot and outputs a PWM signal from 20% to 100%, or outputs 0% if the pot is in the 'off' position.

author: Renate
author_rank: Super Contributor
timestamp: August 07, 2020, 02:30:12 pm
content: The Intel 4 wire PWM fan spec (1.3)https://www.glkinst.com/cables/cable_pics/4_Wire_PWM_Spec.pdf

author: DrG
author_rank: Super Contributor
timestamp: August 07, 2020, 02:51:09 pm
content: Quote from: Renate on August 07, 2020, 02:30:12 pmI don't want to cause any thread drift, but thank you for that. If I am reading section 3.4 correctly, my fan is, by intention, operating the way it is supposed to operate.

author: BGE
author_rank: Contributor
timestamp: August 24, 2020, 08:52:41 am
content: Hi all,sorry for the lack of posts... been kinda busy at work. I have added an RC snubber to the MOSFET. That should negate the interferences if there are any. The plan is to use the board without one, and check if everything is all right and only take further action if needed.I am pretty happy with my boards, would it be too much to ask for a quick review before I place my order?NOT TO SCALE!Attached the schematics and the Gerbers. Any feedback appreciated! I have to order 15 of each so I really don't want to make a mistake!Thanks again for your support!