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

NRF52840 when using Timer and BLE services I found a problem

when using the TIMER,  I set the TIMER's time_ticks=53328 which means that every 3.33ms, the TIMER will call its callback function and start ADC sample. However,  when I use BLE services and TIMER at the same time, I found that ADC cannot be triggered every 3.33ms precisely and the error is about 1%. The crystal oscillator I use is 32MHZ and I thought the error should not be so big. So whether the BLE services will affect the accuracy of  TIMER when using them at the same time?

Parents
  • May you show your create timer ,start timer ,stop timer & timer callback handler procedure?

    Have you ever trigger timer with repeat mode?

  • void saadc_sampling_event_init(void)
    {
    	  ret_code_t err_code;
    	 // uint32_t time_ticks=53028;	
        uint32_t time_ticks=53672;//3.33ms tick=53328 TIME3=16MHZ,1ms tick=16000	
    	
        err_code = nrf_drv_ppi_init();
        APP_ERROR_CHECK(err_code);
    	  	
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    	  
        err_code = nrfx_timer_init(&TIMER_ADC, &timer_cfg, timer_adc_event_handler);
        APP_ERROR_CHECK(err_code);
       
        nrf_drv_timer_extended_compare(&TIMER_ADC, NRF_TIMER_CC_CHANNEL3, time_ticks, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK, true);
    	   uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&TIMER_ADC,
                                                                                    NRF_TIMER_CC_CHANNEL3);
    	
        uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();
        err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    	
    	  err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
                                              timer_compare_event_addr,
                                              saadc_sample_task_addr);
    																					
    		APP_ERROR_CHECK(err_code);	 																		
    }

    this is my code about Timer and ppi init

Reply
  • void saadc_sampling_event_init(void)
    {
    	  ret_code_t err_code;
    	 // uint32_t time_ticks=53028;	
        uint32_t time_ticks=53672;//3.33ms tick=53328 TIME3=16MHZ,1ms tick=16000	
    	
        err_code = nrf_drv_ppi_init();
        APP_ERROR_CHECK(err_code);
    	  	
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    	  
        err_code = nrfx_timer_init(&TIMER_ADC, &timer_cfg, timer_adc_event_handler);
        APP_ERROR_CHECK(err_code);
       
        nrf_drv_timer_extended_compare(&TIMER_ADC, NRF_TIMER_CC_CHANNEL3, time_ticks, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK, true);
    	   uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&TIMER_ADC,
                                                                                    NRF_TIMER_CC_CHANNEL3);
    	
        uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();
        err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    	
    	  err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
                                              timer_compare_event_addr,
                                              saadc_sample_task_addr);
    																					
    		APP_ERROR_CHECK(err_code);	 																		
    }

    this is my code about Timer and ppi init

Children
Related