Author Topic: Fan controller with PWM using STM32 chip  (Read 15942 times)

0 Members and 1 Guest are viewing this topic.

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Fan controller with PWM using STM32 chip
« Reply #25 on: May 11, 2021, 02:34:54 pm »
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.
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #26 on: May 12, 2021, 08:11:17 pm »


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.

To 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

« Last Edit: May 12, 2021, 08:23:40 pm by psysc0rpi0n »
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Fan controller with PWM using STM32 chip
« Reply #27 on: May 12, 2021, 09:24:35 pm »
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%3A19

KiCad 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.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: Fan controller with PWM using STM32 chip
« Reply #28 on: May 13, 2021, 01:00:07 am »
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/
« Last Edit: May 13, 2021, 01:20:53 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #29 on: May 13, 2021, 08:30:52 am »
I'm going to try to address both last 2 posts, one at a time. Too much stuff going on. lol

I need baby steps. I'll probably need to clear a few things about each post. Mostly for @Doctorandus_P post.
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #30 on: May 13, 2021, 09:49:10 am »
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.

But they are supposed to be that way or not? At this point, I'm not sure anymore.

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).

I'll address this later.

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.

Something like this:



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 was told to make C7 and C9 polarized. But I'll make sure about those.

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.

Ah ok I see. But for this purpose, I think it's ok. Don't want to make this too complex.


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.

Something like this:


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.

I'm not going to use Tacho.

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%3A19

KiCad 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.

About the warnings, should I just ignore or add power_flags wherever there are markers???
« Last Edit: May 13, 2021, 10:07:37 am by psysc0rpi0n »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: Fan controller with PWM using STM32 chip
« Reply #31 on: May 13, 2021, 11:59:33 am »
If you use a ferrite beat, then don't use 10ohm resistor. The resistor is just a cheaper method.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #32 on: May 13, 2021, 12:07:31 pm »
If you use a ferrite beat, then don't use 10ohm resistor. The resistor is just a cheaper method.

lol, 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.
 

Offline DIYGUY Chris

  • Contributor
  • Posts: 41
  • Country: us
Re: Fan controller with PWM using STM32 chip
« Reply #33 on: May 13, 2021, 01:04:19 pm »
Saying "that is not going to work" is a bit generic, I can say that it works as well (just because I said so).  :palm:
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)
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #34 on: May 13, 2021, 01:22:02 pm »
Saying "that is not going to work" is a bit generic, I can say that it works as well (just because I said so).  :palm:
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)

What was that responding to?
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #35 on: May 13, 2021, 03:28:03 pm »
If you use a ferrite beat, then don't use 10ohm resistor. The resistor is just a cheaper method.

I'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?
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Fan controller with PWM using STM32 chip
« Reply #36 on: May 13, 2021, 03:48:04 pm »
Power distribution networks and power filtering is a really wide 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 noise amplification i.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 performance is important, 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.
« Last Edit: May 13, 2021, 03:50:23 pm by Siwastaja »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: Fan controller with PWM using STM32 chip
« Reply #37 on: May 13, 2021, 05:38:37 pm »
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.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #38 on: May 13, 2021, 09:35:55 pm »
Ok, so, of what I have right now, what do I need to change?
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Fan controller with PWM using STM32 chip
« Reply #39 on: May 13, 2021, 09:37:30 pm »
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.
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #40 on: May 13, 2021, 10:15:10 pm »
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.

Ok, 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!
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: Fan controller with PWM using STM32 chip
« Reply #41 on: May 14, 2021, 05:55:01 pm »
In series with the fan? Where?
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #42 on: May 15, 2021, 11:06:04 am »
@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:
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: Fan controller with PWM using STM32 chip
« Reply #43 on: May 15, 2021, 12:55:35 pm »
There's nothing in series with the but the mosfet.
You last design looks better.
But you left R5 10K, not ok for pwm.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #44 on: May 15, 2021, 01:29:44 pm »
There's nothing in series with the but the mosfet.
You last design looks better.
But you left R5 10K, not ok for pwm.

Ok, 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 ?
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #45 on: May 15, 2021, 03:44:38 pm »
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
 

Offline psysc0rpi0nTopic starter

  • Frequent Contributor
  • **
  • Posts: 326
  • Country: ar
Re: Fan controller with PWM using STM32 chip
« Reply #46 on: May 24, 2021, 08:06:19 pm »
Well, after some time playing around with this, this is where I am now:


the PCB:


3D view
 

Offline ealex

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: ro
Re: Fan controller with PWM using STM32 chip
« Reply #47 on: May 30, 2021, 09:09:55 am »
Hello

How do you plan to program the MCU ?
I don't see any connector for either SWD or UART0
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: Fan controller with PWM using STM32 chip
« Reply #48 on: May 30, 2021, 04:47:48 pm »
What a strange thing you made! Sorry I couldn't resist... :-DD.


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.
« Last Edit: May 30, 2021, 05:30:57 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline agehall

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: se
Re: Fan controller with PWM using STM32 chip
« Reply #49 on: May 30, 2021, 06:16:30 pm »
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?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf