1.. zephyr:code-sample:: pwm-blinky 2 :name: PWM Blinky 3 :relevant-api: pwm_interface 4 5 Blink an LED using the PWM API. 6 7Overview 8******** 9 10This application blinks an LED using the :ref:`PWM API <pwm_api>`. See 11:zephyr:code-sample:`blinky` for a GPIO-based sample. 12 13The LED starts blinking at a 1 Hz frequency. The frequency doubles every 4 14seconds until it reaches 128 Hz. The frequency will then be halved every 4 15seconds until it returns to 1 Hz, completing a single blinking cycle. This 16faster-then-slower blinking cycle then repeats forever. 17 18Some PWM hardware cannot set the PWM period to 1 second to achieve the blinking 19frequency of 1 Hz. This sample calibrates itself to what the hardware supports 20at startup. The maximum PWM period is decreased appropriately until a value 21supported by the hardware is found. 22 23Requirements 24************ 25 26The board must have an LED connected to a PWM output channel. The PWM 27controlling this LED must be configured using the ``pwm_led0`` :ref:`devicetree 28<dt-guide>` alias, usually in the :ref:`BOARD.dts file 29<devicetree-in-out-files>`. 30 31Wiring 32****** 33 34No additional wiring is necessary if ``pwm_led0`` refers to hardware that is 35already connected to an LED on the board. 36 37In these other cases, however, manual wiring is necessary: 38 39.. list-table:: 40 :header-rows: 1 41 42 * - Board 43 - Wiring 44 * - :zephyr:board:`nucleo_f401re` 45 - connect PWM2 (PA0) to an LED 46 * - :zephyr:board:`nucleo_l476rg` 47 - connect PWM2 (PA0) to an LED 48 * - :zephyr:board:`stm32f4_disco` 49 - connect PWM2 (PA0) to an LED 50 * - :zephyr:board:`nucleo_f302r8` 51 - connect PWM2 (PA0) to an LED 52 * - :zephyr:board:`nucleo_f103rb` 53 - connect PWM1 (PA8) to an LED 54 * - :zephyr:board:`nucleo_wb55rg` 55 - connect PWM1 (PA8) to an LED 56 * - :zephyr:board:`esp32_devkitc_wroom` 57 - connect GPIO2 to an LED 58 * - :zephyr:board:`esp32s2_saola` 59 - connect GPIO2 to an LED 60 * - :zephyr:board:`esp32c3_devkitm` 61 - connect GPIO2 to an LED 62 63Building and Running 64******************** 65 66To build and flash this sample for the :ref:`nrf52840dk_nrf52840`: 67 68.. zephyr-app-commands:: 69 :zephyr-app: samples/basic/blinky_pwm 70 :board: nrf52840dk/nrf52840 71 :goals: build flash 72 :compact: 73 74Change ``nrf52840dk/nrf52840`` appropriately for other supported boards. 75 76After flashing, the sample starts blinking the LED as described above. It also 77prints information to the board's console. 78