LED PWM

How many PWM channels I can define such as the following for nRF52832?

pwmleds {
compatible = "pwm-leds";
pwm_led0: pwm_led_0 {
pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
};

};

in DTSI file I will have corresponding pwm_default and pwm_sleep.

I want to drive six pwm LEDs.

  • Hello,

    The nRF52832 comes with 3 PWM modules with 4 channels.

    So you can get a total of 12 PWM channels, that can drive 12 assigned GPIOs. Though you only have independent frequency control in these 3 PWM modules.

    So driving 6 PWM LEDs is possible, the question is how you want to do it. Do any particular ones need a different frequency?

    Regards,

    Elfving

  • Hello Elfving

    I need 6 PWMs for driving LEDs with the same frequency.

    Regards

    Umesh

  • Hi Umesh, and sorry about the delay.

    umeshdj said:
    Same frequency is required for all six channels

    That makes it easier.

    Have a look at this dts overlay file. Here I am enabling pwm1, and adding GPIO 22 and 23. Note that pwm_led_4 uses channel 1.

    // To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.
    
    // You can also use the buttons in the sidebar to perform actions on nodes.
    // Actions currently available include:
    
    // * Enabling / disabling the node
    // * Adding the bus to a bus
    // * Removing the node
    // * Connecting ADC channels
    
    // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
    // You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html
    // To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.
    
    // You can also use the buttons in the sidebar to perform actions on nodes.
    // Actions currently available include:
    
    // * Enabling / disabling the node
    // * Adding the bus to a bus
    // * Removing the node
    // * Connecting ADC channels
    
    // For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
    // You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html
    &pinctrl {
        pwm0_default: pwm0_default {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 17)>,
                        <NRF_PSEL(PWM_OUT1, 0, 18)>,
                        <NRF_PSEL(PWM_OUT2, 0, 19)>,
                        <NRF_PSEL(PWM_OUT3, 0, 20)>;
    
    
    			nordic,invert;
    		};
    	};
    
    	pwm0_sleep: pwm0_sleep {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 17)>,
                        <NRF_PSEL(PWM_OUT1, 0, 18)>,
                        <NRF_PSEL(PWM_OUT2, 0, 19)>,
                        <NRF_PSEL(PWM_OUT3, 0, 20)>;
    
    			low-power-enable;
    		};
    	};
    	pwm1_default: pwm1_default {
    		group1 {
    			psels = 
    					//for additional module
    					<NRF_PSEL(PWM_OUT1, 0, 22)>,
    					<NRF_PSEL(PWM_OUT2, 0, 23)>;
    
    			nordic,invert;
    		};
    	};
    
    	pwm1_sleep: pwm1_sleep {
    		group1 {
    			psels = 
    					//for additional module
    					<NRF_PSEL(PWM_OUT1, 0, 22)>,
    					<NRF_PSEL(PWM_OUT2, 0, 23)>;
    			low-power-enable;
    		};
    	};
    };
    &pwm1 {
    	status = "okay";
    	pinctrl-0 = <&pwm1_default>;
    	pinctrl-1 = <&pwm1_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    /{
    	pwmleds {
    		compatible = "pwm-leds";
    		pwm_led0: pwm_led_0 {
    			pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
            pwm_led1: pwm_led_1 {
    			pwms = <&pwm0 1 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
            pwm_led2: pwm_led_2 {
    			pwms = <&pwm0 2 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
            pwm_led3: pwm_led_3 {
    			pwms = <&pwm0 3 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
    		
    
    		pwm_led4: pwm_led_4 {
    			pwms = <&pwm1 1 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
    		pwm_led5: pwm_led_5 {
    			pwms = <&pwm1 2 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
            
    		status = "okay";
    		
    	};
    };
    

    I just tried this overlay along with the zephyr led pwm sample and got 6 leds to use pwm on the 52dk.

    Regards,

    Elfving

Related