/** * Set the Counter to return reversed sensing on the direction. * This allows counters to change the direction they are counting in the case of 1X and 2X * quadrature encoding only. Any other counter mode isn't supported. * @param reverseDirection true if the value counted should be negated. */ void Counter::SetReverseDirection(bool reverseDirection) { if (m_counter->readConfig_Mode(&status) == kExternalDirection) { if (reverseDirection) SetDownSourceEdge(true, true); else SetDownSourceEdge(false, true); } }
/** * Set the Counter to return reversed sensing on the direction. * This allows counters to change the direction they are counting in the case of 1X and 2X * quadrature encoding only. Any other counter mode isn't supported. * @param reverseDirection true if the value counted should be negated. */ void xCounter::SetReverseDirection(bool reverseDirection) { if (StatusIsFatal()) return; tRioStatusCode localStatus = NiFpga_Status_Success; if (m_counter->readConfig_Mode(&localStatus) == kExternalDirection) { if (reverseDirection) SetDownSourceEdge(true, true); else SetDownSourceEdge(false, true); } wpi_setError(localStatus); }
/** * Set the source object that causes the counter to count down. * Set the down counting DigitalSource. */ void xCounter::SetDownSource(DigitalSource *source) { if (StatusIsFatal()) return; if (m_allocatedDownSource) { delete m_downSource; m_downSource = NULL; m_allocatedDownSource = false; } m_downSource = source; if (m_downSource->StatusIsFatal()) { CloneError(m_downSource); } else { tRioStatusCode localStatus = NiFpga_Status_Success; unsigned char mode = m_counter->readConfig_Mode(&localStatus); if (mode != kTwoPulse && mode != kExternalDirection) { wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only supports DownSource in TwoPulse and ExternalDirection modes."); return; } m_counter->writeConfig_DownSource_Module(source->GetModuleForRouting(), &localStatus); m_counter->writeConfig_DownSource_Channel(source->GetChannelForRouting(), &localStatus); m_counter->writeConfig_DownSource_AnalogTrigger(source->GetAnalogTriggerForRouting(), &localStatus); SetDownSourceEdge(true, false); m_counter->strobeReset(&localStatus); wpi_setError(localStatus); } }
xCounter::xCounter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted) : m_upSource(NULL), m_downSource(NULL), m_counter(NULL), m_encodingType(encodingType) { if (encodingType != k1X && encodingType != k2X) { wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only supports 1X and 2X quadrature decoding."); return; } InitCounter(kExternalDirection); SetUpSource(upSource); SetDownSource(downSource); tRioStatusCode localStatus = NiFpga_Status_Success; if (encodingType == k1X) { SetUpSourceEdge(true, false); m_counter->writeTimerConfig_AverageSize(1, &localStatus); } else { SetUpSourceEdge(true, true); m_counter->writeTimerConfig_AverageSize(2, &localStatus); } wpi_setError(localStatus); SetDownSourceEdge(inverted, true); }
/** * Set the source object that causes the counter to count down. * Set the down counting DigitalSource. */ void Counter::SetDownSource(DigitalSource *source) { wpi_assert(m_downSource == NULL); unsigned char mode = m_counter->readConfig_Mode(&status); wpi_assert(mode == kTwoPulse || mode == kExternalDirection); m_downSource = source; m_counter->writeConfig_DownSource_Module(source->GetModuleForRouting(), &status); m_counter->writeConfig_DownSource_Channel(source->GetChannelForRouting(), &status); m_counter->writeConfig_DownSource_AnalogTrigger(source->GetAnalogTriggerForRouting(), &status); SetDownSourceEdge(true, false); m_counter->strobeReset(&status); wpi_assertCleanStatus(status); }
Counter::Counter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted) { wpi_assert(encodingType == k1X || encodingType == k2X); InitCounter(kExternalDirection); SetUpSource(upSource); SetDownSource(downSource); if (encodingType == k1X) { SetUpSourceEdge(true, false); m_counter->writeTimerConfig_AverageSize(1, &status); } else { SetUpSourceEdge(true, true); m_counter->writeTimerConfig_AverageSize(2, &status); } SetDownSourceEdge(inverted, true); }