Analog Inputs and Outputs

The RevPi Flat has an analog input and an analog output.

 

Analog Input

With the analog input you can measure either voltage in the range of 0 – 10 V or current in the range of 0 – 20 mA.

U IN: voltage measurement 0 – 10 VDC

I IN: current measurement 0 – 20 mA DC

Note: Current and voltage input must not be connected at the same time, otherwise the measurement result will be distorted.

The current is converted into a proportional voltage via an internal 240 ohm resistor.

The MCP3550-50 analog-to-digital converter (ADC) used for this purpose has a relatively high resolution of 21 bits, but takes 85 milliseconds per measurement which is a comparatively long time.

There are two ways to access the interfaces: either by reading and writing the Linux sysfs or by using our RevPi configuration tool PiCtory and the software tool piTest, which allows you to access the process image of the system. In the following we describe both methods separately for input and output.

Reading out Values with Linux sysfs

Read out voltage (0 – 10 V)

Enter the following command to obtain the input value of the ADC:

cat /sys/bus/iio/devices/*/in_voltage0*

Convert the raw value read out to “in_voltage0-voltage1_raw” with the formula “(($raw * 12500) >> 20) + 12500” to obtain the voltage in mV.

Read out current (0 – 20 mA)

The current should be available on the I IN port of the RevPi Flat. Divide the read out voltage (see above) by a resistance of 240 ohms to obtain the current in mA.

Reading out Values with piTest

You can configure the current/voltage mode for the RevPi Flat in PiCtory with the variables AInMode:

AInMode Voltage 0-10V (standard)

AInMode Current 0-20mA

Simply read out the current or voltage value by entering

piTest -r AIn

Analog Output

You can connect actuators such as frequency converters to the analog output. It can output a voltage between 0 and 10 V.

The DAC121S101 digital-to-analog converter (DAC) used for this purpose has a resolution of 12 bits.

Entering Values with Linux sysfs

Enter the following command to enter the value in the DAC:

echo 2047 | sudo tee /sys/bus/iio/devices/*/out_voltage0_raw

Enter a value between 0 and 4095 into the DAC in “out_voltage0_raw” to output a voltage between 0 and 10 V.

Entering Values with piTest

Simply enter the analog value in mV into the variable AOut, e.g. 5000 mV for the analog output: piTest -w AOut,5000

More information on implementation:

On the software side, the DAC121S101 and MCP3550-50 are treated like IIO modules whose interface is implemented in sysf as “/sys/bus/iio/devices/”, see also here.

After the converters are successfully registered, the following kernel log usually appears.

pi@RevPi0000:~ $ dmesg | grep “spi.*consumer”

[ 4.461004] mcp320x spi0.1: Linked as a consumer to regulator.1

[ 5.747592] ad5446 spi0.0: Linked as a consumer to regulator.2

Two subfolders for the converters are added to the sysfs folder as “/sys/bus/iio/devices/iio:deviceX”. You can use X to distinguish between the converters here. The order depends on the registration of the devices and therefore has no fixed assignment. The assignment becomes apparent, however, when you look at the contents of the folders. The folder with the “out_voltage*” files is the output module and therefore the DAC module. The folder with the “in_voltage*” files is the input module and therefore the ADC module.

In the method with piTest, piControl retains these values permanently in the process image and you can read and write the values with piTest.