2.6

Data communications

2.6.1 Communications

Once an analog signal has been digitised by the ADC, the digital information must then be passed to a port of a microcomputer for subsequent placement on the data bus. An inexpensive, readily available method is by serial communications using the serial port. Other common methods are to use an ADC interface card that interfaces directly to the computer bus system, and the GPIB parallel data bus.

image

Steps in serial transmission of a byte of digital data:

(a) byte is converted into sequential series of bits

(b) bit transmitted over signal wire

(c) bits reassembled into bytes

2.6.2 Byte to serial conversion

At the transmission end of the process, the byte of data is sent bitwise over a signal wire. This is done using a shift register in a special integrated circuit called a UART (Universal Asynchronous Receiver/Transmitter).

image

A shift register can be made using cascaded JK flip-flops. A positive transfer pulse loads the asynchronous inputs R and S with the data to be shifted. For example, if D = 0, then on the transfer pulse, S = 1, R = 0 and Q = 0. If D = 1, then S = 0, R = 1 and Q = 1. Thus, after the transfer pulse, the parallel data is transferred to the J input of each flip-flop. When the transfer pulse goes low, R and S are both at 1 which is the no change state, and on the clock or shift pulse, data is transferred along the chain from Q to J, the serial output bit stream appearing as the last output Q.

At the receiving end, the serial bit stream is converted to parallel 8-bit data by a reverse of the above. Data is clocked in, and then a transfer pulse transfers the data to the parallel outputs.

Now, for long distances, the bit stream is not usually transmitted directly over wires since the binary signals are easily distorted with distance. This, together with the requirement that the transmitter and receiver need to be synchronised, means that alternative arrangements are required to actually transmit the data over distances of more than about 15 m.

2.6.3 RS232 interface

The RS232 interface standard defines the necessary control signals and data lines to enable information to be transmitted between computer equipment (or data terminal equipment DTE) and the modem (or data communication equipment DCE). The modulated carrier signal is transmitted over a two-wire telephone network by the connecting modems.

image

A modem converts or “modulates” digital information into a form suitable for transmission over the telephone network. The receiving modem demodulates the signal back into digital data for use by the receiving computer. Modems transmit information using a sine wave carrier which is modulated (either through amplitude, frequency or phase) to carry binary information.

1. RTS is raised high by the sending computer indicating that data is ready to be sent.

2. The transmitting modem sends a carrier signal to the receiving modem which raises DCD on its connection to the receiving computer which is thus notified of the existence of a carrier signal.

3. The transmitting modem waits for a preset period for the receiving computer to get ready to receive data.

4. The transmitting modem raises CTS signalling to the sending computer that it may now begin to send data.

5. The transmitting modem receives digital data from the sending computer on the TD line and modulates the carrier wave accordingly. The receiving modem demodulates the carrier and puts digital data on the RD line connection to the receiving computer.

6. When the sending computer has finished sending the data, it clears the RTS signal to the transmitting modem which then drops the carrier and clears its CTS signal. The receiving modem detects loss of carrier signal and it drops its DCD line to the receiving computer.

2.6.4 Synchronisation

Start and stop bits frame the data bits. When the signal line is not sending data, it is idle and held at mark or logic high. The start bit is low or space and thus when the receiver sees a transition from mark to space, it knows that the next bit to be received is the lsb of the data being transmitted. After all the data bits have been received, the receiver interprets the next bit to be a stop bit which is mark. If the bit actually received is not mark, then the receiver knows that an error has occurred.

image

The receiver clock is usually made 16 times the bit rate. When a mark to space transition is detected, the receiver counts 8 clocks. If the signal is still at space, then it is assumed that the signal is a valid start bit. The receiver counts off another 16 clocks and then samples the data until all the data bits and stop bit(s) have been received. The bit sampling thus takes place in the centre of the signal levels.

After the data bit and before the stop bit, there may be a parity bit which is used as a check for data validity. In even parity, the total number of 1s (including the parity bit) is made to be an even number (and vice versa). The receiver computes its own parity bit when a byte is received and compares it with that appended by the sender. A mismatch indicates a parity error.

