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

migrating from SDK8 to SDK12 app_timer , APP_PWM_INSTANCE(PWM2, 2);

Hi,

Im migrating from SDK8 to SDK12

app_timer crashes

Debugging at app_error.c shows m_error_data to be :

softdevice, pc 0x000104AE, fault ID 0x00000001 error_info 0x0000000 

I have 4 other timers existing, this specific timer 'start' command crashes the softdevice

removing other timers does not solve this problem

edit : after further debugging I have come to the conclusion that the problem is using PWM2 - Timer2 . that is APP_PWM_INSTANCE(PWM2, 2); 

it fails after it tries to set a duty cycle or tick > 0 

I am using 2 timers for three PWM channels

PWM1 based on Timer1 supports two PWM Channels which don't exhibit the problem

PWM2 based on Timer2 support one PWM channel and it if I keep the duty cycle / tick count to 0 I don't experience this issue

edit : 

it was an sdk_config.h problem, timer2 was not enabled. 

------------------ old comments 

this is my syntax

APP_TIMER_DEF(m_leds_timer_id);

app_timer_create(&m_leds_timer_id, APP_TIMER_MODE_REPEATED, led_effect_timeout_handler);

app_timer_start(m_leds_timer_id, interval, NULL);

would appreciate help,

especially understanding the pc 0x000104AE

Thanks in advance

Parents
  • Strange that this is issue is only triggered by this particular timer instance. Is the SD assert triggered immediately after timer start and do you get the same assert if you comment out the code in led_effect_timeout_handler()? 

  • edit : after further debugging I have come to the conclusion that the problem is using PWM2 - Timer2 . that is APP_PWM_INSTANCE(PWM2, 2); 

    it fails after it tries to set a duty cycle or tick > 0 

    I am using 2 timers for three PWM channels

    PWM1 based on Timer1 supports two PWM Channels which don't exhibit the problem

    PWM2 based on Timer2 support one PWM channel and it if I keep the duty cycle / tick count to 0 I don't experience this issue

    is there some special precaution that should be taken when using several timers for PWM ?

    as for your question, it doesn't occur immediately, apparently it only happens when it eventually attempts to 

    set a duty cycle with 'app_pwm_channel_duty_ticks_set'

    Thanks 

    Eran

    -------------------------------------

    this is my syntax

    APP_PWM_INSTANCE(PWM1, 1); // Create the instance "PWM1" using TIMER1.
    APP_PWM_INSTANCE(PWM2, 2); // Create the instance "PWM2" using TIMER2.

    ..

    /* 2-channel PWM, 200Hz, output on DK LED pins. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(100L, LED_RED, LED_GREEN);
    app_pwm_config_t pwm2_cfg = APP_PWM_DEFAULT_CONFIG_1CH(100L, LED_BLUE);
    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
    pwm2_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_ready_callback);
    err_code = app_pwm_init(&PWM2, &pwm2_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
    app_pwm_enable(&PWM2);

    ...

    void leds_color_set(uint8_t red, uint8_t green, uint8_t blue)
    {
    #define USE_RGB_COLOR_ORDER_STANDARD

    #ifdef USE_RGB_COLOR_ORDER_STANDARD
    while (app_pwm_channel_duty_set(&PWM1, 0, red) == NRF_ERROR_BUSY);
    while (app_pwm_channel_duty_set(&PWM1, 1, green) == NRF_ERROR_BUSY);
    while (app_pwm_channel_duty_set(&PWM2, 0, blue) == NRF_ERROR_BUSY); 

Reply
  • edit : after further debugging I have come to the conclusion that the problem is using PWM2 - Timer2 . that is APP_PWM_INSTANCE(PWM2, 2); 

    it fails after it tries to set a duty cycle or tick > 0 

    I am using 2 timers for three PWM channels

    PWM1 based on Timer1 supports two PWM Channels which don't exhibit the problem

    PWM2 based on Timer2 support one PWM channel and it if I keep the duty cycle / tick count to 0 I don't experience this issue

    is there some special precaution that should be taken when using several timers for PWM ?

    as for your question, it doesn't occur immediately, apparently it only happens when it eventually attempts to 

    set a duty cycle with 'app_pwm_channel_duty_ticks_set'

    Thanks 

    Eran

    -------------------------------------

    this is my syntax

    APP_PWM_INSTANCE(PWM1, 1); // Create the instance "PWM1" using TIMER1.
    APP_PWM_INSTANCE(PWM2, 2); // Create the instance "PWM2" using TIMER2.

    ..

    /* 2-channel PWM, 200Hz, output on DK LED pins. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(100L, LED_RED, LED_GREEN);
    app_pwm_config_t pwm2_cfg = APP_PWM_DEFAULT_CONFIG_1CH(100L, LED_BLUE);
    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
    pwm2_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_ready_callback);
    err_code = app_pwm_init(&PWM2, &pwm2_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
    app_pwm_enable(&PWM2);

    ...

    void leds_color_set(uint8_t red, uint8_t green, uint8_t blue)
    {
    #define USE_RGB_COLOR_ORDER_STANDARD

    #ifdef USE_RGB_COLOR_ORDER_STANDARD
    while (app_pwm_channel_duty_set(&PWM1, 0, red) == NRF_ERROR_BUSY);
    while (app_pwm_channel_duty_set(&PWM1, 1, green) == NRF_ERROR_BUSY);
    while (app_pwm_channel_duty_set(&PWM2, 0, blue) == NRF_ERROR_BUSY); 

Children
Related