aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers
diff options
context:
space:
mode:
authorCeimour <113631258+Ceimour@users.noreply.github.com>2023-04-30 08:50:18 -0500
committerGitHub <noreply@github.com>2023-04-30 15:50:18 +0200
commitc22e30a4a6ef014c7a5086ad47eaab7740a75ff2 (patch)
tree5afdf4ed624a8b41dc4aea723a8c8f38d726545a /src/drivers
parent40f7e1c7be6882e01058b5ccf64d5005c6105346 (diff)
Refactored Ppg for frequency based algorithm. (#1486)
New implementation of the heart rate sensor data processing using a frequency based PPG algorithm. The HRS3300 settings are fine-tuned for better signal to noise at 10Hz. The measurement delay is now set to 100ms. Enable and use the ambient light sensor. FFT implementation based on ArduinoFFT (https://github.com/kosme/arduinoFFT, GPLv3.0).
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Hrs3300.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/drivers/Hrs3300.cpp b/src/drivers/Hrs3300.cpp
index 6c47ae28..004c5362 100644
--- a/src/drivers/Hrs3300.cpp
+++ b/src/drivers/Hrs3300.cpp
@@ -16,6 +16,8 @@ using namespace Pinetime::Drivers;
/** Driver for the HRS3300 heart rate sensor.
* Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/drivers/hrs3300.py
+ *
+ * Experimentaly derived changes to improve signal/noise (see comments below) - Ceimour
*/
Hrs3300::Hrs3300(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} {
}
@@ -26,19 +28,21 @@ void Hrs3300::Init() {
Disable();
vTaskDelay(100);
- // HRS disabled, 12.5 ms wait time between cycles, (partly) 20mA drive
- WriteRegister(static_cast<uint8_t>(Registers::Enable), 0x60);
+ // HRS disabled, 50ms wait time between ADC conversion period, current 12.5mA
+ WriteRegister(static_cast<uint8_t>(Registers::Enable), 0x50);
- // (partly) 20mA drive, power on, "magic" (datasheet says both
- // "reserved" and "set low nibble to 8" but 0xe gives better results
- // and is used by at least two other HRS3300 drivers
- WriteRegister(static_cast<uint8_t>(Registers::PDriver), 0x6E);
+ // Current 12.5mA and low nibble 0xF.
+ // Note: Setting low nibble to 0x8 per the datasheet results in
+ // modulated LED driver output. Setting to 0xF results in clean,
+ // steady output during the ADC conversion period.
+ WriteRegister(static_cast<uint8_t>(Registers::PDriver), 0x2f);
- // HRS and ALS both in 16-bit mode
- WriteRegister(static_cast<uint8_t>(Registers::Res), 0x88);
+ // HRS and ALS both in 15-bit mode results in ~50ms LED drive period
+ // and presumably ~50ms ADC conversion period.
+ WriteRegister(static_cast<uint8_t>(Registers::Res), 0x77);
- // 8x gain, non default, reduced value for better readings
- WriteRegister(static_cast<uint8_t>(Registers::Hgain), 0xc);
+ // Gain set to 1x
+ WriteRegister(static_cast<uint8_t>(Registers::Hgain), 0x00);
}
void Hrs3300::Enable() {