The rate of transmission is the data bit rate which is called the baud rate. Generally, the baud rate is the same as the bit rate; however, some transmission systems are capable of sending more than one data bit (e.g. amplitude and phase modulation) into a transmission bit and the bit rate is thus higher than the baud rate.

2.6.5 UART (6402)

The 6402 UART takes in parallel byte data into the Transmitter Buffer Register at the inputs TBR1–8. This data is transferred into the Transmitter Register for shifting. The output bit stream appears at Transmitter Register Output (TRO). Similarly, serial data is read in at Receive Register Input, converted to a character in the Receive Register and appears at Receive Buffer Register outputs RBR1–8. The transmitter part of the circuit automatically adds start, stop and parity bits according to logic levels applied at control inputs. The receiver checks for parity and stop bit errors and issues logic levels at various indicator outputs.

image

When TBRL goes low, data is read from the input pins TBR1–8 and transferred to the Transmitter Buffer Register. When TBRL goes from low to high, data is transferred from the Transmitter Buffer Register to the Transmitter Register whereupon data is shifted and transmitted out on TRO.

If RRD is held low, then the data on RBR1–8 is that last read from the input stream at RRI. A high level on DR indicates that the data read is available at RBR1–8. Once read, DR needs to be reset by a negative pulse to DRR.

A description of the pin functions on the 6402 UART is given below:

image

The more versatile 8250 (16450) UART extends the functionality of the basic 6402 by having programmable registers that set the baud rate, parity and stop bits, and an interrupt controller. High level commands in an application program set the appropriate bits in the internal registers (see Section 2.4.5). Later 16550 UARTS feature first-in, first-out (FIFO) buffers which allow data transfer to happen at maximum speed while the processor is momentarily occupied by other tasks.

2.6.7 Line drivers

RRI and TRO on the 6402 UART are the serial input and output lines. The polarity of the signals is +5 V for mark or high, and 0 V for space, or low. However, the transmission of serial data along the wire in an RS232 transmission interface requires −15 to −12 V for mark, and +12 to +15 V for space. Line drivers are used to convert the logic levels required by the UART to those required at the RS232 interface pins TD and RD.

A very useful IC is the 232CPE dual RS232 transmitter/receiver. This IC requires a single +5 V supply and generates +10 V and −10 V necessary to drive the RS232 signal lines. (Note: Handshaking signals CTS, RTS, DSR etc are also at +10 V, −10 V.)

The 232 takes either TTL or CMOS logic levels as inputs, and provides ±10 V at the RS232 outputs. It also receives RS232 inputs, and provides equivalent TTL or CMOS levels as an output. There are two separate channels available for both receiving and transmitting.

image

Transmitting: TTL input, RS232 output Receiving: RS232 input, TTL output The external capacitors are used by the internal voltage doublers to obtain ±10 V RS232 signals.

2.6.8 UART clock

The 6402 has two separate clock inputs but normally, these are driven by the same clock so that the transmit and receive baud rates are the same. The clock frequency is to be 16 times the baud rate. The 6402 chip does not have a programmable baud rate divider (as in the 8520) so the desired clock frequency must be supplied externally using a binary counter.

A crystal oscillator can be used in conjunction with a high speed inverter to produce a square wave output which can be stepped down to the desired frequency with a binary counter.

image

image

The crystal’s piezoelectric properties are electrically equivalent to an inductance in series with a capacitance at its resonant frequency.

image

The circuit shown is a CMOS inverter implementation of a Colpitts oscillator. The input-output states of the inverter oscillate at the resonant frequency of the crystal.

2.6.9 UART Master Reset

MR: Master Reset. High level clears PE, FE, OE and DR and sets TRE, TBRE and TRO to high. MR should be pulsed high after power-up to reset the UART. A simple delay circuit using a capacitor and a NAND gate can be used to send a short positive pulse to MR on power-up. The time constant is simply the product RC, and values of R1 = 100 kΩ and C = 4.7 μF give a time constant of about 0.5 sec.

