模拟输入-软件¶

roboRIO的FPGA支持多达8个模拟输入通道，可用于从传感器读取模拟电压值。模拟输入可用于任何输出简单电压的传感器。

初始化模拟输入¶

// Initializes an AnalogInput on port 0


过采样和平均¶

FPGA的模拟输入模块支持过采样和平均。两者非常相似，但在一些重要方面有所不同。两者可以同时使用。

过采样¶

// Sets the AnalogInput to 4-bit oversampling.  16 samples will be added together.
// Thus, the reported values will increase by about a factor of 16, and the update
// rate will decrease by a similar amount.
analog.setOversampleBits(4);


平均¶

// Sets the AnalogInput to 4-bit averaging.  16 samples will be averaged together.
// The update rate will decrease by a factor of 16.
analog.setAverageBits(4);


Values can be read from an AnalogInput with one of four different methods:

getValue¶

analog.getValue();


getVoltage¶

analog.getVoltage();


getAverageValue¶

analog.getAverageValue();


getAverageVoltage¶

analog.getAverageVoltage();


累加器¶

// Sets the initial value of the accumulator to 0
// This is the "starting point" from which the value will change over time
analog.setAccumulatorInitialValue(0);

// Sets the "center" of the accumulator to 0.  This value is subtracted from
// all measured values prior to accumulation.
analog.setAccumulatorCenter(0);

// Returns the number of accumulated samples since the accumulator was last started/reset
analog.getAccumulatorCount();

// Returns the value of the accumulator.  Return type is long.
analog.getAccumulatorValue();

// Resets the accumulator to the initial value
analog.resetAccumulator();


获得同步的计数和值¶

// Instantiate an AccumulatorResult object to hold the matched measurements
AccumulatorResult result = new AccumulatorResult();

// Fill the AccumulatorResult with the matched measurements
analog.getAccumulatorOutput(result);

// Read the values from the AccumulatorResult
long count = result.count;
long value = result.value;
`