Devices & Components
Arduino Uno Rev3
Axial Fan, 12 VDC
Jumper wires (generic)
USB-A to Mini-USB Cable
Software & Tools
Arduino IDE
Project description
Code
The Code
arduino
Download this file and run it under the Arduino IDE.
1const byte OC1A_PIN = 9; 2const byte OC1B_PIN = 10; 3 4const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency (Frequency in HZ!) (Set currently to 25kHZ) 5const word TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ); 6 7void setup() { 8 9 pinMode(OC1A_PIN, OUTPUT); 10 11 // Clear Timer1 control and count registers 12 TCCR1A = 0; 13 TCCR1B = 0; 14 TCNT1 = 0; 15 16 // Set Timer1 configuration 17 // COM1A(1:0) = 0b10 (Output A clear rising/set falling) 18 // COM1B(1:0) = 0b00 (Output B normal operation) 19 // WGM(13:10) = 0b1010 (Phase correct PWM) 20 // ICNC1 = 0b0 (Input capture noise canceler disabled) 21 // ICES1 = 0b0 (Input capture edge select disabled) 22 // CS(12:10) = 0b001 (Input clock select = clock/1) 23 24 TCCR1A |= (1 << COM1A1) | (1 << WGM11); 25 TCCR1B |= (1 << WGM13) | (1 << CS10); 26 ICR1 = TCNT1_TOP; 27} 28 29void loop() { 30 31 setPwmDuty(0); 32 delay(5000); 33 setPwmDuty(25); //Change this value 0-100 to adjust duty cycle 34 delay(5000); 35// setPwmDuty(50); 36// delay(20000); 37// setPwmDuty(75); 38// delay(20000); 39// setPwmDuty(100); 40// delay(20000); 41} 42 43void setPwmDuty(byte duty) { 44 OCR1A = (word) (duty*TCNT1_TOP)/100; 45} 46
Downloadable files
pwm_fan_ctrl_6xm3Jti8le.png
pwm_fan_ctrl_6xm3Jti8le.png

Comments
Only logged in users can leave comments