/** * Set the sample rate on the module. * * This is a global setting for the module and effects all channels. * * @param samplesPerSecond The number of samples per channel per second. */ void AnalogModule::SetSampleRate(float samplesPerSecond) { // TODO: This will change when variable size scan lists are implemented. // TODO: Need float comparison with epsilon. //wpi_assert(!sampleRateSet || GetSampleRate() == samplesPerSecond); m_sampleRateSet = true; // Compute the convert rate UINT32 ticksPerSample = (UINT32)((float)kTimebase / samplesPerSecond); UINT32 ticksPerConversion = ticksPerSample / GetNumChannelsToActivate(); // ticksPerConversion must be at least 80 if (ticksPerConversion < 80) { wpi_fatal(SampleRateTooHigh); ticksPerConversion = 80; } // Atomically set the scan size and the convert rate so that the sample rate is constant tAI::tConfig config; config.ScanSize = GetNumChannelsToActivate(); config.ConvertRate = ticksPerConversion; m_module->writeConfig(config, &status); // Indicate that the scan size has been commited to hardware. SetNumChannelsToActivate(0); wpi_assertCleanStatus(status); }
/** * Create a new instance of an analog module. * * Create an instance of the analog module object. Initialize all the parameters * to reasonable values on start. * Setting a global value on an analog module can be done only once unless subsequent * values are set the previously set value. * Analog modules are a singleton, so the constructor is never called outside of this class. * * @param slot The slot in the chassis that the module is plugged into. */ AnalogModule::AnalogModule(UINT32 slot) : Module(slot) , m_module (NULL) , m_sampleRateSet (false) , m_numChannelsToActivate (0) { status = 0; AddToSingletonList(); m_module = new tAI(SlotToIndex(slot), &status); SetNumChannelsToActivate(kAnalogChannels); SetSampleRate(kDefaultSampleRate); for (UINT32 i = 0; i < kAnalogChannels; i++) { m_module->writeScanList(i, i, &status); SetAverageBits(i + 1, kDefaultAverageBits); SetOversampleBits(i + 1, kDefaultOversampleBits); } if (m_registerWindowSemaphore == NULL) { // Needs to be global since the protected resource spans both module singletons. m_registerWindowSemaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); } wpi_assertCleanStatus(status); }
/** * Create a new instance of an analog module. * * Create an instance of the analog module object. Initialize all the parameters * to reasonable values on start. * Setting a global value on an analog module can be done only once unless subsequent * values are set the previously set value. * Analog modules are a singleton, so the constructor is never called outside of this class. * * @param moduleNumber The analog module to create (1 or 2). */ AnalogModule::AnalogModule(UINT8 moduleNumber) : Module(nLoadOut::kModuleType_Analog, moduleNumber) , m_module (NULL) , m_sampleRateSet (false) , m_numChannelsToActivate (0) { AddToSingletonList(); tRioStatusCode localStatus = NiFpga_Status_Success; m_module = tAI::create(m_moduleNumber - 1, &localStatus); wpi_setError(localStatus); SetNumChannelsToActivate(kAnalogChannels); SetSampleRate(kDefaultSampleRate); for (UINT32 i = 0; i < kAnalogChannels; i++) { m_module->writeScanList(i, i, &localStatus); wpi_setError(localStatus); SetAverageBits(i + 1, kDefaultAverageBits); SetOversampleBits(i + 1, kDefaultOversampleBits); } if (m_registerWindowSemaphore == NULL) { // Needs to be global since the protected resource spans both module singletons. m_registerWindowSemaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); } }