di2608.txt ;************************************************************************************************** ; LISTING 1 - FAN-DRIVER C FILE ; ; "Audio amp makes efficient fan controller," EDN, Nov 9, 2000, pg 182 ; http://www.ednmag.com/ednmag/reg/2000/11092000/designideas.htm#23di8 ; *************************************************************************************************** #include "8saa.h" // Include file for the COP8SLB void init_params(); // Initializtion routine void shutdown(unsigned int state); // Shutdown amplifier routine void fan_speed(unsigned int state); // The Speed of the fan // Alters the PWM duty cycle // In percent of (on) vs (off) void main(){ init_params(); // initialize the parameters // Make sure the amplifier is on shutdown(0); // Scale up the fan speed // Turn up the fan speed fan_speed(20); // Scale down the fan //fan_speed(10); // Shutdown the amplifier (off) shutdown(1); while(1); // forever loop } // The shutdown routine void shutdown(unsigned int state){ if (state==0) PORTDD.0=0; // Turn the pin low else PORTDD.0=1; // else turn the pin high } // The intialization parameters void init_params(){ // Turn PWM on out PORTGC.3=1; // Set so the portgc pin is high PORTGD.3=1; // Lower the portgd pin for PWM mode // Make the high byte zero T1RAHI=0; T1RBHI=0; // Set to PWM: TxA Toggle // Autoreload RA, RB CNTRL.T1C1=1; CNTRL.T1C2=0; CNTRL.T1C3=1; } // The change fan speed routine void fan_speed (unsigned int state){ // Detect if it is less or equal to 100 percent if (state<101){ T1RALO=state; // Initialize the state T1RBLO=state-100; // Turn the lower half state-100 CNTRL.T1C0=1; // Set the timer enabled bit } }