Login| Sign Up| Help| Contact|

Patent Searching and Data


Title:
PRESSURE/VACUUM REGULATOR
Document Type and Number:
WIPO Patent Application WO/1996/041244
Kind Code:
A1
Abstract:
A pressure regulator apparatus and method for controlling the pressure in a pressure system are disclosed. The pressure regulator broadly includes a pressure transducer (24) and a regulator control circuit (26). The pressure transducer (24) measures the pressure of the pressure system, and the regulator control circuit (26) controls the pressure in the pressure system in response to the pressure reading of the pressure transducer. The regulator control circuit (26) compares the measured pressure to a predetermined set-point value for maintaining the pressure within a predetermined optimal pressure range.

Inventors:
TAN JINGLU (US)
WANG LIMIN (CN)
Application Number:
PCT/US1996/010046
Publication Date:
December 19, 1996
Filing Date:
June 07, 1996
Export Citation:
Click for automatic bibliography generation   Help
Assignee:
UNIV MISSOURI (US)
TAN JINGLU (US)
WANG LIMIN (CN)
International Classes:
A01J5/007; A01J5/04; A01M15/00; A01M19/00; G05D16/20; (IPC1-7): G05D16/20
Foreign References:
US4456038A1984-06-26
US5161777A1992-11-10
US5141403A1992-08-25
US4011838A1977-03-15
Other References:
See also references of EP 0830648A4
Download PDF:
Claims:
Claims:
1. A pressure regulator for controlling the pressure of a pressure system, the pressure system having a valve for letting fluid flow into or out of the pressure system, said pressure regulator comprising: measuring means for measuring the pressure of the pressure system; and control means responsive to said measuring means for controlling the amount of fluid flow into or out of the pressure system by controlling the opening and closing of the valve, said control means including maintaining means fo.r maintaining the pressure of the pressure system within a predetermined optimal pressure range.
2. The pressure regulator as set forth in claim 1 , said maintaining means including comparing means for comparing the pressure measured by the measuring means to a predetermined setpoint and for generating a control signal when the measured pressure is different from the setpoint.
3. The pressure regulator as set forth in claim 2, said comparing means including a microprocessor.
4. The pressure regulator as set forth in claim 3, said control means further including a valve operator coupled between said microprocessor and the valve for opening or closing the valve in response to said control signal.
5. The pressure regulator as set forth in claim 1 , said control means being operable for receiving control parameters associated with the pressure system's operating dynamics for controlling the opening and closing of the valve in accordance with the control parameters.
6. The pressure regulator as set forth in claim 5, said control means further including a dip switch coupled with said microprocessor for inputting said control parameters and said setpoint into said microprocessor.
7. The pressure regulator as set forth in claim 6, said measuring means including a pressure transducer for measuring the pressure of the pressure system and for generating an analog pressure signal represen¬ tative of said pressure.
8. The pressure regulator as set forth in claim 7, including amplifying means for amplifying said analog pressure signal and converting means for converting said amplified analog pressure signal to digital format for delivery to said microprocessor.
9. The pressure regulator as set forth in claim 1, the valve including a servo valve.
10. In a milking system including a vacuum pump for creating a vacuum within the system, one or more balance tanks, pipelines for distributing the vacuum, one or more milking stations coupled with the pipelines, and a valve for introducing ambient air into the system, a pressure regulator for controlling the pressure of the system, said pressure regulator comprising: measuring means for measuring the pressure of the milking system; and control means responsive to said measuring means for controlling the opening and closing of the valve for controlling the amount of ambient air inflow into the milking system; said control means including comparing means for comparing the pressure measured by the measuring means to a predetermined setpoint and for generating a control signal when the measured pressure is different from the setpoint, and valve operating means coupled between said comparing means and the valve for opening or closing the valve when said comparing means generates said control signal for maintaining the pressure of the milking system within a predetermined optimal pressure range.
11. The pressure regulator as set forth in claim 10, said comparing means including a microprocessor.
12. The pressure regulator as set forth in claim 10, said valve operating means including a digitaltoanalog converter and an amplifier circuit.
13. The pressure regulator as set forth in claim 10, said control means being operable for receiving control parameters associated with the pressure system's operating dynamics for controlling the opening and closing of the valve in accordance with the control parameters.
14. The pressure regulator as set forth in claim 11 , said control means further including a dip switch for inputting said control parameters and said setpoint into said microprocessor.
15. The pressure regulator as set forth in claim 14, said measuring means including a pressure transducer for measuring the pressure of the pressure system and for generating an analog pressure signal represen¬ tative of said pressure.
16. The pressure regulator as set forth in claim 15, including amplifying means for amplifying said analog pressure signal and converting means for converting said amplified analog pressure signal to digital format for delivery to said microprocessor.
17. The pressure regulator as set forth in claim 10, the valve including a servo valve.
18. A method of controlling the pressure of a pressure system comprising the steps: measuring the pressure of the pressure system; introducing into or removing fluid from the pressure system by a valve means to alter the pressure of the pressure system; and controlling the amount of fluid flow into or from the pressure system by controlling the opening and closing of the valve means, said controlling step including the steps of comparing the measured pressure to a predetermined setpoint and opening or closing the valve when the measured pressure is different from the setpoint.
19. The method as set forth in claim 18, wherein said measuring step is performed with a pressure transducer.
20. The method as set forth in claim 19, wherein said comparing step is performed with a microprocessor.
21. The method as set forth in claim 20, wherein the setpoint range and control parameters are entered into said microprocessor with a dip switch.
22. The method as set forth in claim 18, wherein said valve opening and closing steps are performed with an amplifier coupled between said microprocessor and said valve.
23. The method as set forth in claim 18, said valve means including a servo valve.
Description:
PRESSUREΛ/ACUUM REGULATOR

Microfiche Appendix

A microfiche appendix containing a source code of a computer program useful in accordance with the present invention is appended hereto as 1 sheet of microfiche containing 21 frames.

Background of the Invention

1. Field of the Invention

The present invention relates to pressure regulators for controlling the pressure in pressure systems, and more particularly to a pressure regulator apparatus and method for controlling the pressure in a milking system by maintaining the pressure within a predetermined optimal range. As used herein, pressure is understood to mean absolute pressure which encompasses both vacuum and gauge pressure.

2. Description of the Prior Art

Pressure systems are used in many processes including milking systems, food production and processing systems, oil and gas distribution systems, and other manufacturing and distribution systems. Pressure systems typically include one or more pressure or vacuum pumps, one or more reserve tanks, pipelines, and a control valve for letting fluid flow into or out of the system to alter the pressure in the system. For optimal pressure system operation, a steady pressure is desired. However, during use, the pressure of a pressure system varies due to fluid usage and loss by the components of the pressure system. Pressure regulators attempt to compensate for these variances by controlling the opening and closing of the control valve to maintain a desired pressure. Prior art pressure regulators suffer from several limitations that limit their utility. For example, prior art pressure regulators are not rigorously designed to take into account the system dynamics of pressure systems and thus cannot be reconfigured for different pressure systems. Accordingly, prior art pressure regulators cannot be customized for optimal control of a specific installation.

