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

inner and outer application timers, is it a problem?

Hi everyone,

I have one problem with the application timer. When I change the state of characteristic to the value of 1, the following code is executed:

   err_code = app_timer_stop(m_mass_timer_id);        					   
   p_mass->load_cell_calibration.flag_offset = 1; 				
   err_code = app_timer_start(m_mass_timer_id, MASS_MEAS_100MS_INTERVAL ,NULL);
   APP_ERROR_CHECK(err_code);        			   			   					
    			

The m_mass_timer_id handler is defined as:

    static void mass_timer_handler(void * p_context)
    { 

  uint8_t          err_code; 
  	
	  
		if(m_mass.mass_flag == 1) 
		{											
				
				m_mass.mass_flag = 0;

				err_code = app_timer_start(m_mass_one_cycle_timer_id, MASS_MEAS_30MS_INTERVAL, NULL);
				APP_ERROR_CHECK(err_code);
				SEGGER_RTT_WriteString(0, "MASS_TIMER\n");
				err_code = app_timer_start(m_mass_timer_id, MASS_MEAS_INTERVAL, NULL);
				APP_ERROR_CHECK(err_code);							
							
					
		}		
		else
		{
			SEGGER_RTT_WriteString(0, "MISTAKE\n");
		}	
	
}              			
    				

where m_mass_one_cyler_timer is executed by the following code:

static void mass_one_cycle_timer_handler(void * p_context)
{ 
	

	uint8_t err_code; 	

			if(m_mass.load_cell_calibration.flag_offset == 1)
			{
				
				err_code = ble_mgs_offset_load_cell_update(&m_mass,0); 			
        APP_ERROR_CHECK(err_code); 
								

        }

			m_mass.mass_flag = 1;			



}

If I change the state of characteristic a few times in a row, then the mass_timer_handler does not instantly execute but it holds on for a few seconds. I do not get any error and I do not know why this latency occurs. I am using SDK 10. The initialization of both timers are defined by the following code:

static void timers_init(void)
{
   
	  APP_TIMER_APPSH_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, true);
    uint8_t err_code;	

		
	  err_code = app_timer_create(&m_mass_timer_id, APP_TIMER_MODE_SINGLE_SHOT, mass_timer_handler);
	  APP_ERROR_CHECK(err_code);
//		
		err_code = app_timer_create(&m_mass_one_cycle_timer_id, APP_TIMER_MODE_SINGLE_SHOT, mass_one_cycle_timer_handler);
	  APP_ERROR_CHECK(err_code);
      	 
}

I would kindly appreciate your assistance on this issue.

Edit: A few minutes ago, I tested the program only with timer m_mass_timer_id I removed timer m_mass_one_cycle_timer_id, but I got the same problem as was described.

 static void mass_timer_handler(void * p_context)
        { 
    
               uint8_t          err_code;       	
    	  
    		if(m_mass.mass_flag == 1) 
    		{											
    				
    				if(m_mass.load_cell_calibration.flag_offset == 1)
    			{
    				
    				err_code = ble_mgs_offset_load_cell_update(&m_mass,0); 			
                               APP_ERROR_CHECK(err_code);    								
    
                       }      
    				
    				SEGGER_RTT_WriteString(0, "MASS_TIMER\n");
    				err_code = app_timer_start(m_mass_timer_id, MASS_MEAS_INTERVAL, NULL);
    				APP_ERROR_CHECK(err_code);							
    							
    					
    		}		
    		else
    		{
    			SEGGER_RTT_WriteString(0, "MISTAKE\n");
    		}	
    	
    }              	

	

I hope that I will get reply to my problem as fast as possible.

Thanks in advance.

Best regards Mike

Parents
  • Thanks for this useful information. It makes sense now. I have one additional question which is somehow related to this topic. As I already mentioned I use the scheduler for softdevice and timers. It means that the timers are executed in the main loop. The code in timer usually ends with calling a pstorage function in which the calculated variables are stored. I do not know which of the following solutions are better one: 1) pstorage function is called directly from the timer (it is possible to do because the timer is executed in the main loop) or 2) to call the function app_sched_event_put() in timer and thus additional event is generated in the scheduler.

    Thanks for help in advance Mike

  • I noticed that you are using some flags in your handlers. Have you declared these volatile? It is not completely clear to me how all your timers are connected, but since you are starting and stopping timers in your handlers based on the status of these flags maybe the timings get skewed if the flags aren't handled properly by the compiler.

Reply Children
No Data
Related