Hi there,
I’m a newbie to electronics, programing and of course, arduino so don’t hesitate to tell me everything you feel.
This is my first post and my first question not fully answered on this forum or internet.
The project is about to control a 12v PC fan with Arduino Mega 2560.
The schematic is simple, 12v to the 4 wire pwm fan, ground tied with arduino’s ground, analog 10 pin to the tachometer fan’s pin, digital 12 to the PWM Control Fan’s pin. Furter improvements will include a potentiometer and a relay to power on/of and for speed control.
I have the sensation I’m going to burn up my arduino if don’t use some protection but don’t know what or where , so if you have any advice please just let me know.
I’m using a code provided for dc42 to another newbie like me, it was simplified a bit, also added some readings an writings to see better what is going on, I have to say that the led on digital 13 is visible changing power, but on FAN the changes is more than a feeling than an obvious change.
This is the code:
// Definition of Arduino type
// Analog output (i.e PWM) pins. These must be chosen so that we can change the PWM frequency without affecting the millis()
// function or the MsTimer2 library. So don't use timer/counter 1 or 2. See comment in setup() function.
// THESE PIN NUMBERS MUST NOT BE CHANGED UNLESS THE CODE IN setup(), setTransistorFanSpeed() AND setDiodeFanSpeed() IS CHANGED TO MATCH!
// On the Mega we use OC1B and OC1C
const int transistorFanPin = 12; // OC1B
const int diodeFanPin = 13; // OC1C
// Definitions for PWM fan control
const unsigned char maxFanSpeed = 80; // this is calculated as 16MHz divided by 8 (prescaler), divided by 25KHz (target PWM frequency from Intel specification)
void setup()
{
Serial.begin(9600);
// Set up the PWM pins for a PWM frequency close to the recommended 25KHz for the Intel fan spec.
// We can't get this frequency using the default TOP count of 255, so we have to use a custom TOP value.
// On the Mega we use TC1 and OCR1B, OCR1C
TCCR1A = (1 << COM1B1) | (1 << COM1B0) | (1 << COM1C1) | (1 << COM1C1) | (1 << WGM11) | (1 << WGM10); // OC1A disconnected, OC1B = OC1C inverted fast PWM
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11); // TOP = OCR1A, prescaler = 8
TCCR1C = 0;
OCR1AH = 0;
OCR1AL = 79; // TOP = 79
OCR1BH = 0;
OCR1BL = maxFanSpeed;
OCR1CH = 0;
OCR1CL = maxFanSpeed;
TCNT1H = 0;
TCNT1L = 0;
// We have to enable the ports as outputs before PWM will work.
pinMode(transistorFanPin, OUTPUT);
pinMode(diodeFanPin, OUTPUT);
}
// Set the transistor fan speed, where 0 <= fanSpeed <= maxFanSpeed
void setTransistorFanSpeed(unsigned char fanSpeed)
{
OCR1BH = 0;
OCR1BL = fanSpeed;
}
// Set the diode fan speed, where 0 <= fanSpeed <= maxFanSpeed
void setDiodeFanSpeed(unsigned char fanSpeed)
{
OCR1CH = 0;
OCR1CL = fanSpeed;
Serial.print("Fan Speed: ");
Serial.println(fanSpeed);
}
void loop()
{
int Speed;
setTransistorFanSpeed(80);
setDiodeFanSpeed(80);
Speed=analogRead(10);
Serial.print("RPM: ");
Serial.println(Speed);
delay(30000);
Speed=analogRead(10);
Serial.print("RPM: ");
Serial.println(Speed);
setTransistorFanSpeed(28);
setDiodeFanSpeed(28);
delay(30000);
}
but, I really Don’t understand the fisrt part of the code, can anyone explain it in a dummy way?
more than the obvious register name change, what change on this part of code, and what thats mean?
TCCR2A = 0x23;
TCCR2B = 0x09; // select clock
OCR2A = 79; // aiming for 25kHz
pinMode(controlPin, OUTPUT); // enable the PWM output (you now have a PWM signal on digital pin 3)
OCR2B = 62; // set the PWM duty cycle[/i]
I hope not waiting too much, maybe you must point me to some man or help.
Thanks in advantage.
Kind regards.