Adjusting Micro clock speed for ventilation project

I'm trying to design a project for an enclosure that I need to ventilate, and I am going to run the system on a 12V battery. My plan is to use 4 4-pin 12V fans and use a DHT11 humidity sensor. If the humidity is too high, I want to be able to turn the fans on, and when it gets to a suitable level, I want to be able to turn the fans off to conserve power. I am also thinking about using a voltage divider or trimpot to reduce the battery voltage enough to be able to monitor the battery status with the Arduino and turn the fans off if it gets too low in order to not drain the battery and wreck it.

I was thinking of using the Micro because it has enough pins for the fans, humidity sensor, and battery monitoring; it can run on 7-20V (though 7-12V is recommended) so I can get away with the slightly increased voltage of a charged battery; the 5V signal from the DHT11 should be fine (though it can operate from 3.3V-5.5V from what I understand); and the board is a small form factor that will make it easy to enclose.

I am wondering about the clock speed though. I know that you can run computer fans with Arduinos without the 25 kHz clock speed, but I am trying to keep any potential noise down and fans can get a bit of wine when they aren't running on the right clock speed from what I understand.

Is there a way to adjust the clock speed of a Micro to run the fans with the right 25 kHz signal? Or should I be looking at a different board? Thanks!

It sounds like it should work for you but packaging will be important. Post an annotated schematic showing how you plan on connecting these devices. Be sure to annotate it with part numbers etc and of course the Micro. You want the hardware design basically finished before starting the software.

As far as I know, those fans use PWM. So you need to change the PWM frequency, not the clock frequency.

I know it can be done but have never done it my self. Have a look at https://docs.arduino.cc/tutorials/generic/secrets-of-arduino-pwm/#using-the-atmega-pwm-registers-directly; because the 32U4 and 328P are very similar the article will apply.

Before complicating your life with frequencies, just try your fan with the frequency your arduino gives out of the box. Many 4-pin fans accept wide range of control signal and it doesn't effect the noise. Fan datasheet can give for example 30Hz-300000Hz range for control signal but the fan is internally driven with fixed frequency.

1 Like

Yes, they are run on PWM, but that is calculated in reference to the clock. The clock speed/frequency of Micro is 16 kHz, but PC fans are 25 kHz, so it's essentially overclocking the chips (the chips are often capable of running at different speeds, but are set to 16 kHz with ways to set that higher or lower).

Or maybe little less..
like ~1/1000 of that

1 Like

Yeah, I just caught that, ha ha.

Sorry, I might not be using the right term when I say clock speed (though that's often how I see it written), but rather the timer.

No, the clock speed of the Micro is 16 MHz, not kHz. To get the PWM frequency the system clock is divided down. You can easily get a PWM frequency of 25 kHz.

The main clock speed is 16MHz, not KHz. The PWM frequency is controlled by the settings for the clock divider in the control registers.

You will have to get your numbers right :wink: A 32U4 on an Arduino Micro runs on 16MHz.

And there is no way to overclock the 32U4 with some internal settings; it's not some kind of x86 type processor. You might be able to squeeze 20 MHz out of it, some people did (for fun) overclock AVR based processors; there is somewhere an older topic about it.

See the link that I provided in post #3.

1 Like

Sorry, I shouldn't have been responding to messages while half asleep, ha ha. Yes, 16 MHz chip, 25 kHz fan signal.

I remembered that I saw a similar thing recently, here is a sketch I tested a fan with. As it turned out, the speed control also worked with the default Arduino PWM rate, but I guess not all fans may respond the same way.


/* connections

Fan pin 1 (GND) ---- power ground, Arduino Ground
Fan pin 2 (12V) ---- PSU 12V
Fan pin 3 (TACH) ---- nc
Fan pin 4 (PWM) ---- Arduino pin 9

*/

// Note: Timer1 OC1A PWM output to pin 9
const int PIN_FAN_PWM = 9;


void init_timer(void)
{
  // Timer-1 16-bit, Mode-14 Fast, Top=ICR
  // 25,000 Hz Frequency, Clock is 16 MHz
  // Single channel

  TCCR1B = 0x18;  // 0001 1000, Disable Timer
  TCCR1A = 0x82;  // 1000 0010
  ICR1 = 640 - 1;
  OCR1A = (int)(ICR1 * 0.25);
  TCNT1 = 0x0;

  // UNO-NANO Timer-1 PWM Output Pin
  pinMode(9, OUTPUT);  // OC1a

  TCCR1B |= 1;  // Prescale=1, Enable Timer
}

void setup()
{
  // put your setup code here, to run once:

  init_timer ();
}

void set_duty (float percent)
{
  uint16_t duty = (int)(ICR1 * percent/100.0);
  if (duty < 1)
    duty = 1;
  else if (duty >= ICR1)
    duty = ICR1-1;

  OCR1A = duty;
}

void loop()
{
  set_duty (25.0);
  delay(10000);
  set_duty (75.0);
  delay(10000);
}



1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.