Timer operation, uneven delays

Hello everyone, I combined work with a timer and an example from ble_app_aurt pca10040 s132, the problem is that the timer does not work evenly, yes, I know about the low priority of the timer, but this does not explain why delays of 182μs can last for several seconds!

static void timer_init()
{


    NVIC_SetPriority(TIMER1_IRQn, 2);

	NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;      
	NRF_TIMER2->PRESCALER = 1;	
	
	
	NRF_TIMER2->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos);	


}



/**@snippet [Handling the data received over UART] */
void uart_event_handle(app_uart_evt_t * p_event)
{

	for(;;) {


char str[8];
int p=13;

NRF_TIMER2->TASKS_CLEAR = 1;
NRF_TIMER2->TASKS_START = 1;


    int abc=5;             ///delay check
    abc = abc + 1;


    NRF_TIMER2->TASKS_CAPTURE[0] = 1;
int k;
k = NRF_TIMER2->CC[0];

int f = k;
       sprintf (str, "%d", f);


   uint16_t length = (uint16_t)p;


int x = 5;

        if(x>0)
        {  //Read GPIO
         ble_nus_data_send (&m_nus, &str[0], &length, m_conn_handle);

      }
        else {
 
        NRF_LOG_INFO("Debug logging for UART over RTT started 888.");
	
    
}
}
}

Parents
  • Hello,

    I see a couple of potential issues with the sparse code you have supplied. First of all, you are not checking the error codes returned by SDK functions such as ble_nus_data_send. I do not think that is the reason as to why you are seeing uneven timer interrupts, but it is in general not a good practice which certainly will spawn other issues later in your development.
    Furthermore it seems that you have an infinite for-loop in your uart_handler. This is also bad practice, because you will never return to the main context, and you will block all equal-to-or-lower priority interrupts in your program.

    Please fix these things, and provide more information / more of the code if this does not resolve your issues.

    Best regards,
    Karl

Reply
  • Hello,

    I see a couple of potential issues with the sparse code you have supplied. First of all, you are not checking the error codes returned by SDK functions such as ble_nus_data_send. I do not think that is the reason as to why you are seeing uneven timer interrupts, but it is in general not a good practice which certainly will spawn other issues later in your development.
    Furthermore it seems that you have an infinite for-loop in your uart_handler. This is also bad practice, because you will never return to the main context, and you will block all equal-to-or-lower priority interrupts in your program.

    Please fix these things, and provide more information / more of the code if this does not resolve your issues.

    Best regards,
    Karl

Children
No Data
Related