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

Can I use app_timer and nrf_drv_timer together?

Hi,

I am having problems with using BLE along with gpiote and ppi for measuring the delay between two waveforms and sending the delay between them to an app using bluetooth. I am measuring the delay using the nrf timer driver, which i've learnt that it's very precise. And I got the code for BLE from a Nordic's tutorial that uses app_timer (RTC). However, they are not working together... is there conflict between these two? How do I make the code work???

Thank you in advance.

Parents
  • HI fernandolns , i had the same problem as you ,could you tell me how to resolve it ?

    Thank you in advance.

  • Hi, sorry for taking long to answer, It's been couple of months, but what I changed in order to make it work if I remember clearly was a line at main. There was a conflict with buttons and leds, then I removed it:

    // buttons_leds_init(&erase_bonds);

    (See if it works only by removing this line)

    (I found out by debugging)

    I'm sure this was the problem. However I remember that I also tried changing something with the timers.

    Instead of channel 0, it became channel 1 in this function being used in my main:

    nrf_drv_timer_capture_get(&m_timer, NRF_TIMER_CC_CHANNEL1)

    then at nrf_drv_config.h I changed this /*TIMER*/ part, to this:

    (changing the lines TIMER1_ENABLED 1 and TIMER0_ENABLED 0)

    like this:

    /* TIMER */
    #define TIMER0_ENABLED 0
    
    #if (TIMER0_ENABLED == 1)
    #define TIMER0_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER0_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER0_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_32Bit
    #define TIMER0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER0_INSTANCE_INDEX      0
    #endif
    
    #define TIMER1_ENABLED 1
    
    #if (TIMER1_ENABLED == 1)
    #define TIMER1_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER1_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER1_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER1_INSTANCE_INDEX      (TIMER0_ENABLED)
    #endif
     
    #define TIMER2_ENABLED 0
    
    #if (TIMER2_ENABLED == 1)
    #define TIMER2_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER2_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER2_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER2_INSTANCE_INDEX      (TIMER1_ENABLED+TIMER0_ENABLED)
    #endif
    
    #define TIMER3_ENABLED 0
    
    #if (TIMER3_ENABLED == 1)
    #define TIMER3_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER3_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER3_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER3_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER3_INSTANCE_INDEX      (TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
    #endif
    
    #define TIMER4_ENABLED 0
    
    #if (TIMER4_ENABLED == 1)
    #define TIMER4_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER4_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER4_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER4_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER4_INSTANCE_INDEX      (TIMER3_ENABLED+TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
    #endif
    
    
    #define TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
    

    I also put this next part at nrf_drv_timer.h:

    #define TIMER0_INSTANCE_INDEX 0
    #define TIMER1_INSTANCE_INDEX TIMER0_INSTANCE_INDEX+TIMER0_ENABLED
    #define TIMER2_INSTANCE_INDEX TIMER1_INSTANCE_INDEX+TIMER1_ENABLED
    #define TIMER3_INSTANCE_INDEX TIMER2_INSTANCE_INDEX+TIMER2_ENABLED
    #define TIMER4_INSTANCE_INDEX TIMER3_INSTANCE_INDEX+TIMER3_ENABLED

    becoming like this, the beginnig of nrf_drv_timer.h when adding that:

    /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
     *
     * The information contained herein is property of Nordic Semiconductor ASA.
     * Terms and conditions of usage are described in detail in NORDIC
     * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
     *
     * Licensees are granted free, non-transferable use of the information. NO
     * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
     * the file.
     *
     */
    
    /**@file
     * @addtogroup nrf_timer Timer HAL and driver
     * @ingroup    nrf_drivers
     * @brief      Timer APIs.
     * @details    The timer HAL provides basic APIs for accessing the registers
     *             of the timer. The timer driver provides APIs on a higher level.
     *
     * @defgroup   lib_driver_timer Timer driver
     * @{
     * @ingroup    nrf_timer
     * @brief      Multi-instance timer driver.
     */
    
    #ifndef NRF_DRV_TIMER_H__
    #define NRF_DRV_TIMER_H__
    
    #include "nordic_common.h"
    #include "nrf_drv_config.h"
    #include "nrf_timer.h"
    #include "sdk_errors.h"
    #include "nrf_assert.h"
    
    /**
     * @brief Timer driver instance data structure.
     */
    typedef struct
    {
        NRF_TIMER_Type * p_reg;            ///< Pointer to the structure with TIMER peripheral instance registers.
        uint8_t          instance_id;      ///< Driver instance index.
        uint8_t          cc_channel_count; ///< Number of capture/compare channels.
    } nrf_drv_timer_t;
    
    #define ENABLED_TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
    
    #define TIMER0_INSTANCE_INDEX 0
    #define TIMER1_INSTANCE_INDEX TIMER0_INSTANCE_INDEX+TIMER0_ENABLED
    #define TIMER2_INSTANCE_INDEX TIMER1_INSTANCE_INDEX+TIMER1_ENABLED
    #define TIMER3_INSTANCE_INDEX TIMER2_INSTANCE_INDEX+TIMER2_ENABLED
    #define TIMER4_INSTANCE_INDEX TIMER3_INSTANCE_INDEX+TIMER3_ENABLED
    
    
    /**
     * @brief Macro for creating a timer driver instance.
     */