A more particular limitation of prior art pressure regulators is that they do not control pressure in accordance with an optimal set-point. Thus, prior art pressure regulators often drift away from the desired pressure to a new pressure level when system fluid usage or other conditions change. As a result, when using prior art pressure regulators, it is necessary to frequently measure the pressure in the pressure system and recalibrate the pressure regulator.

Accordingly, there is a need for an improved pressure regulator that overcomes the limitations of the prior art. More particularly, there is a need for a pressure regulator that is designed to take into account the system dynamics of pressure systems so that it can be customized for optimal control of a specific installation. Additionally, there is need for a pressure regulator that controls pressure in a pressure system in accordance with an optimal set-point.

Objects and Summary of the Invention

The present invention overcomes the problems outlined above and provides a distinct advance in pressure regulators. More particularly, the pressure regulator of the present invention can be customized for optimal control of a pressure system and controls the pressure in the pressure system in accordance with an optimal set-point.

The pressure regulator of the present invention broadly includes a pressure transducer and a regulator control circuit. The pressure transducer measures the pressure of a pressure system and the regulator control circuit controls the pressure in the pressure system in response to the pressure reading of the pressure transducer. The pressure regulator maintains a desired pressure within the pressure system by controlling the opening and closing of the pressure system control valve.

Advantageously, the regulator control circuit includes a micropro¬ cessor for comparing the measured pressure to a pre-determined set-point. If the measured pressure is different from the desired set-point, the microproces¬ sor generates an appropriate control signal for opening or closing the pressure system's control valve. The opening and closing of the control valve controls the fluid flow into or out of the pressure system for maintaining the desired pressure in the pressure system.

ln a preferred embodiment of the invention, the pressure regulator is operable for controlling the vacuum in a milking system.

Brief Description of the Drawing Figures A preferred embodiment of the present invention is described in detail below with reference to the attached drawing figures, wherein:

Figure 1 is a schematic diagram of a pressure regulator apparatus shown coupled with a milking system;

Fig. 2 is an electrical circuit diagram of the pressure regulator apparatus constructed in accordance with the preferred embodiment of the invention;

Fig. 3 is a flow diagram illustrating the control steps of the pressure regulator apparatus;

Fig. 4 is a graph illustrating the pressure regulator's response to disturbances in air usage in a pressure system;

Fig. 5 is a block diagram of a closed-loop pressure control system; and

Fig. 6 is a Bode plot of open-loop plant and desired closed-loop transfer functions.

Detailed Description of the Preferred Embodiments

Turning now to Figs. 1 and 2, a pressure regulator 10 constructed in accordance with a preferred embodiment of the invention is illustrated as an example to facilitate the following discussion and description. The pressure regulator 10 is preferably used for controlling the pressure or vacuum in a milking system 12 including pipelines line 14, 15, 17, 19, and 21 one or more milking stations 16 connected to the pipelines, a receiver tank 18 for receiving milk from the milking station 16, two balance tanks 23, a vacuum pump 20 for creating a vacuum within the system and a control servo valve 22 for introducing airflow into the milking system to alter the pressure in the milking system.

The pressure regulator 10 maintains a desired pressure within the milking system 12 by controlling the opening and closing of the milking system control servo valve 22. As best illustrated in Fig. 2, the pressure regulator broadly includes a pressure transducer 24 and a regulator control circuit 26.

In general, the pressure transducer 24 measures the absolute pressure in the milking system 12, and the regulator control circuit 26 controls the pressure in the milking system 12 in response to this pressure measurement.

In more detail, the pressure transducer 24 is operable for measuring the actual pressure at any point in the milking system 12. The pressure transducer 24 measures the pressure and converts it into an analog pressure signal. The pressure transducer 24 is preferably a Model No. ITQ-

1000 transducer manufactured by Kulite Semiconductor Products, Inc.

It is advantageous to position the pressure transducer 24 near the milking stations 16 of the milking system 12 since this is where the level of the pressure is the most important. Accordingly, as illustrated in Fig. 1 , the pressure transducer 24 is preferably positioned on the milk receiver tank 18 of the milking system 12.

The regulator control circuit 26 controls the pressure in the milking system 12 in response to the analog pressure signal generated by the pressure transducer 24. The regulator control circuit 26 broadly includes an input amplifier 28, an analog-to-digital converter 30, a microprocessor 32, a dip switch 34, a pushbutton circuit 36, a digital-to-analog converter 38, an output amplifier 40, and a transistor 42. These components cooperate for controlling the opening and closing of the milking system control servo valve 22 to control the pressure in the milking system 12.

The input amplifier 28 receives the analog pressure signal from the pressure transducer 24 and amplifies the pressure signal for delivery to the analog-to-digital converter 30. The input amplifier 28 is preferably a type AD624 solid-state device.

The analog-to-digital converter 30 receives the amplified pressure signal from the input amplifier 28 and converts the analog signal into a 12-bit digital signal. A 12-bit digital signal is preferred to provide the desired control sensitivity. The analog-to-digital converter 30 is preferably a type AD674B solid-state device. Diode D1 and potentiometer R3 are coupled with the output of the input amplifier 28 to set an upper limit on the analog input to the analog- to-digital converter 30 to protect it from excessive current.

The microprocessor 32 controls the opening and closing of the milking system's 12 control servo valve 22 in response to the pressure signal

generated by the pressure transducer 24. The preferred microprocessor 32 is a Model MC68HC11 type chip.

The microprocessor 32 receives the 12-bit digital pressure reading from the analog-to-digital converter 30 and compares this reading to a pre-determined pressure set-point. If the measured pressure is greater than the desired set-point, the microprocessor 32 generates a control signal for closing the milking system's 12 control servo valve 22. Conversely, if the measured pressure is less than the desired set-point, the microprocessor 32 generates a control signal for opening the milking system's 12 control servo valve 22. The control signals ramp the opening and closing of the control servo valve 22. The opening and closing of the control servo valve 22 controls the inflow of ambient air into the milking system 12 for maintaining the desired pressure in the milking system 12. The logic and operation of the micropro¬ cessor 32 are described in the Operation section below. The dip switch 34 and the pushbutton circuit 36 are provided for entering control parameters and pressure set-points into the microprocessor 32. The dip switch 34 is a conventional 8-bit dip switch. The pushbutton circuit 36 includes a pushbutton switch 44 and a pair of inverters 46.

In the preferred embodiment, three control parameters b 1( b 2 , and b 3 and a pressure set-point in Pascal are entered into the microprocessor 32.

Each of these values are entered into the microprocessor 32 1-byte at a time by the dip switch 34. The pushbutton circuit 36 serves as an "Enter Key" for entering the values set on the dip switch 34. The entering of the control parameters and pressure set-point is discussed in detail in the Operation section below.

The digital-to-analog converter 38 receives the digital control signals from the microprocessor 32 and converts these signals into analog control signals. The digital-to-analog converter 38 is preferably a type DACO800 solid-state device. The output amplifier 40 receives the analog control signal from the digital-to-analog converter 38 and amplifies them for delivery to the transistor 42. The output amplifier 40 is preferably a type LM741 solid-state device.

The transistor 42 receives the amplified control signal and drives the milking system's 12 control servo valve 22 actuator to open or close the

control servo valve 22 to alter the pressure of the milking system 12. The transistor 42 is preferably a type 2N1490 solid-state device.

OPERATION The operation of the above-described pressure regulator 10 is based on applicant's modeling of the characteristics of typical pressure and vacuum systems. A block diagram of a closed-loop system is shown in Fig. 5. G p (s) is the pressure system transfer function from total fluid inflow M(s) to system pressure (or vacuum) P(s), fluid usage M d (s) is a disturbance to system pressure, and M c (s) is the fluid inflow determined by regular G c (s) from pressure error E(s). Proper design of regulator G c (s) requires knowledge of pressure system model G p (s). Applicant has discovered that pressure system dynamics can be described by the following equations and characteristics.

Equation 1

P i s ) K

