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

PWM on port 1

How do I use PWM on a GPIO on port 1 on SDK 15.2? The PWM library examples only sends in the pin number and seems to assume port 0. This answer seemed a bit complex and I'm not sure if it is outdated https://devzone.nordicsemi.com/f/nordic-q-a/22983/how-do-i-change-pwm-port-to-1-on-example-low_power_pwm

static void pwm_init(void)
{
    ret_code_t err_code;

    enum { PERIOD_US = 20L};
    /* 1-channel PWM, 50 kHz, output on DK LED pins. */
    app_pwm_config_t pwm0_cfg = APP_PWM_DEFAULT_CONFIG_1CH(PERIOD_US, BSP_LED_2);
$
    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM0, &pwm0_cfg, NULL);
    APP_ERROR_CHECK(err_code);
}

Parents
  • Hi,

    I would recommend using the PWM driver instead because it uses the PWM peripheral. Not TIMERS+PPI+GPIOTE like the PWM library does (initially made for the 51 that didn't have dedicated PWM HW). However, if you prefer using the library, let me know, and I will find out how you can use port 1. 

  • I can use the PWM driver if that is the recommended library. But as far as I can see it has the same issue. The port doesn't seem to be specified in the PWM driver example. Below from demo3 code.

     nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                BSP_LED_0 | NRF_DRV_PWM_PIN_INVERTED, // channel 0
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
            },
            .irq_priority = APP_IRQ_PRIORITY_LOWEST,
            .base_clock   = NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 25000,
            .load_mode    = NRF_PWM_LOAD_COMMON,
            .step_mode    = NRF_PWM_STEP_AUTO
        };

Reply
  • I can use the PWM driver if that is the recommended library. But as far as I can see it has the same issue. The port doesn't seem to be specified in the PWM driver example. Below from demo3 code.

     nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                BSP_LED_0 | NRF_DRV_PWM_PIN_INVERTED, // channel 0
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
            },
            .irq_priority = APP_IRQ_PRIORITY_LOWEST,
            .base_clock   = NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 25000,
            .load_mode    = NRF_PWM_LOAD_COMMON,
            .step_mode    = NRF_PWM_STEP_AUTO
        };

Children
Related