Hi!
I have problems with PWM on Pin 5, or the latter of it. It seems to be always high with no frequency, frequency is set to 30khz. During my test i used Pin 6 and 7 aswell, both these worked as they should. Pin 5 and Pin 6 are sharing the same timer as far as i see so it should have worked. Any ideas as to what can cause this? Serial is connected.
I have problems with PWM on Pin 5, or the latter of it. It seems to be always high with no frequency, frequency is set to 30khz. During my test i used Pin 6 and 7 aswell, both these worked as they should. Pin 5 and Pin 6 are sharing the same timer as far as i see so it should have worked. Any ideas as to what can cause this? Serial is connected.
Code:
const int fan1_pwm = 5;
const int fan1_rpm = 3;
const int fan2_pwm = 6;
const int fan2_rpm = 4;
const int fan3_pwm = 7;
const int fan3_rpm = 38;
void setup() {
// put your setup code here, to run once:
Serial.begin(38400);
while(!Serial);
analogWriteResolution(10); // Resolution for PWM is set to 0-1023
pinMode(fan1_pwm,OUTPUT);
pinMode(fan2_pwm,OUTPUT);
pinMode(fan3_pwm,OUTPUT);
digitalWriteFast(fan1_pwm,LOW);
digitalWriteFast(fan2_pwm,LOW);
digitalWriteFast(fan3_pwm,LOW);
analogWriteFrequency(fan1_pwm,30000);
analogWriteFrequency(fan2_pwm,30000);
analogWriteFrequency(fan3_pwm,30000);
analogWrite(fan1_pwm, 0);
analogWrite(fan2_pwm, 0);
analogWrite(fan3_pwm, 0);
}
void loop() {
for (int fadeValue = 0 ; fadeValue <= 1023; fadeValue += 1) {
analogWrite(fan1_pwm, fadeValue);
analogWrite(fan2_pwm, fadeValue);
analogWrite(fan3_pwm, fadeValue);
delay(100);
Serial.print(" At Value: ");
Serial.println(fadeValue);
}
for (int fadeValue = 1023 ; fadeValue >= 0; fadeValue -= 1) {
analogWrite(fan1_pwm, fadeValue);
analogWrite(fan2_pwm, fadeValue);
analogWrite(fan3_pwm, fadeValue);
delay(100);
Serial.print(" At Value: ");
Serial.println(fadeValue);
}
}