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

Problem with PWM in COAP simple client

Hello,

I am trying to use PWM in the simple coap client example.
Unfortunately the PWM is not working, I do not get any signal on the output pins.
If I remove the line with thread_instance_init(); then the PWM works.
I only added the following function to the simple coap client example in nRF5_SDK_for_Thread_and_Zigbee_2.0.0_29775ac:

    APP_PWM_INSTANCE(PWM1,2);  
    APP_PWM_INSTANCE(PWM2,3);  
    APP_PWM_INSTANCE(PWM3,4);                   // Create the instance "PWM1" using TIMER1.


    void init_pwm(void)
    {
        ret_code_t err_code;

        /* 1-channel PWM, 200Hz, output on DK LED pins. */
        app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(PWM_PERIOD, LED_1);
        app_pwm_config_t pwm2_cfg = APP_PWM_DEFAULT_CONFIG_1CH(PWM_PERIOD, LED_2);
        app_pwm_config_t pwm3_cfg = APP_PWM_DEFAULT_CONFIG_1CH(PWM_PERIOD, LED_3);
        

        /* Initialize and enable PWM. */
        err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
        APP_ERROR_CHECK(err_code);
        err_code = app_pwm_init(&PWM2,&pwm2_cfg,pwm_ready_callback);
        APP_ERROR_CHECK(err_code);
        err_code = app_pwm_init(&PWM3,&pwm3_cfg,pwm_ready_callback);
        APP_ERROR_CHECK(err_code);
        
        app_pwm_enable(&PWM1);
        app_pwm_enable(&PWM2);
        app_pwm_enable(&PWM3);
        
        while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);
        while (app_pwm_channel_duty_set(&PWM2, 0, 50) == NRF_ERROR_BUSY);
        while (app_pwm_channel_duty_set(&PWM3, 0, 50) == NRF_ERROR_BUSY);
    }

and here the main:

    int main(int argc, char * argv[])
    {
        log_init();
        scheduler_init();
        timer_init();


    
        thread_instance_init();
        thread_coap_init();
        thread_bsp_init();
    
        
        
        timers_start();
        
        init_pwm();

        
        while (true)
        {
          thread_process();
            app_sched_execute();
    
            if (NRF_LOG_PROCESS() == false)
            {
                thread_sleep();
            }
        }
    }

I think my problem could be related to the following post:

https://devzone.nordicsemi.com/f/nordic-q-a/45816/pwm-conflict-with-freertos-thread-example

Doing I am something wrong?

Thanks in advance
Thomas

Parents
  • Hi

    I would strongly recommend you use the nrfx_pwm driver rather than the app_pwm module for PWM. 

    The app_pwm module was originally written for the nRF51 series, which didn't have dedicated PWM hardware. The nRF52 introduced dedicated blocks for PWM, which are much more efficient to use, and allow for more total channels than the app_pwm implementation. 

    In other words I would suggest you switch to that first, and if you stil have problems we can take it from there Slight smile

    Best regards
    Torbjørn

Reply
  • Hi

    I would strongly recommend you use the nrfx_pwm driver rather than the app_pwm module for PWM. 

    The app_pwm module was originally written for the nRF51 series, which didn't have dedicated PWM hardware. The nRF52 introduced dedicated blocks for PWM, which are much more efficient to use, and allow for more total channels than the app_pwm implementation. 

    In other words I would suggest you switch to that first, and if you stil have problems we can take it from there Slight smile

    Best regards
    Torbjørn

Children
No Data
Related