Beispiel #1
0
void FPGA_SetPIDdt(uint16_t dt) {
    NiFpga_MergeStatus(&FPGA_Status,NiFpga_WriteU16(FPGA_Session,NiFpga_mainFPGA_ControlU16_PIDdt, dt));
    if (NiFpga_IsError(FPGA_Status))
    {
            LOG.ERR("Set PID dt failed");
    }
}
Beispiel #2
0
void FPGA_setMaxPIDSpeed(uint16_t max) {
    NiFpga_MergeStatus(&FPGA_Status,NiFpga_WriteU16(FPGA_Session,NiFpga_mainFPGA_ControlU16_maxPIDSpeedTicksPerDt, max));
    if (NiFpga_IsError(FPGA_Status))
    {
            LOG.ERR("Set max PID speed failed");
    }
}
Beispiel #3
0
/**
 * Write a voltage value to a single channel. The channel structure must
 * previously been initialized with the appropriate scale factors with
 * AnalogScaling.
 *
 * @param[in]  channel  A struct containing the registers for the AIO
 *                      channel to be written to
 * @param[in]  value    the voltage value in volts
 */
void Aio_Write(MyRio_Aio* channel, double value)
{
    NiFpga_Status status;
    uint16_t valueScaled;

    /*
     * The value is always stored in an unsigned 16-bit register. For a signed
     * channel, cast this value directly to a signed 16-bit value. Bound the
     * values to their respective limits.
     */
    if (channel->is_signed)
    {
        /*
         * Scale the voltage value to the raw value.
         */
        value = (value - channel->scale_offset) / channel->scale_weight;
        value = (value < INT16_MIN) ? INT16_MIN : value;
        value = (value > INT16_MAX) ? INT16_MAX : value;

        /*
         * Round the scaled value to the nearest integer.
         */
        value += (value < 0.0) ? -0.5 : 0.5;

        /*
         * Convert the scaled value to an unsigned integer.
         */
        valueScaled = (uint16_t)((int16_t)(value));
    }
    else
    {
        value = (value - channel->scale_offset) / channel->scale_weight + 0.5;
        value = (value < 0) ? 0 : value;
        value = (value > UINT16_MAX) ? UINT16_MAX : value;
        valueScaled = (uint16_t) value;
    }

    /*
     * Write the value to the value register.
     *
     * The returned NiFpga_Status value is stored for error checking.
     */
    status = NiFpga_WriteU16(myrio_session, channel->val, valueScaled);

    /*
     * Check if there was an error writing to the write register.
     *
     * If there was an error then print an error message to stdout and return.
     */
    MyRio_ReturnIfNotSuccess(status,
            "Could not write to the AO value registers!");

    /*
     * Write the signal so that the FPGA will apply the new value.
     *
     * The returned NiFpga_Status value is stored for error checking.
     */
    status = NiFpga_WriteU16(myrio_session, channel->set, 1);

    /*
     * Check if there was an error writing to the set register.
     *
     * If there was an error then print an error message to stdout.
     */
    MyRio_ReturnIfNotSuccess(status, "Could not write to the AO set registers!")
}
Beispiel #4
0
bool nifpga::WriteU16(uint32_t control, uint16_t value) {
	if (sessionOpen) return HandleStatus(NiFpga_WriteU16(sessionHandle, control, value));
	return false;
}