Hi,
I am trying to set up PWMs on a custom board, but I am not able to observe the outputs using an oscilloscope (pins are constantly at 0V). The PWM channels should be set to P0.26 and P0.27.
Here is my device tree:
// Copyright (c) 2022 Nordic Semiconductor ASA // SPDX-License-Identifier: Apache-2.0 /dts-v1/; #include <nordic/nrf52840_qiaa.dtsi> / { model = "10_000010_00_Throttle_Splitter"; compatible = "fifteen-motors,10-000010-00-throttle-splitter"; chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; zephyr,code-partition = &slot0_partition; }; leds { compatible = "gpio-leds"; ledbar0: led_0 { gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>; label = "LED Bar 0"; }; ledbar1: led_1 { gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>; label = "LED Bar 1"; }; ledbar2: led_2 { gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>; label = "LED Bar 2"; }; ledbar3: led_3 { gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>; label = "LED Bar 3"; }; ledbuttonl: led_l { gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>; label = "LED Button Left"; }; ledbuttonr: led_r { gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>; label = "LED Button Right"; }; }; pwmdevs { compatible = "pwm-leds"; pwm_dev0: pwm_dev0 { pwms = <&pwm0 26 PWM_USEC(1000) PWM_POLARITY_NORMAL>; }; pwm_dev1: pwm_dev1 { pwms = <&pwm1 27 PWM_USEC(1000) PWM_POLARITY_NORMAL>; }; }; buttons { compatible = "gpio-keys"; buttonl: button_l { gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "Push button switch left"; }; buttonr: button_r { gpios = <&gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "Push button switch right"; }; }; /* These aliases are provided for compatibility with samples */ aliases { buttonl = &buttonl; buttonr = &buttonr; ledbar0 = &ledbar0; ledbar1 = &ledbar1; ledbar2 = &ledbar2; ledbar3 = &ledbar3; ledbuttonl = &ledbuttonl; ledbuttonr = &ledbuttonr; mcfront = &pwm_dev0; mcrear = &pwm_dev1; }; }; &gpiote { status = "okay"; }; &gpio0 { status = "okay"; }; &gpio1 { status = "okay"; }; &pwm0 { status = "okay"; ch0-pin = <26>; // ch0-inverted; }; &pwm1 { status = "okay"; ch0-pin = <27>; // ch0-inverted; }; &flash0 { partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; boot_partition: partition@0 { label = "mcuboot"; reg = <0x0 0xc000>; }; slot0_partition: partition@c000 { label = "image-0"; reg = <0xc000 0x72000>; }; slot1_partition: partition@7e000 { label = "image-1"; reg = <0x7e000 0x72000>; }; scratch_partition: partition@f0000 { label = "image-scratch"; reg = <0xf0000 0xa000>; }; storage_partition: partition@fa000 { label = "storage"; reg = <0xfa000 0x6000>; }; }; };
In the main.c file, I am setting up the PWMs via the following:
// Parameters for PWM control static const struct pwm_dt_spec pwm_front = PWM_DT_SPEC_GET(DT_ALIAS(mcfront)); static const struct pwm_dt_spec pwm_rear = PWM_DT_SPEC_GET(DT_ALIAS(mcrear)); #define PWM_PERIOD PWM_MSEC(1U) // set PWMs to 10kHz
And have the following in my main loop:
// Set up PWMs if (!device_is_ready(pwm_front.dev) || !device_is_ready(pwm_rear.dev)) { return; } ret = pwm_set_dt(&pwm_front, PWM_PERIOD, PWM_PERIOD / 2U); ret = pwm_set_dt(&pwm_rear, PWM_PERIOD, PWM_PERIOD / 2U); // Initialize the LEDs and confirm they are ready to use if (!device_is_ready(led0.port)) { return; }
I have "supported:- pwm" in my YAML file, and "CONFIG_PWM=y" in my project config file.