Main | Penguins | Electronics projects | Other projects | Travel | Photos | Design | Publications

A TLC549 A to D converter on the serial port of a PC

System setup

The TLC549 is an 8 bit AD converter with a serial output and a conversion time of 17μs. The TLC548 is a faster version and the TLC1540 a 10 bit equivalent (21μs).

The connection to the RS232 port can be very simple as shown in Figure 1.

Figure 1: Connection of TLC549 AD converter to control lines of RS232 port

In this set-up the RS232 port is not used as it should be, but the system works on three handshake-lines. The RS232 signals may vary between -12V and +12V so zener-rectifiers are necessary to convert this signals to TTL levels. Notice that the forward potential drop across silicon based diodes is about 0.7, this would result in a -0.7 volt signal at the CS and CLK inputs of the TLC459 with negative RS232 signals. This is too much according to the specifications (max -0.3 volt) so the diodes must be connected to +0.7 volt. In the experimental set-up this was done by the use of a 190Ω/1kΩ voltage devider between 0 and 5 volt. Better RS232 to TTL-level converters are with a transistor as shown in Figure 2.

Figure 2: RS232 To TTL-level converter with a pnp transistor

The connections with the computer port is as follows (the direction is relative to the computer):

GNDDTRRTSDSR
9 - pins sub-D connector5476*)
25 - pins sub-D connector72046
Direction-OutOutIn
*) The DSR signal is not always on the 9 - pins sub D connector

The handshake pins can directly be accessed in Turbo Pascal:

Action:Pascal command:
RTS off, DTR offPort [BA+4] := 0;
RTS off, DTR onPort [BA+4] := 1;
RTS on, DTR offPort [BA+4] := 2;
RTS on, DTR onPort [BA+4] := 3;
Read DSRDSR := ((port [BA+6] and 32) = 32)

with BA is the base adress of the serial port and is 3F8H for COM1 and 2F8H for COM1. This direct access works at least under Windows 98 and Windows 95 and DOS.

The measure range is here set to 0..5 V by connecting Ref+ and Ref- to ground and Vcc. From the specifications it can be seen that this are the maximal allowed boundaries.

An example of a pascal program for controlling the TLC549

This program uses the timer interrupt to synchronize the serial port (RS232). After 300 points are being sampled an oscilloscope image is drawn. The program assumes that the full scale is from 0 to 5 volt. The complete listing is given in appendix B, here is a short functional description.

No second timer is available for timing the sampling routine (according to the specifications of the TLC549 there are some ristrictions to the control signals). The sampling routine may last as long as the time between two sample interrupts. On the slowest possible computer the sampling routine must be fitted to this period.

Figure 3: Clock cycles

The used global constants and variables are:

constants
	BA = $3F8	: Adress of COM1 port 
variables
	samp	 	: Stores 300 sampled bytes
	counter 	: Counts how many samples are taken
	oldvector 	: Stores the pointer to the old timer interrupt;
	samplefreq	: The sample frequency (1kHz by default or else the value after
				the /f parameter on the command line);
	grid      	: toggles grid on/of (off by default, true if /g parameter is
				present on the command line);

In pseudo-pascal the sample method is:

program TLC549;

	procedure sample;
	begin
		give CS signal to TLC549;
		give 8 CLK signals and read 8 Dout values from TLC549;
		increase counter;
	end;

begin
	Re-direct timer interrupt to procedure "sample" and set the required preload value;
	Wait until the desired number of samples is taken;
	Restore timer interrupt;
	Draw a graph;
end.

Description of the procedures:

procedure EGAVGA_driver; external;
Is necessary to link the graphics driver which is stored in an object file. The *.OBJ file can be made from the EGAVGA.BGI file using BINOBJ.EXE which is given with Turbo Pascal and Borland Pascal. Command line example:
	BINOBJ   egavga.bgi   egavga.obj   EGAVGA_driver
procedure Read_commandline;
Interpretes the command line. There are two options: the /g option sets the grid on, the /f #S option sets the sample frequency to the value #S.
procedure str_to_int(stri:string;var intg:integer);
Converts string "stri" to an integer value "intg"
Procedure Init_scoop_beeld;
Initializes the graphics driver, draws the screen including graph and scaling.
Procedure eoi; inline ($B0/$20/$E6/$20);
Takes care of the handling of the old interrupt $08 (with interrupt $1C this is probably not necessary).
procedure sample; interrupt;
Samples on every interrupt $08 a value from the AD-converter. This is done by using two lines out and one line in:
Pascal commandoTLC549 pinRS232 line
Outport[BA+4] := 2/CSRTS
Outport[BA+4] := 1CLKDTR
Inport[BA+6] and 32DoutDSR
procedure init_interrupt;
Loads the timer register with the accurate preload value to obtain the desired timing (sample frequency). After that the timer interrupt $08 is connected to the own procedure "sample" and the old interrupt vector is stored in the variable "oldvector".
procedure interrupt_done;
Returns the interrupt vector to the original interrupt procedure.
procedure draw_grid;
Draws the grid lines.
procedure Scoop_beeld;
Draws the signal ("samp" variable) in the graph and decides if the grid should be drawn.

Some experiments were performed using a 80286 computer with a clock frequency of 12MHz. No wait states between the rise and fall of the CS and CLK signals were necessary and the program was reliable to a sample frequency of 8kHz (in the sensor/actuator system a sample frequency of 1kHz will be high enough). This was checked using an oscilloscope. The limit was dependent on the computer and was the result of the generation of a second interrupt while the previous interrupt routine was not yet finished. The AD-converter could follow the fastest possible frequency.

At the left a 35 Hz sine signal sampled with a samplefrequency of 5 kHz. The right figure shows a pulse signal with a pulse period of 10 ms and a pulse duration of 4 ms. Both pictures were made with the program listed in appendix B and grabbed with the GRAB.COM program from WordPerfect 5.1.

Figure 4: Screenshot of sampled data

The Borland Pascal 7.0 sourcecode can be found here