Difference between revisions of "Project/RelayMatrix"

From initLab
Jump to navigation Jump to search
Line 110: Line 110:
=== Linking it all together ===
=== Linking it all together ===


The PHP-Apache webserver, LXI engine and also the USB virtual COM port all have to communicate with the SCPI language interpreter, so we'll have to get a cross-program link between all of these. Rather to make our own elaborate protocol, there is a turn-key right out-of-the-box solution which is intended to do just that: ZeroMQ. It is supported over a wide variety of languages, including PHP, Python, C, Perl, Java, Lua scipt, .NET, Delphi, Ruby and many others. It communicated over sockets, similar to network interfaces do, but it can be used just as effectively internal to several running programs. The VXI-server, UART server and PHP script are all link initiators, and have to talk to the SCPI command interpreter. In ZeroMQ talk, these are called "REQUEST" ports. The SCPI interpreter is using a "ROUTER" interface, because it has to take connections from different sources, and send the reply to the appropriate requester.
The PHP-Apache webserver, LXI engine and also the USB virtual COM port all have to communicate with the SCPI language interpreter, so we'll have to get a cross-program link between all of these. Rather to make our own elaborate protocol, there is a turn-key right out-of-the-box solution which is intended to do just that: ZeroMQ. It is supported over a wide variety of languages, including PHP, Python, C, Perl, Java, Lua scipt, .NET, Delphi, Ruby and many others. It communicates over sockets, similar to network interfaces do, but it can be used just as effectively internal to several running programs. The VXI-server, UART server and PHP script are all link initiators, and have to talk to the SCPI command interpreter. In ZeroMQ talk, these are called "REQUEST" ports. The SCPI interpreter is using a "ROUTER" interface, because it has to take connections from different sources, and send the reply to the appropriate requester.


[[Category: Project]]
[[Category: Project]]

Revision as of 13:28, 5 March 2016

Introduction

In professional test systems, there is often the need for switching. Power supplies, loads, and various measurement devices need to switch on or off, or be able to be chosen across multiple inputs or outputs on a test system. This is done by relays in most cases. Relays are fairly reliable, oppose little influence on the test system and have good conductivity in the "on" position, and also good isolation in the "off" position. As the complexity increases, the number of relays can also become very large. Purpose-built switching systems are efficient, but also less flexible. If you want maximum freedom, you will look for a system that can connect any input to any output. These kinds of systems have relays in a matrix configuration. For small signal types such as voltage measurements, a reed type relay is very compact, and a high density can be packed in a minimum of space. For switching larger currents, a more conventional type power relay is needed.

Matrix principle.jpg

All of these relays must be switched at the right moment. Usually, there will be some sort of automated sequence system, controlling the progress of the task being performed. Scripting systems such as National Intrument's LabView or Keysight's VEE programs offer easy to understand graphical representation of a test sequence, with great flexibility. The test script systems communicates with equipment with a number of interfaces, varying from the ancient but still widely used IEEE488 parallel bus, to RS232, PCI variants, USB and Firewire buses and Ethernet connections. The common communication standard across all these interfaces is usually SCPI, the Standard Commands for Programmable Instruments. This is an human readable ASCII based set of commands, which is extensible and adaptable to a large number of instruments. Power supplies, vector analysers, multimeters and a host of other measuring and driving equipment can have SCPI support.

Matrix1.jpg Matrix2.jpg

A relay matrix system is often an expensive piece of equipment, bound to a single vendor, and limited to a certain voltage or current. To find a suitable system, it can become neccesary to mix different types of relay matrix configurations. Because there of often the need for a compact system, small relays are used, which can be costly. Many thousands of dollars/euro's can be spent on a matrix system. But what if you could make a system yourself? Choose a cheap relay, buy them in bulk, and make your own system? This project proposes an open source, fairly cheap, modular matrix system with easy to obtain relays, and USB and/or Ethernet configuration ports. On top of this, and not offered very often, an integrated diagnosis system is offered, to keep track of the health of over a thousand relays. See statistics like activated time, number of activations, but also vital figures like contact resistance, can give insight on the condition of a relay. Welcome to project IO Dyne!

Everything you never wanted to know about relays

A relay is just like a regular switch. The difference between the two is where a switch is operated by a mechanical force (like a person), a relay can be operated by an electrical signal. A current is run through an electromagnet inside the relay, and this magnetism is used to operate the switch. There are a large number of switch configurations possible. A normally open (NO) contact can be closed by operating the relay, a normally closed (NC) contact can be opened. Also a combination of these two is possible with a dual throw (DT) or change over (CO) operation. All of these types of switches can be inside a relay 1 time (single pole or SP), or multiple times. If there are two switches inside, it is called a dual pole (DP), but more is certainly possible. The switch configuration is usually mentioned with a combination of these acronyms, like SPDT for a single change over configuration, or a 3PNO for a combination of 3 normally open switches.

