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

App timer misfire after 4000 mSec interval

Hi,

Greetings !

I want to take continuous 40 reading of adc by varying time interval between readings based on RPM value. I want timer interval resolution from 6 Sec to 15 mSec. For that I used app_timer for repeated mode. I start timer when reading count is zero and stop it after completion of 40 readings. Here I used, app_timer as like...

void start_normal_mode()
{
   ret_code_t err_code;
   SamplingRate = 60/(40 * RPM);
   SamplingRate_ms = SamplingRate * 1000;
   
   NORMAL_MODE_MEAS_INTERVAL = APP_TIMER_TICKS(SamplingRate_ms);

   if(normal_mode_reading_count == 0)
   {
      err_code = app_timer_start(m_normalmode_timer_id, NORMAL_MODE_MEAS_INTERVAL, NULL);
      APP_ERROR_CHECK(err_code);
   }
}

I got perfect reading when timer interval is less than 4000mSec but timer is misfires above 4000mSec. It instantly fires and didn’t get perfect time interval.

In same code, I used one more app_timer for fixed interval 1 Sec and I also check it for 6 Sec time interval. It works perfectly. So I didn’t recognized why this second one timer misbehaving like this

Will you please help me out in this matter?

Thanks,

Pooja Uchagaonkar

  • Hi,

    The behavior you describe sounds similar to this known issue. The solution is to switch to using app_timer2, which was introduced in SDK 15.0.0 as an experimental library. In SDK 16.0.0, app_timer2 was updated to production quality and used by default for all examples.

    Instructions on how to switch app_timer are given in this post.

    Best regards,
    Jørgen

  • Sorry Sir for late reply,

    I was trying to resolve this with by implementing nrf_drv_timer, but same thing happened. 

    But I didn't check it with app_timer2. I will do this and let you know soon.

    Thanks,

    Pooja Uchagaonkar

  • HI Jorgen,

    I used app_timer2. But issue is not resolved. I also checked with this nrf_drv_timer but same issue happened. Can you please help me out?

  • What is the value returned by APP_TIMER_TICKS when you input a value above 4000 ms? What is the config APP_TIMER_CONFIG_RTC_FREQUENCY set to?

    Can you provide a minimal example that can be used to reproduce this issue?

  • Hi Jorgen,

    The project is almost in last phase and I completely stuck due to this issue. Thank you so much for your reply.  

    The value returned by APP_TIMER_TICKS is nearly about 1000 ms above 4000 mSec.

    APP_TIMER_CONFIG_RTC_FREQUENCY set as 16384 Hz.

    Actually I used this app timer for variable time interval as shown below code. Here the RPM range varies from 0.25 to 100 and so accordingly time interval changing from 6 Sec to 15 mSec. 

    It works perfectly for 100 to 0.38 RPM setting but misfires below this. 

    void start_normal_mode()
    {
       ret_code_t err_code;
       float RPM;
       RPM = Read_RPM_Param_from_flash();
       SamplingRate = 60/(40 * RPM);
       SamplingRate_ms = SamplingRate * 1000;
    
       NORMAL_MODE_MEAS_INTERVAL = APP_TIMER_TICKS(SamplingRate_ms);
    
       if(normal_mode_reading_count == 0)
       {
          err_code = app_timer_start(m_normalmode_timer_id, NORMAL_MODE_MEAS_INTERVAL, NULL);
          APP_ERROR_CHECK(err_code);
       }
    }
    
    //code in main while loop
    while(1)
    {
        if(RTCMinInterrpt_Flag == 1)    
         {          
            External_RTC_GetDateTime(&GetRTC_DateTime);
            printf("\r\n Date- %d/%d/%d, Time- %d:%d:%d", GetRTC_DateTime.date, GetRTC_DateTime.month, GetRTC_DateTime.year, GetRTC_DateTime.hour, GetRTC_DateTime.minute, GetRTC_DateTime.second);
            RTCMinInterrpt_Flag = 0;
            Normal_Mode_Reading_Flag = 1;
            normal_mode_hour_index++;
            start_normal_mode();       //calculate sampling rate and start timer
         }
         
         if(Normal_Mode_Timer_Flag == 1)
             {          
                 if(normal_mode_reading_count < normal_mode_total_reading)
                 {
                      read_datetimestamp_and_sensor_Data();
                      memcpy(&Normal_Mode_Handling_Buff[normal_mode_reading_count*NormalMode_OneReadingcount], DateTimeStamp_and_Sensor_Buff, sizeof(DateTimeStamp_and_Sensor_Buff));
                      normal_mode_reading_count ++;
                      Normal_Mode_Timer_Flag = 0;
                  }
                  else
                  {
                        normal_mode_reading_count = 0;
                        app_timer_stop(m_normalmode_timer_id);     //stop timer                               
                  }
              }      
    }

     Please let me know if anything I can do

    Regards,

    Pooja Uchagaonkar

Related