G p ( a ) M i s )

with

Equation 2 γRT Y

V V

where P is system pressure, M is mass fluid flow into the system, s is the

Laplace variable, V is the total system internal volume, q is the pump 20 volume flow capacity (combined if multiple pumps are used), R is the gas constant, T is absolute ambient fluid temperature, and y is the heat capacity ratio for the fluid. This model has been validated on systems of different capacities and configurations and proven to be valid at frequencies where the dynamic behavior of the pressure system is most important.

Equation 1 indicates that the pressure system itself acts as a low- pass filter. Variations in fluid inflow above the frequency of α radians/s are attenuated in the pressure responses. The pressure regulator 10, therefore, only needs to provide additional compensation to block disturbances at low

frequencies. This not only makes sense from dynamic considerations but also lowers hardware requirements for the regulator system. For disturbance rejection, a logical choice of the desired closed-loop transfer function from disturbance M d (s) to P(s) (see Fig. 5) is

Equation 3

where K c and β are constants to be selected.

The first factor on the right-hand side of equation 3 is the plant (pressure system) transfer function, which blocks high-frequency fluid flow disturbances. The second factor is the additional compensation provided by the pressure regulator 10, which blocks low-frequency fluid flow disturbances. K c (<1 ) specifies a gain reduction over all frequencies, β is the frequency below which the pressure regulator 10 should provide increased attenuation, β should be greater than α, K,, and β are determined based on the capabilities of the regulator hardware used.

Fig. 6 shows the Bode plots of the desired closed loop G d (s) and open-loop plant G p (s) for the following conditions: The plant has a 0.0755-m 3 /s

(80 CFM-ASME Standard) pump and 0.288-m 3 internal volume, which gives or = 0.367 and K p = 408776 at T - 293 K (20°C). K c and β are selected as K c = 0.5 and β = 100α. As shown by the difference between the two curves in Fig. 6, a pressure regulator satisfying the selected G d (s) would provide a consider- able amount of additional attenuation to disturbances, especially at low frequencies.

In anticipation of digital implementation of the pressure regulator, a zeroth-order hold G h (s) should be added at the output of regulator G c (s) in Fig. 5 to account for the effects of discrete-time sampling and D/A conversion. The transfer function for a zeroth-order hold is usually simplified as follows:

Equation 4

s — τ

where T is sampling period. Since a very small T (about 0.01 s) is used in hardware implementation, the zeroth-order hold will primarily contribute to high- frequency dynamics. For a small T and at low frequencies where the system dynamics is of concern, the zeroth-order hold can be further simplified to a gain T; i.e., G h (s) * T. Realizing that the set-point in Fig. 5 is a constant, we can find the pressure regulator satisfying the desired closed-loop transfer as:

Equation 5

G P G d ( s a ) ( s δ)

G ( s )

G p G d G h„ Bs

where:

Equation 6

β K K τ

P c

K 1 K

Converting the pressure regulator in equation 5 from the s domain to the z domain by using matched pole and zero mapping yields the following digital regulator:

Equation 7

Because the closed-loop gain is high between α and β (Fig. 6), it is of interest to ensure that the gain in this frequency range is not changed by the conversion. This is accomplished by selecting K z so that equations 5 and 7 are equal at angular frequency α; i.e.,

Equation 8

2 (α δ) ( e 2ατ 1 )

K,

Z e 2 ' αmτ ( e a °" τ _ e= δ OτT ) \ _e= ααττ _ e=. ( ot δ) τ

Equation 7 can be written into a digital regulator in the time domain as:

Equation 9 m c ( k) m c ( k 2 ) b^e i k) b 2 e { k 1 ) b 3 e ( k 2 )

where m c is the fluid mass flow admitted by control servo valve 22 controlled by the pressure regulator, e is the error between the pressure set-point and the measured system pressure, k is an integer, and

Equation 10

K

B

K ( e e )

(α δ) τ β

Along with the pressure set-point, b^ b 2 , and b 3 are the four configuration parameters for the pressure regulator 10. The pressure set-point should be specified in Pa. b b 2 and b 3 are dependent on the system capacities and the computation procedure is reiterated as follows:

(1) Use equation 2 to find plant gain k p , and pole α from pump 20 volume flow rate q in m 3 /s and total system internal volume in m 3 . For air, R = 287 Nm/kgK and y = 1.4. An average of absolute ambient fluid temperature in Kelvin should be used for T, such as 293 K.

(2) Choose a gain reduction factor K c and closed-loop pole value β (K c = 0.5 and β = 100α were found adequate for all the systems tested on and are thus recommended). Sampling period T was set at 0.01125 s in the hardware

implementation. Find pole δ and gain B with equation 6, and determine gain K 2 with equation 8. (3) Determine b.,, b 2 and b 3 with equation 10.

The above-described modeling equations are incorporated into a control program in the instructions of the microprocessor 32 for controlling the operation of the regulator control circuit 26. The source code of the control program is reproduced in the attached microfiche appendix and its steps are illustrated in the flow diagram of Fig. 3. The control program employs software- implemented 24-bit floating-point arithmetics. Each floating-ppint number takes

5-bytes: 3-bytes for the mantissa, 1-byte for the exponent biased by hexadeci¬ mal 80, and 1-byte for the mantissa sign.

Referring to Fig. 3, the program enters at step 100 which initializes the pressure regulator control scheme by defining various variables. Step 102 then determines whether the control parameters are to be reconfig¬ ured. To do this, step 102 checks the status of the PA ! port of the microproces¬ sor 32 to see if the pushbutton switch 44 of the pushbutton circuit 36 has been depressed. When the pushbutton switch 44 is depressed, the answer to step 102 is yes; otherwise it is no. If the answer to step 102 is no, the program continues at step

106. If the answer to step 102 is yes, the program proceeds to step 104 for inputting new control parameters. This step is part of the subroutine RDGAINS described in detail in the source code listed in the Appendix.

Step 104 first erases the old control parameters from the EEPROM of the microprocessor 32. Step 104 then waits to receive the control parameters b^ b 2 , and b 3 and the pressure set-point in Pa for reconfiguring the control scheme in the microprocessor 32. Each of the control parameters must be first converted to a 3-byte mantissa with the binary point to the left of the first non-zero most significant bit and a 1-byte exponent biased by hexadecimal 80. The pressure set-point must be first converted into a 2-byte integer.

