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 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.

  • I can only share some parts of my code

    
    void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
        switch (event_type)
        {
            case NRF_TIMER_EVENT_COMPARE0:
            {
                nrf_gpio_pin_toggle(17);
            }
            break;
    
            default:
                //Do nothing.
                break;
        }
    }
    
    
    static void TimerInit1(void)
    {
    
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
        APP_ERROR_CHECK(err_code);
        time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
        nrf_drv_timer_extended_compare(&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
        nrf_drv_timer_enable(&TIMER_LED);
    }
    

Reply Children
Related