Reply
  • Hi, sorry for taking long to answer, It's been couple of months, but what I changed in order to make it work if I remember clearly was a line at main. There was a conflict with buttons and leds, then I removed it:

    // buttons_leds_init(&erase_bonds);

    (See if it works only by removing this line)

    (I found out by debugging)

    I'm sure this was the problem. However I remember that I also tried changing something with the timers.

    Instead of channel 0, it became channel 1 in this function being used in my main:

    nrf_drv_timer_capture_get(&m_timer, NRF_TIMER_CC_CHANNEL1)

    then at nrf_drv_config.h I changed this /*TIMER*/ part, to this:

    (changing the lines TIMER1_ENABLED 1 and TIMER0_ENABLED 0)

    like this:

    /* TIMER */
    #define TIMER0_ENABLED 0
    
    #if (TIMER0_ENABLED == 1)
    #define TIMER0_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER0_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER0_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_32Bit
    #define TIMER0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER0_INSTANCE_INDEX      0
    #endif
    
    #define TIMER1_ENABLED 1
    
    #if (TIMER1_ENABLED == 1)
    #define TIMER1_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER1_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER1_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER1_INSTANCE_INDEX      (TIMER0_ENABLED)
    #endif
     
    #define TIMER2_ENABLED 0
    
    #if (TIMER2_ENABLED == 1)
    #define TIMER2_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER2_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER2_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER2_INSTANCE_INDEX      (TIMER1_ENABLED+TIMER0_ENABLED)
    #endif
    
    #define TIMER3_ENABLED 0
    
    #if (TIMER3_ENABLED == 1)
    #define TIMER3_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER3_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER3_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER3_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER3_INSTANCE_INDEX      (TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
    #endif
    
    #define TIMER4_ENABLED 0
    
    #if (TIMER4_ENABLED == 1)
    #define TIMER4_CONFIG_FREQUENCY    NRF_TIMER_FREQ_16MHz
    #define TIMER4_CONFIG_MODE         TIMER_MODE_MODE_Timer
    #define TIMER4_CONFIG_BIT_WIDTH    TIMER_BITMODE_BITMODE_16Bit
    #define TIMER4_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TIMER4_INSTANCE_INDEX      (TIMER3_ENABLED+TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
    #endif
    
    
    #define TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
    

    I also put this next part at nrf_drv_timer.h:

    #define TIMER0_INSTANCE_INDEX 0
    #define TIMER1_INSTANCE_INDEX TIMER0_INSTANCE_INDEX+TIMER0_ENABLED
    #define TIMER2_INSTANCE_INDEX TIMER1_INSTANCE_INDEX+TIMER1_ENABLED
    #define TIMER3_INSTANCE_INDEX TIMER2_INSTANCE_INDEX+TIMER2_ENABLED
    #define TIMER4_INSTANCE_INDEX TIMER3_INSTANCE_INDEX+TIMER3_ENABLED

    becoming like this, the beginnig of nrf_drv_timer.h when adding that:

    /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
     *
     * The information contained herein is property of Nordic Semiconductor ASA.
     * Terms and conditions of usage are described in detail in NORDIC
     * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
     *
     * Licensees are granted free, non-transferable use of the information. NO
     * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
     * the file.
     *
     */
    
    /**@file
     * @addtogroup nrf_timer Timer HAL and driver
     * @ingroup    nrf_drivers
     * @brief      Timer APIs.
     * @details    The timer HAL provides basic APIs for accessing the registers
     *             of the timer. The timer driver provides APIs on a higher level.
     *
     * @defgroup   lib_driver_timer Timer driver
     * @{
     * @ingroup    nrf_timer
     * @brief      Multi-instance timer driver.
     */
    
    #ifndef NRF_DRV_TIMER_H__
    #define NRF_DRV_TIMER_H__
    
    #include "nordic_common.h"
    #include "nrf_drv_config.h"
    #include "nrf_timer.h"
    #include "sdk_errors.h"
    #include "nrf_assert.h"
    
    /**
     * @brief Timer driver instance data structure.
     */
    typedef struct
    {
        NRF_TIMER_Type * p_reg;            ///< Pointer to the structure with TIMER peripheral instance registers.
        uint8_t          instance_id;      ///< Driver instance index.
        uint8_t          cc_channel_count; ///< Number of capture/compare channels.
    } nrf_drv_timer_t;
    
    #define ENABLED_TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
    
    #define TIMER0_INSTANCE_INDEX 0
    #define TIMER1_INSTANCE_INDEX TIMER0_INSTANCE_INDEX+TIMER0_ENABLED
    #define TIMER2_INSTANCE_INDEX TIMER1_INSTANCE_INDEX+TIMER1_ENABLED
    #define TIMER3_INSTANCE_INDEX TIMER2_INSTANCE_INDEX+TIMER2_ENABLED
    #define TIMER4_INSTANCE_INDEX TIMER3_INSTANCE_INDEX+TIMER3_ENABLED
    
    
    /**
     * @brief Macro for creating a timer driver instance.
     */

Children
Related