Apart from the switch configuration, the coil to make the magnetic field can also vary a lot. DC as well as AC voltage operated coils are possible, and the coil voltage can be very small, like 3 volts, or very large, to over 380 volts. For DC coils, a built-in freewheel diode is possible. If this is the case, polarity must be observed when connecting the coil. Operation of the coil can also be latching. This means that, to switch over, a short period of energising the coil is only needed. This is also called a bistable relay. It can be done with one coil, which can be operated in opposite polarity, but also dual coil latching relays are possible, with each coil responsible for either making or breaking contacts. Non-latching or monostable relays typically have only one coil. As long as the coil is energized, the switch is activated, and without voltage on the coil, the relay is in its default state. Other properties can be a reed-type relay with a reed switch typically suited for small signals, safety relays, coaxial relays, or contact material designed for a specific type of signal.

Relay operation.gif

A coil inside a relay is just like any other coil in terms of behavior. Coils usually conduct DC currents very well, and isolate fast changing AC currents. The coils resists changes by converting the electrical energy into magnetic energy. If you keep running the DC current, the coil can no longer transfer energy, and the magnetic field stabilizes. It is this magnetic field that is used inside the relay to operate the switch contacts. But, if you no longer run current through the coil, it wants to resist this as well. It converts all magnetic energy back to electrical energy. The voltage generated by the relay coil can be very high and was often the cause of malfunction of the electronic component operating the coil. A diode opposite to the normal current flow is used to short-circuit this coil-generated voltage in order to keep semiconductors alive.

Apart from the coil, there is another property of the relay that is of our interest: the contacts. And in particular: the contact resistance. Like every mechanical connection, every switch contact has a certain resistance. Usually, this contact resistance is very low, in order to conduct current very well. But, when a relay ages, the contact resistance can become higher. The contact become corroded, and the ability to conduct electricity decreases. This effect can be minimized by the natural cleaning effect of tiny sparking happening when the contact is energized and a current is run through. Datasheets often specify the minimum amount of current needed for this, and depends on the material of the contacts, the contact surface, and many other parameters. The order of resistance in usually in the milli-ohms.

Resistance measuring

But how to measure these kinds of low resistances? You can no simply plug in your multimeter: it will read closely to 0 ohms, but no milli-ohms. This is because the multimeter uses a tiny current to measure the resistance. For high resistors, this works very well, but it is not suited for very low values. When you apply a higher test current, other factors come into play like wire resistance, whcih can surpass the value you want to measure many times over. Fortunately, there is a way to measure low resistance values accurately. 4-wire measurements!

4wireresistance.png

The principle of a 4 wire resistance measurement is quite clever: each terminal of the resistor has 2 wires connecting to them: One current bearing wire, and 1 voltage measuring wire. On the current wires, a constant known current is applied. Like 1 amps. The voltage drop across these terminals will be significant, due to the current running over them. If we would want to apply Ohm's law, measuring voltage over these wires, the value would be way off. Just like the multimeter would be. Fortunately, we do have a second set of wires connected to our resistor. These we use to measure the voltage! Because for voltage measuring, we have to use near-zero current, the voltage drop is negligible. This means we can accurately determine the voltage across our very low value resistor. With Ohm's law at our hand, we can tell what value our contact resistance is!

Controlling the hurdle

Switch 8x8 schematics.png
Switch 8x8 layout.png

Seeing that we would need a fair amount of relays for our matrix, over a thousand in total, we should best choose one that is cheap, but still good. As far as switch configuration goes, we need the bare minimum: one normally open pole would do just fine. A coil voltage of 12 volts would be OK, and it would help if the relay is low power consuming as well. The Tyco Electronics OJ-SS-112LMH2 relay meets all these demands, while in larger amounts it's priced at about 50 eurocents (that's 1 Leva). It consumes just 200mW, and is capable of switching up to 8 amps. It has a life expectancy of 100.000 actions and can operate in high temperatures.

So now that we have a whole lot of relays, how do we control all of those? If you want to power a relay from, let's say a microcontroller, you could use a transistor. But what if you wanted to drive a whole lot of relays? Simply connecting then all to our microcontroller with a lot of transistors would result in a very large and expensive controller, and a whole lot of wires which will result in a difficult to produce and expensive circuit board. For our conveniece, there is a thing named a SIPO register. This register is a type of shift regsiter which accepts a number of values in a serial manner, and can apply those values to a set of parallel outputs. Often, such regsiters have cascading capabilities with an additional serial out port. A popular 74HC595 is a good example of such a shift register.

