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

What is the minimum Timer interval for nRF52832

Hello,

      I'm using nRF5 SDK with version 15 and nRF52832 IC. I want to sample some data with 3200Hz sampling rate. I can set the timer minimum 1ms Which means 1000Hz. How can I adjust the Timer for microSecond values.

Best Regards

Parents
  • I assume you are referring to the app timer. The app timer uses ISRs to accomplish its task. There is no realistic way to execute microsecond ISRs on a 64MHz processor.

    If you need to sample data at microsecond intervals you will need to use ppi/gpiote to execute that and likely DMA to handle the data. 

  • Can you give me an example code about How to do it with ppi/gpiote ?

    I am also using the SoftDevice.

  • I can't give you anything very specific since all applications are unique.  Also, your requirement of sampling some data is a little vague.

    However here is one link on configuring ppi/gpiote: https://devzone.nordicsemi.com/f/nordic-q-a/24283/measuring-interrupt-interval-with-app_timer/95578#95578

    There is plenty of info on the ppi/gpiote in the product spec. The example above uses the registers.  Nordic has a driver for it, but I rarely use drivers since most of our code has very specific requirement.

    Basically you need to create a timer that runs at 3200Hz then have the timer drive your data sampling. At this point I don't know what you are sampling.  If it sits on gpio then send the task endpoint to gpio to assert your external module.  If instead you need to have the nRF do something, then use the event from the timer to create an ISR. You will have to be careful on the ISR. Again this is a 64MHz processor, so you really can't process many opcodes at a 3200Hz interval.  Also, you won't be able to run the softdevice since the latency from the softdevice can be as much as 800usec to 1.2msec.

  • I wrote a code sample but the LED is toggling in 25ms which is the TIMER_LED period.

    #define PPI_EXAMPLE_TIMER2_INTERVAL             (100)  
    static const nrf_drv_timer_t m_timer2 = NRF_DRV_TIMER_INSTANCE(2);
    static nrf_ppi_channel_t m_ppi_channel2;
    
    static void ppi_init(void)
    {
        uint32_t err_code = NRF_SUCCESS;
    
        err_code = nrf_drv_ppi_init();
        APP_ERROR_CHECK(err_code);
    
    
        /* Configure 2nd available PPI channel to start TIMER0 counter at TIMER2 COMPARE[0] match,
         * which is every odd number of seconds.
         */
        err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel2);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_ppi_channel_assign(m_ppi_channel2,
                                              nrf_drv_timer_event_address_get(&m_timer2,
                                                                              NRF_TIMER_EVENT_COMPARE0),
                                              nrf_drv_timer_task_address_get(&TIMER_LED,
                                                                             NRF_TIMER_TASK_START));
        APP_ERROR_CHECK(err_code);
        
        // Enable both configured PPI channels
        err_code = nrf_drv_ppi_channel_enable(m_ppi_channel2);
        APP_ERROR_CHECK(err_code);
    }
    
    static void timer2_event_handler(nrf_timer_event_t event_type, void * p_context)
    {
        nrf_gpio_pin_toggle(19);
    }
    
    static void TimerInit2(void)
    {
        // Check TIMER2 configuration for details.
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
        ret_code_t err_code = nrf_drv_timer_init(&m_timer2, &timer_cfg, timer2_event_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_timer_extended_compare(&m_timer2,
                                       NRF_TIMER_CC_CHANNEL0,
                                       nrf_drv_timer_us_to_ticks(&m_timer2,
                                                                 PPI_EXAMPLE_TIMER2_INTERVAL),
                                       NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                       true);
    }

  • I do not see a reference in your code for timer_led. You should post the entire main.c 

    Plus it would be better for you to start with my example. Your approach requires the gpio driver and an ISR to work. Both of these require much more code execution.

Reply Children
Related