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

Can timers be accessed after advertisement starts?

I am new to nrf52.

I want to configure TIMER1 as a counter.

However it does not count. I have added it after advertisement_init

Does the nrf52 have any such limitations? How to handle them?

Parents


  • TIMER0-5 mode counter is deprecated? Does that mean we can no longer user TIMER0-5 as a counter?

    Only RTC can be used?

  • Raja Sumant said:
    TIMER0-5 mode counter is deprecated? Does that mean we can no longer user TIMER0-5 as a counter?

    No, only the Counter mode is deprecated - this because the LowPowerCounter mode has been added with the nRF52 series.
    You can absolutely use the TIMER0-5 as counters, just use the LowPowerCounter mode.
    You may of course still also use the deprecated Counter mode, but it comes with a higher power consumption.

    Please see this ticket for further detail.

    Best regards,
    Karl



  • Hello Karl. The Timer Driver method fails to work.

    When I use this,
    const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(3);

    It does not compile. Hence I am working directly with the registers.

  • Hello again,

    Raja Sumant said:
    The Timer Driver method fails to work.

    When I use this,
    const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(3);

    It does not compile. Hence I am working directly with the registers.

    Are you familiar with the sdk_config.h file and its function?
    The compilation error you receive in your included picture is caused by the particular timer not being enabled in the sdk_config.
    Without seeing your sdk_config.h it is hard to say for certain, but I would guess that some *_TIMER_ENABLED defines are not set.
    Could you check this out for me, and let me know their current value?

    Are you able to run the TIMER example from the SDK that I referenced earlier?
    If you are, you may take a look in its sdk_config file, to see how the TIMER driver is set up there.

    I would highly recommend making use of the drivers and libraries provided in the SDK - sincit will save you a lot of work and fine-reading of the register descriptions.

    Best regards,
    Karl

     




  • Hello. This is how it looks. 

    I am unable to run the timer.

    I was only able to get the RTC counter working.

  • Hi,

    Raja Sumant said:
    This is how it looks. 

    I am unable to run the timer.

    Thank you for clarifying on this. From these lines, it seems that you have indeed not enabled the timers.
    So, if you are using the NRFX_TIMER driver, you will need to enable it in the sdk_config ( NRFX_TIMER_ENABLED 1 ), along with the particular timer instances you are intending to use ( NRFX_TIMER3_ENABLED 1 ). If you are using NRFX_DRIVER you will need to remove the legacy NRF_DRV_TIMER_* defines from your sdk_config file. If you are using the legacy nrf_drv_timer driver, then you will need to set their ENABLED's.
    Please do this, and let me know if you are able to use the timer drivers following this.

    For future reference, it is always easiest if you share code using the "Insert -> code" option, instead of including screenshots. Screenshots often does not contain all the right information.

    Best regards,
    Karl

  • I was finally able to get the TIMER working but with registers and not the drv.

    I really do not know what is wrong with the driver. 

    uint32_t counter = 0 ;
    
    static void hfclk_config(void) // Select 
    {
        ret_code_t err_code = nrf_drv_clock_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_clock_hfclk_request(NULL);
    }
    
    static void counter_init()
    {
            // Initialize timer module.
    	NRF_TIMER1->TASKS_STOP = 1;	
            NRF_TIMER1->MODE = 2;// Low Power counter mode
            NRF_TIMER1->PRESCALER = 8;	// Fhck / 2^8 
    	//NRF_TIMER1->CC[0] = 62500;	// 62500 - 1s
    	NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
    	NRF_TIMER1->TASKS_CLEAR = 1;
    }
    
    static void read_TIM(void) // Follow 3 steps.
    {
     NRF_TIMER1->TASKS_COUNT = 1; // Step 1
    NRF_TIMER1->TASKS_CAPTURE[1] = 1 ; // Step 2. The TIMER implements one capture task for every available capture/compare register.
    //Every time the CAPTURE[n] task is triggered, the Counter value is copied to the CC[n] register.
    counter = NRF_TIMER1->CC[1]; // Step 3
    while(counter < 10000)
    {
    NRF_TIMER1->TASKS_COUNT=1;
    NRF_TIMER1->TASKS_CAPTURE[1] = 1 ; // The TIMER implements one capture task for every available capture/compare register.
    //Every time the CAPTURE[n] task is triggered, the Counter value is //copied to the CC[n] register.
    counter = NRF_TIMER1->CC[1];
    }
    
    NRF_TIMER1->TASKS_CLEAR = 1;
    }
    
    
    int main(void)
    {
    
        hfclk_config();
        counter_init();
        NRF_TIMER1->TASKS_START = 1; // Important 
       
     for (;;)
        {
        read_TIM();
       
      }
    }

Reply
  • I was finally able to get the TIMER working but with registers and not the drv.

    I really do not know what is wrong with the driver. 

    uint32_t counter = 0 ;
    
    static void hfclk_config(void) // Select 
    {
        ret_code_t err_code = nrf_drv_clock_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_clock_hfclk_request(NULL);
    }
    
    static void counter_init()
    {
            // Initialize timer module.
    	NRF_TIMER1->TASKS_STOP = 1;	
            NRF_TIMER1->MODE = 2;// Low Power counter mode
            NRF_TIMER1->PRESCALER = 8;	// Fhck / 2^8 
    	//NRF_TIMER1->CC[0] = 62500;	// 62500 - 1s
    	NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
    	NRF_TIMER1->TASKS_CLEAR = 1;
    }
    
    static void read_TIM(void) // Follow 3 steps.
    {
     NRF_TIMER1->TASKS_COUNT = 1; // Step 1
    NRF_TIMER1->TASKS_CAPTURE[1] = 1 ; // Step 2. The TIMER implements one capture task for every available capture/compare register.
    //Every time the CAPTURE[n] task is triggered, the Counter value is copied to the CC[n] register.
    counter = NRF_TIMER1->CC[1]; // Step 3
    while(counter < 10000)
    {
    NRF_TIMER1->TASKS_COUNT=1;
    NRF_TIMER1->TASKS_CAPTURE[1] = 1 ; // The TIMER implements one capture task for every available capture/compare register.
    //Every time the CAPTURE[n] task is triggered, the Counter value is //copied to the CC[n] register.
    counter = NRF_TIMER1->CC[1];
    }
    
    NRF_TIMER1->TASKS_CLEAR = 1;
    }
    
    
    int main(void)
    {
    
        hfclk_config();
        counter_init();
        NRF_TIMER1->TASKS_START = 1; // Important 
       
     for (;;)
        {
        read_TIM();
       
      }
    }

Children
  • Raja Sumant said:
    I was finally able to get the TIMER working but with registers and not the drv.

    I am happy to hear that you have got the timer up and running, great!

    Raja Sumant said:
    I really do not know what is wrong with the driver. 

    I suppose it is not configured correctly. If you would like to see the simplest TIMER driver usage please take a look at the TIMER peripheral example from the SDK that I recommended earlier. You need to make sure that the correct source code file is included in your project, and that the sdk_config file has the correct _ENABLED defines set to 1. You can cross reference your own project's sdk_config against the sdk_config of the TIMER example.

    Alternatively, if you would like to give the driver another try then you can show me the code in which you attempted to make it work with, and the corresponding sdk_config file.

    If you are satisfied with manipulating the TIMER registers directly then you are free to do so, of course.

    Best regards,
    Karl

Related