6 Replies Latest reply on Jul 9, 2015 9:25 PM by prayook

    timing inconsistency in the first few rounds of fine timeout callback

      My goal is to have timing consistency from the point I call bleprofile_StartTimer(); to the first time of fine timeout callback.

       

      At the point I start timer

      life=4;    //to observe only the first few rounds of the callback
      bleprofile_regTimerCb(print_time_and_kill, NULL);
      startTimerTimestamp = bleapputils_currentNativeBtClk();
      bleprofile_StartTimer();
      // bleapputils_Sleep(50);    //sleep for 5 ms
      
      
      
      
      

       

      At the callback function

      void print_time_and_kill()
      {
        ble_trace1(":%u",bleapputils_BtClksSince(startTimerTimestamp));
        if(--life==0)
        {
            bleprofile_KillTimer();
        }
      }
      
      
      
      
      

       

      the code do nothing after bleprofile_StartTimer();

      fine_timer_interval = 12.5 ms

       

      First case (without bleapputils_Sleep in line 5)

      The time gap between the point I start timer and the first callback will vary so much in the range of 1 - 40 units (0.3125 - 12.5 ms)

      but the time gap between two consecutive callbacks is very consistent at 40 units (12.5 ms)

       

      I've notice that in the output Console, these 3 lines will be printed before the first callback is called. (important clue)

      16:49:51   Fine Timer(12 ms, 80/sec)

      16:49:51   Fine TImer tick 1

      16:49:51   Normal Timer(0 s, 0 tick)

      16:49:51 - :31

      16:49:51 - :71

      16:49:51 - :111

      16:49:51 - :151

       

      Second case (with bleapputils_Sleep in line 5)

      In this case, those three lines are printed after the first callback like this.

      17:29:29 - :18

      17:29:29   Fine Timer(12 ms, 80/sec)

      17:29:29   Fine TImer tick 1

      17:29:29   Normal Timer(0 s, 0 tick)

      17:29:29 - :42

      17:29:29 - :82

      17:29:29 - :122

      In this case, the time gap between the point I start timer and the first callback is very consistent at 18 units.(5.625 ms)

      But the gap between the first and the second callback becomes the inconsistent part instead.

      Any gaps after the second callback are consistent at 40 units (12.5 ms)

       

      =================================================================

      My hypothesis is that the code that generate those 3 lines about Fine and Normal Timer are the source of inconsistency.

      Where is it from?

      and How can I skip them to make all time gaps more consistent?

       

      or Anyone know a workaround for this issue?

       

      Thanks,