AVR-based fan temperature controller
A relatively simple application of an ATINY-45 is to control a fan based on a temperature. This solution uses an NTC thermistor in a voltage divisor to generate an analog signal which is fed into the TINY45. A pregenerated lookup table maps the read value to temperature in some unit (in this case degrees celcius (0 to 255 degC). Finally the microprocessor uses a very crude system to regulate the fan speed, where the output to the fan is;
- min_pwr, if t<t_min
- max_pwr, if t>t_max
- ((max_pwr-min_pwr)*(t-t_min))/(t_max-t_min) otherwise
- (optionally) min_pwr, if t<alpha*(t_max-t_min)
Ie. the output is at some minimum power for low temperatures, at some max power for high temperatures and linearly interpolated for temperatures inbetween. Additionally there's a minumum increase in power which is useful if min_pwr is set to completely off, so that the fan is always driven with enough power to ensure it can turn on. Finally hysteresis is applied to the output to reduce irritating fluctuations in the fan speed. Do keep in mind that this is not a "stable" control system, as it's effectively something like a regulator with primarily integrating feedback. However in practice the behavior is nice.
In the file posted below is everything used, schematic, board, matlab code for finding the "optimal" voltage divisor and source code for the AVR. Please excuse the awfully commented and ugly matlab code. (The optimal voltage divider is defined as one that causes the largest swing in ADC counts over a specified temperature range).
Note: Be sure to enable the WDT fuse!