Fan controller with PWM using STM32 chip - Page 1
Forum section: electronics / general

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 06, 2021, 07:42:54 pm
content: Hello.I have already a circuit to make a fan controller, controlled by temperature. What I have is a thermistor sensing the temperature of a device and then, the stm32l031k6t6 I have, will read the temperature and will produce a PWM that will control the fan speed according to a few temperature values.The supply I have is 12V, so I used an AMS1117 to step-down the voltage to 3.3V to feed the microcontroller, then I use a mosfet to drive the microcontroller output voltage back to 12V to feed the fan.The circuit I have is the following:I'm looking for improvement suggestions. These are the components I have, so please, try to stick to the components I have there. I'm looking to improve anything like resistor values, diodes, capacitors, etc.I might have to change the pins that I used to connect the thermistor and the mosfet, but I'll change it to the correct pins later if I can't use the ones I'm using now!Thank you for any help/suggestion

author: gamalot
author_rank: Super Contributor
timestamp: May 06, 2021, 07:53:12 pm
content: The NRST pin should be connected to a 100nF capacitor instead of a 10K pull-down resistor.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 06, 2021, 07:59:45 pm
content: Quote from: gamalot on May 06, 2021, 07:53:12 pmAllow me to ask why. Can I see that in the datasheet? I would like to read about the reasoning.

author: gamalot
author_rank: Super Contributor
timestamp: May 06, 2021, 08:10:32 pm
content: Quote from: psysc0rpi0n on May 06, 2021, 07:59:45 pmPlease read page 85 of the data sheet (DS10668).

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 06, 2021, 08:13:41 pm
content: Quote from: gamalot on May 06, 2021, 08:10:32 pmI see. I started looking the datasheet as soon as I read your reply and found it too in that same page.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 06, 2021, 08:20:41 pm
content: I'm still going to change a few things in the circuit, like connectors, push buttons, and anything else needed.

author: rglory
author_rank: Contributor
timestamp: May 08, 2021, 01:26:48 am
content: I have one toohttps://gitlab.com/rglory/tinyfanThough it uses AVR and either digital DS18B20 or NTC 100K.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: May 08, 2021, 11:39:52 am
content: you cannot pwm a 2 or 3-pin fan, that's not going to work as you might expect; you need a 4-pin pwm capable fan

author: Siwastaja
author_rank: Super Contributor
timestamp: May 08, 2021, 01:14:08 pm
content: Quote from: HB9EVI on May 08, 2021, 11:39:52 amOf course you can, that is being done all the time. Typical BLDC chassis fan is designed to be PWM'd on the low or high side.Tacho output will be nonfunctional though.

author: rglory
author_rank: Contributor
timestamp: May 08, 2021, 02:44:21 pm
content: Quote from: HB9EVI on May 08, 2021, 11:39:52 amLooks like you do not have a 3d printer...

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 08, 2021, 04:44:55 pm
content: You can perfectly do so with a 3-pin fan.The only issue will be the tachometer output not working correctly because you're turning the fan off.You can also add diode and capacitor as filtering, so it works in voltage mode.Usually they will start working at around 4V.If the voltage is stable, the tachometer should be ok.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 09, 2021, 03:36:43 pm
content: I think I had a few things wrongly connected in the image above.I changed the layout a little bit and I still have a question. This is how it looks like right now:The question is if I'm going to connect VDDA to VDD. I'm not sure about this. In the image above, I have connected them together but I don't know if they are supposed to be connected that way.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 09, 2021, 04:24:53 pm
content: If the analog supply needs to be as clean as posible, better to add a small choke and/or low value resistor in series to filter the supply noises.And put a ~10-22uF tantalum cap + ~1nF low esr ceramic cap.If you don't mind some noise, just put a 47...100ohm resistor between vdd and vdda and the CAP close as possible to the vdda pin.Check vdda current demand to ensure the voltage won't drop more than a few mV in the resistor.

