This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

TIMER counting micros

Hi

I am struggling with timer in counter mode. What i need is the counter to calculate time between each loop in microseconds. I do not want time interrupts i just need a function which will return me time in microseconds (like on arduino). 

Greetings

  • I just did it and it is not working for me i have an error:


    Compiling ‘main.c’
    14> In file included from ../../../../../../modules/nrfx/nrfx.h:45,
    14> from ../../../../../../modules/nrfx/hal/nrf_gpio.h:44,
    14> from ../../../../../../components/boards/boards.h:43,
    14> from C:\Users\koron\Desktop\nRF5_SDK_17.1.0_ddde560\examples\peripheral\twi_scanner\main.c:2:
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:72:39: error: 'NRFX_TIMER0_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_TWIM0_INST_IDX'?
    14> ../../../../../../modules/nrfx/drivers/nrfx_common.h:113:37: note: in definition of macro 'NRFX_CONCAT_3_'
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:72:25: note: in expansion of macro 'NRFX_CONCAT_3'
    14> C:\Users\koron\Desktop\nRF5_SDK_17.1.0_ddde560\examples\peripheral\twi_scanner\main.c:46:37: note: in expansion of macro 'NRFX_TIMER_INSTANCE'
    14> In file included from C:\Users\koron\Desktop\nRF5_SDK_17.1.0_ddde560\examples\peripheral\twi_scanner\main.c:14:
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:110:50: error: 'NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY' undeclared (first use in this function); did you mean 'NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY'?
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:110:50: note: in definition of macro 'NRFX_TIMER_DEFAULT_CONFIG'
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:110:50: note: each undeclared identifier is reported only once for each function it appears in
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:110:50: note: in definition of macro 'NRFX_TIMER_DEFAULT_CONFIG'
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:111:45: error: 'NRFX_TIMER_DEFAULT_CONFIG_MODE' undeclared (first use in this function); did you mean 'NRFX_TIMER_DEFAULT_CONFIG'?
    14> C:\Users\koron\Desktop\nRF5_SDK_17.1.0_ddde560\examples\peripheral\twi_scanner\main.c:55:37: note: in expansion of macro 'NRFX_TIMER_DEFAULT_CONFIG'
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:112:50: error: 'NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH' undeclared (first use in this function); did you mean 'NRFX_TIMER_DEFAULT_CONFIG'?
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:112:50: note: in definition of macro 'NRFX_TIMER_DEFAULT_CONFIG'
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:113:27: error: 'NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY' undeclared (first use in this function); did you mean 'NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY'?
    14> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:113:27: note: in definition of macro 'NRFX_TIMER_DEFAULT_CONFIG'
    Build failed

    And i do not know how to fix this 
    I attached "nrfx_timer.h"

  • Have you enabled the TIMER instance you are going to use in the sdk_config.h file?
    Please also remove or comment out any legacy definitions, such as TIMER_ENABLED. You should have NRFX_TIMER_ENABLED defined in your sdk_config, and TIMER_ENABLED should not be present as this may cause issues.

    Please also note that some peripheral instances are blocked or restricted by the SoftDevice.

    Ceranthor said:
    I attached "nrfx_timer.h"

    I do not see any attached file - but you should not modify the driver directly, in any case, since this might break it.

    Best regards,
    Karl

  • I do not have this option in sdk_config.h but i have it on another example "simple timer" and i not know how to add this part to sdk config.

  • You can add the entire nrfx_timer_* section from the other project into your sdk_config for your main project. Make sure to look through the configurations to ensure that they are configured to your requirements.

    // <e> NRFX_TIMER_ENABLED - nrfx_timer - TIMER periperal driver
    //==========================================================
    #ifndef NRFX_TIMER_ENABLED
    #define NRFX_TIMER_ENABLED 0
    #endif
    // <q> NRFX_TIMER0_ENABLED  - Enable TIMER0 instance
     
    
    #ifndef NRFX_TIMER0_ENABLED
    #define NRFX_TIMER0_ENABLED 0
    #endif
    
    // <q> NRFX_TIMER1_ENABLED  - Enable TIMER1 instance
     
    
    #ifndef NRFX_TIMER1_ENABLED
    #define NRFX_TIMER1_ENABLED 0
    #endif
    
    // <q> NRFX_TIMER2_ENABLED  - Enable TIMER2 instance
     
    
    #ifndef NRFX_TIMER2_ENABLED
    #define NRFX_TIMER2_ENABLED 0
    #endif
    
    // <q> NRFX_TIMER3_ENABLED  - Enable TIMER3 instance
     
    
    #ifndef NRFX_TIMER3_ENABLED
    #define NRFX_TIMER3_ENABLED 0
    #endif
    
    // <q> NRFX_TIMER4_ENABLED  - Enable TIMER4 instance
     
    
    #ifndef NRFX_TIMER4_ENABLED
    #define NRFX_TIMER4_ENABLED 0
    #endif
    
    // <o> NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY  - Timer frequency if in Timer mode
     
    // <0=> 16 MHz 
    // <1=> 8 MHz 
    // <2=> 4 MHz 
    // <3=> 2 MHz 
    // <4=> 1 MHz 
    // <5=> 500 kHz 
    // <6=> 250 kHz 
    // <7=> 125 kHz 
    // <8=> 62.5 kHz 
    // <9=> 31.25 kHz 
    
    #ifndef NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY
    #define NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY 0
    #endif
    
    // <o> NRFX_TIMER_DEFAULT_CONFIG_MODE  - Timer mode or operation
     
    // <0=> Timer 
    // <1=> Counter 
    
    #ifndef NRFX_TIMER_DEFAULT_CONFIG_MODE
    #define NRFX_TIMER_DEFAULT_CONFIG_MODE 0
    #endif
    
    // <o> NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH  - Timer counter bit width
     
    // <0=> 16 bit 
    // <1=> 8 bit 
    // <2=> 24 bit 
    // <3=> 32 bit 
    
    #ifndef NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH
    #define NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH 0
    #endif
    
    // <o> NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_TIMER_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_TIMER_CONFIG_LOG_ENABLED
    #define NRFX_TIMER_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_TIMER_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_TIMER_CONFIG_LOG_LEVEL
    #define NRFX_TIMER_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_TIMER_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_TIMER_CONFIG_INFO_COLOR
    #define NRFX_TIMER_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_TIMER_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_TIMER_CONFIG_DEBUG_COLOR
    #define NRFX_TIMER_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>


    Best regards,
    Karl

  • Now it works perfectly i changed freq to 1 Mhz and to 32 bit. Thank you for help 

Related