Devicetree Visual Editor PWM signal configuration question

Hi,

I want to implement a pwm output signal on a particular pin of the nRF52840DK working with the latest nRF Connect for VS Code. What would be the recommended way to setup the configuration using the Devicetree Visual Editor?  I'm getting confused at the start as this pwm is not associated with an LED and I want to differentiate it from the default PWM LED support.  What if I want 2 or 3 of these type signals?  Devicetree node zephyr,user doesn't seem to support more than 1 PWM signal.

Thanks,

Ken

  • Hello Ken, 

    Have you seen our intermediate course for nRF Connect SDK in our Developer Academy? In lesson 4 of this course it covers how to configure a PWM pin. 

    In the exercise section of this lesson, we will practice controlling an LED on the DK using the PWM API. Then we will modify the devicetree to control an external servo motor device, and how to add a second PWM instance to be able to control both the servo and an LED on the board.

    Please have a look at this course and let me know if this answers your questions.

    Kind regards,
    Øyvind

  • Hi Øyvind,

    Yes, I have seen the course, which is good, but it does not address my question.  This picture shows the pwm0 section from the Devicetree Visual Editor.  I set up pwm0 channel 1 using the zephyr,user node.  No problems.  How would you recommend setting up channels 2 and 3 of pwm0?  If I select zephyr,user from the dropdown after clicking the "+" to the left of CH2, my CH1 setup is removed.  It is like I can only setup 1 additional channel beyond the default overlay.  Is there a Kconfig option I'm missing or something else?  Try it yourself.

    Thanks,

    Ken

  • Hi Ken, thanks for elaborating. 

    You configure the channels in the i.e. nrf52840dk_nrf52840.overlay.

    Edit: Here I've used the Blinky PWM sample and its .overlay file as an example.

    &pwm0 {
    	status = "okay";
    };
    
    &sw_pwm {
    	status = "okay";
    	channel-gpios = <&gpio0 13 PWM_POLARITY_INVERTED>;
    };
    
    
    / {
    	pwmleds {
    		compatible = "pwm-leds";
    		pwm_led0: pwm_led_0 {
    			pwms = <&pwm0 0 PWM_MSEC(8) PWM_POLARITY_NORMAL>;
    		};
    		pwm_led1: pwm_led_1 {
    			pwms = <&pwm0 1 PWM_MSEC(8) PWM_POLARITY_NORMAL>;
    		};
    		pwm_led2: pwm_led_2 {
    			pwms = <&pwm0 2 PWM_MSEC(8) PWM_POLARITY_NORMAL>;
    		};
    	};
    };

    This should allow you to select correct channel

    Kind regards,
    Øyvind

  • Hi Øyvind,

    Yes, that will work, but:  My PWM signals are not related to LEDs at all.  How would I separate these signals from "compatible = "pwm-leds"? 

    Also, to confirm what I think your answer shows:  The Devicetree Visual Editor can't do everything you might want.  I had to edit the .overlay file directly to define the required nodes, like pwm_led_0 in your example.  Correct?

    Thanks,

    Ken

  • Hi,

    Øyvind is currently out of office so I'll be handling this case until he's back.

    Ken58 said:
    Yes, I have seen the course, which is good, but it does not address my question

    The PWM course does address this. If you follow along with exercise 2 you will end up with an overlay that looks like this for the nRF52840DK https://github.com/NordicDeveloperAcademy/ncs-inter/blob/main/lesson4/inter_less4_exer2_solution/boards/nrf52840dk_nrf52840.overlay i.e compatibles that are not coupled with the pmw_led instances, which is how I wrote the exercise to do. From here can set up the different channels through the Devicetree visual helper or by further modifying the overlayfile (i.e select which channels the pwm instances should use).

    Ken58 said:
    The Devicetree Visual Editor can't do everything you might want.  I had to edit the .overlay file directly to define the required nodes, like pwm_led_0 in your example.  Correct?

    Yes, this is correct. The proper way to do this is to do it through .overlay files or in the case of custom boards to do it in the .dts or board files directly. Think of the Devicetree helper as a "helper" and not a complete tool w.r.t how the documentations states to modify overlay-files.

    Kind regards,
    Andreas

Related