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

PWM on nRF52840 GPIO with Zephyr

Hello, guys.

We are have nRF52840DK board and Zephyr NCS 1.4.2 development environment.

I am trying to include two PWM channels in the code and control them independently through Zephyr PWM drivers and pwm_pin_set_usec() function.

Everything seems to be OK as long as I select one of the LED GPIOs on DK board (13, 14, 15, or 16) for PWM GPIOs.

However, we want to use some other GPIO for for PWM signals because we want do drive DRV8837 motor controller with them.

Here is what I put in my nrf52840dk_nrf52840.overlay file:

/ {
	model = "Nordic nRF52840 DK NRF52840";
	compatible = "nordic,nrf52840-dk-nrf52840";


	pwmdrv {
		compatible = "pwm-leds";		
		pwm_drv8837p: pwm_drv8837_p {
			pwms = <&pwm0 14>;
		};
		pwm_drv8837n: pwm_drv8837_n {
			pwms = <&pwm1 15>;
		};		
	};


	/* These aliases are provided for compatibility with samples */
	aliases {
		adcctrl = &adc;
		pwm-drv8837p = &pwm_drv8837p;
		pwm-drv8837n = &pwm_drv8837n;
	};
};


&pwm0 {
	status = "okay";
	ch0-pin = <14>;
	ch0-inverted;
};

&pwm1 {
	status = "okay";
	ch1-pin = <15>;
	ch1-inverted;
};
	

As I said, PWMs are working only for GPIOs 13, 14, 15, and 16. When I set GPIO 0 for &pwm0, for example, we don't get PWM signal on P0.0 output.

What we are missing here?

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

Parents
  • Hi,

     

    As I said, PWMs are working only for GPIOs 13, 14, 15, and 16. When I set GPIO 0 for &pwm0, for example, we don't get PWM signal on P0.0 output.

    If you use the external 32k clock, P0.00 and P0.01 is already in use by the LFCLK. If you do not have or plan to use the external LFCLK, you can switch the source to RC for instance, by setting this configuration:

    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y

     

    Kind regards,

    Håkon

  • Hello, Hakon...

    I still have a hard time to properly use Zephyr PWM driver.

    According to some threads (link), in order to stop playing PWM pattern on GPIO, we need to set the pulse width parameter to 0:

    pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, period_us, 0)

    However, here is what I get on GPIO when I want to stop PWM (Channel D0):

    What is the proper way of stop playing PWM pattern on GPIO? Also, where is the place we define the polarity of the PWM signal?

    Thanks in advance. Looking forward to reading from you.

    Sincerely,

    Bojan.

Reply
  • Hello, Hakon...

    I still have a hard time to properly use Zephyr PWM driver.

    According to some threads (link), in order to stop playing PWM pattern on GPIO, we need to set the pulse width parameter to 0:

    pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, period_us, 0)

    However, here is what I get on GPIO when I want to stop PWM (Channel D0):

    What is the proper way of stop playing PWM pattern on GPIO? Also, where is the place we define the polarity of the PWM signal?

    Thanks in advance. Looking forward to reading from you.

    Sincerely,

    Bojan.

Children
Related