7 Replies Latest reply on Mar 5, 2014 5:23 AM by ShawnA_01

    What is the best way to set an application timer to fire?

    legic_1490776

      I noticed the functions bleapptimer_startAppTimer() and bleapptimer_refreshAppTimer() in bleapptimer.h

       

      I thought maybe these could be used to set up a timer callback separate from the built-in ones, but they don't seem to work (or I am using them wrong).

       

      Should something like this work, or do I need to build my own timer framework to multiplex the 'fine timer' callback?

        • 1. Re: What is the best way to set an application timer to fire?
          jota_1939431

          Hello Idgirod,

           

          The functions should work - sorry that you are having problems.

          Can you post a small code snippet of how you are using them?

           

          JT

          • 2. Re: What is the best way to set an application timer to fire?
            legic_1490776

            Hi JT,

             

            Actually I think I figured out my issue, are the timeouts expressed in seconds?

            For my application I need to use a 1/10 second granularity timer, is there a similar facility based on the fine timer?

             

            Also, do I need to call bleapptimer_init()?

             

            Thanks,

            Lewis

            • 3. Re: What is the best way to set an application timer to fire?
              legic_1490776

              Here is an example code trying to use the fine timer:


              void tm_cb(UINT32 arg)

              {

              // .. do someting, this gets called every 100ms?

              // will this timer get retriggered automatically?

              }

               

              bleapptimer_startFineTimer(tm_cb, 100); // 100ms

               

              ...

               

              // later we shut down the timer

              bleapptimer_stopFineTimer();

               

               

              questions:

              1. do I need to call bleapptimer_init()?

               

              2. how does this interact with a call to

                bleprofile_regTimerCb(hello_fine_timer, hello_coarse_timer);

                bleprofile_StartTimer();

              • 4. Re: What is the best way to set an application timer to fire?
                legic_1490776

                OK, this worked after I removed the call to reTimerCb, but the timer is only firing every second, not 10 times per second.  should the call

                 

                bleapptimer_startFineTimer(tm_cb, 100);


                be 100 ms or some other unit?

                is there some other mode i need to enable?

                • 5. Re: What is the best way to set an application timer to fire?
                  jota_1939431

                  Hello idgirod,

                   

                  I would not recommend to start/stop fine timer.

                  We say in the code:

                   

                  // This function will start a fine resolution timer. It should be used with care.

                  You should use app timer, or just rely on fine timer callbacks.

                  Will this work for you?

                   

                  JT

                  • 6. Re: What is the best way to set an application timer to fire?
                    legic_1490776

                    That works for me, although I've found that after advertisements stop the fine timer changes from 10Hz to 2 Hz.

                    Is there some way to prevent it from going into this slower mode?

                    • 7. Re: What is the best way to set an application timer to fire?
                      ShawnA_01

                      To witness the problem of the timer changing from 10Hz (100mS) to 2Hz (500ms):

                      Add bleapp_trace_enable=2 in the APPLICATION_INIT().  Uncomment ble_trace1("hello...") in hello_sensor_fine_timeout().   Compile/program the TAG.  Flip Switches 2,3 of the SW4 bank so we can see debug print statements.  Power cycle the TAG, launch Terminal Program on the COM port the TAG is on to witness the debug prints.

                      They look similar to this....

                      .

                      .

                      .

                      hello_sensor_timeout:27
                      hello_sensor_fine_timeout:270
                      hello_sensor_fine_timeout:271
                      hello_sensor_fine_timeout:272
                      hello_sensor_fine_timeout:273
                      hello_sensor_fine_timeout:274
                      hello_sensor_fine_timeout:275
                      hello_sensor_fine_timeout:276
                      hello_sensor_fine_timeout:277
                      hello_sensor_fine_timeout:278
                      hello_sensor_fine_timeout:279
                      hello_sensor_timeout:28
                      hello_sensor_fine_timeout:280
                      hello_sensor_fine_timeout:281
                      hello_sensor_fine_timeout:282
                      hello_sensor_fine_timeout:283
                      hello_sensor_fine_timeout:284
                      hello_sensor_fine_timeout:285
                      hello_sensor_fine_timeout:286
                      hello_sensor_fine_timeout:287
                      hello_sensor_fine_timeout:288
                      hello_sensor_fine_timeout:289
                      hello_sensor_timeout:29


                      After 30 seconds you see the "cadence" of the message change to 2Hz:


                      AppTimer(adv, conn) stopped: 1
                      BLE_low_un_adv:timer(1)
                      hello_sensor_fine_timeout:290
                      hello_sensor_fine_timeout:291
                      hello_sensor_timeout:30
                      hello_sensor_fine_timeout:292
                      hello_sensor_fine_timeout:293
                      hello_sensor_timeout:31
                      hello_sensor_fine_timeout:294
                      hello_sensor_fine_timeout:295
                      hello_sensor_timeout:32
                      hello_sensor_fine_timeout:296
                      hello_sensor_fine_timeout:297
                      hello_sensor_timeout:33
                      hello_sensor_fine_timeout:298
                      hello_sensor_fine_timeout:299
                      hello_sensor_timeout:34
                      hello_sensor_fine_timeout:300
                      hello_sensor_fine_timeout:301
                      hello_sensor_timeout:35
                      hello_sensor_fine_timeout:302

                      My investigation indicates that after high_undirect_adv_duration expires (30 seconds), the program switches away from using high_undirect_adv_interval (32 slots) over to using low_undirect_adv_interval (1024 slots). 

                      If I now change low_undirect_adv_interval from 1024 to 32, the cadence of the output messages does not drop down to 2Hz.  Not sure of the ramifications of this change but will continue to investigate and report back.

                      Note:  fine_timer_interval has a default value of 1,000mS.  At the advice of the originator of the post, it was changed to 100mS to reproduce the exact issue described above.

                      1 of 1 people found this helpful