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

Timer and PWM (and BLE) in nRF5 v12

(Building with nRF5 12.2.0 / armgcc)

I want to do bursts of pulses using PWM for the pulses and a TIMER to enable the bursts. I need this to be non-blocking so I can also use BLE.

Now PWM uses a timer so its inner timer will be controlled by an outer timer.

The first challenge is to make sure that the two timers are different.

APP_PWM_INSTANCE(PWM1,1); // seems to say to use Timer1
nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
.. where timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
.. which in turn does not specify a timer (.p_context = NULL)

So how can one tell the outer timer to be other than Timer1??

and BTW there's another strange thing happening when I try to build this.

#include "app_pwm.h"
err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);

gives

undefined reference to app_pwm_init

Is hard to understand as the problem goes away if I revert to the PWM example without the outer timer.

Any suggestions appreciated?

Parents
  • Thx @Bjorn, that fixes the build (I also had to add the GPIOTE stuff to sdk_config.h). Is there any doc to help me understand the configuration of timers so I can have an outer timer (TIMER2) around PWM? Pls see above.

    I'm thinking it could be something like:

    const nrf_drv_timer_t TIMER_OUTER = NRF_DRV_TIMER_INSTANCE(2);
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.p_context=&TIMER_OUTER;  // pure guesswork and evidently WRONG!!
    err_code = nrf_drv_timer_init(&TIMER_OUTER, &timer_cfg, timer_led_event_handler);
    

    So the remaining question is how to configure this outer timer.

Reply
  • Thx @Bjorn, that fixes the build (I also had to add the GPIOTE stuff to sdk_config.h). Is there any doc to help me understand the configuration of timers so I can have an outer timer (TIMER2) around PWM? Pls see above.

    I'm thinking it could be something like:

    const nrf_drv_timer_t TIMER_OUTER = NRF_DRV_TIMER_INSTANCE(2);
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.p_context=&TIMER_OUTER;  // pure guesswork and evidently WRONG!!
    err_code = nrf_drv_timer_init(&TIMER_OUTER, &timer_cfg, timer_led_event_handler);
    

    So the remaining question is how to configure this outer timer.

Children
No Data
Related