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); }
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); }
/** * Set the source object that causes the counter to count down. * Set the down counting DigitalSource. */ void xCounter::SetDownSource(DigitalSource &source) { SetDownSource(&source); }
/** * Set the down counting source to be an analog trigger. * @param analogTrigger The analog trigger object that is used for the Down Source * @param triggerType The analog trigger output that will trigger the counter. */ void xCounter::SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType) { SetDownSource(&analogTrigger, triggerType); }
/** * Set the down counting source to be an analog trigger. * @param analogTrigger The analog trigger object that is used for the Down Source * @param triggerType The analog trigger output that will trigger the counter. */ void xCounter::SetDownSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType) { if (StatusIsFatal()) return; SetDownSource(analogTrigger->CreateOutput(triggerType)); m_allocatedDownSource = true; }
/** * Set the down counting source to be a digital input slot and channel. * * @param moduleNumber The digital module (1 or 2). * @param channel The digital channel (1..14). */ void xCounter::SetDownSource(UINT8 moduleNumber, UINT32 channel) { if (StatusIsFatal()) return; SetDownSource(new DigitalInput(moduleNumber, channel)); m_allocatedDownSource = true; }
/** * Set the down counting source to be a digital input channel. * The slot will be set to the default digital module slot. */ void Counter::SetDownSource(UINT32 channel) { if (StatusIsFatal()) return; SetDownSource(new DigitalInput(channel)); m_allocatedDownSource = true; }
/** * Set the down counting source to be an analog trigger. * @param analogTrigger The analog trigger object that is used for the Down Source * @param triggerType The analog trigger output that will trigger the counter. */ void Counter::SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType) { SetDownSource(analogTrigger.CreateOutput(triggerType)); m_allocatedDownSource = true; }
/** * Set the down counting source to be a digital input slot and channel. */ void Counter::SetDownSource(UINT32 slot, UINT32 channel) { SetDownSource(new DigitalInput(slot, channel)); }
/** * Set the down counting source to be a digital input slot and channel. * * @param moduleNumber The digital module (1 or 2). * @param channel The digital channel (1..14). */ void Counter::SetDownSource(uint8_t moduleNumber, uint32_t channel) { if (StatusIsFatal()) return; SetDownSource(new DigitalInput(moduleNumber, channel)); m_allocatedDownSource = true; }