image

Initially, NAND output is at 0 V. When Vcc is applied, the NAND output goes to 1 since one input is at +5 V and the other at 0 V. As the capacitor charges up through R1, voltage at upper input to the NAND rises and after a time characterised by R1C, the NAND gate flips from 1 V to 0 V. The 1 kΩ resistor limits the current into the NAND for protection.

image

2.6.10 Null modem

The RS232 serial protocol was designed to transmit data over a considerable distance using the telephone network but may also be used for local communication to and from a device attached to the serial port of a computer. The exact same control lines may be used to regulate the flow of data between the connected equipment without the use of a modem; however, there is a problem: if both devices are connected pin to pin and attempt to send data over the transmit line, then no signals will appear on the receive lines. Thus, the transmit and receive lines must be crossed over. This type of connection is called a null modem.

image

Tying DTR, DSR and DCD together in effect tells the computer that the modem is connected to a telephone line upon which there is a valid carrier signal and data can be either sent or received. Of course, there is no modem present at all, hence the term null modem. TD, RD and signal ground are the minimum requirements for a serial connection between two computers, the other connections may be required if the communications software on the computers tests the modem status before sending or transmitting data.

In the example above, the connections between RTS and CTS, and DTR, DSR and DCD, cause the computer to regard the connection as occurring between modems even if no modem is used at all. For instance, the computer which is sending data first raises its RTS line, which is now directly connected to CTS. The sending computer thus immediately receives a CTS signal from its own RTS and begins to transmit data on TD. The receiving computer receives this data on its RD line.

2.6.11 Serial port BIOS services

BIOS services may be used to initialise and use the serial port. These services are available through interrupt 20 (14H). Parameters for the interrupt are specified in the AL register. The serial port is specified in DX. The four services available are:

image

AH AL
7 Time out 7 Receive signal detect
6 Transfer shift register empty 6 Ring indicator
5 Transfer holding register empty 5 Data set ready
4 Break-detect error 4 Clear to send
3 Framing error 3 Delta receive signal detect
2 Parity error 2 Trailing edge ring detector
1 Overrun error 1 Delta data set ready
0 Data ready 0 Delta clear to send

“Delta” bits indicate a change in the indicated flags since the last read.

The service to be called is placed into AH. Parameters for the service are placed in AL. The interrupt is called, and the results placed in AL (or AX for service 3).

mov AH, 0

int 14H

2.6.12 Serial port operation in BASIC

Serial communications can be easily implemented in BASIC. This language provides statements which allow programming of the UART without reference to the actual I/O port memory addresses. The serial port initialisation parameters are set using the OPEN statement:

OPEN “COM1:9600, N, 8, 1” AS #1

which initialises COM1 at 9600 baud, no parity, 8 data bits, 1 stop bit. Data is written to or read from a “file” numbered “1”.

To read 1 byte from COM1, we write:

