Flow-X IO interface board

From Electriki
Revision as of 15:37, 29 December 2008 by Michai (talk | contribs)
Jump to navigationJump to search

So what is this anyway?

Below follows a description of a nice hobby-project to make an interface board that basically sits between a PC and an I/O module, to read module-outputs and stimulate module-inputs.

Flow-X module

This is a small but very nice modular flowcomputer for the oil- and gas-industry; since I toy with/at this thing at work, why not make a little something to make Life a bit Nicer.

Interface-board

It would be nice to test test and provide stimuli for various digital/analog I/O's on the module from a PC, while meanwhile trying to keep it safe, or rather fool-proof in case I/O is misconfigured (i.e. misconfigured 'low' output connected to 'high' output), because we all make mistakes.

Some of the module's I/O is read/stimulated by the interface-board directly, while for other signals, the board only multiplexes signals or even simply passes them through to a host-PC. All I/O the board is capable of reading/stimulating itself, is passed to/from a host-PC using a serial protocol. Remaining I/O to be read/stimulated is psysically connected to the board, where it is multiplexed or just passed through to the module.

Covered I/O

Each interface-board only covers half of the module's I/O; therefore, 2 boards are needed to read/stimulate all I/O on a single module. Each board covers the following module-I/O:

1 RS-232/RS-422/RS-485 serial port

Simply passed through from module to host-PC; interface-board only provides a DE-9 connector for convenience sake.

1 PT100 resistance temperature measurement input

Resistance (or temperature) for the module can be specified by supplying an external voltage (0..5V) to the board. The signal is buffered by an opamp and then used to drive a high-intensity LED glued to a LDR. Current is limited to 27mA, just because we are very nice. In fact 27mA is insanely high come to think of it.

3 analog inputs, configurable for current/voltage

Fig.1: analog input stimuli. A relais switches between current- and voltage-modes; in both cases, the board is supplied with a control-voltage; in current-mode, an opamp drives an internal shunt in the module, while in voltage-mode, module-input is high-impedance, and series-resistor only prevents damage in case of misconfiguration.

In case of current-input, the module basically reads the voltage over an internal shunt-resistor. This current can be controlled by feeding the board with a voltage (0..5V), which is buffered by an opamp and fed into the shunt. Current is again limited to 27mA; this is low enough as to not cause damage in the module. V/I will not be linear, mainly because of the current-limiter (LM317), but this can be compensated by software.

In case of voltage input, the board simply places a safety-resistor in between the voltage (0..5V) offered to the board and the module. A relais on the board switches between current/voltage modes.

2 analog current-outputs

To read outputs from these 4..20mA outputs, the board simply contains a 220ohm shunt for each, and outputs the voltage over each shunt as output-level. Software will do conversion back to current.

8 open-collector digital I/O pins

Fig.2: digital I/O circuit. Open-collector pin on module is supplied a weak 4.5V by default, driven hi/lo by a digital I/O-pin from the board's microcontroller, or driven high/low by auxiliary signals 'A' or 'B' if they are not decoupled.

Because the module only has open-collector I/O's, the board provides a 'weak' 4.5V using a voltage-divider. For each digital channel, the module-side can be either input or output. The board-side can be input and output as well; damage because of misconfiguration is eliminated by a series-resistor.

Fig.3: selection of auxiliary signals. Signals 'A' and 'B' can be separately assigned to an I/O-pin, or 'parked' (decoupled).

In addition to reading and stimulating the module's digital I/O, 2 auxiliary signals supplied to the board ('A' and 'B') may each be assigned to a digital I/O. Misconfiguration will not lead to damage by using series-resistors.

Fig.4: swapping auxiliary inputs. Using 2 1-of-2 multiplexers, signals 'A' and 'B' can be swapped. This is for convenience sake, and to allow for arbitration assignment of 'A' and 'B', since each have 1 I/O-pin they cannot be assigned to, reserved for 'parking'.

Auxiliary input 'A' can be assigned to module-inputs 0..6, while 'B' can be assigned to module-inputs 1..7. Signals 'A' and 'B can be 'parked' (decoupled) by assigning them to pins 7 and 0, respectively. To allow for any arbitrary assignment of 'A' and 'B', a swap-function is implemented in the board.

Fig.5: counter-assignment. Each counter can be configured to take its input from an arbitrary I/O-pin.

The microcontroller on the interface-board also has 2 counters; each counter can be assigned to any digital channel (0..7). Counters can be disabled/enabled and configured for positive or negative logic separately. Counters are passive, and don't influence I/O lines in any way.

Microcontroller and software

Fig.6: the mighty MCU. Behold, all its Noodly Appendages.

Of course there is a MCU in here! The mighty (in size) ATmega32 (DIP-40) manages all digital I/O, multiplexing and selection of signals. It runs on a 7.3728 MHz crystal, and communicates to a host-PC over a serial link @ 115k2 bps.

Pin assignments

As can be seen in Fig.6, I/O-pins are given the following functions:

  • general purpose digital I/O DIO0..7 (8 pins)
  • CTR0 and CTR1 inputs (2 pins)
  • status-LED output (1 pin)
  • swap aux inputs A/B enable (1 pin)
  • CTR0 and CTR1 DIO-pin assignment select (3 pins for each counter, 6 in total)
  • aux input A/B DIO-pin assignment (3 pins for each input, 6 in total)
  • voltage-mode enable for each of the module's analog input (3 pins)
  • status-LEDs for CTR0 and CTR1 (not sure what to do with those; 2 pins)

Apart from serial Tx/Rx there was 1 pin left, so why not make that a 'selftest' input using a pullup and a jumper. Basically, it reads/sets I/O pins and thus only handles digital I/O. Analog I/O is handled completely separate from the MCU.

Software functionality

Software functions are roughly as follows:

  • set direction and value of DIO-pins DIO0..7
  • read status of DIO-pins configured as input
  • configure individual counters CTR0 and CTR1 to count on rising/falling edge, reset counter, read counter-value
  • assign aux inputs A and B to DIO-pins DIO0..7, swap or decouple them
  • select analog mode (current/voltage) for each 3 of the module's analog input channels
  • selftest-mode, without need for host-PC

Board/host-PC protocol

Software in MCU will talk to the host-PC using a simple ASCII, human-readable command-set where each command is terminated by CRLF and followed by a status-reply from the MCU. This allows for testing using terminal emulator, and avoids timing problems from sending commands too fast; host-PC should wait for status-reply before sending next command.

Board's power supply

Fig.7:board's power-supply. 2 identical regulators are used to supply either the MCU or the other IC's from a shared 24V source, supplied by the module.

plop.

So... what does it look like?

Fig.8: old (above) and new boards. The old board didn't have a MCU on-board, but instead had select- and enable-lines to be driven externally. It is best forgotten, and besides, it's blown up now.
Fig.9: finished board, component-side. Because of the superb quality of my phone-cam, let me tell you there are a lot (prolly a gazillion (or more)) wires there. I inhaled a fair amount of enamel-smell.
Fig.10: finished board, solder-side. I am very happy with my cheap-ass Velleman soldering iron; it has already given me many, many hours of fun, and many, many burned fingertips.

(put interesting story here.)

--Michai