Skip to content

Commit 425849d

Browse files
committed
Fix sample rate calculation by adjusting periodTicks for clock tick discrepancies
1 parent 1bd8cf6 commit 425849d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Source/Devices/DigitalIO.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ int DigitalIO::configureDevice()
7878
if (rc != ONI_ESUCCESS)
7979
throw error_str("Could not read the base frequency register on the DigitalIO device.");
8080

81-
uint32_t periodTicks = baseFreqHz / (uint32_t)AnalogIO::getSampleRate();
81+
// NB: Two states are not accounted for when comparing clock ticks on the hardware,
82+
// therefore the periodTicks variable must be decreased by 2 to get the correct sample rate.
83+
uint32_t periodTicks = (baseFreqHz / (uint32_t)AnalogIO::getSampleRate()) - 2u;
8284
rc = deviceContext->writeRegister(deviceIdx, (uint32_t)DigitalIORegisters::SAMPLE_PERIOD, periodTicks);
8385
if (rc != ONI_ESUCCESS)
8486
throw error_str("Could not write the sample rate for polling to the DigitalIO device.");

0 commit comments

Comments
 (0)