| 3.2 Microprocessor control system |
|
3.3 Operating software.
A ZX Spectrum computer running an assembler application was used as a development tool, to edit and compile the operating program prior to downloading into the microprocessor control system's EEPROM. A complete listing of the viscometer control software is presented in appendix B.
A modular programming approach was adopted, and a library of subroutines
for elementary functions developed (section 3.3.1).
These are called from subroutines which perform statistical analysis, calculate
the viscosity, control the period between measurements, and log data (section
3.3.2). These in turn are called from a main control program, under
direct user control (section 3.3.3).
The collection of subroutines perform the basic functions listed below [ref. 6 & 7]. A 5 byte floating point format is used, consisting of a 32-hit fractional part, 8-hit exponent part, and sign bit. The numbers so represented have a range of +/- 3.4 x 10^38, to a precision of one part in 4.3 x 10^9.
i) Clock/Timer: The 50Hz mains frequency counter is used to drive a real-time clock/timer, which may be displayed in either hours/minutes or hours/minutes/seconds format, according on the user's preference. The 50 Hz counter is 8-bit so in order to retain the correct time, the clock routine must be called at least every 5 seconds. In fact it is called more often, whenever the keyboard is scanned or readings taken, which in practice accounts for most of the processor's time.
ii) Input routines: These scan the keyboard, accept user input of floating point decimal numbers, and convert to the normalised binary floating point format adopted.
iii) Print routine: This allows the program to output a result to the display. The binary floating point number is converted to decimal, and leading zeros blanked.
iv) Error handling: The user is informed of any measurement or arithmetical errors that have occurred. A list of the possible error codes that may be generated is shown in table I below.
v) Arithmetic functions: These operate on numbers in normalised floating point format, and perform the following operations: addition, subtraction, multiplication, reciprocal and division.
vi) Read routines: These read the mark/space ratio and period of rotation, of the viscometer mechanism. If measurement of a viscosity outside the possible range is attempted, an appropriate error is indicated.
vii) Reset: This routine monitors the 'RST' key; if it is pressed for longer thah 1/2 a second a system reset is pefformed. This is similar to switching the machine off and on again, except that none of the results or user defined parameters are erased, with the exception of the time and measurement interval.
viii) Regld, Regsv: These two routines load/save the
Z80's registers form/to the stack (upper part of the system memory that
is used as temporary storage space by the processor). They are often called
at the start and finish of a subroutine, in order that the Z80's registers
are preserved by the routine.
| Code | Cause | Possible solution |
| E 0 | Division by zero | This could occur if a calibration viscosity of zero was entered, or if there was no calibration |
| E 1 | PRINT overflow | The magnitude of the viscosities is too large, use a smaller unit of viscosity |
| E 2 | PRINT negative | * |
| E 3 | Viscosity too large to measure | Fit a smaller glass stirrer, or larger beaker |
| E 4 | Viscosity too small to measure | Fit a larger giass stirrer, or smaller beaker |
| E 5 | Measurement range too small | * |
| E 6 | FPINT conversion error | * |
| E 7 | FPINT negative conversion | * |
| E 8 | Viscosity < Preset minimum | Decrease the pre-set minimum entered |
| E 9 | Viscosity > Preset maximum | Increase the pre-set maximum entered |
| E A | Too many readings requested | There is only space for 6000 measurements. Enter a smaller number of measurements. |
3.3.2 Viscosity measurement subroutines:
The procedure for viscosity determination is shown in the flow diagram, figure 6. First a useful measurement range is determined, by starting the motor at its maximum rate and gradually reducing the speed in steps until the displacement between the disks in the mechanism falls below 170 degrees. The lower end of the range is found by increasing the motor speed from zero until a displacement is first detected. In order that transitional oscillations in the spring or extreme damping have time to decay, five revolutions of the mechanism are allowed to pass at each speed before reading the angular displacement. Measurements near to the lower end of the range could suffer low resolution and hence inaccuracy; therefore a small amount is added here. Once these two limits have successfully been set, the processor proceeds to take ten readings of displacement angle at ten speeds equally spaced within the range. Again transitional effects are allowed to pass, by now walting for ten revolutions before reading, at each speed. A statistical analysis [ref. 8] performs a least squares best fit on the data, to find the gradient of the graph of displacement against speed (see section 2.3). This gradient is related to that obtained from a previous calibration reading, and the viscosity calculated.
Having obtained the viscosity, it is then checked to ensure that it
lies within a user specified range. If for instance if it becomes to large,
no further measurements are taken. This useful function could also be used
to sound an alarm if the viscosity of the test fluid deviated too greatly
from a specified value. The viscosities are logged in the system memory,
where there is space for up to six thousand results. After the experiment,
these may be scanned by the operator.
Figure 6: Flow diagram of the subroutine for viscosity measurement.
The main control program is under direct control of the user, and calls the various subroutines as required. The user selects the desired operation by typing its code on the keyboard and pressing 'RUN'. A list of the avallable programs is shown in table 2 below. The system may be reset at any time by pressing the RST' key for longer than 1/2 a second.
The 'A' programs allow the user to enter parameters for the measurements.
The time may be set (Al) and the frequency of automatic measurements specified
(A2). The desired format of time display is also selectable: type 'A' for
hours/minutes format, and 'B' for hours/minutes/seconds format. A
calibration reading is carried out by program A3: the user must immerse
the stirrer of the mechanism in a fluid of known viscosity, and type in
this value (in stokes, centistokes or poise: as long as later measurements
are in units consistent with this calibration). The system then performs
a set of readings and calculates the gradient of the displacement/speed
graph (section 3.3.2). All subsequent
measurements are referenced to this value. Minimum and maximum alarm viscosities
may be entered (A4), and the number of measurements required specified
(A5). Note that programs A3-A5 have no default values, thus it is essential
that they are run every time the system is
first switched on, although not necessarily following a system reset.
The 'B' programs are for actual viscosity determination. For a oneoff measurement program B1 may be run, while for continuous viscosity monitoring B2 is used. Programs B3 and B4 are for automatlc timed measurements, and both log the results in system memory. The interval between measurements, number of readings required, and range are as specified in programs A2, A5, and A4 respectively. The difference between programs B3 and B4 is that the former displays the actual time as set by A3, while the latter displays the time elapsed since the start of the experiment. This would be useful for example in lubticant oxidattion experiments.
Program 'C' allows the user to scan through the recorded data, using
the +/- keys. The measurement number or viscosity value may be displayed,
by pressing the A or B keys respectively.
| Program | Function |
| A1 | Set the system clock; default value 0:00 |
| A2 | Specify the interval between measurements; default value 1:00 |
| A3 | Perform a calibration reading using a fluid of known viscosity |
| A4 | Enter minimum and maximum alarm viscosities |
| A5 | Specify the number of measurements required |
| B1 | One-off viscosity measurement |
| B2 | Continuos viscosity measurement |
| B3 | Automatic operation, with the display showing the clock |
| B4 | Automatic operation, with the display showing the time elapsed |
| C | Scan through the results of B3 or B4 |
| 3.2 Microprocessor control system |
|