author: gamalot
author_rank: Super Contributor
timestamp: May 09, 2021, 04:44:55 pm
content: Quote from: psysc0rpi0n on May 09, 2021, 03:36:43 pmVDD and VDDA are shorted.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 09, 2021, 05:43:26 pm
content: Some examples:

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 10, 2021, 06:49:50 pm
content: Quote from: DavidAlfa on May 09, 2021, 04:24:53 pmCan you tell me exactly where to place the components you mention?I'm not familiar with the term choke and about the small value resistor, where would it be placed?The ~10-22uF tantalum cap + ~1nF low esr ceramic cap should go where?About the noise and the 47...10ohm resistor between VDD and VDDA and the CAP close as possible to the VDDA pin. If it brings noise, why you suggest to put it there? What would be the goal?------------------------------------------------------------------------------------------------------------------Quote from: gamalot on May 09, 2021, 04:44:55 pmI know, I just said it above. And I also said I was not sure it was correct... :\------------------------------------------------------------------------------------------------------------------Quote from: DavidAlfa on May 09, 2021, 05:43:26 pmCould you please elaborate a bit further? Be more specific, please?I mean, the example you give is with a different IC, not the same pin out, an I got lost in the specific goal of your examples.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 10, 2021, 07:38:31 pm
content: What you don't understand? Yes, it's a different circuit/part, but the working principle is the same.In any circuit you must put a decoupling capacitor close as possible to the power pin. This is no exception.You don't connect VDD and VDDA directly, as VDD will have digital noises and other high frequency stuff that can affect the analog circuits.Instead, you put a small resistor or choke in series that barely drops any voltage. So you do: VDD-> Choke/Resistor ->VDDAYou must know the current for VDDA. Checking the datasheet it seems it's not higher than 1mA when operation the ADC at max speed.Using a 10ohm resistor, the Vdrop will be 10mV, which is fine.Add some capacitors and you made a low band pass filter. All the high frequency noise in VDD will be eliminated.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 10, 2021, 08:15:04 pm
content: Quote from: DavidAlfa on May 10, 2021, 07:38:31 pmLike this ?Quote from: DavidAlfa on May 10, 2021, 07:38:31 pmThis way?The circuit is now like this:

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 10, 2021, 08:29:40 pm
content: For example, although 10uF would be better. Be careful to what you connect PWR_FLAG to, you don't want to inject any noises there.In the pcb, put the VDDA capacitors near the pin. Ideally few mm away at most.Also, it's better to add a small capacitor when reading voltage coming from a resistor.This is because when the ADC samples the pin, the sample-and-hold circuit charges an internal capacitor and then disconnects the pin.That time is usually adjustable, called sample or adquisition time. The higher the input inpedance, the higher the time you need to wait.The internal capacitor is usually in the 5-10pF range. Seems low, right? But if the sample time is too low, the resistor might not let it charge completely, and your reading will be wrong.Ex, if TH1 is 5K, to completely charge 10pF you need about 250nS. If it's 10K, it will be 500nS.Doesn't seem a lot, but you need to know that when designing the analog frontend.Depending in the application you might have issues. A small capacitor, ex. 100pF close to the ADC pin help to compensate this.What's the PWM frequency? Driving mosfets that way is usually ok for low frequencies, but in the best scenario, not more than few KHz.Depending on the gate capacitance, you might end making a RC integrator.What happens next is that instead fully turning the fet on and off, the gate remains charged at a intermediate voltage.That is very dangerous because the mosfet can work in the ohmic region (work as a resistor) and overheat very quickly. Also the load won't get perfectly controlled.You can see the effect yourself, run the PWM at 50% and 500Hz, then start increasing the frequency in ex. 500Hz steps (Don't put load in the transistor) and keep watching the signal before and after R4.As you rise the PWM frequency, it will start looking like this:As you see the voltage is not reaching zero, also the rising and falling times are terrible, so the transistor will start to heat up if there was load.If you keep increasing the frequency it will get worse and worse:Now the transistor is probably turned on all the time!Your load is out of control, and if the transistor is in the ohmic region and the flowing current high enough, it will overheat and fail in no time.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 10, 2021, 08:45:28 pm
content: Quote from: DavidAlfa on May 10, 2021, 08:29:40 pmYou mean 10u for the cap between 12V and GND?This 12V are already coming from a RockPro64 board. So I assume they are already kinda "clean", so to speak.The POWER_FLAGs were added jus to pass the Electrical Test. Those points are all coming from this RockPro64 board.The capacitor near the ADC pin would be to the ground, right?Like this:

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 10, 2021, 09:04:08 pm
content: No, 10uF for C5. 1uF will be probably good enough, I'm just a little fanatic with filteringYeah, that's exactly what I mean in the ADC pin. Check it yourself, make 100 readings with and without it, and see if there are differences, little noises...

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 10, 2021, 09:31:18 pm
content: Quote from: DavidAlfa on May 10, 2021, 09:04:08 pmBeing paranoid with filtering, it's not bad, I guess. Unless the paranoid starts getting too expensive for the application.Anyway, other than the corrections I did, suggested by you and others, would this be good to go?I'm sure I'll make some more adjustments as time goes by. One starts remembering that is missing this here and there, mostly about connectors, test points, etc.Also, most of the capacitors and resistors here are already beyond what the datasheet suggests. That's why even simple circuits like this, tend to get tricky and a bit complex when you have no experience (like me).I still have to write down which capacitors needs to be tantalum, which needs to be placed close as possible to leads, etc. And some other minor details before sending this to the mill factory to make the PCB. I think this is not worth but I want to make this, for learning purposes!

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 10, 2021, 10:08:16 pm
content: You have duplicated the VDDA filtering.In the upper side you have the 10R resistor.In the lower you have a 10uH coil?I don't understand power_flag.It's connected to VDDA at one side, but shorted to VSS/GND at the other.Another tip: put a 3.3v zener in the stm32 pin that drives the mosfet (before R4).So if the mosfet blows up and gets shorted, the zener will clamp the voltage, protecting not only the stm32, but everything connected to VDD.Otherwise the stm32 pin clamping diode will put 12V into VDD!If 12V gets into, with 220ohm R4 the zener will take 0.13W and R4 0.35W.You can also put a very low power R4 (1/10w or less), so it acts as a fuse if such condition happens.You usually put a NPN transistor in the middle to help with isolation and protection.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 11, 2021, 07:35:10 am
content: Quote from: DavidAlfa on May 10, 2021, 10:08:16 pmAs you may have noticed, I'm far from understanding all the circuitry. I mean, I understand after I know about it. I added the inductor there by suggestion of a friend of mine. I think he told me it would help to compensate for voltage drops happening in PCB tracks. It was not for filtering purposes. I think this was what he told me.Quote from: DavidAlfa on May 10, 2021, 10:08:16 pmI added the power flags only to get rid of the warnings from Electrical check. Otherwise, how would I get rid of them? I'll show later a picture with the warning fllags.Quote from: DavidAlfa on May 10, 2021, 10:08:16 pmI can do part of that. I'm not sure I have 1/10W resistors here but when I'm about to assemble the whole circuit, I'll have to decide each component ratings.Can you be more specific about the transistor? The exact place where to put it? In the middle of what?

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 11, 2021, 11:02:19 am
content: Use a lower value for R1, so the mosfet switches faster. 220 or 100ohms should be ok.10K is ok for simple on/off applications, but too slow for pwm.This circuit have more strenght, so the mosfet will switch faster.Of course that is the simplest circuit. There are much better ones. For example push-pull circuits that use a npn+pnp, they switch even faster. Search push-pull mosfet driver.Now if everything shorts out, the 10K resistor will limit the current a lot, max 1.2mA.

author: Siwastaja
author_rank: Super Contributor
timestamp: May 11, 2021, 02:34:54 pm
content: Fan controller where ADC is used to read thermistor to adjust fan speed definitely does not need any kind of VDDa filtering. Just connect them together for smallest complexity, BOM and cost. Regular 100nF decoupling caps right next to all Vdd pins and all Vdda pins takes the sharpest edges away.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 12, 2021, 08:11:17 pm
content: Quote from: DavidAlfa on May 11, 2021, 11:02:19 amTo apply the changes you suggest, I'll have to make some changes. For instance, your R2 at Q1 base is 10k ohm. I have a 220 ohm resistor (R4) and then I have another resistor (R5) from the mosfet gate to GND to avoid unknown states at the mosfet gate. Are these resistors ok to ignore and just use the block you suggest, or in case of Q1 and/or M1 get damaged, what will happen?My R4 value is there for a reason. To protect the uC pin from any damage. The pin max current is about 16mA, and at 3.3V, that means 206 ohm. So, I used a 220 ohm resistor there!Edited;About the power flags, see images below

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 12, 2021, 09:24:35 pm
content: The nets VDD and VDDA are connected to each other by both L1 and by R6. Before you added R6 you even shorted L1. I usually put all those power supply caps in a row, that makes it easier to spot how the power is actually distributed.I also like to draw schematics in a logical order. Currents and signals from west to east (normal reading direction) and voltages from top to bottom (which you've done).For the power stuff, that would be: Start with the connector J1 on the left side, (and rotate that secton 90 degree CCW), then draw U1 (AMS1117) directly to it, and then put all the decoupling caps on it's 3V3 output.This gives a logical flow of the whole power delivery system in a single overview, instead of spread around the schematic as it is now.You've also drawn c1 as a ceramic (or at least unpolarized) 10u cap and C7 & C9 as polarized 100nF caps, while these probably are ceramic.I do not like SW1 directly over C8. Ceramic capacitors can deliver very high peak currents, and this is of course through the switch when it is still bouncing. Small switches are rated for small currents, and this can and will destroy the switch over time. For a reset switch it's not such a biggie, but for switches that get pushed often (keyboards, mouse buttons) it is definitely a No-No.I would add some (solder) jumper to the BOOT0 pin, so you have easy access to it on the PCB to put 3V3 on it if and when it's ever needed.You can use the tacho output, but it will be gated with your PWM output, and therefore needs some finicky programming to get it to work.But your uC has nothing else to do. But you have to connect the Tacho output to your uC (with suitable resistor divider) to do so of course.The simplest way to measure RPM is to temporarily disable PWM (Turn the fan ON) and then measure the time between two rising (or falling) flanks of the tacho pin.At least draw the resistors and wiring in the schematic and on the PCB, If you don't like it later, then you don't have to place the resistor divider.The "Pin connected to some other pins but no pin to drive it" Is a thing that commonly confuses KiCad beginners.Short answer: ERC in KiCad checks if the power inputs of IC's are connected to some power output, and if ERC can't find it, it emits that warning.The warning can be suppressed by indicating that some nets really do have power applied by adding a "PWR_FLAG" symbol to a net.I usually treat the "PWR_FLAG" symbols as power labels, and place them near the location where the power comes from (such as a connector).ERC can not look "over" filter capacitors and inductors, so if there is such a component in between a power output (from the LM1117) and a power input, then the ERC warning is issued again.More about this in the FAQ section of the KiCad users forum:https://forum.kicad.info/search?q=Pin%20connected%20to%20some%20other%20pins%20but%20no%20pin%20to%20drive%20it%20category%3A19KiCad itself is getting improved at a faster rate then it's documentation is updated, and the FAQ section on the user forum has the most up-to-date info on many subjects.I also want to suggest to try out your PWM amplifier on a breadboard.It's quite easy to work with SOT-23 on a breadboard. Just snap of a 3 pin section of a male header and solder the SOT-23 to two of those pins, and add a short wire to the 3rd pin of the SOT-23.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 13, 2021, 01:00:07 am
content: That is a very very bad idea. Yeah, if the mosfet shorts to gnd, at 3.3V and R4=220ohms the current will be 15mA.But if the mosfet is shorted to 12V, then you will have 12V going into your pin. And the current will be much higher, 54mA.all that current will go into VDD through the internal clamp diode. If the load in VDD is less than 54mA, then the voltage will rise.And you risk to kill everything connected to it. Put a zener, or don't use that risky method.With 10K, the worst will be 1.2mA. Will hardly kill anything.In your last picture, use a lower value for R1 for fast switching. 220-470ohms should be ok. What's your pwm frequency?Also, as now you're powering the gate with 12V, it will do a lot better (Lower RDS on, faster switching).Check the datasheet to ensure the gate voltage is within limits.Also a low value resistor (10ohms) is usually used between the gate and the driving circuit (Instead direct connection).This is because the gate is a capacitor itself. If you drive it too hard, it migh cause ringing and oscillations.That way you limit the slew rate while not causing performance issues.Mosfet ringing:Optimum:Nice reading:https://www.powerelectronicsnews.com/switching-edge-control-for-emc-power-supply-design-tutorial-section-4-1/

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 08:30:52 am
content: I'm going to try to address both last 2 posts, one at a time. Too much stuff going on. lolI need baby steps. I'll probably need to clear a few things about each post. Mostly for @Doctorandus_P post.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 09:49:10 am
content: Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmBut they are supposed to be that way or not? At this point, I'm not sure anymore.Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmI'll address this later.Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmSomething like this:Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmI was told to make C7 and C9 polarized. But I'll make sure about those.Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmAh ok I see. But for this purpose, I think it's ok. Don't want to make this too complex.Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmSomething like this:Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmI'm not going to use Tacho.Quote from: Doctorandus_P on May 12, 2021, 09:24:35 pmAbout the warnings, should I just ignore or add power_flags wherever there are markers???

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 13, 2021, 11:59:33 am
content: If you use a ferrite beat, then don't use 10ohm resistor. The resistor is just a cheaper method.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 12:07:31 pm
content: Quote from: DavidAlfa on May 13, 2021, 11:59:33 amlol, and more and new things are coming in.I want to try to keep this simple. If the 10 ohm resistor is ok'ish, then I'll keep it. I still haven't addressed your post.I'm waiting to see if the changes I made (from previous post) are correct and better! Want to try to address a post at a time and finish with it, then move to the next, otherwise, this will be an endless circle because people will be indefinitely adding new and better improvements to the circuit and I won't be able to call it ready.

author: DIYGUY Chris
author_rank: Contributor
timestamp: May 13, 2021, 01:04:19 pm
content: Saying "that is not going to work" is a bit generic, I can say that it works as well (just because I said so).Well for the 2 pins Fan it is just one phase DC motor to control and controlling it through PWM signal is like controlling the brightness of an LED (+ for Anode - for Cathode and voila it works) three wires Fans are in general fans with feedback ( commonly used on computers and cooling systems) so just use the two power wires and ignore the third ( in most cases it has a yellow color)

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 01:22:02 pm
content: Quote from: DIYGUY Chris on May 13, 2021, 01:04:19 pmWhat was that responding to?

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 03:28:03 pm
content: Quote from: DavidAlfa on May 13, 2021, 11:59:33 amI've seen a couple of situations where ferrite is used for filtering, yes. It would replace the 10 ohm resistor literally in the same place and the same way? Are there any parameters the ferrite should comply with for this particular situation?

author: Siwastaja
author_rank: Super Contributor
timestamp: May 13, 2021, 03:48:04 pm
content: Power distribution networks and power filtering is areallywide and complex area, really. You can waste years in that rabbit hole. For example: whenever using LC filter (which is the case with ferrite bead), there is a very real risk of noiseamplificationi.e., making the problem worse than without filtering. Anyone suggesting just some random circuit with no analysis or no part numbers is taking that risk. Even if the filter isn't making things worse, it's likely it isn't making anything significantly better, either.For your case where analog performance is not of paramount importance, just use a full ground plane, and 100n bypass caps at each power input pin - this is what you should always do by default anyway - and forget about separate AVDD filtering. You'll likely get at least ten noise-free bits which is many orders of magnitude more than you need in the fan controller.If analog performanceisimportant, then start learning about it; and experimenting takes you a long way.Answering your question, a 10ohm resistor creates a DC voltage drop so it's a pretty devastating filter unless you are sure whatever you are powering with that filter (the ADC in this case) takes so little current that voltage drop R*I over that resistor does not cause issues. Also 10 ohms is not very much for noise filtering. The ferrite bead offers lower resistance (typically <1ohm) for DC and low frequencies while it provides higher resistance (as speficied in the part description - often around 100ohms) for high frequencies (tens of megahertz). But if the ferrite bead saturates, it doesn't filter. Also, if it isn't made with AC lossy material enough, it can amplify noise at some unlucky frequencies. Ferrite beads are notorious of having poor specifications so you either design by luck, or experiment with prototypes. One with a much higher current rating than you actually need, and mid-range resistance spec - i.e., not a 20 ohm part, not a 1000 ohm part, but say a typical 100 ohm part - is quite a safe initial guess. But as I said, if your target is to get the fan controller working, forget about the AVDD filtering for now.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 13, 2021, 05:38:37 pm
content: Oh, the resistor is not so dramatic.It's usually used for very low currents, maybe 5-10mA, so the Vdrop won't be a problem.And adds the benefit of a simple RC filtering, so no "unlucky" frequencies.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 09:35:55 pm
content: Ok, so, of what I have right now, what do I need to change?

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 13, 2021, 09:37:30 pm
content: You have to use your own brain a bit more.Don't just draw something, and then ask if it's all right or you have to change it.You also have to be more careful when you move things around.Putting all the power supply sections together (instead of spreading them over the schematic) is indeed a lot clearer, and it immediately makes it obvious that L1 and R6 are paralleled and a bit redundant.But while doing so, you have also changed the schematic.In your previous schematics you put R1 (10 Ohm) between the power input connector and the LM1117, but after you put everything in a row the LM1117 is directly connected to the power connector and R1 goes to "12V", and you have suddenly put that resistor in series with the fan.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 13, 2021, 10:15:10 pm
content: Quote from: Doctorandus_P on May 13, 2021, 09:37:30 pmOk, so I was reading a bit about inductor filters and looks like I don't need a resistor as part of the inductor filter. So, I removed R6 (10 ohm).But regarding R1 in series with the fan, I can't see this. I tried to mentally figure out if the current going through R1 would be the same as the current going through the fan and I can't see it as being the same current because the top terminal of R1 is in fact at the same point as the positive lead of the fan. They are both attached to the 12V supply, but then, the negative lead of the fan is not attached to the bottom lead of R1, so I think they are not in series!Could you please show me how they are in series?This is how I have the circuit right now but I will reset all component indexation so that I get a more reasonable numbering after have all the components in the right place!

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 14, 2021, 05:55:01 pm
content: In series with the fan? Where?

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 15, 2021, 11:06:04 am
content: @DavidAlfa, I also think that resistor is in series with the fan. I wanted to make sure I wasn't missing anything.In the meantime I did some improvements to the circuit in terms of components disposition. I think I looks way better this way:But I still have these 2 problems to fix:

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 15, 2021, 12:55:35 pm
content: There's nothing in series with the but the mosfet.You last design looks better.But you left R5 10K, not ok for pwm.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 15, 2021, 01:29:44 pm
content: Quote from: DavidAlfa on May 15, 2021, 12:55:35 pmOk, placed a 220 ohm there now, for R5. I forgot to change it!And do you know how to solve the 2 markers I have in U1 ?

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 15, 2021, 03:44:38 pm
content: Anyway, I fixed them. I'm not sure this is the most reasonable way but that's how I managed to fix the markers. I have reset the components numbering now to make them more logical according to their disposition in the circuit!I also removed the 10 ohm resistor I had between the +12V and j1 connector. I think it's not needed there. Please, let me know if otherwise

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: May 24, 2021, 08:06:19 pm
content: Well, after some time playing around with this, this is where I am now:the PCB:3D view

author: ealex
author_rank: Frequent Contributor
timestamp: May 30, 2021, 09:09:55 am
content: HelloHow do you plan to program the MCU ?I don't see any connector for either SWD or UART0

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 30, 2021, 04:47:48 pm
content: What a strange thing you made! Sorry I couldn't resist....Restore the transistor driver circuit as before. Just invert the PWM signal in the MCU registers!With that circuit you're making a voltage divider. Not only that, a bipolar transistor needs current to turn on.If you put a resistor in the emitter, the max voltage you can get there is Vbase-0.7.So yes, luckly you will set the Mosfet gate to 2.4V. If it works at all.Once the emitter voltage reaches that voltage, no more current can flow from base to emitter since the MCU sends 3.3V.It seems you're using the one of these computer-like fans, they take little currents, maybe 300mA.... Consider replacing the whole thing with a Darlington transistor, it will be easier:These have huge current gains, easily >1000. So with 5mA you can drive 5Amps.

author: agehall
author_rank: Frequent Contributor
timestamp: May 30, 2021, 06:16:30 pm
content: I’m going to take this opportunity to ask another stupid question in hopes of getting educated..Wouldn’t simply a logic level MOSFET do the job here in terms of switching for the fan?

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 30, 2021, 06:24:40 pm
content: Yes. For single on/off applications you can put a 100K resistor to the gate and it will work.But, as I said before, when it comes to fast switching, PWM, you need a strong drive for the mosfet to fully turn it on/off, to overcome the gate capacitance.And to do that you need a low value resistor. But that gives another issue: if the mosfet blows, you'll have a low impedance path to the mcu pin and burn it and mayber more things connected to it.You can't use a 10K resistor to drive a mosfet with PWM, the current is very limited and it will make the switching speeds very slow, to the point where you might set the mosfet half turned on.A bipolar transistor doesn't have a gate to charge, negligible RC constant. Thus, as long as it has enough HFE(gain), you can drive it with high resistor values.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: June 25, 2021, 09:50:26 pm
content: Quote from: ealex on May 30, 2021, 09:09:55 amIt's quite different now.Well, I did my best. It might get better over time, I hope!Quote from: DavidAlfa on May 30, 2021, 04:47:48 pmI didn't come to this thread for a while. In the meantime I made some changes. Check above.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 26, 2021, 03:20:03 am
content: Are you afraid of the thick traces?- Vdd comes out of the regulator, goes to C6, mcu, back to C8. Why? Put them in parallel in the same trace.- Mcu Vdd pin goes to L1, L1 goes to C9 and C10 goes nowhere?- VDDA goes to C11, but not connected to VDD through L1.Ahh but you appplied via stitching to reinforce the ground, avoiding capacitance and current loops. Was you, or did the program make it automatically?I'm not a professional designer, but I like it... Check this one-boring-raining-day board design I did few months ago. I think it wasn't complete but I don't remember right know.Perhabs you could get some tips by checking it (Or also might I, nobody knows everything!)For the analog, since the current was only 2-3mA, I used a TL431 circuit designed for 7mA. For each analog device (op-amp, mcu vdda) I put a 10Ohm resistor and a 10uF cap after it.10ohm, 2mA=20mV drop, so no problem... Use Proteus, the demo version will allow to see everythingThe red square in the bottom left is a MP2315 DC/DC regulator module:

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: June 26, 2021, 03:47:00 pm
content: Quote from: DavidAlfa on June 26, 2021, 03:20:03 amYou gotta be kidding... You're not a pro? ahahah. okYou're a pro to me.Anyways, replying to your post:About the C9, C10 an C11, it's strange because the connection is present on the schematics. C9, C10 and C11 should all be connected to each other and to VDDA. I have no idea why Kicad is not complaining about a missing connection.About the Via stitching, it was me by hand, but there are plugins to do it I think. But someone told me to do it. I didn't know this improves ground and etc.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 26, 2021, 05:03:22 pm
content: I don't know that software... is it kicad? I've wanting to learn it for a long time but I never started!Can you send the file? Or is it a FBI top-secret fan controller?

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: June 26, 2021, 05:15:31 pm
content: Quote from: DavidAlfa on June 26, 2021, 05:03:22 pmI say in my post it is Kicad.What file you want? the schematic? You gotta keep it secret. It's not FBI but it's PSS. Keep it safe from the MOSSAD and the 8200 UNIT. xD

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 26, 2021, 07:30:25 pm
content: Haha I just want to see how it works and help showing the proper ways(And sell the design to China government)

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: June 28, 2021, 08:27:02 pm
content: Quote from: DavidAlfa on June 26, 2021, 07:30:25 pmWell, as this was made as a project in Kicad, I think you need to have the same lybraries I have, the same folder structure, etc. But I can bzip (gzip, whatever) it to you and send it.Will attach it in a few minutes if I can.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: June 30, 2021, 09:11:51 pm
content: Quote from: DavidAlfa on June 26, 2021, 07:30:25 pmDid you see that I have attached the super secret file you requested?

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 01, 2021, 05:13:59 am
content: Yes, but I didn't install kicad yet!

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: July 02, 2021, 09:01:25 pm
content: Well, I had to change the circuit a redo almost everything because I couldn't get the chip I was expecting to get. The one I was able to buy has more pins and is even more overkill for this, but the chip shortage is kinda global and the shop told me they could only send me the one I ordered in the first place in 2022. So I bought a different one which was the only one the shop had in stock.But now I have a couple of questions about this new chip: STM32L412CB6TThe symbol I have for the chip is split into 2 units in Kicad. The power unit and the chip unit.And the power unit is not exactly the same as it shows in the datasheet.Datasheet shows Vref+ AND VDDA pins separated:But the symbol in Kicad, shows them together at pins 9 and 24So, my question is if the picture below is respecting the datasheet about the filtering/decoupling capacitors for VDDA and Vref+ pins (ignore L1, C8 and C9 as they are not in the datasheet).In datasheet they say 10nF + 1uF between VDDA and VSSA and 100nF + 1uF for Vref+ and VSSA.So, as there are 2 pairs of Vref+/VSSA, I have 2 pairs of 100nF + 1uF for them and one pair of 10nF + 1uF for VDDA/VSSA. Or should I add another pair for VDDA/VSSA once the symbol also has 2 pairs of this one too?

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: July 05, 2021, 08:02:03 pm
content: Ok, I ended up changing the symbol pin 24 name from VDDA/Vref+ to simply VDD because according to the datasheet, there is only one VDDA and 2 VDD.So, I changed the original symbol pin 24 name from VDDA/Vref+ to VDDSo, for the filtering part, this is my circuit:This is the PCB laayoutand the 3D view

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 14, 2021, 11:17:12 am
content: I finally installed Kicad and started fiddling around! Totally noob in this program but I had to start some day!The stm32l412 lib is missing. I downloaded it from ultralibrarian, seems to be the same as yours. But after importing it, most connections were gone.If you could reupload it with the libs....Definitely the power connections in the pcb are wrong. For the power traces, use the thickest you can without exceding certain limits.Ex. do't use 10mm thickness for 10mA VDD!But 2mm will certainly improve the impedances. For 12v and VDD/VDAA... then make it slimmer when reaching the stm32 or other small parts.You don't need to use electrolytic caps, they're bulky and less reliable than ceramics, I'd put 10uF 0805 / 0603 ceramic caps.Same for D1. Whenever you can go for smd instead through-hole, it make things easier. TH is only better to stand forces. Ex. a connector, or a heatsink.Also such capacitor infantry is crazy! I'd put just 10uF+100nF packs. one at eachg side of the Vreg, and another two near the stm32 VDD and VDDA pins. That's a nice filter there!

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: July 15, 2021, 08:42:09 pm
content: Quote from: DavidAlfa on July 14, 2021, 11:17:12 amWell, things are done. I'm not changing the whole thing again. If there is there nothing that will break the normal working of the circuit, then, I'll leave it as is.Due to several factors, I'm already out of steam to keep doing this shitty project. I'm with this thing for weeks now and I'm already sick of it.Yeah, one of my struggles is yet to judge when to use electrolytic, polarized, non-polarized, ceramic, film, etc. I've been told that from some value and up, they don't do them ceramic, they do it electrolytic, or something like that, but seems that this limit value is somewhat variable. It's not like that you can say that exactly from 1uF up, they are all electrolytic or polarized or so.I have attached the files I have downloaded. I have changed the pin name of this chip because it didn't exactly match the datasheet. I have opened a ticket in STM32 site and they told me they would escalate the issue.Hope this is enough to get you started.

author: Bassman59
author_rank: Super Contributor
timestamp: July 16, 2021, 12:50:01 am
content: Quote from: psysc0rpi0n on July 15, 2021, 08:42:09 pmThe values shown in this thread -- 100 nF, 1 uF, 4.7 uF, -- are all available as ceramic caps in 0603, 0805, 1206, 1210, so pick a case size you like and the appropriate working voltages and get on with it.

author: David Hess
author_rank: Super Contributor
timestamp: July 16, 2021, 04:13:03 pm
content: Quote from: Siwastaja on May 08, 2021, 01:14:08 pmSome brushless DC fans will work reasonably well and some will not; it depends on internal details like input capacitance.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 21, 2021, 03:26:38 am
content: I'm unable to do anything. The whole schematic layout is misaligned, cannot select a single pin!.Edit: Ok you used 5mil grid for the schematic? That's crazy!After aligning, everything was pretty smooth. Kicad seems good!Made few changes.. It seems the power_flag confused you! It's only used for power lines coming from elsewehere, ex. a connector.So in theory only gnd and +12V would need them. I might be wrong, Kicad is completely new to me!