Workaround for impedance measurement bug #19
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addressing the issue regarding impedance test bugs with the new board.
After some debugging, it seemed that the issue with running impedance measurements at sampling rates other than 30 kS/s was failing due to the estimate of how many blocks to write/read. The original line to compute
numBlocks
wasint numBlocks = ceil((numPeriods + 2) * period / 60.0);
numBlocks
is used to determine themaxTimeStep
and the number of frames to read via setting the number ofRhd2000DataBlocks
. Feels like the magic number,60.0
is a potential culprit... doesn't really make sense... the denominator here should probably befloat(SAMPLES_PER_DATA_BLOCK(board->evalBoard->isUSB3())
.I tried to sus out what the correct calculation should be by digging through other parts of the code and the chip datasheets - but after much obsessive sleuthing and several changes that made things better but still fail, I decided I should just pass on what I've found to someone more familiar with how the chip works.
As a workaround, I noticed that in
DeviceThread::scanPorts
, the sampling rate is temporarily set to 30 kS/s. For now, I've used this approach for impedance measurements as well and it seems to work. I have a component with a known of impedance of 4.5 kOhm which I used to verify this change.Some potential clues on the core issue:
board->evalBoard->readDataBlocks(numBlocks, dataQueue);
. The infinite loop is a result of(*frame)->dev_idx == DEVICE_RHYTHM
being false for the frames that are read.numBlocks = 11
which is the value computed for 30 kS/s, there's no more infinite loop for all sampling rates but the calculation only correct for 30 ks/S. Not sure if there's anything to this, but it makes me think that somewhere else in the code, there's another value that implicitly depends on the sampling rate being 30 kS/s - like60.0
. Or maybe some chip setting for outputs isn't set or isn't compatible with subsampled rates?maxStepSize
.60.0
tofloat(SAMPLES_PER_DATA_BLOCK(board->evalBoard->isUSB3())
, and the impedance test still works for 30 kS/s even thoughnumBlocks = 3
now. However, it still fails for other rates. Nonetheless, I left this change in since I think it's correct.In any case, the current workaround seems fine, and it doesn't add much time to switch sampling rates.