The control parameters and the pressure set-point are entered into the microprocessor 32 in the form of fourteen 8-bit numbers. These numbers are entered one at a time by the dip switch 34 and the pushbutton circuit 36 into ports PC 0 -PC 7 of the microprocessor 32. The control parameters are preferably entered in the following order: the exponent byte of b^ the high,

middle, and low mantissa bytes of b^ 4-bytes for b 2 and 4-bytes for b 3 in the same order as for b^ and the high and low bytes for the pressure set-point. After a byte is set on the dip switch 34, the pushbutton switch 44 of the pushbutton circuit 36 is depressed to enter the number into ports PC 0 -PC 7 of the microprocessor 32.

Step 104 then stores the control parameters b 1f b 2 , b 3 and the pressure set-point into memory and converts the pressure set-point into a floating-point number.

The program next moves to an error checking loop defined by step 106. Step 106 checks the difference between the pressure set-point and the actual system pressure measured by the pressure transducer 24. If the difference is not greater than a pre-determined value, the program enters a loop through step 106. This prevents the regulator algorithm from integral winding-up when the pump is off or recently turned on. In the preferred embodiment, the comparison pressure value in step 106 is 1.5 kPa.

If step 106 determines that the difference between the pressure set-point and the actual system pressure is within 1.5 kPa, the program proceeds to control loop consisting of steps 108 -118. In the control loop, step 108 is another comparison to determine if the pump is turned off. In the preferred embodiment, the second comparison pressure value is 10 kPa. If the difference is less than -10 kPa, the program determines that the pressure system pump 20 is turned off and thus returns to step 106. However, if the difference is greater than -10 kPa, the program moves to steps 110-118 for adjusting the pressure of the pressure system. Step 110 first reads the measured pressure from ports PE 0 -PE 7 of the microprocessor 32. Steps 112 and 114 then compute the error value e(k), and the control variables b 1 e(k), b 2 e(k-1), and b 3 e(k-2). The control variables and a past controller output m c (k-2) are summed together according to equation 9 above to produce the current controller output. Step 116 then checks the new controller output for proper limits, converts the controller output into an integer, and sends the controller output to the digital-to-analog converter 38 for controlling the opening and closing of the servo valve 22. Finally, step 118 saves the error and control output values for future control computations.

Fig. 4 illustrates the operation of a prototype of the above described pressure regulator 10. The prototype included a 0.0755-m 3 /s (80

CFM) vacuum pump and 0.288-m 3 internal system volume. With a selection of K c =0.5 and B = 100α as recommended, the computed configuration parameters were: b, = 0.0569 (O.E90F*16 7C ) hex b 2 = 0.0816 (O.A758*16 7D ) hex b 3 = 0.0248 (O.CB28*16 7B ) hex

The pressure set-point was 50 kPa. An ll-L/s free ambient air, about 1/3 of the vacuum pump 20 capacity at 50 kPa, was suddenly added at about 6 s and removed at about 15 s. This created step changes of consider¬ able size in air usage. As seen from Fig. 4, the maximum overshoot was only about 1 kPa, which is very small considering the size of the disturbance. Recovery to the original set-point was immediate for practical purposes. The curve shape of pressure deviations agrees with the desired closed-loop transfer function G d (s), so the pressure regulator performed as it was designed. Performance as shown by Fig. 4 or better was obtained on all systems tested. The overshoot was generally between 0.5 and 1 kPa for the above mentioned step changes in air usage. Although the invention has been described with reference to the preferred embodiment illustrated in the attached drawing figures, it is noted that equivalents may be employed and substitutions made herein without departing from the scope of the invention as recited in the claims. For example, the pressure regulator of the present invention has been illustrated and described in conjunction with a milking system. Those skilled in the art will appreciate that the pressure regulator can also be used in other pressure systems including food production and processing systems and oil and gas distribution systems. Additionally, the control scheme of the pressure regulator can be implemented by various types of control hardware. Having thus described the preferred embodiment of the invention, what is claimed as new and desired to be protected by Letters Patent includes the following:

Document as affixed to Application as Microfisch Appendix

VACUUM REGULATOR Inventor: Jinglu Tan Docket No. 23542

-14-

***W***ι r»*w****w******** _-******τr**ιlr*-*w-*ι r*τr**»-r*****

SOFTWARE PACKAGE FOR THE CONFIGURABLE PRESSURE/VACUUM REGULATOR *

» *

PROGRAMMED IN THE ENHANCED M6800/M6801 INSTRUCTION SET

* *

pτr************«r*ι '^EQUATES AND VARIABLES IN FP SUBROTINE" rn-************

SYSRAM EQU $C500

ROUTINES EQU $CF00

*

OVFΞRR EQU 2 floating point overflow error

UNFΞRR EQU 3 floating point underflow error

DIVOERR EQU 4 division by 0 error

TOLGSMER EQU 5 number too large or small to convert to int.

*

ORG SYSRAM

FPACC1EX RMB 1 FLOATING POINT ACCUMULATOR #1..

FPACC1MN RMB 3

MANTSGN1 RMB 1 MANTISSA SIGN FOR FPACC1 (0=+, FF=-) .

FPACC2EX RMB 1 FLOATING POINT ACCUMULATOR #2.

FPACC2MN RMB 3

MANTSGN2 RMB 1 MANTISSA SIGN FOR FPACC2 (0=+, FF=-) .

VARIABLES FOR REGULATOR

COUNTER RMB 1 USED FOR READING CONFIGURABLE PARAMETERS

PC RMB 1 FOR READING FROM PORTC IN PORTC SUBROUTINE

PE RMB 2 FOR READING FROM PORTE IN PORTE SUBROUTINE

CALIB.EX RMB 1 CALIBRATION FACTOR /RAW NUMBER TO PASCALS

CALIB.MN RMB 3

CALIB.SN RMB 1

P.EX RMB 1 PRESSURE

P.MN RMB 3

P.SN RMB 1

SETP.EX RMB 1 SETPOINT

SETP.MN RMB 3

SETP.SN RMB 1

ER.EX RMB 1 ERRORS

ER.MN RMB 3

ER.SN RMB 1

OLDE .EX RMB 1

OLDE .MN RMB 3

OLDER.SN RMB 1

OOLDER.EX RMB 1

OOLDER.MN RMB 3

OOLDER.SN RMB 1

DM.EX RMB 1 OUTPUT FROM REGULATOR

DM.MN RMB 3

DM.SN RMB 1

OLDDM.EX RMB 1

OLDDM.MN RMB 3

OLDDM.SN RMB 1

OOLDDM.EX RMB 1

OOLDDM.MN RMB 3

OOLDDM.SN RMB 1

Bl.ΞX RMB 1

*** ** **** *** ** * * **** ** ****START OF MAIN PROGRAM************* ****** * * * * ** ***

ORG $C000

* ** * * * ** *** * * *** * ** *** * ** * * * * INITIALIZE * * **** ** **** * r**************ι

LDAA #$13 SHUT OFF ON-CHIP A/D

STAA $1039 * * * ** * * **»****»****»«*»»**SE C ALIBRATI O N FA C T O R****** *********************

8 BITS EXPONENT

HIGH 16 BITS OF MANTISSA

LOW 8 BIT OF MANTISSA

POSITIVE SIGN

