diff options
Diffstat (limited to 'docs/esp32/quickref.rst')
-rw-r--r-- | docs/esp32/quickref.rst | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst index 7391a4aa4b..97b6fba38d 100644 --- a/docs/esp32/quickref.rst +++ b/docs/esp32/quickref.rst @@ -218,20 +218,24 @@ range from 1Hz to 40MHz but there is a tradeoff; as the base frequency *increases* the duty resolution *decreases*. See `LED Control <https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/ledc.html>`_ for more details. -Currently the duty cycle has to be in the range of 0-1023. -Use the ``machine.PWM`` class:: +Use the :ref:`machine.PWM <machine.PWM>` class:: from machine import Pin, PWM - pwm0 = PWM(Pin(0)) # create PWM object from a pin - pwm0.freq() # get current frequency (default 5kHz) - pwm0.freq(1000) # set frequency - pwm0.duty() # get current duty cycle (default 512, 50%) - pwm0.duty(200) # set duty cycle - pwm0.deinit() # turn off PWM on the pin + pwm0 = PWM(Pin(0)) # create PWM object from a pin + pwm0.freq() # get current frequency (default 5kHz) + pwm0.freq(1000) # set PWM frequency from 1Hz to 40MHz + pwm0.duty() # get current duty cycle, range 0-1023 (default 512, 50%) + pwm0.duty(256) # set duty cycle from 0 to 1023 as a ratio duty/1023, (now 25%) + pwm0.duty_u16(2**16*3//4) # set duty cycle from 0 to 65535 as a ratio duty_u16/65535, (now 75%) + pwm0.duty_u16() # get current duty cycle, range 0-65535 + pwm0.duty_ns(250_000) # set pulse width in nanoseconds from 0 to 1_000_000_000/freq, (now 25%) + pwm0.duty_ns() # get current pulse width in ns + pwm0.deinit() # turn off PWM on the pin pwm2 = PWM(Pin(2), freq=20000, duty=512) # create and configure in one go + print(pwm2) # view PWM settings ESP chips have different hardware peripherals: @@ -251,6 +255,8 @@ but only 8 different PWM frequencies are available, the remaining 8 channels mus have the same frequency. On the other hand, 16 independent PWM duty cycles are possible at the same frequency. +See more examples in the :ref:`esp32_pwm` tutorial. + ADC (analog to digital conversion) ---------------------------------- |