/** * Get a value from a PWM channel. The values range from 0 to 255. * * @param channel The PWM channel to read from. * @return The raw PWM value. */ uint8_t DigitalModule::GetPWM(uint32_t channel) { CheckPWMChannel(channel); tRioStatusCode localStatus = NiFpga_Status_Success; return m_fpgaDIO->readPWMValue(channel - 1, &localStatus); //wpi_setError(localStatus); }
/** * Initialize PWMs given an module and channel. * * This method is private and is the common path for all the constructors for creating PWM * instances. Checks module and channel value ranges and allocates the appropriate channel. * The allocation is only done to help users ensure that they don't double assign channels. */ void PWM::InitPWM(UINT8 moduleNumber, UINT32 channel) { char buf[64]; Resource::CreateResourceObject(&allocated, tDIO::kNumSystems * kPwmChannels); if (!CheckPWMModule(moduleNumber)) { snprintf(buf, 64, "Digital Module %d", moduleNumber); wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf); return; } if (!CheckPWMChannel(channel)) { snprintf(buf, 64, "PWM Channel %d", channel); wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf); return; } snprintf(buf, 64, "PWM %d (Module: %d)", channel, moduleNumber); if (allocated->Allocate((moduleNumber - 1) * kPwmChannels + channel - 1, buf) == ~0ul) { CloneError(allocated); return; } m_channel = channel; m_module = DigitalModule::GetInstance(moduleNumber); m_module->SetPWM(m_channel, kPwmDisabled); m_eliminateDeadband = false; nUsageReporting::report(nUsageReporting::kResourceType_PWM, channel, moduleNumber - 1); }
/** * Set how how often the PWM signal is squelched, thus scaling the period. * * @param channel The PWM channel to configure. * @param squelchMask The 2-bit mask of outputs to squelch. */ void DigitalModule::SetPWMPeriodScale(uint32_t channel, uint32_t squelchMask) { CheckPWMChannel(channel); tRioStatusCode localStatus = NiFpga_Status_Success; m_fpgaDIO->writePWMPeriodScale(channel - 1, squelchMask, &localStatus); wpi_setError(localStatus); }
/** * Set a PWM channel to the desired value. The values range from 0 to 255 and the period is controlled * by the PWM Period and MinHigh registers. * * @param channel The PWM channel to set. * @param value The PWM value to set. */ void DigitalModule::SetPWM(uint32_t channel, uint8_t value) { CheckPWMChannel(channel); tRioStatusCode localStatus = NiFpga_Status_Success; m_fpgaDIO->writePWMValue(channel - 1, value, &localStatus); wpi_setError(localStatus); }
/** * Initialize PWMs given an module and channel. * * This method is private and is the common path for all the constructors for creating PWM * instances. Checks module and channel value ranges and allocates the appropriate channel. * The allocation is only done to help users ensure that they don't double assign channels. */ void PWM::InitPWM(UINT32 slot, UINT32 channel) { Resource::CreateResourceObject(&allocated, tDIO::kNumSystems * kPwmChannels); CheckPWMModule(slot); CheckPWMChannel(channel); allocated->Allocate(DigitalModule::SlotToIndex(slot) * kPwmChannels + channel - 1); m_channel = channel; m_module = DigitalModule::GetInstance(slot); m_module->SetPWM(m_channel, kPwmDisabled); m_eliminateDeadband = false; }
/** * Allocate a PWM given a channel number. * * Checks channel value range and allocates the appropriate channel. * The allocation is only done to help users ensure that they don't double * assign channels. * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP * port */ PWM::PWM(uint32_t channel) { std::stringstream buf; if (!CheckPWMChannel(channel)) { buf << "PWM Channel " << channel; wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); return; } int32_t status = 0; allocatePWMChannel(m_pwm_ports[channel], &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); m_channel = channel; setPWM(m_pwm_ports[m_channel], kPwmDisabled, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); m_eliminateDeadband = false; HALReport(HALUsageReporting::kResourceType_PWM, channel); }
/** * Set a PWM channel to the desired value. The values range from 0 to 255 and the period is controlled * by the PWM Period and MinHigh registers. * * @param channel The PWM channel to set. * @param value The PWM value to set. */ void DigitalModule::SetPWM(UINT32 channel, UINT8 value) { CheckPWMChannel(channel); m_fpgaDIO->writePWMValue(channel - 1, value, &status); }
/** * Set how how often the PWM signal is squelched, thus scaling the period. * * @param channel The PWM channel to configure. * @param squelchMask The 2-bit mask of outputs to squelch. */ void DigitalModule::SetPWMPeriodScale(UINT32 channel, UINT32 squelchMask) { CheckPWMChannel(channel); m_fpgaDIO->writePWMPeriodScale(channel - 1, squelchMask, &status); }
/** * Get a value from a PWM channel. The values range from 0 to 255. * * @param channel The PWM channel to read from. * @return The raw PWM value. */ UINT8 DigitalModule::GetPWM(UINT32 channel) { CheckPWMChannel(channel); return m_fpgaDIO->readPWMValue(channel - 1, &status); }