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

Problem with PWM and Timer simultaneous with WS2812B leds

I'm using nRF52832 SDK board with softdevice s132_nrf52_5.0.0 and SDK 14.2. The program compile without an error. I tested the led and timer separately and these work.

When the timer throws the timeout_handler and try to send pwm to set ws2812b leds, the program crashed.

<error> app: ERROR 3735928559 [Unknown error code] at C:\Nordic_Semi\nRF5_SDK_14
.2.0_17b948a\components\drivers_nrf\pwm\nrf_drv_pwm.c:286

when I comment the part code of to send pwm to leds, it works fine.

static void animation_timeout_handler(void * p_context)
{   

 //set_pixel_RED(0);
 //nrf_drv_WS2812_show(); //error, send pwm to leds.

 NRF_LOG_INFO("animation_counter %d", counter_iteration);
 counter_iteration--;
 if(counter_iteration<=0){
    stop_animation_timer();
    counter_iteration = ITERATION_MAX;
 }   
}

I'm using app_timer.h in timer, and nrf_drv_pwm.h to pwm0.

Parents
  • Thanks Sigurd, My mystake was that I had wrongly initialized (I had not added it) the module nrf_drv_WS2812_init(pin) in which pwm was initialized. There was no error in compile.

    void nrf_drv_WS2812_init(uint8_t pin)
    {
    
    nrf_gpio_cfg_output(pin);
    nrf_gpio_pin_clear(pin);
    
    uint32_t err_code;
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            pin, // 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_LOW,
        .base_clock   = NRF_PWM_CLK_16MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = PERIOD_TICKS,
        .load_mode    = NRF_PWM_LOAD_COMMON,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    
    err_code = nrf_drv_pwm_init(&m_pwm0, &config0, NULL);  // handler is NULL
    APP_ERROR_CHECK(err_code);
    
    for(int i = 0; i < NRF_PWM_VALUES_LENGTH(m_seq_values); i++)
    {
        m_seq_values[i] = ONE_HIGH_TICKS;
    }
    	
    for(int i = 0; i < RESET_ZEROS_AT_START; i++)
    {
    m_seq_values[i] = 0x8000;
    }
    
    m_seq_values[NR_OF_PIXELS * 24 + RESET_ZEROS_AT_START] = 0x8000;
    
    nrf_drv_pwm_simple_playback(&m_pwm0, &m_seq, 1, 0);
    }
    
Reply
  • Thanks Sigurd, My mystake was that I had wrongly initialized (I had not added it) the module nrf_drv_WS2812_init(pin) in which pwm was initialized. There was no error in compile.

    void nrf_drv_WS2812_init(uint8_t pin)
    {
    
    nrf_gpio_cfg_output(pin);
    nrf_gpio_pin_clear(pin);
    
    uint32_t err_code;
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            pin, // 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_LOW,
        .base_clock   = NRF_PWM_CLK_16MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = PERIOD_TICKS,
        .load_mode    = NRF_PWM_LOAD_COMMON,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    
    err_code = nrf_drv_pwm_init(&m_pwm0, &config0, NULL);  // handler is NULL
    APP_ERROR_CHECK(err_code);
    
    for(int i = 0; i < NRF_PWM_VALUES_LENGTH(m_seq_values); i++)
    {
        m_seq_values[i] = ONE_HIGH_TICKS;
    }
    	
    for(int i = 0; i < RESET_ZEROS_AT_START; i++)
    {
    m_seq_values[i] = 0x8000;
    }
    
    m_seq_values[NR_OF_PIXELS * 24 + RESET_ZEROS_AT_START] = 0x8000;
    
    nrf_drv_pwm_simple_playback(&m_pwm0, &m_seq, 1, 0);
    }
    
Children
No Data
Related