Simple PICAXE PWM Fan Controller

This was written in about 5 minutes to test 12V DC fans noise and airflow characteristics before installing them in a PC. The code will run on any of the current generation PICAXE chips at their native frequency (i.e. not overclocked via the setfreq command or poking registers). The pins used need to be modified to suit the selected chip.

speedup, slowdown and power are all input pins interfacing to switches. The PICAXE-08M was used for this so the pwm pin is pin 2 (hardware limitation). PWM frequency is set to 25kHz, above the human hearing range to avoid audible whining due to magneto-restriction, and a reasonable compromise on efficiency. Duty cycle is set as an integer between 0 and 160 i.e. 50% = 80, 75% = 120, 100% = 160. Pauses are used as a rudimentary method to debounce the input switches – 200ms was adequate for the tactile switches I had on hand, though some momentary push-buttons may need longer. You may wish to set the minimum value to something other than 0, eg 32 (20% duty cycle) so that fans never turn completely off, or to prevent stalling at low speeds.

Input switches need to be connected via a 10k resistor to ground and a 1k resistor in series with the input pin. The fan can be driven via a NPN transistor and a 1k resistor in series with the transistor base. RevEd recommends you use a darlington transistor, although a BD139 NPN transistor worked just fine for me and only became lukewarm in operation with a fan rated at 200mA current. Ensure you use a diode (1N4004 or similar) across the fan to suppress back emf. I had two power supplies on hand so ran the PICAXE-08M from 5V and the fan off 12V directly. See the PICAXE Interfacing Circuits (#3) manual for more information on wiring up external input/output devices.