One major disadvantage of the 595 register is its output driving capability. It simply lacks the power to drive our relays. The output is of TTL level. 5V, about 20mA, simply isn't enough to drive relays. A suitable relays driver would be an Allegro ULN type darlington driver, like the ULN2803. It takes the TTL level signaals, and it can perfectly drive relays. It even has integrated freewheel protection diodes for driving inductive loads, like our relays are. The register-driver pair is a very commonly used solution for connection a large number of relays to a microcontroller, but in our high-density demands, it would result in a large circuit board because we have to use both a register and a driver for 8 relays. For 1024 relays, this means 256 IC's just for the relays! Apart from the number, the ULN2803 is only available in DIP and SO wide package. Not ideal for a high density matrix.

There are several purpose-built chips that provide a solution for this problem. For example, the MAX4820 from Maxim integrated. This is a SIPO relay driver, just like we need! It can be cascaded, can be supplied from 3.3V or 5V, has space-saving packages for high density solutions. One drawback is the price. It is expensive! Our final implementation uses the TPIC6C595 from Texas Instruments. It is available in a TSSOP package, which is reasonably small, and can drive 8 relays directly from a serial input. 8 of these are daisy-chained to control 64 relays, from a single microcontroller.

One level up

The relay boards have 64 relays, arranged in a matrix configuration. If we want to connect multiple boards together, we would have to connect the rows and colomns also, so we can expand the matrix. These connections will have to withstand the full current capability of the matrix system, and also have a dependable connection. Preferably, the relay boards should be universal, so a spare could be kept aside, in case one of the boards would need replacing. Also, interchanging should be easy. If we would use a single pole connection, there would be a lot of them. With 8 connections on either of the 4 sides of the PCB, 32 connections would be kind of a hassle.

Fortunately, Samtec has an ideal solution. An 8 pole connector, suitable for high currents, and side entry connect will make the UPPT-08-01-01-L-RA-SD connector a perfect choice. Being a hermaphroditic is also a benefit, because the connector is its own mating adversary. To prevent against wrongfull oriëntation of boards, the connectors are placed off-centre.

Uppt.jpg

The next step is to control the relays boards. If we have 64 relays on a board, and 1024 relays in total, we would need 16 relays boards. All of these must be interconnected, and supplied with power. To maximize flexibility, a minimum of interconnections would be most beneficial. We can serialize data again like we did with the relay drivers, but a break in the chain would mean a breakdown of the entire system. Also, because of the distance that need to be covered, there would be a speed penalty, and signal integrity issues. We would need to look at a solution of a serial bus, which is kind of fast, and can handle cross-PCB distances with as little signal degradation as possible.

The automotive industry has a turn-key solution: The Local Interconnect Network or LIN bus. At the base of the LIN bus is a serial interface, and a bus master. It talks to all the connected slaves with an addressing protocol, and negotiates speed with a learning sequence. It handles noise and other interfering influences very well, and has only 1 connecting wire. Microchip has a whole range of microcontrollers supporting the LIN bus, as well as interface chips for level conversion. To identify individual boards on the bus, all relay boards are equipped with configuration DIP switches to indicate its position in the matrix.

Central command

LB controller.png
LB current source.png
LB LIN.png
LB power.png
LB relays.png
LB USB.png
LB interconnect.png
LB layout.png

The bus master for the LIN bus controls all relay boards, and is the central command center for all things relay related. So what else can we implement? How about the resistance measurement? As mentioned, we need two things for this. The first one being a constant current source. 1 amps would be sufficient to accurately measure milli-ohms. We only need a chip to generate exactly 1 amps. The most obvious way is to use a regulator. Where voltage regulators can be very precise, it can be hard to obtain a precision 1 amp current source. Ohms law to the rescue! If we can make a voltage source adjusted to 1.25 volt, and run it across a 1.25 Ohms resistor, we have our 1 amp current!

A Linear Technology LTC6655 precision voltage reference source is used. To drive the current, we need a driving transistor, for example a Fairchild NDT3055. In a DPAK housing, it can handle up to 12A, which is more than enough for our application. As a feedback buffer, Burr Brown's OPA376 is used because it has a very small offset voltage. Alltogether, this should generate an accurate 1 amps of current for measuring resistance.

The other thing for determining contact resistance is the voltage measurement. A differential voltage measurement would be preferred, because we want to look at the voltage drop across the switch contact. Again, Burr Brown offers very precise instrumentation differential amplifiers, like the INA122. With just 1 external resistor, we can set the amplification of the voltage. This output voltage can then be converted to a digital value by means of a Microchip MCP3421. 18 bits of resolution ensures a high level of density in our measured value, and a serial output simplifies PCB layout.

The constant current source and the millivolt measurement must be switched across all of the inputs and outputs of the relay matrix, in order to determine the resistance of each relay contact. Of course, while this is happening, there can be no normal functionality in between. Isolating relays on I/O boards are used to change to diagnostic mode, while a whole bunch of relays are used to switch the current and voltage signals onto all isolated I/O.

