Close

Microcontroller results

A project log for USB Powered 12V Fan Controller

A small fan controller for 12V Casefans powered from 5V. With built-in Splitter

foxhoodFoxHood 11/04/2025 at 12:110 Comments

Had to take a break from electronics projects due to personal circumstances. Honestly the first version of the code been working for a while now, but never got around to adding a log...

Anyway back to where i was. Code was put on the Github.

FAN control (brief):

On FAN control theory i am mostly relying on the engineering documentation publicized by Noctua. Which describes the standard PWM control scheme as:

Whenever possible the controller will stick to PWM control, but if all else fails it can try to control the fan by pulsing the 12V load switch.

PWM Generation:

The ATtiny414 used has by default a clock speed via internal oscillator of 20Mhz. Which is a nice significant improvement over older AVR chips that could only reach like 8Mhz.. But that doesn't matter here. It just needs to generate a PWM signal, blink leds and read an encoder.

I figured that by dividing the main clock by 8 i would get 2.5Mhz. Which when run without prescaling through a Timer with a TOP limit of 100. Gives a very clean 25Khz signal of which the duty cycle is handled in 1% steps. Which is perfect for this application.

Tachometer monitor:

The tachometer serves two purposes. During power-up the controller will try to check if the FAN is PWM capable by monitoring the tachometer frequency and checking if it speeds up significantly when the PWM signal goes up. This sets whether it will be controlling the fan by PWM control signal or by PWM on the power. If no signal is present, the controller will cut power and lock itself.

During operation the Tachometer monitors for any error. If the fan halts (jammed/disconnect) or speeds up abnormally . The controller will cut power and lock itself until the next power-cycle.

Originally i wanted to hook the Tachometer up directly to a timer in frequency measurement mode via the AVR Event System, but I've been unable to get it working just yet (might need to check the errata). So for now i'm just sticking to a Timer implementation that counts pulse width duration via a variable and calculates the actual RPM whenever the state changes. It is effective enough.

Encoder Input:

Encoder input is handled by a simple input Interrupt on the A signal, with B then being tested to know if a value increment or decrement occurs and then adjusting the target speed. The new value is passed on to the PWM generator and LED output.

Led Output:

Handing the charlieplexing of the leds is done in the main while(1) loop. It is nothing fancy. Just constant blinking to keep persistence of vision up.

RESULTS:

Honestly am already quite happy. It isn't perfect, but it does the job admirably and for what is meant to be the most compact little controller i could create that could be powered from a old charger: That is good enough.

Bugs:

The monitoring is still a bit buggy. Adjusting the speed also moves the expected RPM and if you do something like very quickly changing speed or suddenly try to reduce speed while the fan is spinning up. It might trip and think something went wrong. Will need to improve logic or make the net wider. Honestly would probably need to get one of the smaller speed-demon fans to also test.

TO-DO:

Discussions