12V 4-pin PC fan controller (AVR)
Over the weekend I built a PC fan controller using an Arduino Diecimila (containing a ATmega168 microcontroller). As a learning exercise, I decided to write the firmware with avr-libc and forgo use of the Arduino environment and libraries.
The device has a potentiometer to control the fan speed and outputs the current RPM over serial. The hardware is straightforward: the fan is connected as described in Intel and Noctua's documentation and the supporting circuitry for the ATmega168 is contained in the Arduino itself. After building the circuit on a breadboard, I captured the schematic in KiCad.
The firmware uses several peripherals:
- ADC - read potentiometer value
- PWM (TIMER1) - send control signal to fan at 25 kHz
- External interrupt INT0 - count pulses from fan's tachometer
- Real time clock (TIMER0) - keep track of time to calculate RPM
- UART - send current RPM over serial console
I suspect the firmware would have been significantly shorter if written using the Arduino libraries. I may revisit this in the future and make a comparison.
The project files are available on GitLab: https://gitlab.com/equivariant/pc_fan_control