Test using the base BLE_HeartRate example to see the effect of increasing the "ticker" rate on stability (intending to do AnalogIn around 1ms rate)

Dependencies:   BLE_API mbed nRF51822

Revision:
8:7407b18dfc5d
Parent:
7:ec41c916136a
Child:
9:1cfd6c7055b5
--- a/main.cpp	Wed Oct 01 07:09:28 2014 +0000
+++ b/main.cpp	Wed Oct 01 07:34:46 2014 +0000
@@ -21,7 +21,7 @@
 #include "DeviceInformationService.h"
 
 BLEDevice  ble;
-DigitalOut led1(LED1);
+DigitalOut indicatorLed1(LED1);
 DigitalOut indicatorLed2(LED2);
 
 #define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
@@ -61,7 +61,7 @@
     if (callbackCount == 500)
     {
         callbackCount = 0;
-        led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
+        indicatorLed1 = !indicatorLed1;
         /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
          * heavy-weight sensor polling from the main thread. */
         triggerSensorPolling = true;
@@ -70,9 +70,10 @@
 //    sampleTimeout.attach_us(periodicCallback, sampleIntervalUs);
 }
 
+int bleUpdateCount = 0;
 int main(void)
 {
-    led1 = 1;
+    indicatorLed1 = 1;
     indicatorLed2 = 1;
     
     // Start timer and sampling
@@ -101,20 +102,34 @@
     BatteryService battery(ble);
     DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
 
-    while (true) {
-        if (triggerSensorPolling) {
+    while (true) 
+    {
+        bool updateNow = false;
+        if (triggerSensorPolling) 
+        {
             triggerSensorPolling = false;
-
+            bleUpdateCount++;
+            if (bleUpdateCount >= 1)
+            {
+                bleUpdateCount = 0;
+                updateNow = true;
+            }
+        }
+        if (updateNow)
+        {
             /* Do blocking calls or whatever is necessary for sensor polling. */
             /* In our case, we simply update the dummy HRM measurement. */
             hrmCounter++;
-            if (hrmCounter == 175) {
+            if (hrmCounter == 175) 
+            {
                 hrmCounter = 100;
             }
 
             indicatorLed2 = !indicatorLed2;
             hrService.updateHeartRate(hrmCounter);
-        } else {
+        } 
+        else 
+        {
             ble.waitForEvent();
         }
     }