This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Inverted PWM channels in DeviceTree

Hi,

I have a custom PCB that uses the nRF9160 and an RGB LED. I want to drive this LED with PWM but it uses an active LOW style of GPIO drive. I have been able to use normal GPIO active LOW configurations to drive the LED on and off but I don't know how to do this for PWM.

I have code made for the thingy:91 which uses normal PWM to drive LEDs and have reconfigured this code to run on my LEDs but obviously, everything is backwards because the pins are supposed to be driven LOW not HIGH.

I have found that you can add something like:

n: node {
        pwms = <&pwm1 1 PWM_POLARITY_NORMAL>,
               <&pwm2 3 PWM_POLARITY_INVERTED>;
};

To the device tree in order to set how the PWM should behave. I use PWM 0 to drive a Buzzer (Normal) and have PWM 1 for the RGB (Inverted) but I don't know where to deploy this snippet to allow me to use DT_ALIAS_PWM_1_CH0_INVERTED when setting up my PWM pins. Note: I am using the SDK version 1.3.0 but I am still using the legacy devicetree macros through prj.conf options.

I understand that I could just change how my code drives the PWM channels for the specific platform using CONFIG_BOARD_XXX but I already have a PWM controller function that uses a list of pre-created PWM colours based off work with the thingy:91. So it would actually be easier to not tweak this and just invert the PWM channels.

Many thanks,

Michael

  • Hi,

    Looking at the thingy91_nrf9160_common.dts for Thingy:91, I don't see 'pwms' used.  But, If you are using PWM0 for RGB control, similar to how it's done in the Thingy:91 dts file,snippet:

    /* PWM0 is intended for RGB LED control */
    &pwm0 {
    	status = "okay";
    	ch0-pin = <29>;
    	ch1-pin = <30>;
    	ch2-pin = <31>;
    };

    Then, you can try to set chx-inverted; for the x pins you need to be inverted:

    Snippet:

    /* PWM0 is intended for RGB LED control */
    &pwm0 {
    	status = "okay";
    	ch0-pin = <29>;
    	ch0-inverted;
    	ch1-pin = <30>;
    	ch1-inverted;
    	ch2-pin = <31>;
    	ch2-inverted;
    };

Related