Electronics
Btrieve
Motorcycling
Software

ATtiny85 based temperature dependent PWM fan controller

This is a replacement for my 555 timer based PWM controller to regulate speed of 12V fan. Small number of parts, temperature dependent operation including stopping the fan, and room of creative improvements makes it a much better altermative. On the down side, you need to be able to program Atmel's ATTiny microcontroller.

Hardware

The hardware is very simple. 12V is fed to the circuit from JP2, and this is used directly as fan power. R1, D2, C2 form a crude power regulator for microcontroller. Q1 is used as a low side switch to drive the fan with 32kHz PWM, a jellybean FET like BS170 or 2N7000 will work here.

The microcontroller's (I used Attiny85 but Attiny45 would work just as well) internal temperature sensor is not very precise, so you may need to calibrate it - for this the firmware outputs ADC value on JP4 in serial format at 38400 bps, 8 bits, no parity. The internal 8MHz clock is borderline acceptable for serial communication, so you may get some broken characters but the valus is updated about once per second and you are likely to get some good readings through.

JP3 is programming connector, and you do not need to have it on board if you can program the microcontroller using some other method.

As the temperature sensor is embedded inside the AVR microcontroller, you need to place the entire controller module at the point where temperature needs to be measured. With its small number of parts the entire thing should easily fit on 20x20mm piece of prototyping board if you omit serial programming connector, and you can wire it inline with fan wires.

Software

All C++ code is available at GitHub, in my tiny_pwm repository. I also made hex files available if you do not want to build the code yourself, but keep in mind that you will have to rebuild if you want to calibrate the temperature reading. For building you need a working make, avr-g++, and avrdude.

Building

Just type make, and you should get hex and eep files. make flash will try to write the code to microcontroller using avrdude with usbtiny compatible programmer. make clean will clean the clutter from directory, and make erase will try to erase microcontroller's flash memory.

Code contents

The actual firmware for the AVR microcontroller is in tiny_pwm.cpp. There is a rudimentary bit-banged serial terminal code in bb_terminal.cpp, a quick and dirty hack of a terminal I/O code from my debugging terminal project. Comments should help to get around in the few lines of code that this project needs.

The important features of the firmware are that when the fan is started, then it is given a short full-power kick to get it rotating, and there is a hysteresis of couple of degrees at the fan turn-off point to avoid it rapidly switching on and off.

Copyright © Madis Kaal 2000-