PWM Output on Pin 5 - Teensy 3.5

Status
Not open for further replies.

stianb

New member
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.
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);
      }

}
 
Your sketch works for me on T3.5. logic analyzer shows all three PWM pins behaving the same.
How are you verifying that PWM is working/failing?

check your soldering/wiring
 
Last edited:
Im using MiniDSO to verify pin outputs. Just found the issue on the PCB, a 3.3v track has come in contact with pin 5 trace due to too much solder, no wonder it was always high :-S
 
Status
Not open for further replies.
Back
Top