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

pwm

Hi every body,

There is a problem with pwm driver example in demo3 part! after downloading, the board led is just on as it must, but after changing top_value there is no changing in led brightness!

If somebody know, please let me know how to change the brightness?

Kind regards

  • after changing top_value

    to what? and how did you change it?

  • Thank you for replying. i saw your post before which it was about set a fixed duty cycle. i want to turn the led on with different brightness . My main goal is using these different brightness for making different color in one RGB led.

    i dont need the led go from 0 to 100 or vice versa. just a constant led brightness.

  • I mean to say that for example turning an led on with 80 percent brightness or 10 percent or...

  • moreover i put it bellow code instead of demo 3:

    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_2MHz,//NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 32768, // = 0x8000
            .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[] =
        {
            0x3000,
    //        0x2000,
    //        0x4000,
    //        0x6000,
    //        0x7FFF,
    //        0x8000
        };
        nrf_pwm_sequence_t const seq =
        {
            .values.p_common = seq_values,
            .length          = NRF_PWM_VALUES_LENGTH(seq_values),
            .repeats         = 0,
            .end_delay       = 0
        };
    
        (void)nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 3, NRF_DRV_PWM_FLAG_LOOP);
    }

  • So what, exactly, happens when you run that code?

    And what were you expecting to happen?

    And what testing / debugging / investigation have you done to find the problem?

Related