zephyr/samples/basic/blinky_pwm
Yishai Jaffe 899fde5763 samples: pwm: Add overlay for nucleo_l4r5zi board
Add Devicetree overlay for sample drivers/led/pwm and fix the one in
basic/blinky_pwm for nucleo_l4r5zi board to set appropriate to enable
pwdleds and set appropriate timer prescaler.

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
2024-12-17 09:48:40 +01:00
..
boards samples: pwm: Add overlay for nucleo_l4r5zi board 2024-12-17 09:48:40 +01:00
src samples: basic: blinky_pwm: add testing base on console output 2024-06-04 13:36:10 +02:00
CMakeLists.txt samples: blinky_pwm: fix missing project renaming 2022-10-31 09:22:59 -05:00
prj.conf logging: Revamp menuconfig 2021-01-26 06:15:42 -05:00
README.rst boards: st: adopt new zephyr:board directive and role 2024-10-24 17:51:15 +02:00
sample.yaml samples: basic: blinky_pwm: add testing base on console output 2024-06-04 13:36:10 +02:00

.. zephyr:code-sample:: pwm-blinky
   :name: PWM Blinky
   :relevant-api: pwm_interface

   Blink an LED using the PWM API.

Overview
********

This application blinks an LED using the :ref:`PWM API <pwm_api>`. See
:zephyr:code-sample:`blinky` for a GPIO-based sample.

The LED starts blinking at a 1 Hz frequency. The frequency doubles every 4
seconds until it reaches 128 Hz. The frequency will then be halved every 4
seconds until it returns to 1 Hz, completing a single blinking cycle. This
faster-then-slower blinking cycle then repeats forever.

Some PWM hardware cannot set the PWM period to 1 second to achieve the blinking
frequency of 1 Hz. This sample calibrates itself to what the hardware supports
at startup. The maximum PWM period is decreased appropriately until a value
supported by the hardware is found.

Requirements
************

The board must have an LED connected to a PWM output channel. The PWM
controlling this LED must be configured using the ``pwm_led0`` :ref:`devicetree
<dt-guide>` alias, usually in the :ref:`BOARD.dts file
<devicetree-in-out-files>`.

Wiring
******

No additional wiring is necessary if ``pwm_led0`` refers to hardware that is
already connected to an LED on the board.

In these other cases, however, manual wiring is necessary:

.. list-table::
   :header-rows: 1

   * - Board
     - Wiring
   * - :zephyr:board:`nucleo_f401re`
     - connect PWM2 (PA0) to an LED
   * - :zephyr:board:`nucleo_l476rg`
     - connect PWM2 (PA0) to an LED
   * - :zephyr:board:`stm32f4_disco`
     - connect PWM2 (PA0) to an LED
   * - :zephyr:board:`nucleo_f302r8`
     - connect PWM2 (PA0) to an LED
   * - :zephyr:board:`nucleo_f103rb`
     - connect PWM1 (PA8) to an LED
   * - :zephyr:board:`nucleo_wb55rg`
     - connect PWM1 (PA8) to an LED
   * - :zephyr:board:`esp32_devkitc_wroom`
     - connect GPIO2 to an LED
   * - :zephyr:board:`esp32s2_saola`
     - connect GPIO2 to an LED
   * - :zephyr:board:`esp32c3_devkitm`
     - connect GPIO2 to an LED

Building and Running
********************

To build and flash this sample for the :ref:`nrf52840dk_nrf52840`:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/blinky_pwm
   :board: nrf52840dk/nrf52840
   :goals: build flash
   :compact:

Change ``nrf52840dk/nrf52840`` appropriately for other supported boards.

After flashing, the sample starts blinking the LED as described above. It also
prints information to the board's console.