/** * Get a scaled sample from the output of the oversample and average engine for the channel. * * The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset(). * Using oversampling will cause this value to be higher resolution, but it will update more slowly. * Using averaging will cause this value to be more stable, but it will update more slowly. * * @param channel The channel to read. * @return A scaled sample from the output of the oversample and average engine for the channel. */ float AnalogModule::GetAverageVoltage(UINT32 channel) { INT32 value = GetAverageValue(channel); UINT32 LSBWeight = GetLSBWeight(channel); INT32 offset = GetOffset(channel); UINT32 oversampleBits = GetOversampleBits(channel); float voltage = ((LSBWeight * 1.0e-9 * value) / (float)(1 << oversampleBits)) - offset * 1.0e-9; return voltage; }
/** * Get a scaled sample from the output of the oversample and average engine for the channel. * * The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset(). * Using oversampling will cause this value to be higher resolution, but it will update more slowly. * Using averaging will cause this value to be more stable, but it will update more slowly. * * @param channel The channel to read. * @return A scaled sample from the output of the oversample and average engine for the channel. */ float AnalogModule::GetAverageVoltage(uint32_t channel) { int32_t value = GetAverageValue(channel); uint32_t LSBWeight = GetLSBWeight(channel); int32_t offset = GetOffset(channel); uint32_t oversampleBits = GetOversampleBits(channel); float voltage = ((LSBWeight * 1.0e-9 * value) / (float)(1 << oversampleBits)) - offset * 1.0e-9; return voltage; }
/** * Get a scaled sample from the output of the oversample and average engine for the channel. * * The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset(). * Using oversampling will cause this value to be higher resolution, but it will update more slowly. * Using averaging will cause this value to be more stable, but it will update more slowly. * * @param channel The channel to read. * @return A scaled sample from the output of the oversample and average engine for the channel. */ float AnalogModule::GetAverageVoltage(UINT32 channel) { INT32 value = GetAverageValue(channel); UINT32 LSBWeight = m_module->readLSBWeight(channel - 1, &status); INT32 offset = m_module->readOffset(channel - 1, &status); UINT32 oversampleBits = GetOversampleBits(channel); float voltage = ((LSBWeight * 1.0e-9 * value) / (float)(1 << oversampleBits)) - offset * 1.0e-9; wpi_assertCleanStatus(status); return voltage; }
/** * Resets the accumulator to the initial value. */ void AnalogInput::ResetAccumulator() { if (StatusIsFatal()) return; int32_t status = 0; resetAccumulator(m_port, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); if (!StatusIsFatal()) { // Wait until the next sample, so the next call to GetAccumulator*() // won't have old values. const float sampleTime = 1.0f / GetSampleRate(); const float overSamples = 1 << GetOversampleBits(); const float averageSamples = 1 << GetAverageBits(); Wait(sampleTime * overSamples * averageSamples); } }