int eth32_set_analog_assignment(eth32 handle, int channel, int source);
This function assigns a logical analog channel to one of the physical channels. The logical channel assignment specifies which physical pins are used to determine the value of the analog reading when that logical channel is read or monitored for events. There are eight logical channels, each of which may be arbitrarily assigned to physical channels using this function.
handle - The value returned by the eth32_open function.
channel - The logical channel number (0-7) to configure.
source - The code identifying which physical channel to assign to the specified logical channel. This may be any of the ANALOG_ constants defined in the tables below.
This function returns zero on success and a negative error code on failure. Please see the Error Codes section for possible error codes.
The logical channels simply provide a way to select which of the many physical channel sources listed below will be continually updated for reading on the device and, if configured to do so, monitored for analog events.
The assignments given to the logical channels may be completely arbitrary. Also, it is permissible to have more than one logical analog channel assigned to the same physical channel source. This can occasionally be advantageous for event monitoring. Since there are two possible event definitions per logical channel, assigning more than one logical channel to the same physical channel allows more than two event definitions on that physical channel.
When the device is first powered up or the eth32_reset function is called, the logical channel assignments revert to their defaults. Logical channel 0 is assigned to single-ended channel 0, logical channel 1 to single-ended channel 1 and so on.
The assignments made with this function are effective until they are either overwritten by calling the function again or the board is reset (hard reset or by calling eth32_reset). There is no limitation on how often you may reassign logical channels.
The following settings are the valid physical channel sources to which a logical channel may be assigned. The constant definition should typically be used in your source code, but its hexadecimal value is shown for reference.
For single-ended channels, the reading comes from the voltage of the specified pin with respect to ground.
Table 1. Single-Ended Channels
Constant | Value | Physical Pin |
---|---|---|
ANALOG_SE0 | 0x00 | Port 3, Bit 0 |
ANALOG_SE1 | 0x01 | Port 3, Bit 1 |
ANALOG_SE2 | 0x02 | Port 3, Bit 2 |
ANALOG_SE3 | 0x03 | Port 3, Bit 3 |
ANALOG_SE4 | 0x04 | Port 3, Bit 4 |
ANALOG_SE5 | 0x05 | Port 3, Bit 5 |
ANALOG_SE6 | 0x06 | Port 3, Bit 6 |
ANALOG_SE7 | 0x07 | Port 3, Bit 7 |
For differential channels, the reading comes from the voltage difference between two pins. It is permissible for either to be positive or negative with respect to the other. They are simply labeled positive and negative inputs to specify how the reading is determined. Please note that the voltage on each pin must still remain within the range of 0 to 5V with respect to the ground of the device.
Table 2. Differential Channels
Constant | Value | Positive Input | Negative Input | Gain |
---|---|---|---|---|
ANALOG_DI00X10 | 0x08 | Port 3, Bit 0 | Port 3, Bit 0 | 10x |
ANALOG_DI10X10 | 0x09 | Port 3, Bit 1 | Port 3, Bit 0 | 10x |
ANALOG_DI00X200 | 0x0A | Port 3, Bit 0 | Port 3, Bit 0 | 200x |
ANALOG_DI10X200 | 0x0B | Port 3, Bit 1 | Port 3, Bit 0 | 200x |
ANALOG_DI22X10 | 0x0C | Port 3, Bit 2 | Port 3, Bit 2 | 10x |
ANALOG_DI32X10 | 0x0D | Port 3, Bit 3 | Port 3, Bit 2 | 10x |
ANALOG_DI22X200 | 0x0E | Port 3, Bit 2 | Port 3, Bit 2 | 200x |
ANALOG_DI32X200 | 0x0F | Port 3, Bit 3 | Port 3, Bit 2 | 200x |
ANALOG_DI01X1 | 0x10 | Port 3, Bit 0 | Port 3, Bit 1 | 1x |
ANALOG_DI11X1 | 0x11 | Port 3, Bit 1 | Port 3, Bit 1 | 1x |
ANALOG_DI21X1 | 0x12 | Port 3, Bit 2 | Port 3, Bit 1 | 1x |
ANALOG_DI31X1 | 0x13 | Port 3, Bit 3 | Port 3, Bit 1 | 1x |
ANALOG_DI41X1 | 0x14 | Port 3, Bit 4 | Port 3, Bit 1 | 1x |
ANALOG_DI51X1 | 0x15 | Port 3, Bit 5 | Port 3, Bit 1 | 1x |
ANALOG_DI61X1 | 0x16 | Port 3, Bit 6 | Port 3, Bit 1 | 1x |
ANALOG_DI71X1 | 0x17 | Port 3, Bit 7 | Port 3, Bit 1 | 1x |
ANALOG_DI02X1 | 0x18 | Port 3, Bit 0 | Port 3, Bit 2 | 1x |
ANALOG_DI12X1 | 0x19 | Port 3, Bit 1 | Port 3, Bit 2 | 1x |
ANALOG_DI22X1 | 0x1A | Port 3, Bit 2 | Port 3, Bit 2 | 1x |
ANALOG_DI32X1 | 0x1B | Port 3, Bit 3 | Port 3, Bit 2 | 1x |
ANALOG_DI42X1 | 0x1C | Port 3, Bit 4 | Port 3, Bit 2 | 1x |
ANALOG_DI52X1 | 0x1D | Port 3, Bit 5 | Port 3, Bit 2 | 1x |
Note that the entries above which show both the positive side and negative side with the same input pin can be used for calibration of the differential amplifier. Any nonzero reading from those indicates an offset error within the differential amplifier which you can subtract out of other channels that share the same negative input and gain.
Table 3. Calibration Channels
Constant | Value | Description |
---|---|---|
ANALOG_122V | 0x1E | Internal 1.22V Voltage Reference |
ANALOG_0V | 0x1F | 0V (Ground) |
The above two entries connect a logical channel to internal chip voltages. They can be used as calibration points to determine errors within the analog conversions.