-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESP32: Per-pin PWM/LEDC frequency and resolution
- Loading branch information
Showing
4 changed files
with
62 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Example configuring PWM frequency and resolution. Only on ESP32 for now. | ||
# Capture output with logic analyzer or oscilloscope to verify accuracy. | ||
# | ||
require 'bundler/setup' | ||
require 'denko' | ||
|
||
board = Denko::Board.new(Denko::Connection::Serial.new) | ||
pwm = Denko::PulseIO::PWMOutput.new(board: board, pin: 2) | ||
|
||
# Resolution test: ~1% duty at 1 kHz / 10-bit. | ||
# On and off approx. 10us and 990us respectively. | ||
pwm.pwm_enable(frequency: 1_000, resolution: 10) | ||
pwm.write 10 # of 1023 | ||
sleep 0.5 | ||
pwm.digital_write 0 | ||
|
||
sleep 0.5 | ||
|
||
# Frequency test: ~50% duty at 10 kHz / 8-bit. | ||
# On and off both approx. 50us. | ||
pwm.pwm_enable(frequency: 10_000, resolution: 8) | ||
pwm.write 127 # of 255 | ||
sleep 0.5 | ||
pwm.digital_write 0 | ||
|
||
board.finish_write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters