![]() We want to take the clock as it is (no prescale) and feed it to the counter we use mode 10, which counts up to the value of register ICR1, which we set to 320 instead of 65535, giving us a period of roughly 25 kHz. ![]() Timer 1 (Pins 9,10) is a high resolution 16 bit timer.You can run a fan with this signal but it will behave erratically. ![]() With the default settings and using analogWrite with a value of 127, this is what we see on an oscilloscope:Īs you can see it's nowhere near the required frequency. The PWM signals on the Arduino Uno (and others based on the ATmega328p, such as the Nano) are generated by 3 internal timers. SetPWM1B(0.2f) //set duty to 20% on pin 10 SetPWM1A(0.5f) //set duty to 50% on pin 9 note that pin 11 will be unavailable for output in this mode! Set PWM frequency to about 25khz on pins 9,10 (timer 1 mode 10, no prescale, count to 320) Code //configure Timer 1 (pins 9,10) to output 25kHz PWM I'll show you the code first and then explain it. By using some timer tricks, we can make it generate 3 PWM signals at the correct frequency. The specs require a PWM signal with a frequency of 25 kHz (with tolerance, 21-28 kHz), but our usual analogWrite function doesn't output anywhere near that frequency. Important: the VIN pin on the Arduino has no polarity protection, double check your connections before turning it on! Note: if you're using really shitty fans, you should add a flyback diode between the ground and power pins of each fan. Note that the Arduino can only take up to 12V as input in the VIN pin, and the Arduino and the fan MUST share the same ground! If you have a 24V fan, you'll have to power both the fan and the Arduino externally. If unsure, power the Arduino and the fan in parallel with a 5V supply connected to both the fan and the 5V pin. If you have a 5V fan, you can power it directly from the 5V pin on the Arduino, but I don't recommend it if it draws more than 4-500 mA, as it could damage the voltage regulator on the Arduino, and also generate noise that could cause the Arduino to be unstable. It's a good idea to put a diode in front of the VIN pin if you have it, that way you can connect both the 12V and the USB without damaging anything. If you have a 12V fan, the best way to power it is to put the Arduino and the fan in parallel, using the VIN pin to power the Arduino. Polarity protection is a requirement of the spec so even if you force it, you won't damage the motherboard or the fan. Notice the presence of a notch on the connector: this is to ensure that you don't connect it backwards, and also to ensure compatibility with older 3 pin connectors. Yellow: +5V, +12V or +24V (depends on fan model, usually 12V for desktops, 5V for laptops).This is the pinout of a standard PWM fan: We can connect up to 3 PWM fans to a single Arduino. The exact specs of these fans were made by Intel in the mid-00s and are available here: Original | Latest version | Noctua Connecting the fan to the Arduino This allows the BIOS to change the fan speed according to the current temperatures using a PWM signal instead of changing the voltage of the fan, which means that motherboards are cheaper to make (less voltage regulators), but also that fans are much easier to control, since DC motors won't even move below a certain voltage threshold. How to properly control PWM fans with Arduino IntroductionĬomputers have been using PWM-controlled fans for ages now (they're the ones with a 4 pin connector).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |