PC Fans: Difference between revisions
clean up whitespace, use canonical timer names |
|||
| Line 65: | Line 65: | ||
To use a different timer, replace all '5's above with the desired timer number. The relevant pin ought be placed into <tt>OUTPUT</tt> mode, and [https://www.mathworks.com/help/supportpkg/arduino/ug/pin-mapping-for-arduino-timer-dependent-blocks.html must be associated] with the configured timer (say, Pin 44 for Timer 5). No direct manipulation of the pins is necessary, and the PWM is handled in hardware. | To use a different timer, replace all '5's above with the desired timer number. The relevant pin ought be placed into <tt>OUTPUT</tt> mode, and [https://www.mathworks.com/help/supportpkg/arduino/ug/pin-mapping-for-arduino-timer-dependent-blocks.html must be associated] with the configured timer (say, Pin 44 for Timer 5). No direct manipulation of the pins is necessary, and the PWM is handled in hardware. | ||
====On ESP32==== | ====On ESP32==== | ||
The [[ESP32]]'s [https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html <tt>ledc</tt>] library can be harnessed to do this at a high level, while still using hardware PWM. You | The [[ESP32]]'s [https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html <tt>ledc</tt>] library can be harnessed to do this at a high level, while still using hardware PWM. You might need step up the voltage to 5V via one mechanism or another (failure to do can, in my experience, result in devices running at lower speeds than expected). A level shifter will do nicely. Supply a chosen channel (of 8) and an <tt>OUTPUT</tt> pin, together with a <tt>freq</tt> of 25000, to e.g.: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
static int initialize_pwm(ledc_channel_t channel, int pin, int freq){ | static int initialize_pwm(ledc_channel_t channel, int pin, int freq){ | ||