• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

boards/03-Aug-2024-716599

src/03-Aug-2024-8152

CMakeLists.txtD03-Aug-2024192 85

README.rstD03-Aug-20242.3 KiB7860

prj.confD03-Aug-2024141 87

sample.yamlD03-Aug-2024509 2019

README.rst

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   * - :ref:`nucleo_f401re_board`
45     - connect PWM2 (PA0) to an LED
46   * - :ref:`nucleo_l476rg_board`
47     - connect PWM2 (PA0) to an LED
48   * - :ref:`stm32f4_disco_board`
49     - connect PWM2 (PA0) to an LED
50   * - :ref:`nucleo_f302r8_board`
51     - connect PWM2 (PA0) to an LED
52   * - :ref:`nucleo_f103rb_board`
53     - connect PWM1 (PA8) to an LED
54   * - :ref:`nucleo_wb55rg_board`
55     - connect PWM1 (PA8) to an LED
56   * - :ref:`esp32_devkitc_wroom`
57     - connect GPIO2 to an LED
58   * - :ref:`esp32s2_saola`
59     - connect GPIO2 to an LED
60   * - :ref:`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