make baseline track rising direction slower and track falling direction faster

change some documents to be correct

add NHDT, NCLT, FDLT configurables, but user shouldn't need this.
raw-data
xyqyear 2023-12-01 15:45:15 +08:00
parent 1f0824b00c
commit 62110bef8d
2 changed files with 24 additions and 24 deletions

View File

@ -72,29 +72,24 @@ const uint8_t RELEASE_THRESHOLD_OFFSET = 0;
// NHDF = 1
// NCLF = 16
// FDLF = 4
// if some regions get stuck easily, you can try the following values
// to make the system more sensitive to environmental changes
// MHDR = 2;
// NHDR = 2;
// NCLR = 4;
// FDLR = 0;
// MHDF = 4;
// NHDF = 2;
// NCLF = 16;
// FDLF = 2;
// rising NHD is larger than falling NHD because rising is the release direction
// the rising changes are more likely to be environmental changes
// rising NCL being smaller than falling NCL is because of the same reason
// the user can experiment with different values to find the best one
// but those values should be good for most cases
const uint8_t MHDR = 2;
const uint8_t NHDR = 2;
const uint8_t NCLR = 4;
const uint8_t FDLR = 0;
const uint8_t MHDF = 2;
const uint8_t MHDR = 1;
const uint8_t NHDR = 1;
const uint8_t NCLR = 2;
const uint8_t FDLR = 2;
const uint8_t MHDF = 1;
const uint8_t NHDF = 1;
const uint8_t NCLF = 32;
const uint8_t FDLF = 4;
const uint8_t FDLF = 2;
// Don't worry about those
const uint8_t NHDT = 0;
const uint8_t NCLT = 0;
const uint8_t FDLT = 0;
// range: 0 - 3
// 0: 6 samples
@ -142,14 +137,14 @@ const uint8_t RELEASE_DEBOUNCE = 0;
// this smoothes out the signal and prevents false touch
// however, a debounce value that's too high might cause touches that are too short to be missed
// if the user notices too many false touches, try to increase this value. but don't set it too high
const uint8_t TOUCH_DEBOUNCE = 1;
const uint8_t TOUCH_DEBOUNCE = 2;
// ! the touch response time is debounce * SFI * ESI ms
// ! so in the main code we set read interval to SFI * ESI ms
// please refer to AN3889 page 9 for more information
// the user should not change those values
const uint8_t AUTO_CONFIG_RETRY = 0;
const uint8_t AUTO_CONFIG_BVA = 2;
const uint8_t AUTO_CONFIG_BVA = 0b10;
const uint8_t AUTO_CONFIG_ARE = 1;
const uint8_t AUTO_CONFIG_ACE = 1;

View File

@ -88,12 +88,10 @@ void MprSetup(Adafruit_MPR121 cap)
// those values control the baseline tracking to environment changes
// suffix R and F means rising and falling
// falling is the touch direction, rising is the release direction
// MHD is the max half delta, the max difference between the baseline and the data
// if the difference is larger than this value, the baseline will be updated (NCL and FDL conditions must also be met)
// NCL is the noise count limit, at least this many of changes must be larger than MHD to trigger a baseline update
// FDL is the filter delay count limit, the baseline will be updated after this many samples
// if a touch is detected mid way, the update is cancelled
// NHD is the noise half delta, the baseline will be changed this much when the above conditions are met
// MHD is the max half delta, if the difference between the data and baseline is lower than double this value in the specific direction, the baseline will be adjusted to the data on the next cycle
// NCL is the noise count limit, at least this mount of changes in one direction is required to trigger an update
// NHD is the noise half delta, the baseline will be changed by this amount when NCL conditions are met
// FDL is the filter delay count limit, the system will average the data for this amount of cycles before calculating with NHD and NCL
// please note that the actual update delay is affected by the second stage filter
cap.writeRegister(MPR121_MHDR, MHDR);
cap.writeRegister(MPR121_NHDR, NHDR);
@ -104,6 +102,13 @@ void MprSetup(Adafruit_MPR121 cap)
cap.writeRegister(MPR121_NCLF, NCLF);
cap.writeRegister(MPR121_FDLF, FDLF);
// there are also NHDT, NCLT and FDLT. Those are for datapoints when the electrode is touched.
// these are 0 by default, which means when a electrode is touched, the baseline will not be updated at all.
// Note: "When the data changes between these conditions, the current filter process is cancelled and all filter counters return to zero" from AN3891 page 3.
cap.writeRegister(MPR121_NHDT, NHDT);
cap.writeRegister(MPR121_NCLT, NCLT);
cap.writeRegister(MPR121_FDLT, FDLT);
// @AN3892 page 7
// 1 bit unused, 3 bit DR, 1 bit unused, 3 bit DT
// DR is the debounce count for release detection