Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API Queue mbed nRF51822
Fork of BLE_HeartRate by
sampler.cpp
00001 #include "mbed.h" 00002 #include <qrsdet.h> 00003 // Use a ticker (interrupt routine) to sample the ADC at a fast rate (is 200Khz the max?), and generate an average value 00004 // Use another ticker to grab the average value at 1Khz, which is the maximum useful sampling rate for HRV data collection 00005 00006 00007 // These need to divide evenly into each other 00008 00009 // 3 means sample at 8x read-out rate - SAMPLE_RATE is defined in qrsdet.h 00010 #define SHIFT_FOR_READ_OUT 1 00011 #define ADC_RATE (SAMPLE_RATE<<SHIFT_FOR_READ_OUT) 00012 #define READ_OUT_RATE_HZ SAMPLE_RATE 00013 00014 #define SAMPLES_PER_READOUT (1<<SHIFT_FOR_READ_OUT) 00015 00016 AnalogIn ECG(P0_1); 00017 Ticker sampling_rate; 00018 int NumReadings=0; 00019 int32_t ReadingTotal=0; 00020 void (*SamplingFunction)(uint32_t); 00021 00022 00023 void ADC_read() 00024 { 00025 NumReadings++; 00026 ReadingTotal += ECG.read_u16(); 00027 if (NumReadings == SAMPLES_PER_READOUT) 00028 { 00029 SamplingFunction(ReadingTotal>>SHIFT_FOR_READ_OUT); 00030 ReadingTotal = 0; 00031 NumReadings = 0; 00032 } 00033 } 00034 00035 void setup_sampler(void (*function)(uint32_t)) 00036 { 00037 SamplingFunction = function; 00038 sampling_rate.attach(&ADC_read, 1.0/ADC_RATE); 00039 }
Generated on Sun Jul 24 2022 05:18:22 by
1.7.2