CHECK IF NEED TO READ CONFIGURABLE PARAMETERS

GO AHEAD WITHOUT READING IN NEW PARAMETERS READ IN NEW PARAMETERS

PARAMETERS STORED IN EEPROM STARTING FROM $3600

-16-

'S~

r * CHECK ERROR*

ErLOOP

GIVE INITIAL OPEN TO VALUE

WHEN Er>-1.5kPa, JUMP TO CONTROL LOOP

*********** * **************** START OF MAIN PROGRAM**************************

LOOP CHECK TO SEE IF THE PUMP SHUT OFF

IF ER<-10kPa PUMP OFF & GET OUT OF CONTROL

LOOP1

LDD #0 ZERO HIGH 16 BITS OF MANTISΞA1 BEFORE

STD FPACC1EX CONVERTING INT P TO FP

STD FPACClMN+1

STAA MANTSGNl

JSR PORTE READ INT P FROM PORTE

LDD PE LOAD P INTO PE FROM SUBROUTINE PORTE

*CONV INT P TO FP

STD FPACClMN+1 PUT P INTO THE LOW 16 BITS OF MANTISSA1

JSR UINT2FLT

JSR COMP GO TO CONRTOL ALGORITHM

JSR DLY5

BRA LOOP

RTS ******************** * ****** £2JD OF MAIN PRO G RA M ******************** *** * ** ****

*

* SUBROUTINES

*

ORG ROUTINES

READ FROM PORTE******* * ************+* * * * *** * ***

PORTE EQU

"READ FROM PORTE (USE PORTD AS OUTPUTS TO CONTROL A/D AND PAO FOR STS)

SET PORTD DATA DIRECTION AS OUTPUTS

SET 0

$1008 IS REGISTER OF PORTC

SET CE HIGH

WAIT FOR CONVERSION ($1000 IS REGISTER OF PORTA)

SET CE AND A0 LOW

SET R/C HIGH

SET CE HIGH WHILE KEEP R/C HIGH AND A0 LOW

DUMMY LOOP WAITING FOR DATA READ

READ THE 8 HIGHEST BITS FROM PORTE ($100A) SET CE LOW AND A0 HIGH WHILE KEEP R/C HIGH

SET CE HIGH WHILE KEEP R/C AND A0 HIGH

DUMMY LOOP WAITING FOR DATA READ

READ THE 4 LSBΞ+4 TRAILING ZEROES

SHIFT THE DATA IN A & B FOUR TIMES TO RIGHT

LSRD

LSRD

LSRD

LSRD

STD PE

RTS ***_ *** ***********»** ** * * * * * *ERROR C HE C KING*** * *** * * * ****** ****************

ErCHK EQU PRESSURE MINUS SETPOINT RESSURE

LDD #0 ZERO HIGH 16 BITS OF MANTISSA1 BEFORE STD FPACC1EX CONVERTING INT P TO FP STD FPACClMN+1 STAA MANTSGNl JSR PORTE READ INT P FROM PORTE LDD PE LOAD P FROM PE IN SUBROUTINE PORTE *CONV INT P TO FP STD FPACClMN+1 PUT P IN THE LOW 16 BITS OF MANTISSA1 JSR UINT2FLT LDD CALIB.EX CONV TO PASCALS STD FPACC2EX LDD CALIB. N+1 STD FPACC2MN+1 LDAA CALIB.SN STAA MANTSGN2 JSR FLTMUL LDD FPACC1EX STD P.EX LDD FPACClMN+1 STD P. N+1 LDAA MANTSGNl STAA P.SN

*COMPUTE ERROR

*********************** E^£) CONFIGURABLE PARAMETERS**** * ************** ****** *

RDGAINS EQU *

*ROW ERASE ($B600-$B60F)

*

ERASE ROW $B600-$B60F SET TO ROW ERASE MODE

WRITE ANY DATA TO ANY ADDRESS IN ROW TURN ON HIGH VOLTAGE

DELAY 10 MS

TURN OFF HIGH VOLTAGE

SET COUNTER VALUE

INDEX ADDRESS

CHECK IF READY TO READ IN

DATA TO BE PROGRAMMED AND X=AN EEPROM ADDRESS SET EELAT BIT TO ZERO

STORE DATA TO EEPROM ADDRESS TURN ON HIGH VOLTAGE

DELAY 10 MS

TURN OFF HIGH VOLTAGE

CHECK IF THE PUSH BOTTON RELEASED

CHANGE INDEX ADDRESS

****** * **** * ** * * ****** TIME DELAY F0R iOmS F O R E=2MHZ ***** ****************** *

DLY10 EQU *

PSHX

LDX #$0D06 DDLOOP DEX

BNE DDLOOP

PULX

RTS

r********************pREr'AD FROM PORTC

CLEAR STAF

SET STRA ZERO

SET PORTC AS INPUT

SET HANDSHAKE IN REGISTER $1002

SET STRA HIGH

CHECK STAF

READ IN AND CLEAR STAF

** * *** * * * * * *** *. 'COMPUTATION IN THE CONTROL LOOP********************* ** *'

COMP EQU

ER"

LDD 31.MN+1

STD FPACClMN+1

LDAA Bl.SN

STAA MANTSGNl

LDD ER.EX

STD FPACC2EX

LDD ER.MN+1

STD FPACC2MN+1

LDAA ER.SN

STAA MANTSGN2

JSR FLTMUL

LDD FPACC1EX

STD B1BLK.EX

LDD FPACClMN+1

STD B1BLK.MN+1

LDAA MANTSGNl

STAA B1BLK.SN

B2*E(K-1)*" ** ** * **********************

LDD 32.EX

STD FPACC1EX

LDD B2.MN+1

STD FPACClMN+1

LDAA B2.SN

STAA MANTSGNl

LDD OLDER.EX

STD FPACC2EX

LDD OLDER. N+1

STD FPACC2MN+1

LDAA OLDER.SN

STAA MANTSGN2

JSR FLTMUL

LDD FPACC1EX

STD B2BLK.EX

LDD FPACClMN+1

STD B2BLK.MN+1

LDAA MANTSGNl

STAA B2BLK.SN

************ * ********************g 3 *E(K-2 )**********************•_■****** + *,

LDD B3.EX

STD FPACC1EX

LDD 33.MN+1

STD FPACClMN+1

LDAA B3.SN

STAA MANTSGNl

LDD OOLDER.EX

STD FPACC2EX

LDD OOLDER.MN+1

STD FPACC2MN+1

LDAA OOLDER.SN

STAA MANTSGN2

JSR FLTMUL

LDD FPACC1EX

STD 33BLK.EX

LDD FPACClMN+1

STD 33BLK.MN+1

LDAA MANTSGNl

STAA 33BLK.SN

SUBTRACT 323LK FROM 313LK, ADD B3BLK AND OOLDDM AND THEN CONV BACK TO INTEGER

LDD 313LK.EX

STD FPACC1EX

LDD B13LX.MN+1

STD FPACClMN+1

LDAA B1BL .SN

STAA MANTSGNl

LDD B2BLK.EX

STD FPACC2EX

LDD B2BLK.MN+1

STD FPACC2MN+1

LDAA B2BLK.SN

STAA MANTSGN2

