I've got some basic filter code setup (but not yet tested).

Dependencies:   BLE_API Queue mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Revision:
61:1de72bdab0ef
Child:
62:8e2fbe131b53
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sampler.cpp	Sun May 17 00:27:16 2015 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+
+// Use a ticker (interrupt routine) to sample the ADC at a fast rate (is 200Khz the max?), and generate an average value
+// Use another ticker to grab the average value at 1Khz, which is the maximum useful sampling rate for HRV data collection
+
+
+// These need to divide evenly into each other
+#define SAMPLING_RATE_HZ 4000   
+#define READ_OUT_RATE_HZ 50  
+
+#define SAMPLES_PER_READOUT (SAMPLING_RATE_HZ/READ_OUT_RATE_HZ)
+
+AnalogIn ECG(P0_1);  
+Ticker sampling_rate;
+int NumReadings=0;
+uint32_t ReadingTotal=0;
+void (*SamplingFunction)(uint32_t);
+
+
+void ADC_read()
+{    
+    NumReadings++;
+    ReadingTotal += ECG.read_u16();    
+    if (NumReadings == SAMPLES_PER_READOUT) 
+    {
+        SamplingFunction(ReadingTotal/NumReadings);
+        ReadingTotal = 0;
+        NumReadings = 0;
+    }                                                                                                 
+}
+
+void setup_sampler(void (*function)(uint32_t)) 
+{
+    SamplingFunction = function;
+    sampling_rate.attach(&ADC_read, 1.0/SAMPLING_RATE_HZ);
+}