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

Parents
  • 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

  • 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

Reply
  • 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

Children
  • Pooja Uchagaonkar said:
    The value returned by APP_TIMER_TICKS is nearly about 1000 ms above 4000 mSec.

     Not sure what you mean by this. If you input 4000 ms and the frequency is 16384 Hz, this should return 65536. Which data type is NORMAL_MODE_MEAS_INTERVAL?

    Pooja Uchagaonkar said:
    APP_TIMER_CONFIG_RTC_FREQUENCY set as 16384 Hz.

    Is the value of the config set to 16384, or is it set to 1 (which corresponds to a frequency of 16384 Hz)?

  • Hi Jorgan,

    Sorry for late reply. I was on leave due to unwell health conditions so couldn't able to work on this.

    Yes, right. The value of APP_TIMER_CONFIG_RTC_FREQUENCY is set to1 in sdk_config file, which corresponds to a frequency of 16384 Hz)

    The value returned by APP_TIMER_TICKS is 0 for 4000 mSec.

    The value returned by APP_TIMER_TICKS 16384 for 1000 mSec and 63989 value for 3900 mSec. But for 4050 mSec, it returns APP_TIMER_TICKS value is 819.

    If I set APP_TIMER_CONFIG_RTC_FREQUENCY is 0, which corresponds to a frequency of 32767 Hz, The value returned by APP_TIMER_TICKS value 0 for 2000mSec and 4000 mSec.

    If I set APP_TIMER_CONFIG_RTC_FREQUENCY is 3, which corresponds to a frequency of 8192 Hz, The value returned by APP_TIMER_TICKS  is  49152 for 6000 mSec and APP_TIMER_TICKS value 0 for 8000 mSec .

    My observation is APP_TIMER_TICKS value is overload from 65535 to 0. I have done exercise for different time set and frequency by setting APP_TIMER_CONFIG_RTC_FREQUENCY 0 to 4 which is corresponds to  32768 Hz, 16384 Hz, 10922 Hz and 8192 Hz frequency respectivelyI added reading file herewith. Can you please check at once and revert me on this?

    AppTimerTicks reading for different rtc timer frequnecy.xlsx

    If I set APP_TIMER_CONFIG_RTC_FREQUENCY is 3, which corresponds to frequency of 8192 Hz, I got resolution from 6 Sec to 0.15 mSec which I need to set in my application. But I just have one question that, the ble stack and soft device use same app_timer_2 for ble_stack and soft device. If I set 8192 Hz frequency, is this suitable for this?

  • The APP_TIMER_TICKS macro is defined like this:

    ((uint32_t)ROUNDED_DIV(                        \
                (MS) * (uint64_t)APP_TIMER_CLOCK_FREQ,         \
                1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))

    As you can see, it returns a 32-bit unsigned integer, and uses a 64-bit unsigned integer internally to make sure the accuracy is not lost due to variable overflow.

    This is why I asked what data type NORMAL_MODE_MEAS_INTERVAL is in your application. If this is declared as uint16_t and this is the variable you check for the output from APP_TIMER_TICKS, you will get the behavior that you describe.

Related