JSR FLTSUB

LDD B3BLK.EX

STD FPACC2EX

LDD B3BLK.MN+1

STD FPACC2MN+1

LDAA B3BLK.SN

STAA MANTΞGN2

JSR FLTADD

LDD OOLDDM.EX

STD FPACC2EX

LDD OOLDDM.MN+1

STD FPACC2MN+1

LDAA OOLDDM.SN

STAA MANTSGN2

JSR FLTADD

LDD FPACC1EX

STD DM.EX

LDD FPACClMN+1

STD DM.MN+1

LDAA MANTSGNl

STAA DM.SN

LDAA MANTSGNl SET OUTPUT ZERO IF OUTPUT IS NEGATIVE

CMPA #$FF

BNE CNV

LDD #0

STD FPACC1EX

STD FPACClMN+1

STAA MANTSGNl

CNV JSR FLT2INT ***** -*****-***CHECK OUTPUT RANGE *_ OUTPUT FROM POR T S**** ** ** **************

USE REGISTER B AS OUTPUT REGISTER

LDD FPACClMN+1 SET OUTPUT $FF IF OUTPUT >$FF CPD #$FF BLS SKIP LDAB #$FF

SKIP STAB $1004

E(K-2), DM(K-l) AND DM(K-2!

LDAA OLDER.SN

STAA OOLDER.SN

LDD ER.EX

STD OLDER.EX

LDD ER.MN+1

STD OLDER. N+1

LDAA ER.SN

STAA OLDER.SN RTS

*

* ..,,» * » * ...* * *****.»*»***.» TIME DELAY 5 ms*»* ********************** . ******* DLY5 EQU

PSKX

LDX #$0500 DLOOP DEX

BNE DLOOP

PULX

RTS

*

**»»******************* ZER0 ERRORS, DMS AND COUNTER*********** * * ** ********** *

INITILIZΞ EXPONENT & HIGH 8 BITS OF MANTISSA INITILIZΞ LOW 16 BITS OF MANTISSA INITILIZE SIGN

******************************************************* ******************** .

* .

* SUBROUTINES FOR MUL, ADD, SUB, AND DIV

POINT TO FPACC1.

CHECK TO SEE IF IT'S 0.

YES. JUST RETURN.

IS THE NUMBER ALREADY NORMALIZED?

YES. JUST RETURN..

GET THE LOWER 16 BITS OF THE MANTISSA.

DECREMENT THE EXPONENT FOR EACH SHIFT.

EXPONENT WENT TO 0. UNDERFLOW.

SHIFT THE LOWER 16 BITS.

ROTATE THE UPPER 8 BITS. NUMBER NORMALIZED?

NO. KEEP SHIFTING TO THE LEFT.

PUT THE LOWER 16 BITS BACK INTO FPACC1.

SHOW NO ERRORS.

YES. RETURN.

FLAG ERROR.

RETURN.

CHECKS FOR ZERO IN FPACC POINTED TO BY X. SAVE D.

LDD o , x

BNE GET FPACC EXPONENT & HIGH 8 3 TS

CHCKO1

LDD NOT ZERO. RETURN. 2,X

CHCK01 PULA CHECK LOWER 16 BI^ S RESTORE D.

PULB

RTS RETURN WITH CC SET.

CONSTP1 FC3 $7D,$4C,$CC,$CD CONST10 FC3 0.1 DECIMAL $84,$20,$00,$00 10.0 DECIMAL

TTL FLTMUL

fr****************************** !

* * **** ** * * * * i , ir ir ir ir 1r ir ir ir ir ir ir ******** ,

FPMULT: FLOATING POINT MULTIPLY

****** . ******** ** *****************

****** * ** ********************,

SAVE FPACC2.

POINT TO FPACC1

C HECK TO SEE IF FPACC1 I S ZER O .

IT IS. ANSWER IS 0.

POINT TO FPACC2.

IS IT 0?

NO. CONTINUE.

CLEAR D.

MAKE FPACC1 0.

RETURN.

GET FPACC1 EXPONENT.

SET THE SIGN OF THE RE S ULT.

SAVE THE SIGN OF THE RESULT.

GET FPACC1 EXPONEN T .

ADD IT TO FPACC2 EXPON E NT.

IF RESULT IS MINUS AND

THE CARRY IS SET T H EN :

OVERFLOW ERROR.

SET ERROR FLAG.

RETURN.

IF RESULT IS PLUS & THE CARRY IS SET THEN ALL OK.

ELSE UNDERFLOW ERROR OCCURED.

FLAG ERROR.

RETURN.

ADD 128 BIAS BACK IN THA T WE LOST.

SAVE THE NEW EXPONENT.

GO MULTIPLY THE "INTEGER" MAN T IS S AS.

WAS THERE AN OVERFLOW ERROR FROM ROU N DIN G?

YES. RETURN ERROR.

SHOW NO ERRORS.

RESTORE FPACC2.

C RE AT E PARTIAL PRODUCT REGISTER AND CO UN T ER. P O INT TO THE VARIABLES.

SET COUNT TO THE NUMBER OF BITS.

GET THE L.S. BYTE OF THE MULTIPLIER.

PUT L.S. BIT IN CARRY.

IF CARRY CLEAR, DON'T ADD MULTIPLICAND TO P.P.

GET MULTIPLICAND L.S. 16 BITS.

ADD TO PARTIAL PRODUCT.

SAVE IN P.P.

GET UPPER 8 BITS OF MULTIPLICAND.

ADD IT W/ CARRY TO P.P.

SAVE TO PARTIAL PRODUCT.

ROTATE PARTIAL PRODUCT TO THE RIGHT.

SHIFT THE MULTIPLIER TO THE RIGHT 1 BIT.

DONE YET?

NO. KEEP GOING.

DOES PARTIAL PRODUCT NEED TO BE NORMALIZED?

NO. GET ANSWER & RETURN.

GET BIT THAT WAS SHIFTED OUT OF P.P REGISTER.

PUT IT BACK INTO THE PARTIAL PRODUCT.

FIX EXPONENT.

DO WE NEED TO ROUND THE PARTIAL PRODUCT?

NO. JUST RETURN.

YES. GET THE LEAST SIGNIFICANT 16 BITS.

ADD 1.

SAVE RESULT.

PROPIGATΞ THROUGH.

IF CARRY CLEAR ALL IS OK.

IF NOT OVERFLOW. ROTATE CARRY INTO P.P.

UP THE EXPONENT.

TAKE COUNTER OFF STACK.

GET M.S. 16 BITS OF PARTIAL PRODUCT.

PUT IT IN FPACC1.

GET L.S. 8 BITS OF PARTIAL PRODUCT.

PUT IT IN FPACC1. RETURN.

TTL FLTADD ******************************************************* ******************** *

* FLOATING POINT ADDITION

* ************************************************************ *************** *

RESTORE FPACC2.

ANSWER IN FPACCl. RETURN.

POINT TO FPACCl.

IS IT ZERO?

NO. GO ADD THE NUM3ER.

ANSWER IS IN FPACC2. MOVE IT INTO FPACCl.

MOVE LOWER 16 3ITS OF MANTISSA.

MOVE FPACC2 MANTISSA SIGN INTO FPACCl.

RETURN.

GET FPACCl EXPONENT.

ARE THE EXPONENTS THE SAME?

YES. GO ADD THE MANTISSA'S.

NO. FPACC1EX-FPACC2EX. IS FPACCl > FPACC2?

YES. GO CHECK RANGE.

NO. FPACCl < FPACC2. MAKE DIFFERENCE POSITIVE.

ARE THE NUMBERS WITHIN RANGE?

NO. FPACC2 IS LARGER. GO MOVE IT INTO FPACCl.

PUT DIFFERENCE IN B.

CORRECT FPACCl EXPONENT.

SAVE THE RESULT.

POINT TO FPACCl MANTISSA.

GO DENORMALIZE FPACCl FOR THE ADD.

FPACCl > FPACC2. ARE THE NUMBERS WITHIN RANGE?

NO. ANSWER ALREADY IN FPACCl. JUST RETURN.

POINT TO THE MANTISSA TO DENORMALIZE.

SHIFT THE FIRST BYTE OF THE MANTISSA.

THE SECOND.

AND THE THIRD.

DONE YET?

NO. KEEP SHIFTING.

GET FPACCl MANTISSA SIGN.

ARE THE SIGNS THE SAME?

YES. JUST GO ADD THE TWO MANTISSAS.

NO. IS FPACCl THE NEGATIVE NUMBER?

NO. GO DO FPACCl-FPACC2.

YES. EXCHANGE FPACCl _ FPACC2 BEFORE THE SUB.

SAVE IT.

GET PART OF FPACCl.

PUT IT IN FPACC2.

GET SAVED PORTION OF FPACC2

PUT IT IN FPACCl.

GET LOWER 8 BITS & SIGN OF FPACC2.

SAVE IT.

GET LOWER 8 BITS _ SIGN OF FPACCl.

PUT IT IN FPACC2.

GET SAVED PART OF FPACC2.

PUT IT IN FPACCl.

GET LOWER 16 BITS OF FPACCl.

SUBTRACT LOWER 16 BITS OF FPACC2.

SAVE RESULT.

GET HIGH 8 BITS OF FPACCl MANTISSA.

SUBTRACT HIGH 8 BITS OF FPACC2.

SAVE THE RESULT. IS THE RESULT NEGATIVE?

NO. GO NORMALIZE THE RESULT.

YES. NEGATE THE MANTISSA.

SAVE THE RESULT.

GET LOWER 16 3ITS. FORM THE ONE'S COMPLEMENT.

-26-

ΞS _£ _£._ τ ∞»

SAVE RESULT ™"

SH O W THAT ΓPACCI. IS .E G ATIVE.

PACC 2

UP THE MANTISSA BY 1

FLAG ERRrø. ° LARGE " 0VE *™. RETURN.

TTL FLTSUB ************************ ********** ************ * *************************** ** **

* *

* FLOATING POINT SUBTRACT SUBROUTINE *

* *

* ************************ ********** ****** * *********************************** * *

FLTSUB EQU *

BSR FLTSUB1 INVERT SIGN.

JSR FLTADD GO DO FLOATING POINT ADD.

FLTSUB1 LDAA MANTSGN2 GET FPACC2 MANTISSA SIGN.

EORA #$FF INVERT THE SIGN.

STAA MANTSGN2 PUT BACK.

* RTS RETURN.

TTL FLTDIV

FLOATING POINT DIVIDE

'****************************************************** ** .

POINT TO FPACC2.

IS THE DIVISOR 0?

NO. GO SEE IF THE DIVIDEND IS ZERO.

YES. RETURN A DIVIDE BY ZERO ERROR.

FLAG ERROR.

RETURN.

POINT TO FPACCl.

IS THE DIVIDEND 0?

NO. GO PERFORM THE DIVIDE.

YES. ANSWER IS ZERO. NO ERRORS.

RETURN.

SAVE FPACC2.

GET FPACC2 MANTISSA SIGN.

SET THE SIGN OF THE RESULT.

SAVE THE RESULT.

SET UP WORK SPACE ON THE STACK.

PUT LOOP COUNT ON STACK.

SET UP POINTER TO WORK SPACE.

COMPARE FPACCl & FPACC2 MANTISSAS.

ARE THE UPPER 16 BITS THE SAME? ~

NO.

YES. COMPARE THE LOWER 8 BITS.

IS FPACC2 MANTISSA > FPACCl MANTISSA? NO.

ADD 1 TO THE EXPONENT TO KEEP NUMBER THE SAME.

DID OVERFLOW OCCUR?

NO. GO SHIFT THE MANTISSA RIGHT 1 BIT.

YES. GET ERROR CODE.

FLAG ERROR.

REMOVE WORKSPACE FROM STACK.

RESTORE FPACC2.

RETURN.

DO AN INITIAL SUBTRACT IF DIVIDEND MANTISSA IS

GREATER THAN DIVISOR MANTISSA.

SUBTRACT 1 FROM THE LOOP COUNT. SHIFT THE DIVISOR TO THE RIGHT 1 BIT.

GET FPACCl EXPONENT. GET FPACC2 EXPONENT. ADD THE TWO'S COMPLEMENT TO SET FLAGS PROPERLY.

A3A BMI FLTDIV5 IF RESULT MINUS CHECK CARRY FOR POSS. OVERFLOW. BCS FLTDIV7 IF PLUS & CARRY SET ALL IS OK. LDAA #UNFERR IF NOT, UNDERFLOW ERROR. BRA FLTDIV6 RETURN WITH ERROR. FLTDIV5 BCS FLTDIV8 IF MINUS ∑ CARRY SET OVERFLOW ERROR. FLTDIV7 ADDA #$81 ADD BACK BIAS+1 (THE '1' COMPENSATES FOR ALGOR. STAA FPACC1EX SAVE RESULT. FLTDIV9 LDD FPACC1MN SAVE DIVIDEND IN CASE SUBTRACTION DOESN'T GO. STD 4,X LDAA FPACClMN+2 STAA 6,X LDD FPACClMN+1 GET LOWER 16 BITS FOR SUBTRACTION. SU3D FPACC2MN+1 STD FPACClMN+1 SAVE RESULT. LDAA FPACC1MN GET HIGH 8 BITS. SBCA FPACC2MN STAA FPACC1MN BPL FLTDIV10 SUBTRACTION WENT OK. GO DO SHIFTS. LDD 4,X RESTORE OLD DIVIDEND. STD FPACC1MN LDAA 6,X STAA FPACClMN+2 FLTDIV10 ROL 3,X ROTATE CARRY INTO QUOTIENT. ROL 2,X ROL l . X LS FPACClMN+2 SHIFT DIVIDEND TO LEFT FOR NEXT SUBTRACT. ROL FPACClMN+1 ROL FPACC1MN DEC o,x DONE YET? BNE FLTDIV9 NO. KEEP GOING. COM 1,X RESULT MUST BE COMPLEMENTED. COM 2,X COM 3,X LDD FPACClMN+1 DO 1 MORE SUBTRACT FOR ROUNDING. SU3D FPACC2MN+1 ( DON'T NEED TO SAVE THE RESULT. LDAA FPACC1MN SBCA FPACC2MN ( NO NEED TO SAVE THE RESULT. ) LDD 2,X GET LOW 16 BITS. BCC FLTDIV11 IF IT DIDNT GO RESULT OK AS IS. CLC CLEAR THE CARRY. BRA FLTDIV13 GO SAVE THE NUMBER. FLTDIV11 ADDD #1 ROUND UP BY 1. FLTDIV13 STD FPACClMN+1 PUT IT IN FPACCl. LDAA l. GET HIGH 8 BITS. ADCA #0 STAA FPACC1MN SAVE RESULT. BCC FLTDIV12 IF CARRY CLEAR ANSWER OK. ROR FPACC1MN IF NOT OVERFLOW. ROTATE CARRY IN. ROR FPACClMN+1 ROR FPACClMN+2 FLTDIV12 CLC NO ERRORS. JMP FLTDIV6 RETURN.

TTL INT2FLT r*********************************************************» ****-ι r ***** *

UNSIGNED INTEGER TO FLOATING POINT

This subroutine performs "unsigned" integer to floating point conversion of a 16 bit word. The 16 bit integer must be in the lower 16 bits of FPACCl mantissa. The resulting floating point number is returned in FPACCl.

POINT TO FPACCl.

IS IT ALREADY 0?

NO. GO CONVERT.

YES. JUST RETURN.

GET BIAS + NUMBER OF BITS IN MANTISSA.

INITIALIZE THE EXPONENT.

GO MAKE IT A NORMALIZED FLOATING POINT VALUE.

NO ERRORS. RETURN.

.****************************************+*************** .

SIGNED INTEGER TO FLOATING POINT

!• ************** » ******

SINT2FLT EQU LDD FPACClMN+1 GET THE LOWER 16 BITS OF FPACCl MANTISSA. PSHA SAVE SIGN OF NUMBER. BPL SINTFLT1 IF POSITIVE JUST GO CONVERT. COMA MAKE POSITIVE. COMB ADDD #1 TWO'S COMPLEMENT. STD FPACClMN+1 PUT IT BACK IN FPACCl MANTISSA.

SINTFLT1 BSR UINT2FLT GO CONVERT. PULA GET SIGN OF ORIGINAL INTEGER. LDAB #$FF GET "MINUS SIGN" . TSTA WAS THE NUMBER NEGATIVE? BPL SINTFLT2 NO. RETURN. STAB MANTSGNl YES. SET FPACCl SIGN BYTE.

SINTFLT2 CLC NO ERRORS. RTS RETURN.

TTL FLT2INT

*****

FLOATING POINT TO INTEGER CONVERSION

******************************************************* ***********************

FLT2INT EQU *

LDX #FPACC1EX POINT TO FPACCl.

IS IT 0?

YES. JUST RETURN.

GET FPACCl EXPONENT.

IS THERE AN INTEGER PART?

NO. GO PUT A 0 IN FPACCl.

IS THE NUMBER NEGATIVE?

YES. GO CONVERT NEGATIVE NUMBER.

IS THE NUMBER TOO LARGE TO BE MADE AN INTEGER?

YES. RETURN WITH AN ERROR.

SUBTRACT THE BIAS PLUS THE NUMBER OF BITS.

MAKE THE NUMBER AN INTEGER.

DONE SHIFTING?

NO. KEEP GOING.

ZERO THE EXPONENT (ALSO CLEARS THE CARRY) .

IS THE NUMBER TOO SMALL TO BE MADE AN INTEGER?

YES. RETURN ERROR.

SUBTRACT BIAS PLUS NUMBER OF BITS.

GO DO SHIFT.

GET RESULTING INTEGER.

MAKE IT NEGATIVE.

TWO'S COMPLEMENT.

SAVE RESULT.

CLEAR MANTISSA SIGN. (ALSO CLEARS THE CARRY)

RETURN.

NUMBER TOO LARGE OR TOO SMALL TO CONVERT TO INT

FLAG ERROR.

RETURN.

ZERO FPACCl.

(ALSO CLEARS THE CARRY) RETURN.

TTL PSHPULFPAC2 ******************************************************* ******************** *

* The following two subroutines, PSHFPAC2 & PULPFAC2, push FPACC2

* onto and pull FPACC2 off of the hardware stack respectively.

* The number is stored in the "memory format".

* ************************************************************ ***************

GET THE RETURN ADDRESS OFF OF THE STACK. ALLOCATE FOUR BYTES OF STACK SPACE.

PUT THE RETURN ADDRESS IN D.

POINT TO THE STORAGE AREA.

PUT THE RETURN ADDRESS BACK ON THE STACK. GO PUT FPACC2 ON THE STACK _ RETURN

PULFPAC2 EQU TSX POINT TO THE RETURN ADDRESS.

-31-

NX POINT TO THE SAVED NUMBER.

INX

JSR GETFPAC2 RESTORE FPACC2.

PULX GET THE RETURN ADDRESS OFF THE STACK.

INS REMOVE THE NUMBER FROM THE STACK.

INS

INS

INS

JMP o,x RETURN.

*** * *

TTL GΞTFPAC

************* ******* **** ** ***************************************************

GETFPACx SUBROUTINE

******************************************************* **********************

GET THE EXPONENT & HIGH BYTE OF THE MANTISSA,

IF NUMBER IS ZERO, SKIP SETTING THE MS BIT.

SET UP FOR POSITIVE NUMBER.

IS NUMBER NEGATIVE?

NO. LEAVE SIGN ALONE.

YES. SET SIGN TO NEGATIVE.

RESTORE MOST SIGNIFICANT BIT IN MANTISSA.

PUT IN FPACCl.

GET LOW 16-BITS OF THE MANTISSA.

PUT IN FPACCl.

RETURN.

GET THE EXPONENT - HIGH BYTE OF THE MANTISSA,

IF NUMBER IS 0, SKIP SETTING THE MS BIT.

SET UP FOR POSITIVE NUMBER.

IS NUMBER NEGATIVE?

NO. LEAVE SIGN ALONE.

YES. SET SIGN TO NEGATIVE.

RESTORE MOST SIGNIFICANT BIT IN MANTISSA.

PUT IN FPACCl.

GET LOW 16-BITS OF THE MANTISSA.

PUT IN FPACCl. RETURN.

TTL PUTFPAC

************* .»» ** » ************** » ********************** , ********* , **********

PUTFPACx SUBROUTINE

******************************************** * ****************************** » *

PUTFPAC1 EQU LDD FPACC1EX GET FPACCl EXPONENT & UPPER 8 BITS OF MANT. TST MANTSGNl IS THE NUMBER NEGATIVE? BMI PUTFP11 YES. LEAVE THE M.S. BIT SET. ANDB #$7F NO. CLEAR THE M.S. BIT.

PUTFP11 STD 0,X SAVE IT IN MEMORY

-32-

O F THE MANTISSA.

GET FPACCl EXPONENT & UPPER 8 BITS OF MANT.

IS THE NUMBER NEGATIVE?

YES. LEAVE THE M.S. BIT SET.

NO. CLEAR THE M.S. BIT.

SAVE IT IN MEMORY GET L.S. 16 BITS OF THE MANTISSA. S