This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWM

how to set the duty cycle of a pwm? how to set the pwm frequency?  what is that nrf_pwm_values_common_t in the pwm ?

  • static uint16_t /*const*/ seq_values[] =
    {
    0x8000,
    0,
    0x8000,
    0,
    0x8000,
    0
    };

    why only 6 values what actually it represents? what actually seq_values represents? if i set the sequence value > top_value in pwm configuration waht will happen?

    if i use common mode then is it sequence value range is 0-100?

  • static void demo3(void)
    {
    NRF_LOG_INFO("Demo 3");

    /*
    * This demo uses only one channel, which is reflected on LED 1.
    * The LED blinks three times (200 ms on, 200 ms off), then it stays off
    * for one second.
    * This scheme is performed three times before the peripheral is stopped.
    */

    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
    };
    APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
    m_used |= USED_PWM(0);

    // This array cannot be allocated on stack (hence "static") and it must
    // be in RAM (hence no "const", though its content is not changed).
    static uint16_t /*const*/ seq_values[] =
    {
    0x8000,
    0,
    0x8000,
    0,
    0x8000,
    0
    };
    nrf_pwm_sequence_t const seq =
    {
    .values.p_common = seq_values,
    .length = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats = 0,
    .end_delay = 4
    };

    (void)nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 3, NRF_DRV_PWM_FLAG_STOP);
    }

    why in common mode sequence_value is 0x8000,0,0x8000,0,0x8000,0?

  • Hello,

    What will you be using the PWM for? It might be easier for you to familiarize with the PWM Library (app_pwm) instead of the PWM driver, in many cases. We have a separate example that demonstrate its usage.

    The PWM Library lets you set the PWM duty cycle and frequency directly, like you ask about in your original ticket, it is also easier to get started with than using the PWM driver directly.

    Best regards,
    Karl

  • thats fine but i need to know how to set the duty cycle and frequency in the pwm driver ?

  • thats fine but i need to know how to set the duty cycle and frequency in the pwm driver ?

Related