A$=INPUT$(1,#1)

The byte is read from the receive buffer in the UART and converted to an ASCII character and then assigned to a string variable A$. To display the decimal number actually read, we can use the ASC function:

PRINT ASC(A$)

The INPUT$ function is the preferred method of reading data from the serial port. Other statements such as INPUT and LINE INPUT may work, but may give unpredictable results if the data in the input stream contains ASCII control characters such as LF and CR. If we were to use INPUT, then the input would stop when the incoming data contained a comma or a CR character. This is OK for reading in data from the keyboard, but not from a file where we may wish to capture all the data.

In Visual Basic (VB), the procedure is very similar. The COMM port object is placed on a form, in the example below, the form is called d frm MainMenu and the COMM port object is called MSComm1.

MSComm1 has properties that can be set in code that allow the serial port to which is assigned to be configured.

image frm_MainMenu.MSComm1.Settings = “9600, E, 7, 1”

frm_MainMenu.MSComm1.InputLen = 0

frm_MainMenu.MSComm1.RTSEnable = True

frm_MainMenu.MSComm1.DTREnable = False

frm_MainMenu.MSComm1.PortOpen = True

Methods available to the serial port object allow characters to be read and assigned to a variable, or the value of a variable to be written and transmitted from the computer:

ReadChar = frm_MainMenu.MSComm1.Input

frm_MainMenu.MSComm1.Output = WriteString + vbCr

2.6.13 Hardware handshaking

Although at first sight reading the serial port using BASIC appears fairly straightforward, difficulties arise when the data cannot be read fast enough and the input buffer overflows. The buffer holds 255 characters (i.e. 1 character = 1 byte). Handshaking (either software codes or hardware signals) is used to halt transmission of data from the sending computer until the receiving computer has emptied the buffer. Various functions are available in BASIC to allow either software or hardware handshaking.

image

For the serial data acquisition circuit, hardware handshaking must be used since there is no method of interpreting software codes such as XON and XOFF. The RTS line offers the most convenient form of hardware handshaking. RTS is arranged to go logic high (−10 V on RS232 signal lines) when the buffer is full, and then low when the buffer is empty. Now, the RTS signal line is available via the 2nd bit in the Modem Control Register. Setting this bit to 0 will actually set RTS to logic high. The BASIC OUT statement can be used to send a byte to an I/O port address. Thus:

OUT &H2FC,&H8 Set RTS logic high

OUT &H2FC,&HA Set RTS logic low

Note: The BASIC INPUT$ statement makes use of interrupts to read the data from the serial port. Make sure that OUT2 remains set at 1 when writing data to the MCR.

These statements, in combination with the LOC, LOF and EOF functions, can be used to control RTS. The RTS signal in turn can be wired to halt and resume transmission of data as required.

2.6.14 RS485

The maximum distance allowed by RS232 is about 15 m which in an industrial environment can be a severe limitation, especially when the computer is located say in a control room some distance away from the transducer. Further, the maximum data transfer rate can be a limitation for fast data acquisition. Standards such as RS422 and RS485 were developed to overcome these limitations and permit greater flexibility and performance for instrumentation applications.

An increase in transmission speed and maximum cable length is done by using voltage differentials on signal lines A and B. For a space, or logic 0, the voltage level on line A is greater than that on line B by 5 V. For a mark, or logic 1, the voltage level on line B is greater than that on line A. The receiver inputs on the line driver chip determine whether or not the signal is mark or space by examining the voltage difference between lines A and B. Two signal wires are thus required for data transmission.

Unlike RS232, in which there is usually a connection between two pieces of equipment, the RS485 standard allows for up to 32 line drivers and 32 receivers on the one set of signal lines. This is achieved by tri-state logic on the line driver pins.

image

Features of RS485:

image

2.6.15 GPIB

The General Purpose Interface Bus (GPIB) or IEEE 488 interface was developed in 1965 by Hewlett Packard for connecting multiple scientific measuring instruments together. Up to 15 devices may be attached to the interface lines (or bus). One of the devices can be activated as the “controller”. Control can be passed to another device if required.

The interface consists of:

• 8 data lines

• 3 data control lines

• 5 management lines

• 8 ground lines

image

GPIB connector

8-bit data can be transmitted in parallel, each bi-directional line carrying 1 Mbit/second. A maximum total cable length of 20 m with a maximum separation of 4 m between devices is recommended. Bus extenders and expanders can also be used.

image

Devices may be configured as listeners, talkers and controllers.

• Listener: A device set to be a listener can accept data over the bus from another device. More than one listener at any one time is permitted. A listener receives data when the controller signals it to read the bus.

• Talker: A device set to be a talker can send data to another device on the bus. Only one talker can be specified at any one time. The talker waits for a signal from the controller and then places its data on the bus.

• Controller: A controller can set other devices as listeners or talkers or to take control. The presence of a controller is optional. For example, if there is only one talker and all other connected instruments are listeners, then no controller is required.

Data is put onto the data bus by a talker when no device has pulled NRFD (not ready for data) low (negative logic). DAV (data valid) indicates that data is ready, and all devices then pull NDAC (no data accepted) low until the data is read. The parallel connection of devices ensures that NDAC goes high again when all listeners have accepted the data.

Each device responds to commands sent over the data bus. Each device can recognise its address when it appears on the data bus. The device address is usually set by dip switches or from software. The management of the bus is done by the controller which typically contains a special purpose IC on a GPIB interface card.

2.6.16 USB image

The range of peripheral devices now connected to personal computers are attached by serial, parallel and PS/2 ports, and the requirement for ease of use has resulted in the development of the Universal Serial Bus (USB). USB is designed to be a low cost, expandable, high speed, serial interface that offers “plug and play” functionality primarily for business and consumer peripherals.

Data transfer rates for the first implementation of USB were up to 12 Mbps. USB 2.0 allows up to 480 Mbps making it suitable for real time video and audio, high resolution digital cameras and data storage devices. A USB system consists of:

image

A maximum of seven tiers is allowed. Tier 1 is the root hub and Tier 7 can only contain devices.

In the USB system, one device must be the host and this places some restrictions on its use in an industrial setting. A simple modem, for example, can be wired using a null modem connection and be used with a PLC or other RS232 supported transducer. With a USB system, a computer must generally act as a host, even if communication is wanted only from one device to another.

The “on the go” (OTG) supplement to the USB 2.0 standard allows some degree of peer to peer communication without the need for a fully featured host.

In RS232 communications, the format of the data is not defined – it is usually ASCII text but need not be so. The USB uses layers of transmission protocols to transmit and receive data in a series of packets. Each USB transmission consists of:

• token packet

• optional data packet

• status packet

The USB host initiates all transactions. The token packet describes the type of communication (read or write and the destination address). The data packet contains the data to be communicated. The handshaking packet reports if the data was received or transmitted successfully.

image

USB is designed to be “plug and play”. When a device is plugged into the bus, the host detects its presence by signal levels on the data lines. It then interrogates the new device for its device descriptor, assigns a bus address to the device, and then automatically loads the required device driver. When the device is unplugged, the host detects this and unloads the driver. This process is called enumeration.

Firewire (IEEE 1394) is a serial interface standard originally developed by Apple Computer (ISB was originally developed by Intel). Firewire allows up to 400 Mbps and is a competitor to ISB (when first introduced, Firewire was several times faster than the then USB standard). Like USB 2.0, the main consumer benefit is high speed for video capture from digital cameras and camcorders without the need for dedicated video capture interface cards.

2.6.17 TCP/IP

TCP stands for Transmission Control Protocol, and IP stands for Internet Protocol. TCP/IP is a set of protocols that allows computers to communicate over a wide range of different physical network connections. TCP/IP provides protocols at two different layers of the OSI Reference Model. In everyday terms, the world wide web (www) and email (SMTP) make use of TCP/IP to communicate over the internet which in turn runs on a variety of packet switching network systems the most popular of which is the Ethernet. The actual connections between host computers is done by satellite, coaxial cable, phone lines etc. For interfacing applications, the internet is useful for communicating commands and results from a remote sensor, but would be unsuitable for a direct interface to the transducer due to the response time of the process.

image

2.6.18 Review questions

1. What basic digital logic circuit forms the basis of a UART used for serial communications?

2. The RS232 serial interface is very popular because of its availability and simplicity. Without actually describing the sequence of events, describe the function of the six most commonly used signal lines.

3. What is a “null modem’ and under what circumstances should it be used?

4. In a UART, why would the receiver clock be made to oscillate 16 times the rate of data transmission?

5. What is a parity bit?

6. Why is a 232 line driver IC required for communications between two UARTs which take place over an external signal cable?

7. Why, in serial communications, is there a choice of 5, 6, 7 or 8 data bits for the data being transmitted or received? (Hint: Investigate the ASCII code for character transmission.)

8. What is the main advantage of the RS485 interface standard?

9. What advantage would a GPIB interface have over an RS232 communication in an interfacing application?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.192.4