PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

38 linhas
1.1KB

  1. #include <TimerOne.h>
  2. // This example creates a PWM signal with 25 kHz carrier.
  3. //
  4. // Arduino's analogWrite() gives you PWM output, but no control over the
  5. // carrier frequency. The default frequency is low, typically 490 or
  6. // 3920 Hz. Sometimes you may need a faster carrier frequency.
  7. //
  8. // The specification for 4-wire PWM fans recommends a 25 kHz frequency
  9. // and allows 21 to 28 kHz. The default from analogWrite() might work
  10. // with some fans, but to follow the specification we need 25 kHz.
  11. //
  12. // http://www.formfactors.org/developer/specs/REV1_2_Public.pdf
  13. //
  14. // Connect the PWM pin to the fan's control wire (usually blue). The
  15. // board's ground must be connected to the fan's ground, and the fan
  16. // needs +12 volt power from the computer or a separate power supply.
  17. const int fanPin = 4;
  18. void setup(void)
  19. {
  20. Timer1.initialize(40); // 40 us = 25 kHz
  21. Serial.begin(9600);
  22. }
  23. void loop(void)
  24. {
  25. // slowly increase the PWM fan speed
  26. //
  27. for (float dutyCycle = 30.0; dutyCycle < 100.0; dutyCycle++) {
  28. Serial.print("PWM Fan, Duty Cycle = ");
  29. Serial.println(dutyCycle);
  30. Timer1.pwm(fanPin, (dutyCycle / 100) * 1023);
  31. delay(500);
  32. }
  33. }