Generating 6 fast PWM signals

Hey, first post, so I hope I'm in the right topic.

I have 6 4-wire pc fans that I would like to control individually. To fans have a dedicated powersupply, and the speed is set by the PWM signal.

I found a tutorial from Hackster, that I have working allready. right now I have hooked op a potentiometer. I use this to control to pwm signal.

However, I can't really understand how to generate 6 individual signals. Is it possible to do this simply by coding? Right now I'm using an uno. Perhaps i need another board, or several boards. Or is there a shield of some kind that can generate these pwms. I found a couple of pwm modules, but they seem to include display and control buttoms. I'm not really interested in that, as my end goal is to control these fans remotely from a server.

Any suggestions?
I've added the code below... Let me know if I did some wrong formatting or I need to add some info.

Thanks Anders

int pwmPin1    = 3; // digital PWM pin 9
int pwmVal     = 1; // The PWM Value
int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the value coming from the sensor

unsigned long time;
unsigned int rpm;
String stringRPM;
String stringOne;
void setup()
{
   // declare the ledPin as an OUTPUT
   pinMode(ledPin, OUTPUT); 

   // generate 25kHz PWM pulse rate on Pin 3
   pinMode(pwmPin1, OUTPUT);   // OCR2B sets duty cycle
   // Set up Fast PWM on Pin 3
   TCCR2A = 0x23;     // COM2B1, WGM21, WGM20 
   // Set prescaler  
   TCCR2B = 0x0A;   // WGM21, Prescaler = /8
   // Set TOP and initialize duty cycle to zero(0)
   OCR2A = 79;    // TOP DO NOT CHANGE, SETS PWM PULSE RATE
   OCR2B = 0;    // duty cycle for Pin 3 (0-79) generates 1 500nS pulse even when 0 :
   digitalWrite(2, HIGH);   // Starts reading

   Serial.begin(9600);
}
void loop()
{
 unsigned int x;
val = analogRead(potPin);    // read the value from the sensor


OCR2B = val/13;
getRPMS ();
delay(5000);

/*
 // ramp up fan speed by increasing duty cycle every 200mS, takes 16 seconds
for(x = 0; x < 80; x++) {
   OCR2B = x;    // set duty cycle
   getRPMS();
   Serial.println(x);
   delay(2000);
 }
 while (Serial.available() == 0);
 int val = Serial.parseInt();
 if (val > 0 && val < 80) {
     OCR2B = val;
 }
 */
}
char getRPMS() {
 time = pulseIn(2, HIGH);
 rpm = (1000000 * 60) / (time * 4);
 stringRPM = String(rpm);
 //if (stringRPM.length() < 5) {
   Serial.print("rpm = ");
   Serial.println(rpm, DEC);
   Serial.print("Pot = ");
   Serial.println(val, DEC);
 //}
}

I recommend an Arduino Mega for that many PWM signals. A Mega has 5 timers, each of which can generate 3 PWM signals. Boards with that controller are available in various form factors, if size is important. An Uno or equivalent only can generate 4 fast PWM signals, so that two such boards will be sufficient as well.

Your code indicates that you don't have to vary the duty cycle much, using 79 for the TOP value with consequently 80 duty cycle steps. Just as a note, for fans this will be sufficient.

For using all possible PWM channels you should change the frequency generation from OCRxA to ICRx, so that OCRxA, OCRxB, and on a Mega OCRxC, are usable for PWM. And that for timers x=1..2 on an Uno, x=1..4 on a Mega. See the controller data sheets.

Just to through it out there as I’ve only just come across this. There’s such a thing as a Mega 2560 Pro, which is smaller compared to the regular mega.
As the Dr states in #2, it does come in various forms but thought I’d say.

DrDiettrich:
I recommend an Arduino Mega for that many PWM signals. A Mega has 5 timers, each of which can generate 3 PWM signals. Boards with that controller are available in various form factors, if size is important. An Uno or equivalent only can generate 4 fast PWM signals, so that two such boards will be sufficient as well.

Your code indicates that you don't have to vary the duty cycle much, using 79 for the TOP value with consequently 80 duty cycle steps. Just as a note, for fans this will be sufficient.

For using all possible PWM channels you should change the frequency generation from OCRxA to ICRx, so that OCRxA, OCRxB, and on a Mega OCRxC, are usable for PWM. And that for timers x=1..2 on an Uno, x=1..4 on a Mega. See the controller data sheets.

Thanks a lot. This definitely got me in the right direction. I have a mega lying around, so i will test this. I found the datasheet and found the pinout for the timers.

I'm looking a bit into the code, as it is not my strong side. But this Video gives a great explanation of the timers, and this topic seems to also be discussing multiple fast pwms. Just throwing it in if anybody ells reads along...

exiledyorkie:
Just to through it out there as I’ve only just come across this. There’s such a thing as a Mega 2560 Pro, which is smaller compared to the regular mega.
As the Dr states in #2, it does come in various forms but thought I’d say.

Thanks. I have not come across this before now. Size isn't an issue at this current stage, but might be later on... :slight_smile: