念慈菴

PWM fan speed control board

 
Overview

## Use MCU to measure and control common 4pin or 3pin computer fans
**Attention! The USB interface specification of this project is 5V1A, and the total power should not exceed 5W. Do not use high-power violent fans, otherwise it may burn the components on the board and even the motherboard USB interface! ! **

![IMG_20230401_133634.jpg] ![IMG_20230401_132958.jpg] ![IMG_20230401_133206.jpg]
### Project description
MCU: STM32F030C8T6
digital tube driver: CH455G
5V to 12V boost: MT354 0-F23 (note that this chip has 3 specifications , corresponding to 3 kinds of FB voltages. This project uses 1.23V. If you use other voltages, you need to modify the corresponding FB resistor value)
5V to 3.3V step-down: AMS1117-3.3

uses USB 5V power supply, and 4 pins are 5V straight out, suitable Low-voltage small fan, the other channel is 12V boost output, suitable for 12cm chassis fans. The two fans are independently controlled, and two touch buttons are used to select and display the speed of which fan. The self-resetting button is used to adjust the PWM duty cycle to control the fan speed. When adjusting the speed, the digital tube displays the current duty cycle, and automatically switches to display speed (RPM) after 2 seconds of no operation. The fan speed defaults to 50% after power on.
Since the charging of the capacitor will instantly lower the voltage when powering on, the CH455G delays initialization for 1 second, otherwise the initialization may fail due to voltage instability.

Except for the self-resetting buttons in this project, all the components can be found in Lichuang Mall, and the cost of a single finished product is less than 10 yuan.

STM32F030C8 is completely overkill in this project, but why did I choose this MCU? Because the company has ready-made ones for free... and ST's ecological chain is so comfortable. The underlying CubeMX is directly generated, and you only need to write it yourself Just the application layer is enough, there is no need to manually configure so many registers. The entire code writing + debugging only took half a day.
**If you want to save costs, you can use an 8-bit MCU with fewer pins instead, but it is strongly recommended to choose a model with the following specifications: **
At least 2 independent timers, one for PWM precise output and one for For accurate speed measurement and system ticking,
at least 2 GPIO ports that support edge triggering are used to detect speed measurement signals.
At least 1 hardware I2C port is used to drive the CH455G digital tube display.
An optional hardware UART serial port can be used to communicate with the host computer to achieve The host computer can control and read the speed, and you can even use a wireless module to achieve wireless control.
If you choose a 5V power supply microcontroller, you can also save 3.3V LDO.

**If you want to use it to control a high-power violent fan, be sure to switch to one that supports high current. Type-C interface and uses a higher power DCDC chip. Or directly switch to DC12V or PD input, and then reduce the voltage to power the MCU for control, and the fan directly uses DC power supply. **

### Principle
! [GV4ThDapWDVoDSjgtkaraiiJY7HiHRW8y9826pKS2Fo.jpg] Our common 4pin fan pin definition is as shown above, while 3pin has no speed regulation and lacks the fourth speed regulation line. (Even so, we can also adjust the speed by controlling the voltage of pin 2 VDC)
#### Speed ​​measurement
The speed measurement line of pin 3 is connected to a Hall switch inside the fan. Whenever most fans rotate once, the Hall switch will output 2 rising edges or falling edges (a few fans have different numbers of edges when rotating once, you can test it yourself). **Note that this pin is an open-drain output and must have an external pull-up resistor, otherwise the MCU cannot detect it**
![IMG_20230401_133100.jpg] By calculating the interval between two rising or falling edges, we can calculate the current voltage of the fan Speed:
```
RPM (revolutions per minute) = 60*1000/Δt/2
```
As shown in the figure above, we can calculate that the current speed is approximately 1764 rpm
using the external interrupt IO pin of the MCU, plus the hardware timer , we can accurately calculate the current speed (actually there is still a certain error, related to the timer and external interrupt resolution)

####
The 4th pin of speed regulation is the speed regulation input, by changing the duty cycle of the input square wave , the fan speed can be adjusted. When this line is pulled low to GND, the fan speed is minimum (not 0), and when it is pulled high to 5V, the fan speed is maximum. In most cases, this pin is pulled up to 5V internally by the fan, which means that when this pin is left floating, the fan speed defaults to the highest speed.
![IMG_20230401_133020.jpg]
### Software code
The MCU code corresponding to this project has been open sourced to github, and future code updates will be here. If you find it useful, please give it a star, thank you!
[STM32F030C8 code](https://github.com/Cathgao/FAN_PWM)
If you just want to burn it directly into the MCU, there is a compiled HEX file attached to this page. You can use STM32 ST-LINK Utility to burn it.
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-18 22:03:13

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号