Communicate to the outside world

In order to speak to the outside world, we need interfaces on which the SCPI command set can run on. Possible interfaces are:

  • GPIB parallel bus. Ancient, but still wirdely used. Also referred as IEEE488.
  • Serial RS232 connection. A well known and easy to implement interface, but not very well suited for high speeds, or long distances.
  • Firewire. Fast and cheap, but it's becoming a less-used bus.
  • USB. Two variants of this can exist: A purpose-built USB driver that must be installed on the host, or a virtual COM port. While USB is fast and reliable, it's not that great for a larger distance.
  • PCI-like implementations. These require a specialised interface card in the computer that connects to the device. It can be a ver fast and robust solution, but it's usually also expensive.
  • Ethernet. Widely known in the computer world, can be fast with gigabit speeds, cheap and reliable, this seems a good way to go!

On our relay matrix, the choices we are going for are Ethernet and USB virtual COM port. On the Ethernet side, there is a standard that describes the control of measuring instruments with the SCPI language: LXI or the Lan eXtensions for Instrumentation. There are a number of requirements that comes with this standard, like a web interface, a connection port, openening and closing connections, and so forth. Because all of this is heavy lifting for a common microcontroller, there is a way to implement this, plus the USB connection, in a much easier way: An open source ARM development board. Many choices exist, like the ever-popular Raspberry Pi, but we will choose a Beaglebone Black for its support on hardware. However, there is no problem in choosing another solution.

Bbblack.jpg

The base

At the foundation of our software platform is the operating system. For the Beaglebone Black there are a couple of operating systems available. Ubuntu Linux, Debian, Android and others. Our choice would be Debian Linux because it is lightweight, functional, stable, expandable and widely supported. The current version at the time of writing is Debian Jessie (8.3), and can be put on the embedded EMMC flash memory present on the Beaglebone. This eliminates the need for a memory card constantly being present.

From SCPI to hardware

The next thing we would need is some kind of interface to translate the SCPI commands to actual hardware changes. To make this happen, we need a programming language. And there is a whole lot out there. Most commonly used on linux are C or variants of this, and Python. This last one is particularly interesting because it is easy to learn and understand, can be expanded with lots of library functionality, and is cross platform as well. We can use a Beaglebone Black hardware supporting library to manipulate the I/O on the beaglebone.

Webserver

The next thing we would need is a webserver. We can use this interface to debug, examine, diagnose and test functionality of our device. It can give feedback on the status of our relay matrix, such as usage statistics, as well as configuration settings. Linux in general and Debian in particular already has a turnkey solution for a webserver: Apache. This program can return web pages to request on the most commonly used port for this: HTTP port 80. In order to not only display static information, we need a scripting backend for dynamically generating pages. PHP is the most obvious choise. Many systems run on this scripting language, and it can be installed on Debian in a heartbeat.

LXI interface

What also is required is a interface towards common test & measurement sequence programs, such as National Instrument's Labview or Keysight's VEE programs. The common way over a TCP connection is to use the VXI-11 protocol. It is based upon Sun's RPC or Remote Procedure Call protocol (RFC standard 1057), once intended to run programs on a computer remotely. All attached programs have numbers, and the RPC server assigns a free port to every program. For VXI-11 core connection, the RPC program number is 395183. For the abort channel, it's 395184. These programs can be opened, and standard SCPI commands can be sent to our relay matrix. If a response is triggered, such as a measured value or an acknowledge, it is also returned over this channel. If the interface fails to response, the abort channel can be used to close the connection.

A lot of programming scripts are out on the internet to interface to an VXI-11 client, using the functionality of an instrument. Not a lot are out there to actually make such a device. To create our own, we'll use the Python language again. A VXI-11 server is created using the generic socket library, tapping into the raw network communication channel of our Beaglebone. Structured packets must be decoded and formed to conform to the RPC protocol. Proper responses must be formed according to the VXI protocol to open, use and close a communication link.

Linking it all together

The PHP-Apache webserver, LXI engine and also the USB virtual COM port all have to communicate with the SCPI language interpreter, so we'll have to get a cross-program link between all of these. Rather to make our own elaborate protocol, there is a turn-key right out-of-the-box solution which is intended to do just that: ZeroMQ. It is supported over a wide variety of languages, including PHP, Python, C, Perl, Java, Lua scipt, .NET, Delphi, Ruby and many others. It communicates over sockets, similar to network interfaces do, but it can be used just as effectively internal to several running programs. The VXI-server, UART server and PHP script are all link initiators, and have to talk to the SCPI command interpreter. In ZeroMQ talk, these are called "REQUEST" ports. The SCPI interpreter is using a "ROUTER" interface, because it has to take connections from different sources, and send the reply to the appropriate requester.