PWM with EasyDMA on Zephyr

After trying to do this in Zephyr using NCS v2.2.0 and v2.3.0, I've ended up in confusion and doubt.  
Some Dev Zone posts by Torbjørn seem to indicate that I need to use Nordic code to accomplish what I am after
so I am just seeking some clarification.  THis is on a custom board using nRF5340 SoC. 

The goal, 4 PWM outputs, all same frequency but dynamically updated duty cycles using DMA. 

What I know: With STM32 this would be done (roughly) by setting up timers and gpio, set freq, countup and to update dc set new compare.

What I tried to setup in Zephyr I noticed the sys clock is 32K not 16 MHz and that it appears to utilize cpu based a rate monitoring of a loop. 

DTS

&pwm0 {
  status = "okay";
  pinctrl-0 = <&pwm0_default>;
  pinctrl-1 = <&pwm0_sleep>;
  pinctrl-names = "default", "sleep";
};

Overlay - values\names changed

pwmxout {
    compatible = "pwm-leds";
    pwm_x1: pwm_motor_1 {
      pwms = <&pwm0 0 PWM_USEC(5000) PWM_POLARITY_NORMAL>;
    };
    pwm_x2: pwm_motor_2 {
      pwms = <&pwm0 1 PWM_USEC(5000) PWM_POLARITY_NORMAL>;
    };
    pwm_x3: pwm_motor_3 {
      pwms = <&pwm0 2 PWM_USEC(5000) PWM_POLARITY_NORMAL>;
    };
    pwm_x4: pwm_motor_4 {
      pwms = <&pwm0 3 PWM_USEC(5000) PWM_POLARITY_NORMAL>;
    };
  };

This would be where my confusion sets in, how to change duty cycle (compare)? Do I call pwm_set_pulse? 

AM I better off using nrf code to do this? 

  • I think an easier question I may have is this... 

    For the nRF PWM module on Zephyr, is the base clock 16MHz or 32K?  If 32K by default, how do I make it 16 MHz like in the nrfx library? 

    Second question, when switching Duty Cycle, how long does it take?  If period stays the same it switches on the fly correct? 

  • Hi, have you looked at the sample at zephyr/samples/basic/blinky_pwm? It shows how to handle basic operation of the PWM.

    I believe the new duty cycle should be represented at the start of the next period.

  • Yes, I've definitely got the dedicated pwm module working.  I just need/want to make certain that it's operating at 16 MHz. 

  • I don't know why I didn't think about turning on PWM logging to figure out what was really happening under the covers.  

    At any rate, I've got dialed in now.  Still couldn't write a book about it but it works lol