You are on page 1of 304

DR300

Laboratory Setup Speed Control


with Variable Load

© Copyright amira GmbH 1999, 2000 printed 06. December 2000

Bismarckstraße 67 . im Technologiezentrum . D-47057 Duisburg . Telefon 0203/37809-50 . Telefax 0203/37809-56


Laboratory Setup Speed Control DR300 Table of Contents

Assembly and Start-Up 1

Technical Data 2

Practical Instructions 3

Fuzzy Practical Instructions 4

Program Operation 5

The PC Plug-in Card DAC98 6

DR300 Software 7

i
Laboratory Setup Speed Control DR300 Assembly and Start-Up

Assembly and Start-Up

Date: 18.12.2000

Assembly and Start-Up


Laboratory Setup Speed Control DR300 Table of Contents

1 Assembly and Start-Up 1-1

1.1 Unpacking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2 Setting up the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2.1 DR300 Mechanical Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2.2 Actuator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.3 Description of the DR300 Mechanical Setup . . . . . . . . . . . . . . . . . . . . . . 1-1

1.4 The Rear Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.5 The Front Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.5.1 SERVO GENERATOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.5.2 SERVO MOTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.5.3 POWER SERVO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.5.4 SENSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.5.5 Mains Supply and Signal Adaption Unit (POWER module) . . . . . . . . . . . . . . 1-3

1.5.6 SIGNAL ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5.7 INPUT EXTERN-CONTROLLER . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5.8 Analog PI-controller (PI-CONTROLLER) . . . . . . . . . . . . . . . . . . . . . 1-4

1.6 Connecting the System components and Start Up . . . . . . . . . . . . . . . . . . . . 1-5

1.7 Control with Internal Analog Controller . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.8 Control with External Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.9 Control with PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.10 Output Stage Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.11 Locating errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

Assembly and Start-Up i


Table of Contents Laboratory Setup Speed Control DR300

ii Assembly and Start-Up


Laboratory Setup Speed Control DR300 Assembly and Start-Up

disc contains the executable Fuzzy-controller


1 Assembly and Start-Up program.

1.1 Unpacking • Option 300-04


An electrical disturbance module, which is
contained in the actuator box at the time of
After the DR300 has been unpacked, all components are delivery.
to be checked visually for damages as well as for
completeness. Should anything be damaged notify us and • Option 300-05
save the item and the packaging material until the matter A 3,5" floppy disc containing the C source
is resolved. program files of the Options 300-02 and 300-03.

The standard shipment of the DR300 consists of: 1.2 Setting up the System
• The DR300 mechanical setup consisting of two
DC motors with one tacho generator and one 1.2.1 DR300 Mechanical Setup
incremental encoder completely mounted and
wired. The lead to connect the DR300 mechanical Choose a place, where the system is not exposed to
setup to the actuator is fixedly mounted to the extreme temperatures. In particular direct sun light and
mechanic. direct heat radiation, e. g. by a radiator, are to be avoided.
Otherwise the Plexiglas cover could be damaged.
• A 19" module box (actuator) containing power
supplies, servo amplifiers operating as current The system must be placed on a solid surface.
controllers, signal adaption unit and a module for
measuring outputs. 1.2.2 Actuator

• A mains supply lead. The air must be able to circulate freely above, below as
well as behind the actuator box.
• A manual containing detailed documentation of
the hardware and software. Do not use a soft surface. Otherwise the ventilation slots
located on the bottom of the actuator box could be covered
Depending on the desired system option, the shipment due to its weight.
also includes the following items:
Do not place any objects, e. g. manuals on top of the
• Option 300-01 actuator box. (heat exchange).
An analog PI controller module integrated in the
actuator. 1.3 Description of the DR300
Mechanical Setup
• Option 300-02
An A/D-D/A converter card DAC98 for a
PC-AT-computer with a 50-pol. lead to connect to The platform and the rear panel of the laboratory setup are
the actuator and a 3.5" floppy disk containing the constructed of aluminium and are covered with an acrylic
executable program for the practical course. glass cover which can be opened. An aluminium box is
mounted at the left side of the platform. The lead which
• Option 300-03 connects the mechanic to the actuator is located at its rear
As an extension to Option 300-02, a 3,5" floppy panel. The leads to connect to the motors and sensors can

Assembly and Start-Up 1-1


Assembly and Start-Up Laboratory Setup Speed Control DR300

Figure 1.1: The system DR300

be seen at the right side of the aluminium box. A micro • the 50-pol. lead for the connection between the
switch is located at the same location, which is activated actuator and the adapter board. (Options 300-02,
when the cover is closed. The two motors are mounted 300-03),
facing each other. The drive shafts are rigidly coupled.
Figure 1.1 shows the arrangement of the motors and the • two BNC terminals to measure the control signals
sensors. of the servo controllers.

The left motor (M1) contains a tacho generator. An 1.5 The Front Panel
additional incremental rotary encoder is mounted at its
free drive-shaft. The right motor (M2) is the load of the
motor M1 when it is operating in generator mode. Its free Figure 1.3 displays the components located on the front
drive-shaft can be used to mount an additional mass to panel.
increase the inertia.
1.5.1 SERVO GENERATOR
1.4 The Rear Panel
The servo amplifier functioning as a current controller for
the generator is located on the left side of the front panel.
Figure 1.2 displays the components located on the rear
panel. The mains input unit is located on the right side. It 1.5.2 SERVO MOTOR
contains two fuse holders, the mains inlet and the power
switch. Located on the left side of the ventilation cover This module contains the servo amplifier for the motor
are: which functions as a current controller. The time constant
of the current controller is adjustable with a switch. The
• the 30-polar connector for the mechanical system, switch position "Time 2" corresponds to an optimal

CONTROL SIGNAL CONTROL SIGNAL


MOTOR GENERATOR
TYPE PLATE

PC-CONNENTOR
FUSE

POWER
SWITCH
SYSTEM
MAINS
INLET

Figure 1.2 : Rear panel with denotations

1-2 Assembly and Start-Up


Laboratory Setup Speed Control DR300 Assembly and Start-Up

controller, whereas the switch position "Time 1" 1.5.4 SENSOR


simulates a first order lag behaviour of the closed loop
control with a large time constant (approx. 30 msec). This module provides the following signals at its 4
BNC-terminals:
1.5.3 POWER SERVO
• Tacho: Tacho generator signal from the output of
Light emitting diodes indicated different functions/states the signal adaption unit
of the system:
• I-Motor: DC-current signal of the motor
• System (green): Mechanical system is connected
to the actuator • I-Generator: DC-current signal of the generator

• Ready (green): The acrylic cover is closed • Index: Index signal of the incremental encoder

Controller: Additionally this module contains the logic circuit to


enable the control signals.
• Analog PI (red): Analog PI-controller is enabled
1.5.5 Mains Supply and Signal
• PC (red): PC controller is enabled Adaption Unit (POWER module)

The power module contains the power supply for the


• Extern (red): An external controller is enabled amplifiers, the digital electronics and the incremental
encoders as well as amplifiers to adapt the tacho signal
• +35V (green): +35V power supply for the servo and the input signals of the monitored current. Three light
amplifiers is available. emitting diodes indicate the availability of the voltages.

• -35V (green): -35V power supply for the servo • +15V (green): A voltage of +15V is available.
amplifiers is available.
• -15V (green): A voltage of -15V is available.
• Stop: Using this key will disconnect the input
signals of the servo amplifiers. • +5V (green): A voltage of +5V is available.

Additionally this module contains the power supply unit


for the servo amplifiers.

Figure 1.3 : Front panel with denotations

Assembly and Start-Up 1-3


Assembly and Start-Up Laboratory Setup Speed Control DR300

1.5.6 SIGNAL ERROR switch last state new state


direction
This module is present only when your system is equipped off normal
with Option 300-04. upwards normal off
scaled off
It allows for a disturbance of the tacho signal and the off scaled
control signals for the motor servo amplifiers. The signals downwards normal scaled
can be scaled, disconnected (voltage of 0V) or left scaled normal
unchanged. The signals are changed by means of keys
with three positions. Light emitting diodes indicate the
chosen signal function. 1.5.7 INPUT EXTERN-CONTROLLER

This module is present only when the Option 300-01 is


Tacho:
included. It allows a direct control of the two servo
amplifiers.
• Potentiometer(0-10): Scales the filtered tacho
signal in a range of 0% to 100% of its original
• Jack Setpoint I-Motor: Input for setpoint of the
value. ^ ± 2,37 A).
motor current (range ± 10 V =

• Jack Setpoint I-Generator: Input for setpoint of the


• Key : Switching to position "Off" disconnects the ^ ± 2,37 A).
generator current (range ± 10 V =
signal, switching to position "Scaled" scales the
signal. Switching again to the same position
• Key Start: Connects the voltages provided at the
removes the error.
two jacks to the corresponding servo amplifier.
This switch function is disabled when another
• LED red: Tacho signal is disconnected (0V).
controller is enabled. Switching the key again
disconnects the signals.
• LED yellow: Tacho signal is scaled.

Control Signal Motor: 1.5.8 Analog PI-controller


(PI-CONTROLLER)
• Potentiometer (0-10): Scales the control signal for
This module is present only when the system is delivered
the motor servo amplifier in a range of 0% to
with the Option 300-01.
100% of the original output signal of the active
controller.
It contains an analog PI-controller built with analog
electronics. Its amplification and time constant is
• Key : Switching to position "Off" disconnects the
adjustable using coefficient potentiometers.
signal, switching to position "Scaled" scales the
signal. Switching again to the same position
Its transfer function in the Laplace domain is
removes the error.

• LED red: Control signal is disconnected (0V). KR (1 + TR s)


GPI (s) =
s

• LED yellow: Control signal is scaled. The I portion of the controller can be switched off, which
reduces its transfer function to
Table signal switching functions:

1-4 Assembly and Start-Up


Laboratory Setup Speed Control DR300 Assembly and Start-Up

GP (s) = KR TR. The light emitting diode labelled "system" should light
up. Now close the acrylic cover of the laboratory setup.
• Integrator switch: Switches the I portion of the The light emitting diode labelled "Ready" should light up.
controller "On" or "Off".
The system is no ready for operation.
• Potentiometer TR: Allows adjustment of the time
constant of the PI-controller (Scale 0-10 = ^ An additional adjustable DC supply voltage is required to
0-1sec.). perform a function test. Connect this supply voltage to the
input labelled "Extern Setpoint I-Motor" on the module
• Potentiometer KR: Allows adjustment of the INPUT EXTERN-CONTROLLER (with Option 300-01
^ 0-100).
controller amplification (Scale 0-10 = module PI-CONTROLLER). Adjust the voltage to 0 volt.
Using the key "Start" will enable the control voltage for
• BNC-terminal Setpoint Speed: Input for the speed the motor servo amplifier. The light emitting diode
setpoint of the analog controller (± 3000 Upm =^± labelled "Controller: Extern" should light up now.
7,5 V). The difference between this signal and the Increase the input voltage until the motor starts to rotate.
tacho signal (2,5mV / Upm) is the input signal The measurement jacks (outputs) can be used to control
(error signal) of the controller. the tacho signal (2,5 mV/Upm). The motor current can be
measured using the jack "I-Motor" (0,226 A/V). The
• BNC-terminal Setpoint I-Generator: Input for the motor operating in generator mode can be tested in the

current setpoint of the generator (range ± 10V = same way.
2,37 A).
1.7 Control with Internal Analog
• Start key: Connects the output of the analog Controller
controller to the servo amplifier of the motor and
the setpoint voltage of the generator current to the
servo amplifier of the generator. This switch The analog PI-controller is adjustable with two
function is disabled when another controller or the coefficient potentiometers. Its measured value is the tacho
external input is enabled. Switching the key again signal (range ± 10 V, 2,5mV / Upm). This connection is
disconnects the signals. existing inside the actuator. The controller setpoint (speed
of the motor) is connected to the input jack "Setpoint
The components for connecting an external controller Speed" using a voltage in the range of -7,5 to +7,5 volt
(see chapter 1.5.7) are located on the lower part of this (2,5mV/Upm). The load moment is adjusted by
module. connecting a voltage signal (range ± 1,38 Ncm, 0.138
Ncm/V) to the input jack "Setpoint I-Generator". Using
1.6 Connecting the System the key "Start" will connect these signals to the servo
components and Start Up amplifiers of the motor and the generator. The control can
be aborted by using the key "Start" again, using the key
"Stop" located on the module "POWER SERVO" or by
Before setting up the system, please check whether your opening the acrylic cover.
mains supply provides a 230V/50Hz voltage. Switch off
the actuator and connect it to the mains supply. Then
establish the lead connection between the actuator and
the mechanical system. Now open the acrylic cover of the
laboratory setup. Switch on the actuator. Then check,
whether the light emitting diodes on the front panel of the
actuator indicate the availability of the supply voltages.

Assembly and Start-Up 1-5


Assembly and Start-Up Laboratory Setup Speed Control DR300

1.8 Control with External installation dialog but their names must contain only 8
Controller characters besides an extension). Following a successful
installation the controller program may be started
immediately.
The measured value for an external controller is provided
by the output jack "Tacho" (range ± 10V, 2,5mV/Upm). 1.10 Output Stage Release
The output of the controller has to be connected to the 40 - 100 us

input jack "Extern Setpoint I-Motor" (range ± 10V,


H
0,4A/V). The load moment is adjusted by connecting a
DO1 L
voltage signal (range ± 1,38 Ncm, 0.138 Ncm/V) to the
input jack "Setpoint I-Generator". Using the key "Start H

Extern" will connect these signals to the servo amplifiers DO2 L


of the motor and the generator. The control can be aborted max.
by using the key "Start Extern" again, using the key 100 ms

"Stop" located on the module "POWER SERVO" or by Figure 1.4 : Signals for the output stage release
opening the acrylic cover.

If you use your own PC controller via the 50-pol.


1.9 Control with PC connector on the rear panel please think of the release of
the output stage. The output stage release is a safety
Controlling the system by a PC is described in the chapter function so that in case of program failure the motor stops
"Program Operation". To install the controller program immediately.
the installation program SETUP.EXE from the enclosed
floppy disk is to be started with Windows 3.1 or Windows You need two digital signals for the output stage release.
95/98 (arbitrary subdirectories may be entered in the DO1 (pin 35 of the 50-pol. connector) gets first a

Problem Possible cause

The LEDs do not light up Check the connection to the mains supply
Check the fuses for the mains supply (rear panel)

LED + 35 V does not light up Check the fuse of the mudule "POWER SERVO"

LED - 35 V does not light up Check the fuse of the module "POWER SERVO"

LED + 15 V and - 15 V do not light up Check the fuse of the module "POWER UNIT SIGNAL ADAPTION"

LED + 5 V does not light up Check the fuse of the module "POWER UNIT SIGNAL ADAPTION"

LED "System" does not light up Check the lead connection between mechanical system and actuator

Chosen controller cannot be enabled Check whether another controller, is enabled (LEDs on "POWER
SERVO" module)
Check LED "Ready" lights up (cover closed)

Controller enabled but motor does not Check whether, the control signal for the servo amplifier is scaled or
rotate switched off on the disturbance module "SIGNAL ERROR"

Controller enabled but motor rotates Check whether, the tacho signal is scaled or switched off on the
too fast disturbance module "SIGNAL ERROR"

1-6 Assembly and Start-Up


Laboratory Setup Speed Control DR300 Assembly and Start-Up

high-level with pulse to low, duration 40 - 100 µs. After


going high DO2 (pin 36 of the 50-pol. connector) needs
within the next 100 ms a rect-signal in the range of 10 Hz
and 1 kHz. (see fig. 1.4)

1.11 Locating errors

First try to eliminate problems with the help of the


following table. In case you cannot solve problems with
your DR300 yourself, please contact us.

Assembly and Start-Up 1-7


Assembly and Start-Up Laboratory Setup Speed Control DR300

1-8 Assembly and Start-Up


Laboratory Setup Speed Control DR300 Technical Data

Technical Data

Date: 01.07.1998

Technical Data
Laboratory Setup Speed Control DR300 Table of Contents

1 Technical Data 1-1

1.1 DR300 Mechanics, Drives, Sensors . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.1.1 Dimensions and Weight of the DR300 Mechanics . . . . . . . . . . . . . . . . . . 1-1

1.1.2 The Drives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.1.3 The Tacho Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.1.4 The Metal Diaphragm Clutch . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.1.5 The Incremental Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.2 The Actuator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.2.1 SERVO GENERATOR Module . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.2.2 SERVO MOTOR Module . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.2.3 POWER SERVO Module . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.2.4 SENSOR Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.2.5 POWER Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.2.6 SIGNAL-ERROR Module . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.2.7 PI-CONTROLLER Module (Opt. 300-01) . . . . . . . . . . . . . . . . . . . . . 1-5

1.2.8 EXTERN CONTROLLER Module (Standard) . . . . . . . . . . . . . . . . . . . 1-5

1.3 Pin Reservations of the Plug Connections . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.3.1 Connection Actuator to the PC Plug-in Card . . . . . . . . . . . . . . . . . . . . 1-6

1.3.2 Connection Actuator to the DR300 Mechanic . . . . . . . . . . . . . . . . . . . . 1-7

1.3.3 BNC Sockets (Rear Panel) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

Technical Data i
Table of Contents Laboratory Setup Speed Control DR300

ii Technical Data
Laboratory Setup Speed Control DR300 Technical Data

1 Technical Data Drives Value Unit


Type GNM3125
Armature weight 0.19 kg
1.1 DR300 Mechanics, Drives,
Motor weight 0.77 kg
Sensors
Moment of inertia 0.177 kg ⋅ cm2
Rated torque 9.6 Ncm
1.1.1 Dimensions and Weight of the
Starting torque 40.0 Ncm
DR300 Mechanics
Max. continuous torque 10.5 Ncm
Dimensions and Value Unit during standstill
Weight Friction torque 2.0 Ncm
Length 700 mm Mechanical time constant 15.4 ms

Depth 205 mm Connected resistance 3.13 Ω

Height 150 mm Armature inductance 3 mH


Armature resistance 2.6 Ω
Weight 10 kg
Voltage constant 6.27 mV ⁄ Rpm
Torque constant 6.0 Ncm / A
1.1.2 The Drives max. Peak current 16 A

Prinziple: Electrical time constant 0.96 ms

Both drives are permanently exited DC drives with ball


bearings. The carriers of the graphite brushes are 1.1.3 The Tacho Generator
accessible by opening the lateral plastic covers.
Principle:
Drives Value Unit
Type GNM3125 The tacho generator is integrated in the drive, i. e. the
armature of the tacho is mounted directly on the drive
Rated voltage 24 V
shaft. The arrangement of bearings of the drive is external
Rated speed 3000 Rpm to the two armatures. The graphite brushes are accessible
Rated current 2 A by opening the plastic covers mounted on the side of
Rated power 30 W drive.

Technical Data 1-1


Technical Data Laboratory Setup Speed Control DR300

Tacho Generator Value Unit 1.1.5 The Incremental Encoder


Type T 9.05
Incremental Encoder Value Unit
Electromotive force 5 mV ⁄ Rpm Type RI58 or ROD426
E.m.f. tolerance ± 10 % Mode of attachment synchro
flange
Armature voltage with <7 %
1000 1⁄min Shaft diameter 6 mm

Rated current 10 mA Max. speed


RI58 10000 Rpm
Connected resistance 23 Ω ROD426 12000 Rpm
Load impedance >2.5 kΩ Torque <1 Ncm
Max. speed 5000 Rpm Moment of inertia
Moment of inertia 0.106 kg ⋅ cm 2 RI58 0.014 kgcm2
ROD426 0.0145 kgcm2
Armature weight 0.13 kg
Mass
Number of poles 2
RI58 0.36 kg
Number of armature slots 12 ROD426 0.25 kg
Number of laminas 24 Resolution 1024 lines/
rotation
Interface RS 422
1.1.4 The Metal Diaphragm Clutch
Supply voltage 5 V
Principle: Impulse channels A/A
B/B
Stainless steel diaphragm with aluminium clamping N/N
drive, non-floating.
Impulse wave shape rectangle
Phase shift A/B 90 °
Metal diaphragm Value Unit
clutch Index signal N/N 1 1/Rotation

Length 56 mm
Diameter 41 mm
Max. misalignment of 0.17 mm
lateral axes
Max. misalignment of 0.5 mm
axial axes
Max. torque 900 Ncm
Torsion spring constant 4200 Nm/rad
Moment of inertia 0.33 kg ⋅ cm2
Weight 0.13 kg

1-2 Technical Data


Laboratory Setup Speed Control DR300 Technical Data

1.2 The Actuator 1.2.2 SERVO MOTOR Module

Inputs Value Unit

Supply voltages +35 V


-35 V
Current consumption 2 A
Current signal from ±10 V
signal adaption unit
Amplification 0.4 A/V
Dimensions and Value Unit
Time constant TIME 2 5 ms
Weight TIME 1 30 ms
Length 471 mm
Depth 340 mm
Height 152 mm
Outputs Value Unit

Motor terminal ± 30 V
Weight 10 kg
voltage
Current monitor for 2.5 V/A
sensor modul
Mains input Value Unit

Mains supply 230 V


Frequency 50 Hz 1.2.3 POWER SERVO Module
Fuses S1 and S2 1.6 A mT
Inputs Value Unit

Supply voltages 2*24 V~ V


1.2.1 SERVO GENERATOR Module Servo power unit
Current consumption 2.5 A
Inputs Value Unit
Internal digital inputs:
Supply voltages +35 V Cover switch TTL level
-35 V System control TTL level
Control signal from ±10 V - Enable signal of the analog
signal adaption unit PI-controller: TTL signal
- Enable signal of the PC controller: TTL signal
Amplification 0.2 A/V
- Enable signal of the external
Time constant <1 ms controller: TTL signal

Outputs Value Unit Outputs Value Unit

Generator terminal ± 30 V Servo supply voltage ± 35, V


voltage 2.5 A
Current monitor for 5 V/A Reset signal for enable TTL signal
sensor modul circuit

Technical Data 1-3


Technical Data Laboratory Setup Speed Control DR300

1.2.4 SENSOR Module Input signals Value Unit

Internal digital inputs:


adaption unit
Digital input for enabling TTL signal
• Reset enable circuit from STOP key of the control signals (static)
Tacho signal 5 mV / Rpm
• Cover switch
Current monitor generator 0.2 V/A
• Enable signal analog PI Current monitor motor 0.2 V/A
Control signal for motor ± 10 V
• Enable signal PC servo from enabled
controller
• Enable signal external
Control signal for ± 10 V
generator servo from
Outputs:
enabled controller
3 outputs for enable signal indicator LEDs located on the
CONTROL module
Output signals Value Unit
Measuring signals Value Unit adaption unit
(BNC Socket) Tacho signal ± 10 V
Tacho signal from signal ± 10, V 2.5 mV / Rpm
adaption unit (TACHO) 2.5 mV / Rpm
Control signal for motor ± 10 V
Signal for motor servo ± 10, V servo
(I-MOTOR) 0.4 A/V Control signal for V
± 10
Signal for generator servo ± 10, V generator servo
(I-GENERATOR) 0.2 A/V

Index signal incremental 1 TTL pulse./


1.2.6 SIGNAL-ERROR Module
encoder (INDEX) motor rot.

Inputs Value Unit

1.2.5 POWER Module Tacho signal from signal ± 10 V


adaption unit
Mains supply Value Unit Control signal for motor ± 10 V
Input voltage 230 V servo from signal
2 primary fuses 100 mA T adaption unit

Frequency 50 Hz
Output voltage ± 15 V
+5 V

1-4 Technical Data


Laboratory Setup Speed Control DR300 Technical Data

Outputs Value Unit 1.2.8 EXTERN CONTROLLER Module


(Standard)
Scaled tacho signal for 0 ... 1
controller Inputs Value Unit
Scaled control signal for 0 ... 1 BNC Socket Extern ± 10 V
motor servo Setpoint I-Generator
BNC Socket Extern ± 10 V
Setpoint I-Motor
1.2.7 PI-CONTROLLER Module (Opt.
300-01)

Inputs Value Unit Outputs Value Unit

BNC Socket ± 10 V Control signal for motor ± 10 V


Setpoint Speed ^
= Control signal for ± 10 V
4000 Upm
generator
BNC Socket ± 10 V Reference voltages ± 2.5 V
Setpoint I-Generator (for internal use)
BNC Socket Extern ± 10 V
Setpoint I-Generator
BNC Socket Extern ± 10 V
Setpoint I-Motor
Tacho signal from ± 10 V
disturbance module ^
=
4000 Upm

Outputs Value Unit

Output of the analog PI ± 10 V


controller connected to
the disturbance module
resp. signal adaption unit
Control signal for ± 10 V
generat.
(via signal adaption unit)
Control signal for motor ± 10 V

Control signal for ± 10 V


generat.
Reference voltages ± 2.5 V
(for internal use)

Technical Data 1-5


Technical Data Laboratory Setup Speed Control DR300

1.3 Pin Reservations of the Plug Pin- Pin- Reservation


Connections No. Den.
25 n.c. n.c.

1.3.1 Connection Actuator to the PC 26 n.c. n.c.


Plug-in Card 27 n.c. n.c.
28 n.c. n.c.
PC-Connector (DAC98) 29 n.c. n.c.
Pin- Pin- Reservation 30 n.c. n.c.
No. Den.
31 AGND AGND
1 INC0 CHA Incremental Encoder channel A
32 AIN2 A/D 2 Tacho
2 INC0 CHB Incremental Encoder channel B
33 AIN3 n.c.
3 n.c. n.c.
34 Dout0 n.c.
4 n.c. n.c.
35 Dout1 D/O 1
5 n.c. n.c. Pulse (release output stage)
6 n.c. n.c. Hihg-level with pulse to low,
7 n.c. n.c. duration 40-100 µs

8 n.c. n.c. 36 Dout4 D/O 2


Rect (release output stage)
9 DIN0 System ready min. 10 Hz, max. 1 kHz
10 DIN1 n.c. 37 Dout3 n.c.
38 n.c. n.c.
11 DIN2 n.c.
39 n.c. n.c.
12 DIN3 Index
40 n.c. n.c.
13 n.c. n.c. 41 n.c. n.c.
14 n.c. n.c. 42 DGND DGND
15 AGND AGND 43 DGND DGND
16 AIN0 A/D 0 Motor current 44 n.c. n.c.
17 AIN1 A/D 1 Generator current 45 n.c. n.c.
18 INC0 /CHA Incremental Encoder ch. A (inv.) 46 n.c. n.c.
19 INC0 /CHB Incremental Encoder ch. B (inv.) 47 Aout0 D/A 0 Control signal from PC for
20 n.c. n.c. generator
21 n.c. n.c. 48 Aout1 D/A 1 Control signal from PC for
motor
22 n.c. n.c.
49 AIN4 AGND
23 n.c. n.c.
50 AIN5 AGND
24 n.c. n.c.
PC-Connector (DAC98)

1-6 Technical Data


Laboratory Setup Speed Control DR300 Technical Data

1.3.2 Connection Actuator to the 1.3.3 BNC Sockets (Rear Panel)


DR300 Mechanic

System connection BNC Sockets Value Unit


Pin- Reservation Pin- Reservation Pin- Reservation CONTROL SIGNAL ± 10 V
No. No. No. MOTOR 2.5 V/A
a1 Inc. CHB- b1 Inc. CHB+ c1 n.c. Control signal motor
current controller
a2 Inc. CHA- b2 Inc. CHA+ c2 n.c.
CONTROL SIGNAL ± 10 V
a3 Inc. Index- b3 Inc. Index+ c3 n.c.
GENERATOR 5 V/A
a4 Shield b4 Shield c4 n.c. Control signal generator
a5 D. Gnd b5 +5 VD c5 n.c. current controller

a6 A. Gnd b6 Sig. Tacho c6 n.c.


a7 n.c. b7 LED/Sys. c7 n.c.
a8 PE b8 Stop/Ready c8 n.c.
a9 Generator- b9 Generator+ c9 n.c.
a0 Motor- b0 Motor+ c0 n.c.

Technical Data 1-7


Technical Data Laboratory Setup Speed Control DR300

Subject to change without further notice (Date 01.07.1998)

1-8 Technical Data


Laboratory Setup Speed Control DR300 Practical Instructions

Practical Instructions

Date: 01.06.1995

Practical Instructions
Laboratory Setup Speed Control DR300 Table of Contents

1 Theoretical Background 1-1

1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2 Mathematical Description of the Permanently Exited DC Motor . . . . . . . . . . . . . . 1-1

1.2.1 The Structure Diagram of the Constantly Exited DC Motor . . . . . . . . . . . . . . 1-2

1.3 Principal Structure of a Speed Control . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.4 Structure Simplification of the Cascade Control . . . . . . . . . . . . . . . . . . . . . 1-4

1.5 The Cascaded Current Control Loop . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.6 Calculation of the Speed Controller . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.7 Controller Design Using Optimization Methods . . . . . . . . . . . . . . . . . . . . . 1-7

1.7.1 The Absolute Value Optimum . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

1.7.2 The Symmetrical Optimum . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

1.8 Application to the Given Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

2 Description of the System 2-1

3 Preparations for the Laboratory Experiment DR300 3-1

4 Performing the Experiment 4-1

5 Solutions 5-1

5.1 Solutions to the preparation problems from chapter 3 . . . . . . . . . . . . . . . . . . 5-1

5.2 Solutions to Performing the Experiment from Chapter 4 . . . . . . . . . . . . . . . . . 5-2

Practical Instructions i
Table of Contents Laboratory Setup Speed Control DR300

ii Practical Instructions
Laboratory Setup Speed Control DR300 Theoretical Background

LA : armature loop inductance.


1 Theoretical
Background The electromotive force of the motor is a function of the
motor speed, the motor constant and the constant
magnetic exitation as follows:
1.1 Introduction
E=CΦΩ Eq. 1.2
The task of the experiment is to adjust the parameters of
a speed control loop, to develop a suitable controller and Where:
to examine the dynamic behaviour of the closed control
loop using different controller settings. C : motor constant

Φ : magnetic exitation
1.2 Mathematical Description of
the Permanently Exited DC
Motor Ω : aramture frequency.

The frequency is correlated to the speed by


IA RA LA
2πn
Ω= with n in R⁄min.
60

UA E Machine
ML

So the electrical portion of the motor is described


sufficiently. In order to describe the overall motor
behaviour the correlation between the electrical and the
Figure 1.1: Electrical circuit diagram of the motor mechanical portion has to be established. This is obtained
by using the relation for the torque M produced by the
motor. The motor manufacturer gives the value of the
Bow equation from figure 1.1: motor constant KM in the relation

d
UA − E = RA IA + LA I Eq. 1.1 M = KM IA. Eq. 1.3
dt A

Where: The driving torque is in balance with the torques which


load the drive. For every time moment the following
UA : armature terminal voltage formulation is valid:

E : induced electromotive force during


M = ML + MB Eq. 1.4
armature rotation

IA : armature current With:

ML : the sum of all load torques, inclusive speed


RA : sum of the resistances contained in the
dependent friction torques.
armature loop

MB : acceleration torque

Practical Instructions 1-1


Theoretical Background Laboratory Setup Speed Control DR300

MB stands for the acceleration of the drive. Using the


ML
1
second Newton rule for rotations it can be stated as: KM J
UA 1⁄
RA IA M - MB Ω
- 1+TAs
dΩ E

MB = J Eq. 1.5
dt

Here J is the common moment of inertias of the motor


armature and the rigidly coupled load. Figure 1.2: Block diagram of the motor with load

1.2.1 The Structure Diagram of the the Laplace domain:


Constantly Exited DC Motor
1 1
At first the transfer functions of the above mentioned ω (s) = UA (s)
CΦ J RA J TA RA 2
equations are formulated: 1+ s+ s
KM C Φ KM C Φ

Using Laplace transformation with initial values set to


RA 1 + TA s
zero it follows for Eq. 1.1 : − ML (s)
KM C Φ J RA J TA RA 2
1+ s+ s
UA − E = RA IA + s LA IA KM C Φ KM C Φ
Eq. 1.8
and solved for IA:
The time behaviour of the mechanics is described by the
time constant TM. It is defined by the follwing:
1⁄R
1 UA − E A
IA = = (U − C Φ Ω) Eq. 1.6
RA 1 + TA s 1 + TA s A
J RA
TM =
KM C Φ
LA
where TA = is denoted as armature time constant.
RA
Thus equation 1.8 can be formulated as
Laplace transformation of the equations Eq. 1.3, Eq. 1.4
and Eq. 1.5 yields 1 1
ω (s) = U (s)
C Φ 1 + T s + T T s2 A
M M A
M = KM IA = ML + s J Ω

RA 1 + TA s
that means − ML (s)
KM C Φ 1 + T s + T T s2
M M A

1 Here the first numerator characterizes the reference


Ω= (K I − ML) Eq. 1.7
Js M A behaviour whereas the second describes the disturbance
behaviour.
The equations Eq. 1.6 and Eq. 1.7 describe the electrical
as well as the mechanical behaviour of the armature. With It can be observed from the equation Eq. 1.8 that the drive
these equations we can design the structure diagram of a acts like a second order lag element relating to its input
motor with load. The result is shown in figure 1.2. variable UA. The comparison with the general
formulation of a second order lag element
With figure 1.2 we can easily derive the transfer
behaviour of the shown feed back system. It follows in

1-2 Practical Instructions


Laboratory Setup Speed Control DR300 Theoretical Background

1 therefore required that the controlled variable Ω is


1 + 2 d T s + T 2 s2 measured continuously and compared with the reference
variable. In case of deviations the control voltage US of
and a short calculation ascertains the time constant the actuator has to be adjusted by a suitable controller.

JR T
T= 
√ A A
K CΦ
= 
√
TM TA The aquisition of the angular velocity Ω is usually
M performed by a tacho generator which is mounted on the
motor shaft. Its output voltage UT is proportional to the
and the attenuation rotation. UT is then subtracted from the reference variable
Usoll. The controller uses the difference UD to derive the
J RA TM
d=
1
2

√ KM C Φ TA
=
1
2
T
√ . control variable US for the actuator. The result is the
A
diagram shown in figure 1.3.

Transformation of the last equation reveals that in case of


This is a simple variant of a speed control loop. But the
a step-wise change of the armature voltage the result is an
dynamic behaviour of this variant is only moderate since
aperiodic speed action such as
changes of load or armature voltage first have to pass the
integrator at the output before they can be observed in the
d > 1 at TM > 4 TA.
control difference variable at the input of the controller.

1.3 Principal Structure of a An essential improvement of the dynamic behaviour can


Speed Control be obtained by using a cascaded current control as shown
in figure 1.4. Such a structure is usually denoted as
cascade control. Here the main controller (speed
When the DC drive, as described above, is connected to controller) functions like a setpoint transmitter for the
a supply voltage, the speed of the drive is easily adjustable cascaded control loop which operates autonomously.
to desired values. But such a structure is merely an open That means the cascaded controller uses the difference
loop control because changes of the load will invariably between the measured control variable, the armature
result in changes of the speed since the armature voltage current, and the setpoint adjusted by the speed controller
is not automatically adjusted. Whereas the fundamental to derive a control variable for the armature control loop
feature of a closed loop control is that the reference which is a member of the complete control loop.
variable (setpoint) will not change even in case of
disturbing external influences (changes of load). It is

1 ML 1
Controller RA TA KM J
Uref UA IA M - MB ω

- -
UT E

KT

Figure 1.3: Block diagram of the speed control loop

Practical Instructions 1-3


Theoretical Background Laboratory Setup Speed Control DR300

1 ML 1
Ω − Controller IA − Controller RA TA KM
J
ωref Iref UA IA M MB ω
-
- - -
ωmeas IA meas E

KW

KT

Tacho

Figure 1.4: Control with cascade current control

Since usually TA << TM, disturbances in the armature can be converted to a clearer structure after rearrangement
control loop can be compensated rapidly. In addition to of the integrator. At the same time the time constant TM
improving the controller dynamics, the cascaded current is used which was introduced in 1.2.1.
control loop offers another advantage. Limit values of the
motor such as maximum armature current and maximum In figure 1.5 the drive feedback Ω is included in the
current rise time can be considered during controller current control loop (transfer function Fi (s)). In such a
parameter adjustment.
structure the suitable controller design is obtained at first
for the inner and then for the outer control loop. Thus, at
1.4 Structure Simplification of first the structure and the parameters of the IA-controller
the Cascade Control are designed. Then the calculated transfer function of the
inner closed loop is included in the outer control loop.
After that the speed controller is designed.
Figure 1.4 shows that the control variable Ω of the outer
control loop is coupled into the cascaded control loop. To
separate the two control loops one therefor asssumes that 1.5 The Cascaded Current
the load moment does not change (ML=const.). One Control Loop
designs the reference behaviour and hopes that the
disturbance behaviour will be acceptable. In these The isolated control loop, which is of interest in this case
assumptions the influence of ML is omitted and figure 1.4 is shown in figure 1.6. Before we start with the controller
1
IA − Controller TA RA 1
RA
Ω − Controller CΦ TM
ωref Iref IA ω
- - -
ωmeas IA meas 1 RA
TM
KW

KT

Tacho

Figure 1.5: Reduced block diagram of the cascade speed control

1-4 Practical Instructions


Laboratory Setup Speed Control DR300 Theoretical Background

1 RA
IA − Controller RA TA
Iref UA IA CΦ
- -
Imeas 1
TM
RA denoted in figure 1.5 is included in the amplification of
KW the current control loop to obtain a better overall view.
With that the result for the transfer function of the
cascaded current control loop is

Figure 1.6: The cascaded current control loop K ’i RA 1


Gir (s) = ⋅ Eq. 1.9
CΦ 1 + Ti s
design we will carry out two other simplifications:

Because of the usual values for TA and TM, the integrating


feedback will respond with a large delay in comparison Current 1
Ω -Controller control loop TM

1 -
IA − Controller RA TA
Iref IA
KT
-
Imeas Tacho

KW
Figure 1.8: Speed control with cascade current control

1
Figure 1.7: Reduced current control loop Gir (s) = Ki ⋅
1 + Ti s

to the rapid armature control loop since TM > TA. So we Figure 1.8 shows the diagram of the speed control loop
with the cascaded current control loop described as a first
can neglect this feedback in our evaluation of the dynamic
order lag element.
behaviour. In that case the plant under consideration acts
like a first order lag element which is shown in figure 1.7.
It should be noted that only the dynamic reference
behaviour of the system was considered in the shown
Since the plant includes no integral portion, a PI controller
structure. In that structure an adjusted armature current
is chosen to reach steady state precision. The transfer
will not yield a stationary rotation which does not
function of the closed control loop is now again described
correspond to reality (friction). On the other hand it is not
as a first order lag element.
possible to define the disturbance behaviour.
K ’i
G ’ir (s) = 1.6 Calculation of the Speed
1 + Ti s
Controller
The amplification ki is adjusted to 0,4 A/V. Using the
switch located on the front panel of the actuator, the time A PI controller with the transfer function
constant Ti is adjusted to Time2 = 0.005 s or Time1 = 0.03 1 + TRn s
s. Rn (s) = KRn
s
shall be used for the speed controller. In that case we have
The amplification factor
two degrees of freedom, KRn and TRn to influence the

Practical Instructions 1-5


Theoretical Background Laboratory Setup Speed Control DR300

phase is denoted as the phase margin ϕD at the frequency


ωD which is called the intersection frequency.
1 1 1
TM T RN T RI
We can easily realize that the position and the size of the
0 dB |FR (j ω)| maximum phase reserve depends on the value of the
controller time constant TRn. Increasing TRn means

|FS (j ω)| shifting 1⁄TRn to the left in figure 1.9 which results in an
|FKO (j ω)|
earlier phase shift to smaller values since the time constant
of the cascaded current control TRI has little influence at
o
0 ϕR (j ω)
these frequencies. Conversely the maximum of ϕD is
ϕS (j ω)
o
-90 reduced when TRn is reduced since 1⁄TRn approaches 1⁄TRI,
o which compensates for the decreasing effect of the
-180 ϕK (j ω)
controller time constant TRn.

Figure 1.9: Construction of the Bode diagram The phase reserve (phase margin) is a suitable measure
for the dynamics of the transient response. A small ϕD

control. To elucidate their effects we consider the Bode yields a large overshoot response and a long transient time
diagram of the control loop. since we approach the limit of stability. On the other hand
an increasing phase reserve will result in a reduced
Figure 1.9 shows the amplitude and phase characteristic overshoot amplitude and transient time until the transient
of the controller (with KRn =1), of the plant (amplification response is aperiodic. Increasing the phase reserve will
slow down the control loop. So we realize that small as
KSn=1) and of the corrected open control loop
well as large phase reserves yield less desirable results
(FKO (j ω)). We see that the controller increases the phase since in both cases the time duration is long until steady
angle (integral portion: -90°), which approaches zero with state is reached at the desired reference value.
rising frequency according to the denominator term. It can
be seen in the complete phase characteristic that For this reason one has to modify TRn to obtain acceptable
ϕK (j ω) starts at - 180°, rises to values in the range of -90° speed of the control loop combined with sufficient
> ϕK > -180° in the middle until it approaches stability. A suitable transient with a small overshoot and
a relatively short transient time is achieved using a phase
asymtotically the phase characteristic of the plant (current
control loop). reserve in the range of 40° ≤ ϕD ≤ 70°. To adjust those
values, the controller time constant has to approach the
Only the range -90° > ϕK (j ω) > -180° is of interest in our mechanical time constant TM of the DC drive.

considerations. We know that a control loop becomes


unstable when the absolute value of the frequency Let us assume, TRn is chosen. Then the amplification
characteristic is | FKO (j ω) | > 1 for ϕK (j ω)=-180°. KRn of the PI controller has to be determined. For this
Conversely, the closed control loop stabilizes as the angle reason we draw the Bode diagram of the open control loop
of ϕK (j ω) increases from -180° (in positive direction) to on the assumption that the overall amplification of the
the point where the amplitude characteristic of the plant and the controller is given by V = KRn KSn = 1.
corrected open control loop | FKO (j ω) | intersects the With this we obtain an amplitude characteristic and a
phase characteristic as shown in figure 1.10.
0-dB line. The distance ϕD = 180° − | ϕK (j ωD) | of the

1-6 Practical Instructions


Laboratory Setup Speed Control DR300 Theoretical Background

a
log(KRn KSn) = . Eq. 1.10
20
1 1
T RN T RI

0 dB 1.7 Controller Design Using


a Optimization Methods

Application of the method described in the preceding


section allows insight into the physical behaviour of the
0
o system but it requires. In addition it does not guarantee
that the control loop designed by this method has a good
o
-90 disturbance behaviour.
ϕD
o
-180 The method described below has two significant
advantages. At first it supplies a simple mathematical
model for the controller parameters in form of complete
formulations. Secondly the control loop designed by this
Figure 1.10: Determination of the controller
amplification with the Bode diagram method has optimum disturbance and transient behaviour.

Now we have to define a phase margin ϕD in the range


between 40° and 70° so that we can determine the But in this case the method does not deal with parameter
amplification of the controller from figure 1.10 as optimization in the usual sense since the quality functions
follows: are not optimized. The method is applied by modifying
the physical parameters of the dynamics of the control
We know that the absolute value of the transfer function loop, ie. by controller parameter adjustment.
of the corrected open control loop has to be
| FKO (j ωD) | = 1 at the point ϕ (j ωD) = ϕD. Then the The two methods are known from literature and are
denoted as "absolute value optimum" and "symmetrical
amplitude characteristic intersects the 0-dB line in
optimum" (direct translations from german denotations).
ω = ωD, the intersection frequency. We can see from
Since the derivation is extensive, we will not introduce it
figure 1.10 that  FKO (j ωD)dB = 0 when the loop in detail, but only sketch the significant thoughts and
amplification is set to V = KRn KSn = 1. To achieve those results.

requirements, either the amplitude characteristic has to be


raised by "a" dB or the 0-dB line has to be lowered by "a"
1.7.1 The Absolute Value Optimum
dB where the latter is easier.

To use the absolute value optimum it is required that the


At this point V=1, the amplitude characteristic above the
plant (including the actuator element) is represented by a
new 0-dB line corresponds to a control loop with a loop
pure lag element. Thus its transfer function can be written
amplification of
as

VdB = (KRn KSn)dB = adB.


KS
FS (s) = Eq. 1.11
(1 + T1 s) (1 + T2 s) . …
When the plant amplification KSn is known, KRn can be
determined using A PI controller is used as the correction element with the
transfer function

Practical Instructions 1-7


Theoretical Background Laboratory Setup Speed Control DR300

1 + TR s But this requirement cannot be met for all ω with a


FR (s) = KR Eq. 1.12
s restricted number of variable parameters (KR, TR). The
aim of the optimization is now to approach the ideal state
The frequency characteristic of the reference variable is in a range arround ω = 0 as wide as possible. Here we will
given by restrict the discussion of the formulations to the special
case that the plant includes a significant time constant
FR (s) FS (s) T1 and a number of (n-1) smaller time constants which
FW (s) = Eq. 1.13
1 + FR (s) FS (s) can be combined into the overall time delay

It can be stated in the ideal case with s = j ω u


TS = ∑ Ti << T1
| FW (s = j ω) | = 1, i=2

Substituting Eq. 1.11 and Eq. 1.12 in Eq. 1.14 gives the
since the absolute value of the controlled variable
result for the PI controller parameters
| X (j ω) | is equal to the absolute value of the reference
value | W (j ω) | or in the time domain
1
TR = T1 und KR = , Eq. 1.15
2 KS TS
| x (t) | = | w (t) | .
where KS is the amplification of the plant including the
From the identity | FW (j ω) | = 1 it follows with (Eq.
measuring element.
1.13):

| FW (j ω) | 2 = FW (j ω) FW (−j ω) 1.7.2 The Symmetrical Optimum

1 1 Again the plant is assumed to be represented by a pure


= time delay system with real poles. The significant
1 1
1+ 1+
FR (j ω) FS (j ω) FR (−j ω) FS (−j ω) difference from the absolute value optimum is the
assumption that the time constants can be devided into a
1 group of large values T1 to to tn from the beginning.
= ≡1
FR (j ω) FS (j ω) − FR (−j ω) FS (−j ω) + 1 Where
1+ 2 2
| FR (j ω) | | FS (j ω) |
n
T1 ,..., Tm >>TΣ = ∑ ti
Ehen this expression is set equal to one, the following
i=m+1
formulation

is valid.
FR (j ω) FS (j ω) − FR (−j ω) FS (−j ω) + 1
=0
| FR (j ω) | 2 | FS (j ω) | 2 Again a PI controller is taken as the correction element.
Eq. 1.14
As we have seen from the controller design using the
must be valid. frequency characteristic method, it is possible to move the
intersection frequency ωD of the corrected open control
loop using a suitable controller. Thus one can locate the
intersection frequency for instance in the (logharithmic)

1-8 Practical Instructions


Laboratory Setup Speed Control DR300 Theoretical Background

middle between the low bend frequencies 1⁄Ti and the high Now the load moment ML in figure 1.4 is considered in
the following. It can be combined by the load moment
bend frequencies 1⁄ti. Since then ωD is relatively far away
resulting from the coupled machine and the moments of
from both groups, only the large time constants Ti become
friction. One component of the moments of friction is the
noticeable in form of a straight line part falling with sliding friction proportional to the rotation. When this
m ⋅ 20 dB ⁄ dek in the neighbourhood of ωD. So the sliding friction is described by a feedback (Kreib) of the
frequency characteristic has some symmetry arround ωD integrator with the machine time constant TM its transfer
function is stated as
and can be taken as a representation of an single or
multiple integration element.
Ki
TM s
Starting from these assumptions one furthermore tries to GM (s) =
make the frequency characteristic of the reference Kreib ⋅ Ki
1+
variable equal to 1 in a range arround ω = 0 as wide as TM s
possible using suitable controller parameters. This is
similar to the absolute value optimum. This requirement 1 1
= ⋅ Eq. 1.17
is approximated when Kreib TM
s+1
Ki ⋅ Kreib
m

∏ Ti
i=1 1
TR = 4 m TΣ und KR = ⋅
(4 m TΣ) m 2 KS TΣ The amplification factors of the current controller (Ki)
and the measuring system are known. So the overall
with m=number of the large time constants and transfer function of the current controller, the motor and
TΣ= sum of the small time constants the measuring system is given by:

1 1 1 1
that means when m = 1 Gges (s) = ⋅ ⋅ ⋅
1 + Ti s Kreib TM 1 + Tmess s
s+1
Ki ⋅ Kreib
T1
TR = 4 TΣ and KR = Eq. 1.16 Eq. 1.18
8 KS TΣ 2

1
The amplification is measureable in the open control
is valid. Kreib
loop.
Here again KS is taken as the product of the amplification
of the plant and the measuring element. So the new machine time constant can be determined
using the measured amplification Vreal by:
1.8 Application to the Given
Structure TM ers =
TM ⋅ Vreal
Eq. 1.19
Ki

To apply both methods described in chapter 1.7 to the


Then the transfer function of the open speed control loop
controller adjustments, the plant has to be described in
is given by:
form of a pure time delay element (see Eq. 1.11).

Practical Instructions 1-9


Theoretical Background Laboratory Setup Speed Control DR300

Vreal
Gges (s) = Eq. 1.20
(1 + TM ers s) (1 + Ti s) (1 + Tmess s)

Now the optimization methods described in chapter 1.7


can be applied to the plant given by 1.20.

1-10 Practical Instructions


Laboratory Setup Speed Control DR300 Description of the System

The motor M1 is controlled by a servo amplifier (current


2 Description of the controller). Its input voltage range is from -10.0 to +10.0
System volt with an amplification of 0.4 A/V. Its transfer function
behaviour is like a first order lag with a time constant of
5 or 30 ms. The motor current is available as a measuring
The plant consists of a permanently exited DC motor M1.
signal at the socket "I-Motor" (measuring range: 2.0
Its input signal (the armature current) is provided by a
V/A).
cascaded current control loop. The servo amplifier of the
current controller operates in 4 quadrant mode, so that the
The motor M2 is controlled by a servo amplifier (current
orientation of the current and correspondingly the
controller). Its input voltage range is from -10.0 to +10.0
orientation of the rotation of the motor is arbitrarily
volt with an amplification of 0.237 A/V. Its transfer
adjustable. Available sensors for the output signal
function behaviour is approximately like a proportional
(rotation) are an analog tacho generator and a digital
element. The motor current is available as a measuring
incremental encoder. The free shaft of the motor is rigidly
signal at the socket "I-Generator" (measuring range: 4.4
coupled to a second identical motor M2 using a clutch K.
V/A).
This motor operates in generator mode. Its output current
is adjustable by another current controller.
The maximum output current of each servo amplifier is 8
A (20ms), the continuous current 2A.

Technical Data: The tacho signal is scaled with 0.5 using an input
amplifier and is filtered by a first order lag with a time
Motor
constant of 1 ms. The measuring signal available at the
Rated voltage 24 V
socket "Tacho" ranges from -10.0 V to + 10.0 V with 2.5
Rated current 2A
mV/Rpm.
Rated power 30 W
Rated speed 3000 Rpm
Rated torque 0.096 Nm
Voltage constant 6.27 mV/Rpm
Moment of inertia 17.7 10-6 Kgm2
Torque constant 0.06 Nm/A
Connected resistance 3.13 Ohm

Tacho
Output voltage 5 mV/Rpm
Moment of inertia 10.6 10-6 Kgm2

Incremental encoder
Number of lines 1024
max. resolution 4096/R
Moment of inertia 1.45 10-6 Kgm2

Clutch
Moment of inertia 33.0 10-6 Kgm2

Practical Instructions 2-1


Description of the System Laboratory Setup Speed Control DR300

2-2 Practical Instructions


Laboratory Setup Speed Control DR300 Preparations for the Laboratory Experiment DR300

3 Preparations for the


Laboratory Experiment
DR300
3.1 Use the given technical data to determine the
mechanical time constant TM of the complete
system.

3.2 Use equation 1.8 ’Theoretical Background’ to


determine the overall amplification of the current
control loop.

3.3 Determine the plant amplification ( motor with


current control loop ) between the input signal of
the current controller (in Volt) and the output signal
( rotation in Rpm ).

3.4 Determine the maximum resolution of the sensors.


Tacho signal: 2.5 mV / rotation
Input voltage range
of the A/D-converter: -10V ... +10V
Resolution of the converter: 12Bit
Incremental encoder: 4096 pulse/rotation
Sampling period of the controller: 5 ms

3.5 Draw the Bode diagram of the open control loop.


Take the plant amplification from 3.3. The
controller amplification is set to 1. The controller
time constant has to be greater than the machine
time constant to reach sufficient phase reserve.
Therefore TR is set to 3.0 * TM. Determine the
controller amplification for a phase reserve of 40°.
KS (1 + TR s)
G (s) =
TM (1 + Ti s) s2
TR = 3.0 * TM
Ti = 0.03 s

3.6 A first order lag is used as a filter to reduce the


ripple of the tacho signal. The time constant of the
filter is set to 5 ms. Extend the transfer function of
task 3.5 with this first order lag. Determine the
controller amplification again for a phase reserve
of 40°.

Practical Instructions 3-1


Preparations for the Laboratory Experiment DR300 Laboratory Setup Speed Control DR300

3-2 Practical Instructions


Laboratory Setup Speed Control DR300 Performing the Experiment

for the load with an amplitude of 1,0 V and a period


4 Performing the of 5s. Start a measurement (measurement time 5
Experiment sec) and evaluate the disturbance behaviour of the
control.

Please follow the instructions of your tutor while


4.7 Adjust the parameters determined by the
performing the experiment.
’symmetrical optimum’ and repeat the
measurements from sections 4.4 and 4.6.
The switch at the module "SERVO MOTOR" has to be
in position "Time 1".
4.8 Adjust the parameters of the PI controller according
to the preparation task 3.6 and repeat the
4.1 Switch off the control. The amplification of the
measurements from sections 4.4 and 4.6.
plant will be determined as follows. Switch on the
open loop control. Increase the input voltage of the
servo amplifier in steps of 0.5 volt until the motor
rotates in the range 2000 to 2500 Rpm. Generate a
square wave control signal with an amplitude of 0.1
volt. Choose a period of the signal so that a steady
state is reached for every final value of the speed.
Determine the amplification of the plant. Compare
this result with the plant amplification determined
by the preparation tasks. Use these values to
calculate the transfer function of the plant in form
of a n-th order lag element.

4.2 Use the ’absolute value optimum’ to determine the


parameters of the PI controller.

4.3 Use the ’symmetrical optimum’ to determine the


parameters of the PI controller.

4.4 Adjust the parameters according to the ’absolute


value optimum’. Start the PI controller. Generate a
square wave reference signal in a range of 2300 to
2700 Rpm with a period of 5 sec. Start a
measurement without trigger conditions (
measurement time 5 sec ). Evaluate the precision of
the control.

4.5 Set the load current to -1.0 A. How does the


reference behaviour change?

4.6 Adjust a constant reference speed with 3000 Rpm.


Switch on the load. Adjust the offset of the load
setpoint so that the motor current (!!!) reaches
approx. 1,5 A. Now adjust a square wave setpoint

Practical Instructions 4-1


Performing the Experiment Laboratory Setup Speed Control DR300

4-2 Practical Instructions


Laboratory Setup Speed Control DR300 Solutions

ref. 3.3:
5 Solutions
60 1
KRpm = Kiges ⋅ = 200.0 => 46 dB
2π V min
5.1 Solutions to the preparation
problems from chapter 3
ref. 3.4:
ref. 3.1:
Tacho:
Jsum = Jmotor+ Jgenerator+ Jclutch+ Jtacho+ Jincremental encoder
Umax − Umin
= (17.7 + 17.7 + 33.0 + 10.6 + 1.45) 10-6 Kgm2 = 1.953 Rpm
mV
212 ⋅ 2.5
rotation
= 80.45 10-6 Kgm2
Incremental encoder:
Jges RA
TM = Revolution = increments/increments maximum/sampling
KM C Φ
period*60

C Φ is to be determined from the voltage constant:


Resolution: 1/4096/0.005*60 = 2.929 Rpm
6.27mV/Rpm

6.27 mV ⋅ 60 s
CΦ= = 0.0598 Vs ≈ 0.06 Vs ref. 3.5:
2⋅π
Figure 5.1 shows the amplitude characteristic.
80.45 10−6 Kgm2 ⋅ 3.13Ω
TM = = 69.94 ms ≈ 70 ms
Nm DR300
0.06 ⋅ 0.06 Vs
A 50

ref. 3.2:
Amrplification[dB]

30

-25 dB

A RA
Kiges = 0.4 ⋅
V CΦ 10

A
0.4 ⋅ 3.13Ω
V
= -10
0.06 Vs 0.1 1 10 f1 100 1e+03
Frequency

Figure 5.1: Amplitude characteristic


1
= 20.86
Vs
To reach a sufficient phase reserve of 40° the controller
amplification has to be -25 dB.

25
KR = 10− ⁄20 ≈ 0.056

Practical Instructions 5-1


Solutions Laboratory Setup Speed Control DR300

Figure 5.2 shows the phase characteristic. Figure 5.4 shows the phase chartacteristic.

DR300 DR300
-120 -120
Phase [Degree]

Phase [Degree]
-140 -140

40°

-160 -160
40°

-180 -180
0.1 1 10 f1 100 1e+03 0.1 1 10 f2 100 1e+03
Frequency Frequency

Figure 5.2: Phase characteristic Figure 5.4: Phase characteristic

The right value of 40° is chosen to determine the The right value of 40° is chosen to determine the
amplification. The amplification taken from the diagram amplification. The amplification taken from the diagram
is -25 dB. The corresponding result for KR is 0.056. is approx. 27 dB. The corresponding result for KR is
0.042.

ref. 3.6: 5.2 Solutions to Performing the


Experiment from Chapter 4
KS (1 + TR s)
G (s) =
TM (1 + Ti s) (1 + Tfilter s) s2
ref. 4.1:
Figure 5.3 shows the amplitude characteristic.
The following measurements were taken with the
following adjustments:
DR300
Offset of the control signal : 1.9 volt
50
Amplitude: 0.05 volt
Period: 15 s
Speed from Incremental Encoder
Amplification[dB]

30
-27.5 2.8e+03
dB

10 2.63e+03
RPM

2.47e+03
-10
0.1 1 10 f2 100 1e+03
Frequency

Figure 5.3: Amplitude characteristic 2.3e+03


0 10 20 30

Time in s
8.11.1993 12:33:37

KR = -27.5 dB ≈ 0.042 Figure 5.5: Speed characteristic to determine


amplification

5-2 Practical Instructions


Laboratory Setup Speed Control DR300 Solutions

Speed amplitude: 350 Rpm ref. 4.6:


Voltage amplitude: 0.1 Volt
Speed from Tacho

3300.00
The result is a plant amplification of 3500 Rpm/V and
with this a time constant of

3100.00
0.07 * 3500 / 200 = 1.225 sec.

RPM
2900.00
ref. 4.2:

T = 1.225 s
2700.00
0 1 2 3 4 5
Time in sec
12.10.1994 13:59:16
K = 1/(2 * 3500 * 0.035) = 0.004
Figure 5.6: Parameters according to ’absolute value
optimum’, disturbance behaviour

ref. 4.3: The controller adjustment according to the ’absolute


value optimum’ shows a bad disturbance behaviour.
T = 4 * 0.035 sec = 0.14 sec

K = 1.225 / (8 * 3500 * 0.0352) = 0.0357 ref. 4.7:


Speed from Tacho

2900.00
ref. 4.4:

Speed from Tacho


2600.00
2800.00
RPM

2300.00
2600.00
RPM

2000.00
2400.00 0 1 2 3 4 5
Time in sec
12.10.1994 13:56:33
Figure 5.8: Parameters according to ’symetrical
optimum’, reference behaviour
2200.00
0 1 2 3 4 5
Time in sec
12.10.1994 13:55:07
Figure 5.7: Parameters according to ’absolute value
optimum’, reference behaviour

ref. 4.5:

The reference behaviour is unchanged in the steady state.

Practical Instructions 5-3


Solutions Laboratory Setup Speed Control DR300

Speed from Tacho

3200.00

3066.67
RPM

2933.33

2800.00
0 1 2 3 4 5
Time in sec
12.10.1994 14:00:35
Figure 5.9: Parameters according to ’symetrical
optimum’, disturbance behaviour

Speed from Tacho

2900.00

2633.33
RPM

2366.67

2100.00
0 1 2 3 4 5
Time in sec
12.10.1994 13:57:22
Figure 5.10: Parameters according to ’Bode Diagram’
reference behaviour

Speed from Tacho

3200.00

3066.67
RPM

2933.33

2800.00
0 1 2 3 4 5
Time in sec
12.10.1994 14:01:30
Figure 5.11: Parameters according to ’Bode Diagram’
disturbance behaviour

5-4 Practical Instructions


Laboratory Setup Speed Control DR300 Fuzzy Practical Course

Fuzzy Practical Course

Date: 01.06.1995

Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Table of Contents

1 Backgrounds of the Fuzzy Controller 1-1

1.1 The Fuzzy Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2 The Linguistic Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.3 The Fuzzification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.4 The Rule and the Rule Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.5 The Inference Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5.1 The Aggregation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5.2 The Implication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5.3 The Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5.4 The Inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.6 The Defuzzification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.7 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

2 Preparation Tasks for the Fuzzy Practical Course 2-1

3 Carrying-Out the Experiment 3-1

4 Solutions 4-1

4.1 Solutions to the Preparation Tasks from Chapter 2 . . . . . . . . . . . . . . . . . . . . 4-1

4.2 Solutions to Carrying-Out the Experiment from Chapter 3 . . . . . . . . . . . . . . . . 4-4

Fuzzy Practical Course i


Table of Contents Laboratory Setup Speed Control DR300

ii Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Backgrounds of the Fuzzy Controller

1 Backgrounds of the
Fuzzy Controller

Fuzzy Controller

Knowledge Base

Data Base (Linguistic Variables)

Rule Bases

← ←
W Inference ←
e u
Fuzzyfication Aggregation Implication Conclusion Defuzzyfication Process

X ←
Ymeas

Measuring

Figure 1.1: Components of the fuzzy Controller

1.1 The Fuzzy Set Data Set X

1[m]

The role of the numbers for the arithmetic is played by the ∅

fuzzy sets, also known as fuzzy aggregates, for the fuzzy 0 1 2 x

theory. They are the mathematical base objects for which Figure 1.2: Mapping of the data set X to the real
corresponding operators are defined. numbers

Correspondingly a set of expressions can be mapped. A


To control a process, the required data are provided by a
special case is the set with the element true, which can be
measuring system. Those data include the unit of
mapped to the numbers 0 and 1. In addition both sets are
measuring, the measured variable and possibly some
combinable in the case an expression true or false is
other values which are not of interest in this case. The unit
assigned to each measured value. This representation
of measuring is the physical unit i.e. meter, whereas the
corresponds to the well-known binary logic.
measured value is a non-dimensional measured result. To
order the inordinate group of all possible data they could
Statement Set M
be mapped to the group of real numbers, using for true

example the corresponding number of the measured not true



value. Those numbers are representable graphically by a
straight line of numbers. 0 1 µ

Figure 1.3: Mapping of the statement set M to the


real numbers

Fuzzy Practical Course 1-1


Backgrounds of the Fuzzy Controller Laboratory Setup Speed Control DR300

Using this method a bar with the length less than 1 meter The difference between the figures 1.5 and 1.6 can be seen
is clearly representable by the set of x contained in the from the transition region from µA (x) = 0 to µA (x) = 1.
data set X which results with the expression µ = 1. Those While the membership changes step-wise in the figure
are all values which apply to 0 ≤ x ≤ 1. 1.5, a sliding transition of the membership values takes
place in the figure 1.6. Doing this according to human
mind a more natural description of the term length is
possible. Such a set is called an indistinct set or a fuzzy
set.

In the most general case the set of expressions is


completely mappable to the interval of the real numbers.
This is representable by the so-called membership
Figure 1.4: Example for a distinct set function µA (x). It describes the degree of membership of
all elements a ∈ A ⊆ X.
Such a set, described by binary expressions, is called a
distinct set. With that it is possible to describe indistinct terms like
nearly true, fairly true, quite false, etc. mathematically.
The set of all bars, which are longer than 1 meter, can be
described using the complement of the above mentioned So the fuzzy set is described by an ordered set of pairs of
set. This again is a distinct set. the form:

A = {(x,µA (x)) | x « X }

Features of the Membership Functions:

• The membership function µ(x) describes an onto


Figure 1.5: Example for the complement of the mapping, that means for each picture point µ ∈ U
distinct set (see above) there exists at least one original picture point a∈
A. So only A →U describes a distinct mapping,
Human meaning will consider the difference between whereas the reverse mapping U →A is indistinct in
0.99 m and 1.01 m as being not significant so that the general.
statement the bar with a length of 0.99 m does not belong
to the set whereas the bar with 1.01 m belongs to it seems • The range of values µ(x) is the set of the positive,
to be unnatural. A more plausible description is reachable real numbers R +. Usually µ(x) is normalized to 1
by expanding the set of expressions. The representation when no other statements are made. So the fuzzy
of long bars could then look like the following: logic is a generalization of the classical logic.

µ (x)
A1 1.2 The Linguistic Variable

0.5
It was shown in the previous section that with human
mind fuzzy terms are describable mathematically. With
0 this one must not forget that those terms always apply to
0 1 2 x/[m]
Figure 1.6: Example for a fuzzy set the set A ⊆ X with the membership function µA (x).

1-2 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Backgrounds of the Fuzzy Controller

Example: Unfortunately the following operation is called with the


same name. This is the expression xi is lij contained in the
Let us assume the length x ∈ X is given, so the term very rules. In this case xi is the fuzzificated measured value,
short (Set SK) is definable using the fuzzy set µSK(x). i.e. x=1[m], and lij is the j-th fuzzy set of the i-th linguistic
Similar to this further terms like short, normal, long are variable, i.e. l0,0 = very short. The index i indicates that
definable using further fuzzy sets, but all the fuzzy sets
the fuzzy sets, which are to be compared, belong to the
have to belong to the same base set X. The fuzzy sets built
same base set and range of values. Since the connections
in such a manner are combined to the so-called linguistic
and units in physical systems clearly define, which
measured value is assigned to which linguistic variable
µ (x)
very short short normal long very long the index i is neglectable.
1

It is also to be regarded that the keyword is describes an


operator. It determines the maximum degree of
correspondence aij of the both fuzzy sets using an and

0
µ(x) µ(x)
xi li j xi li j
0 1 x/[m] 1 1
Figure 1.7: Example for a linguistic variable

ai j ai j maximum degree
variable. of corres pondance
xi AND l i j
0
So a linguistic variable can be taken as a group of fuzzy
0 x x 0 x x
sets, which are defined with respect to the same base set Meas Meas
X and the same range of values i.e. µ(x) ∈ [0,1]. Crisp value Value with tolerance
Figure 1.8: Fuzzification

There are no limits for the overlapping regions so that an


arbitrary number of fuzzy sets may overlap. combination (minimum result) of both fuzzy sets
followed by the determination of the maximum
The totality of all input and output linguistic variables is membership value. This is a number out of the range from
called the data base which is used for control. Zero to the maximum value of µ(x).

1.3 The Fuzzification 1.4 The Rule and the Rule Base

Since the fuzzy theory generally defines operators only A rule also called fuzzy implication has the general form:
for fuzzy sets, a fuzzy set is to be assigned to each distinct
measured value (crisp value), i.e. the components of the if Premise then Conclusion
control error vector →
e. This process is called fuzzification.
It can be seen easily that µ(x) of a crisp value is identical An arbitrary number of expressions xi is lij is combined
to the normalized impulse function γo (x) as well as the by the operators and or or in the premise.
result is a square function rect(x) (see figure 1.8) in case
Example for a premise:
the value is full of tolerances.

x is near and v is great

Fuzzy Practical Course 1-3


Backgrounds of the Fuzzy Controller Laboratory Setup Speed Control DR300

The terms near, great are defined as fuzzy sets in the • or


linguistic variables position and speed. The fuzzy sets x, aab or acd ⇔ MAX (aab, acd)
v are the fuzzificated currently measured values.
• and
The conclusion is an expression of the form xo is loj. In aab and acd ⇔ MIN (aab, acd)
this case loj is the j-th fuzzy set of the linguistic variable
In general the order of the operators has to be regarded,
describing the output value and changed by the
because not all operators are commutative or associative
implication. The equal sign is here an assignment of the
at all. But the and and or operators meet this condition so
fuzzy set loj to the output variable xo.
that the premise can be interpreted recursively. The result
of the a aggregation ag is again a number. It is a measure
A rule base is a combination of an arbitrary number of
of the fulfilment of the premise.
rules.

The rule base describes the experience and the knowledge 1.5.2 The Implication
about the process and therefore must not be complete. For
The implication is used to infer the degree of fulfilment
instance it could be the case that due to the ignorance of
a′gr at the output from the degree of fulfilment agr of the
the developer not all physical actions are known. The lack
of dominant rules is the result of the incompleteness of premise.
the rule base. This leads to a bad or useless control
behaviour. This is repairable by the addition of further if agr then a′gr ⇔ agr → a′gr ≤ µmax
rules to the rule base.
Usually the identity agr ≡ a′gr is taken as a mapping
The totality of all linguistic variables and rule bases,
instruction.
which characterize the fuzzy controller is called
knowledge base.
1.5.3 The Conclusion
1.5 The Inference Operation After the implication has determined the degree of
fulfilment a′gr of the output the conclusion determines the
resulting fuzzy set.
1.5.1 The Aggregation

The aggregation (combination) of the degrees of Example:


membership aij, determined by the fuzzification, of a rule
is performed by operators given in the premise.
µ (x) µ (x)
Example of such a premise: 1 1
a a
a1,2 and a2,1 or a1,1 oj oj

The degrees of membership ai,j are numbers with


0 ≤ ai,j ≤ µmax.
0
0 x x
Operators: Minimum Determination
0 Product determination

Figure 1.9: Min- and product method

1-4 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Backgrounds of the Fuzzy Controller

xo is stark y= min {y | µ(y) = µmax}


Doing this the fuzzy set of the output linguistic variable
named in the rule is suitably combined with a′gr. Usual • Mean Value of the Maximum (MOM, Mean of
combinations are the determination of the minimum or Maximum)
the product.
l
wi
1.5.4 The Inference
y=∑
l ∩ µ(wi) = µmax
i=1

All rules of a rule base are interpreted in this way. The


degree of fulfilment a′gr is determined for each rule. The • Center of Area (COA, Center of Area)
This is the most general operation. Therefore this
rules have to be combined because each rule delivers a
method of defuzzification is implemented in our
resulting fuzzy set. This is performed by means of
controller. Here the abscissa co-ordinate of the
combining all the resulting fuzzy sets which apply to one
Center of area is determined. The special
and the same output linguistic variable.
advantage of this method is the result with
continuous values in contrast to the first mentioned
In the special case that the conclusion is carried out using
methods.
the product or minimum method and that the combination
uses the maximum determination, the combination can be
carried out previously to the conclusion using the
following instruction:
µ (y)
1
aoj = MAX (agr 1 ,..., agr n ) 0 ≤ agr ≤ 1
j j

The index j references to the fuzzy set of the output


linguistic variable. This is a significant simplification.
The fuzzy sets of the output linguistic variable converted 0
in such a way are combined to one result. The 0 MOA COA y
MAX
combination is usually carried out by the maximum
Figure 1.10: Defuzzification
operator. Doing this the inference leads to the resulting
fuzzy set, which describes the degrees of membership to
the resulting set of all output values.
∫ µ(y) y dy
y=
1.6 The Defuzzification ∫ µ(y) dy

To come from the resulting fuzzy set determined by the ∑ ( µ( y + ∆2y ) + µ( y − ∆2y ) ) yi ∆y
i i
inference to a crisp value, i.e. the control signal u a y=
so-called defuzzification has to be carried out. That means ∑ ( µ( y + ∆2y ) + µ( y − ∆2y ) ) ∆y
i i

a characteristic value of the resulting fuzzy set has to be


found. To do this several methods are available, which
1.7 Remarks
can be distinguished with respect to the computing effort
and the general application field.
The fuzzy controller belongs to the non-linear steady
• Maximum Choice (MAX) controllers. So its input/output behaviour is definitely

Fuzzy Practical Course 1-5


Backgrounds of the Fuzzy Controller Laboratory Setup Speed Control DR300

given by its control characteristic area. Unfortunately • the observation of the process.
there is no general method available to find suitable fuzzy
sets and rules for a given problem. The rules can be found with respect to

The fuzzy sets of the linguistic variables can be found with • the experience of the operators,
respect to
• the knowledge of the control engineers,
• the characteristic values of the actuator and
measurement system, • the observation of the process.

• the knowledge of the control engineers,

Figure 1.11: Example for a characteristic control area

1-6 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Backgrounds of the Fuzzy Controller

Linguistic Variable: x0 Linguistic Variable: x1 Output Linguistic Variable: yout


µ µ µ
1 PM0 1 PM1 1 PMo
a0,0

AN D
a1,0
a o0

PROD.

µ µ a1,1 µ
NM0 1 NM1 1 NMo 1
a o1
OR

a 0,1

x0v x1v

µ µ µ
1 PMo NMo 1 MAX 1

y
outv
Rule 0: if x0 is PM0 and x1 is PM1 then yout is PMo end
Rule 1: if x0 is NM0 or x1 is NM1 then yout is NMo end
Input variables: x0, x1
Sets of Input variables: PM0, NM0, PM1, NM1
Values of input variables: x0v, x1v
Output variable: yout
Sets of Output variables: PMo
Value of output variable: youtv
µ is degree of fulfilment

Figure 1.12: Example for the execution of a fuzzy algorithm using the Max-Product-Method

Fuzzy Practical Course 1-7


Backgrounds of the Fuzzy Controller Laboratory Setup Speed Control DR300

1-8 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Preparation Tasks for the Fuzzy Practical Course

2.5 Determine a suitable intervall for the input and


2 Preparation Tasks for output variables of the fuzzy control with respect to
the Fuzzy Practical the technical data of the plant, to the result of
preparation task 4.3 for the PI controller and under
Course consideration of the fuzzy controller structure
shown in figure 2.1. Give meaningful names to the
2.1 The fuzzy controller implemented in the control three variables.
software of the laboratory setup DR300 has the
structure, which is shown in figure 2.1. Determine 2.6 Define three fuzzy sets for each of the variables
a comparable classical structure (ie. P, PI, DID, PD mentioned in 2.5. Regard that the complete
etc.) assuming that the fuzzy controller kernel is definition range of the input variables is covered.
describable by the transfer function Use fuzzy sets as simple as possible with only a few
z = Kp * x + Ki * y. base points. Give meaningful names to the sets.
Prove this assertion by structure transformation.
2.7 How big is the number of rules, in case all
combinations of variables with their sets are
1 T Fuzzy-Controller considered and the premise uses only the
x z 1/T "and"-operator ?
n in z Uout
y
Does a fuzzy controller always require such a
y
x number of rules ?

2.8 Determine rules to control the DR300 plant based


Figure 2.1: The structure of the fuzzy controller on the solutions of 2.5, 2.6 and 2.7. Make clear in
your own mind how the controller should react on
variations of the input signals.
2.2 How would the 3D representation of the fuzzy
controller kernel look like, in case the transfer
2.9 Create a complete description file for the fuzzy
function mentioned in 2.1 is assumed ?
controller based on the solutions of 2.8. Use
meaningful comments for all variables and rules.
2.3 What is the difference of the real transfer function
of the fuzzy controller kernel in comparison with
the transfer function assumed 2.1 ?

2.4 How would the parameters of a PI controller have


to be adjusted so that it has an identical transfer
behaviour like the fuzzy controller ?
A fuzzy controller is given with two linguistic
variables for the input and one linguistic variable
for the output. The output variable contains only
one fuzzy set. The output value adjusted by the
fuzzy controller kernel can lay in which intervall ?
How is this intervall defined, in case the output
variable contains two fuzzy sets with different
center of areas ?
Give reasons for your answer.

Fuzzy Practical Course 2-1


Preparation Tasks for the Fuzzy Practical Course Laboratory Speed Control DR300

2-2 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Carrying-Out the Experiment

3 Carrying-Out the
Experiment
3.1 Edit the fuzzy description file according to the
preparation task and test the controller.
How do you evaluate the control behaviour? What
are the possible reasons for the observed
bahaviour?

3.2 Examine the definition domain of the input and


output variables once again. (Hint: Which input
signals lead the PI controller to supply output
signals inside the permitted range of the control
signals even in case the integral portion is
neglected?) Try different adjustments and evaluate
the effects.

3.3 Change the fuzzy rules and evaluate the effects on


the system behaviour.

3.4 Repeat the changes according to 3.2 and 3.3 to get


a suitable system behaviour. Give reasons for the
changes in comparison with 3.1.

3.5 How do you evaluate the fuzzy control in


comparison with the PI control (see practical course
PI controller)?
Which of the controllers possesses the better
prerequisites for the plant? Does this answer
correspond to the observed system bahaviour?

Fuzzy Practical Course 3-1


Carrying-Out the Experiment Laboratory Setup Speed Control DR300

3-2 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Solutions

surface along the x-direction is Kp and along the


4 Solutions y-direction Ki. The plane passes the zero point of the
coordinate system.
4.1 Solutions to the Preparation
Tasks from Chapter 2

ref.2.1

With the transfer function of the fuzzy controller kernel


one is able to represent figure 2.1 of the preparation tasks
by simple transformations of the structure. The result is
the structure of a PI controller with the coefficients Kp
und Ki:

Fuzzy-Controller

x Figure 4.2: 3D-representation of the fuzzy controller


s
n in z Uout kernel
z = KP*x + KI*y 1/s
y
ref.2.3

The actual transfer function of the fuzzy controller kernel


x is z = f(x,y), where the function f defined by fuzzy sets,
s KP
n in z Uout
+ 1/s fuzzy variables and fuzzy rules is arbitrary. Therefore an
y
KI equivalent PI controller can only be achieved in case each
of the parameters Kp and Ki is described by a function of
x and y.

s 1/s KP
n in Uout 1
+ G(s) = Kp(x,y) + Ki(x,y) * , mit x = s * y
s
1/s KI

But this structure is only a PI controller for constant Kp


and Ki. In single cases other structures corresponding to
KP conventional controllers can be found for other functional
n in Uout
+ connections of Kp resp. Ki with x and y. Usually an exact
1/s KI
mathematical connection is not given with fuzzy
controllers and on the other hand this connection does not
Figure 4.1: The transformed structure of the fuzzy meet the concept of the fuzzy control.
controller

ref.2.2
ref.2.4
The three dimensional representation of the function
z = Kp * x + Ki * y, As described in the theoretical backgrounds of the fuzzy
where x,y and z are the coordinates of a cartesian system, controller only the method "Center of Area" is used by
is a plane surface in the space. The gradient of the plane our fuzzy controller for defuzzyfication. A single fuzzy
set always has the same center of area independent of its

Fuzzy Practical Course 4-1


Solutions Laboratory Setup Speed Control DR300

weighting by the Max-Prod-method. Therefore the value The definition range of x is limited by the maximum
of a fuzzy output variable with only one fuzzy set is change of y during a sampling period. To calculate this
always equal to the value of the constant center of area of value the maximum control signal 10V is assumed. The
this fuzzy set. So the output value is: result is:

out = coa( set ) = const. 5ms


1
∆ Y = 10 V ⋅ Kupm ⋅ ∫ dt = 142,8 min−1
0 TM
If in contrast the fuzzy output variable has two sets the
value of the variable can only be between the two center ∆ Y 142,8
of areas of both sets depending on the weighting of each x= = = 28560
∆ t 0,005
set. In the extreme case the weighting of one of the two
fuzzy sets of the variable is zero, which leads to a value
Therefore the definition range of x is:
of the output variable equal to the center of area of the
other fuzzy set. So the output value is:
x ∈ [ −28560, +28560 ]

out ∈ [ coa( set1 ), coa( set2 ) ]


The control signal of the controller is limited to the range
of -10V to +10V. The integrator following the fuzzy
controller kernel cannot operate with greater values. The
ref.2.5 definition range of the output variable directly affects the
loop amplification and therefore determines the dynamic
Sampling period of the digital system: 5ms
of the closed loop to an extent. In case the control signal
Speed range: ±3000 Rpm range of 20V is to be passed in n sampling periods of 5
Digital control range: ±10V ms, the maximum output value of the fuzzy controller
mechanical time constant kernel is determined by:
of the system: TM = 70ms
Plant amplification
without integrator: Krpm = 200 1⁄min V n * 5 *10-3 * zmax = 20V -> zmax = 20V/(5*n*10-3)
(Result of 4.3 ref.
preparation tasks for the with n=20 it follows zmax=200V, the definition range of
PI controller) z is then:

With respect to the speed range of ±3000 rpm a maximum z ∈ [ −200, +200 ]
control error signal of 6000 rpm can be reached. The
definition range of y is therfore: Remark:
In the normal case the complete definition range of an
y ∈ [ −6000, +6000 ] output variable is never reached, since the center of areas
of the fuzzy sets of this variable determine the value of
If however the desired performance of the speed control the output variable (see task 2.4). The position of the
is considered it is recommended to significantly restrict center of area depends on the form of the fuzzy set but can
the above mentioned intervall. The value of a fuzzy set at never reach the limit of the definition range.
the limits of the definition range of a fuzzy variable is
continued to the infinity. That means if for instance the The following names are chosen for the fuzzy variables:

above mentioned intervall is restricted to the range ±1000


y: SpeedError
and the input value is +6000, the input variable behaves
x: Acceleration
just as if the input value would be +1000.
z: ControlSignal

4-2 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Solutions

ref.2.6 ref.2.7

Since the behaviour of the fuzzy controller is unknown at In case of 2 input variables with 3 fuzzy sets each and only
this time, the definition range of each variable is divided one operator 3*3=9 input combinations are possible.
into three segments, "positive", "null" and "negative". Therefore 9 suitable rules are required to cover all cases.
The set with the name "null" will be defined above the
zero point and extends over 1/3 of the entire definition If in some cases the "and"-operator is replaced by the
range. This segmentation will be optimized during "or"-operator, the number of rules is reduced (1 rule per
experiments wit the plant. "or"-combination can be saved). It is even more
significant in case the premise of a rule considers only one
"SpeedError" of the two variables (2 of 9 rules can be saved).
Combinations of inputs, which can not occur due to the
1 negative positive physics of the plant, need not be considered in the rule
Membership

base.
null

ref.2.8
0
-6000 -2000 0 2000 6000 The result are the following 9 rules:
if SpeedError is null and Acceleration is null then ControlSignal
Figure 4.3: Variable y, SpeedError is null
if SpeedError is null and Acceleration is positive then
ControlSignal is positive
"Acceleration" if SpeedError is null and Acceleration is negative then
ControlSignal is negative
1 negative positive if SpeedError is positive and Acceleration is null then
Membership

ControlSignal is positive
if SpeedError is positive and Acceleration is positive then
null ControlSignal is positive
if SpeedError is positive and Acceleration is negative then
ControlSignal is null

0 if SpeedError is negative and Acceleration is null then


-28400 -10000 0 10000 28400 ControlSignal is negative
if SpeedError is negative and Acceleration is positive then
ControlSignal is null
Figure 4.5: Variable x, Acceleration if SpeedError is negative and Acceleration is negative then
ControlSignal is negative

"ControlSignal"
ref.2.9
1 negative positive
Membership

/* a simple description file for a fuzzy controller */

null var input SpeedError

set negative -6000 1 00 endset


0 set null -6000 0 01 6000 0endset
-200 -70 0 70 200
set positive 0 0 6000 1 endset

Figure 4.4: Variable z, ControlSignal endvar

Fuzzy Practical Course 4-3


Solutions Laboratory Setup Speed Control DR300

var input Acceleration ref.3.2

set negative -28560 1 00 endset The reason for the very small control amplification
set null -28560 0 01 28560 0endset determined with 3.1 is to be found in the definition range
set positive 0 0 28560 1 endset of the input/output variables and its fuzzy sets. The output
values of the fuzzy controller lay between the center of
endvar areas of the sets belonging to its output variable. The
center of areas are shifted further to the limit of the
var output ControlSignal definition range of the output variables by reducing the
sets of this variable to a smaller region. There is no need
set negative -200 1 -67 0 endset for an output variable to cover the complete definition
set null -67 0 01 67 0 endset range.
set positive 67 0 200 1 endset
The definition range of both input variables is
endvar significantly to wide. In case only the proportional part of
if SpeedError is null and Acceleration is null then ControlSignal a suitable PI controller is considered (its amplification is
is null end KR * TI = 0.0336, see practical course PI controller), one
if SpeedError is null and Acceleration is positive then realizes that the maximum control signal at the output of
ControlSignal is positive end
the proportional part is already reached below a control
if SpeedError is null and Acceleration is negative then
ControlSignal is negative end error signal of 300 rpm.
if SpeedError is positive and Acceleration is null then
ControlSignal is positive end To improve the control behaviour the definition range of
if SpeedError is positive and Acceleration is positive then the input variables is reduced and the center of areas of
ControlSignal is positive end the fuzzy sets belonging to the output variables are shifted
if SpeedError is positive and Acceleration is negative then
ControlSignal is null end
further to the limit of the definition range. One possible
solution looks like the following:
if SpeedError is negative and Acceleration is null then
ControlSignal is negative end
if SpeedError is negative and Acceleration is positive then /* The definition range of SpeedError is reduced to 10%
ControlSignal is null end of its original size. The definition of ’null’ is reduced
if SpeedError is negative and Acceleration is negative then
much more. */
ControlSignal is negative end

var input SpeedError


4.2 Solutions to Carrying-Out set negative -600 1 00 endset
the Experiment from set null -500 0 01 500 0 endset
Chapter 3 set positive 0 0 600 1 endset
endvar

ref.3.1 /* The definition range of Acceleration is reduced to 50%


of its original size. The definition of ’null’ is even reduced
As an arbitrary solution to the preparation task 2.9 the to only 10%. */
fuzzy controller described above is not satisfactory. The
controlled system operates very slow with an steady state var input Acceleration
error. The reason for this effect among other things is set negative -14300 1 00 endset
control amplification, which is too small. set null -2860 0 01 2860 0endset
set positive 0 0 14300 1 endset
endvar

4-4 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Solutions

/* The definition range of ControlSignal is left var input Acceleration


unchanged. The center of areas of the outer sets are shifted set negative -14300 1 00 endset
to the limit of the definition range.*/ set null -2860 0 01 2860 0endset
set positive 0 0 14300 1 endset
var output ControlSignal endvar
set negative -200 1 -190 0 endset
set null -20 0 01 20 0 endset /* Enlarged to 5 sets, experiment with the definition
set positive 190 0 200 1 endset range. */
endvar
var output ControlSignal
The control behaviour is significantly improved with this set bignegative -200 1 -190 0 endset
definition of the fuzzy variables but with unchanged rules. set negative -200 0 -190 1 -20 0 endset
Further improvements are reachable by changing the set null -20 0 01 20 0 endset
definition ranges, adding further fuzzy sets to the set positive 20 0 190 1 200 0 endset
variables and changing the form of the fuzzy sets. The set bigpositive 190 0 200 1 endset
experiments are only limited by the run time of your endvar
computer. In case the run time needed for a fuzzy /*
controller is not sufficient, the program will inform you The rules are adapted to the changed output variable.
and the controller will NOT be started. */
if SpeedError is null and Acceleration is null then ControlSignal
is null end
if SpeedError is null and Acceleration is positive then
ref.3.3 ControlSignal is positive end
if SpeedError is null and Acceleration is negative then
The fuzzy rules from solutions to the preparation task 2.9 ControlSignal is negative end
consider every combination of the input variables with if SpeedError is positive and Acceleration is null then
their sets. Therefore additional rules are not required. The ControlSignal is positive end
if SpeedError is positive and Acceleration is positive then
values of the output variables with respect to the different
ControlSignal is bigpositive end
input values may however be changed. It is remarkable if SpeedError is positive and Acceleration is negative then
for the given rule base that the reaction of the controller ControlSignal is null end
to a difference of only one input signal is identical to the if SpeedError is negative and Acceleration is null then
reaction to the difference of both input signal with the ControlSignal is negative end
same direction. The reason for that is the small number of if SpeedError is negative and Acceleration is positive then
ControlSignal is null end
fuzzy sets belonging to the output variable. In example
if SpeedError is negative and Acceleration is negative then
the following controller description uses 5 fuzzy sets to ControlSignal is bignegative end
define the output variable:
ref.3.4
/* left unchanged, see above */
The reasons for changing the fuzzy description file are
var input SpeedError mentioned where the changes are carried out.
set negative -600 1 00 endset
set null -500 0 01 500 0 endset
set positive 0 0 600 1 endset ref. 3.5
endvar
In comparison with a PI controller the fuzzy controller is
/* left unchanged, see above */ able to reach better results, since its control behaviour is
adpted to changes of the input signals. The parameters of

Fuzzy Practical Course 4-5


Solutions Laboratory Setup Speed Control DR300

a PI controller are constant independant of its input


signals. But for a PI controller methods are known for
optimum adjustment of the control parameters. Whereas
such methods are unknown for a fuzzy controller up to
now. In this case the steps have to be carried out, which
were shown in this practical course. With respect to the
great number of possible solutions for a fuzzy controller
it is not always guaranteed that a suitable solution is found
in a short time. The exact mathematical model of the plant
is not required in case a fuzzy controller is used, but one
should know how the plant behaves in principle. If
experiences with the plant are already available and one
is clear in one’s mind about the desired controller
bahaviour the fuzzy controller is certainly the better
choice. In case the modelling of the plant is impossible or
too complex, the fuzzy controller often may be the only
possible choice. But it should be clear that the fuzzy
controller is no ’miracle cure’ and that its optimization
may take a lot of time.

The fuzzy controller shown with this solution has a better


control behaviour than the PI controller (see solutions to
practical course PI controller). Depending on the steps of
the controller development the result could even be quite
different.

4-6 Fuzzy Practical Course


Laboratory Setup Speed Control DR300 Program Operation

Program Operation

Speed Control

(Windows Version)

Date: 02-November-2000

Program Operation Speed Control


Laboratory Setup Speed Control DR300 Table of Contents

1 Program Operation 1-1

1.1 Program Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2 Main Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.3 Menu File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.4 Menu IO-Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

1.5 Menu Edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.6 Menu Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.7 Menu View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

1.8 Menu Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

1.9 Description of the File Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

1.9.1 The Format of the Fuzzy Description File (*.FUZ) . . . . . . . . . . . . . . . . . . 1-10

1.9.2 Format of the Error Output File ERROR.OUT . . . . . . . . . . . . . . . . . . . 1-12

1.9.3 Format of the Fuzzy Description File for the Laboratory Experiment DR300 (*.FUZ) . . . . 1-12

1.9.4 Format of the PI Controller File for the Laboratory Experiment DR300 (*.PI) . . . . . . . 1-13

1.9.5 The Format of the Documentation File *.PLD . . . . . . . . . . . . . . . . . . . 1-13

1.10 The DEMO Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

Program Operation Speed Control i


Table of Contents Laboratory Setup Speed Control DR300

ii Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

An additional driver DUMMY.DRV is required for the


1 Program Operation DEMO version of the program.

The software package provides two versions to control The help file DR300.HLP allows for operating the
the plant "Speed Control with Variable Load". The first program without having this manual at hand. The function
version is a PI controller as described in the previous key F1 or a specific ’Help’ button presented in a dialog is
sections. Controller parameters are on-line adjustable. to be used to activate the corresponding help section.
The second version to control the DR300 is a fuzzy
controller as described in chapter "Fuzzy Practical The initialization file DR300.INI is completely
Course". Controller adjustments are storable to a hard controlled by the executable program itself and should not
disk and may be read at a later time. The setpoint for the be changed by the user. It serves for handling the
motor speed position is adjustable as a constant value or IO-adapter card driver.
a time function. Measurements of system variables are
recordable with various trigger conditions. Recorded data DR300.FUZ is the fuzzy description file, loaded
are representable in a graphic on the screen. automatically during the program start and used by the
fuzzy controller of the system. The file format is described
1.1 Program Start in 1.9.3.

DR300.PI contains the parameters of the PI controller.


Operating the program is significantly simplified when a This file is loaded automatically during program start. The
mouse is used. So ascertain that a mouse is installed at file format is described in 1.9.4.
your computer and that the mouse driver is running before
you start the controller program. After starting the program DR300W16.EXE the standard
data files (see above) are loaded and checked. Missing
The correct execution of the program requires that besides files will result in corresponding error messages. The
DR300W16.EXE the following files are available in the check procedure includes trying to open the recently
actual directory: selected driver (DAC98.DRV, DAC6214.DRV or
DIC24.DRV) for the PC adapter card. When this driver
DAC98.DRV or DAC6214.DRV or DIC24.DRV could not be opened the TIMER16.DLL will present the
PLOT16.DLL error message ’StartTimer - InitDriver failed’. After
DR300.HLP prompting this message, the main window of the program
DR300.INI will appear offering the menu item ’IO Interface’ to select
DRSRV16.DLL another driver or to change the address of the adapter card.
TIMER16.DLL

together with the parameter file and fuzzy description file

DR300.PI
DR300.FUZ

The executable program requires at least all of the


mentioned dynamic link libraries (*.DLL) as well as one
of the IO-adapter card drivers (*.DRV), which may be
contained in another directory but with a public path (like
Windows/System).

Program Operation Speed Control 1-1


Program Operation Laboratory Setup Speed Control DR300

1.2 Main Window The ’Measurement’ panel indicates the state of a


measurement acquisition which is either ’Not active’ or
its progress is visualized by a status bar.
Following a successful program start the main window
titled Speed Control DR300 for Windows appears on
the screen as shown in figure 1.2. The first window row
contains the main menu items. Its submenus are described
in the following sections. The lower parts of the window
Speed Control Monitor indicate the ’Active controller’,
the ’System data’ as well as the state of the
’Measurement’.

The ’Active controller’ panel displays one line indicating


the type of the current controller (No controller, PI
controller or Fuzzy controller).

The ’System data’ panel contains the setpoint of the motor


speed as well as its measured value and the control signals
as well as the measured currents of the motor and
generator. In the middle of this panel an animation picture
of the coupled motor/generator system is displayed.

Figure 1.2: The main DR300 window with monitor

1-2 Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

1.3 Menu File detected. Further information about the fuzzy description
file can be found in the chapter 1.9.1 "Format of the Fuzzy
Description File (*.FUZ)".
The pulldown menu File (see figure 1.3) provides
functions for loading or saving of different files, to print Load Recorded Data: Opens a file dialog window for
plot windows as well as to terminate the program. user selection of a data file containing recorded
measurements (documentation file with extension
*.PLD).

Save Recorded Data as ...: is enabled only after the first


measurement acquisition is started. It saves the
measurements previously recorded and the current system
adjustments in a data file. The file name is selected by the
user by means of a file dialog window (extension *.PLD).

Print: Opens the Print Window Dialog to select one or


several plot windows for print output. This dialog
presents a listbox containing the titles of all open plot
windows. One or several windows may be selected for
print output on the currently selected printer device (see
Print Setup ...). A single window is printed on the upper
half of a DIN A4 paper. The second window would be
Figure 1.3: The sub menu ’File’ printed on the lower half of this paper. The following
windows are printed on the next pages accordingly.

Load PI Controller: Loads a parameter file (default


Print Setup ... Opens the Windows dialog to select a
extension *.PI) for the PI controller. The file name is
printer and to adjust its options.
selected by the user from a file dialog window.

Selecting the menu item Exit will terminate the program


Save PI Controller: Saves the adjusted parameters of the
(equivalent to pressing Ctrl+F4).
PI controller in a disk file. Destination file is the parameter
file of the PI controller, which was recently opened.
Please notice that the file "DR300.PI" was opened and
loaded automatically during the program start and may be
overwritten by this command.

Save PI Controller as ...: Operates similar to the item


"Save PI Controller", the name of the destination file is
however selected by the user by means of a file dialog
window.

Load Fuzzy Controller: Loads a fuzzy description file


(extension *.FUZ) for the fuzzy controller. The file is
selected by the user by means of a file dialog window. An
existing fuzzy description file is loaded automatically and
checked. A fuzzy rule base is generated if no errors were

Program Operation Speed Control 1-3


Program Operation Laboratory Setup Speed Control DR300

1.4 Menu IO-Interface The function Setup opens a dialog (see figure 1.4b) to
adjust the drivers hardware address of the installed
IO-adapter card. This address has to match the hardware
The pulldown menu IO-Interface provides functions to settings !
manipulate the driver for the PC plug-in card (see figure
1.4a). The selected address is stored automatically as a decimal
number in a specific entry of the file SYSTEM.INI from
the Windows directory. This entry may look like:

[DAC98]
Adress=768

This menu item is selectable only when no controller is


active.
Figure 1.4a: The sub menu ’IO-Interface’

The first three items


DAC98
DAC6214
DIC24

represent the selectable drivers (DAC98.DRV,


DAC6214.DRV, DIC24.DRV) for the IO-adapter cards
which may be installed in the PC. Each driver is selectable
only when it is contained in the same directory as the
program DR300W16.EXE (or in a directory with a public
path like Windows/System). The recently selected driver
is emphasized with a check mark. On program start the
selected driver is read from the file DR300.INI which is
controlled by the program automatically. When this file
is missing the default driver is always the DAC98.DRV.

Figure 1.4b: The card address setup dialog

1-4 Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

1.5 Menu Edit the button ’Abort’ which leaves the file unchanged.

The pulldown menu Edit contains items to change the


type of the speed sensor and to edit parameters of the PI
controller as well as the file for the fuzzy controller (see
figure 1.5a).

Figure 1.5c: The ’Fuzzy Controller Parameter’ dialog

Any changes of the fuzzy description file will become


Figure 1.5a: The sub menu ’Edit’ active only by pressing the button ’Reload’ of the dialog.
The dialog is terminated by means of the ’Cancel’ button.
The menu item PI Controller Setup opens a dialog to
adjust the proportional and integral coefficient of the PI The following two items
controller with the transfer function as given in the upper Use Encoder
part of this dialog (see figure 1.5b). Use Tacho
allow for selecting the active sensor to measure the speed
in a control loop. As long as the PC adapter card provides
an analog input (DAC98, DAC6214) the measurements
of both sensors are taken but only the measurement of the
active sensor is used by any controller. The active sensor
is indicated by a check mark. On program start this
information is read from DR300.INI.

Figure 1.5b: The ’PI Controller Parameter’ dialog

The menu item Fuzzy Controller Setup displays a dialog


containing buttons labelled ’Select’ and ’Edit’ for the
fuzzy controller file providing methods either to select a
new fuzzy description file or to edit the currently selected
file which opens a new edit field below the dialog
displaying the content of the fuzzy description file.

The following figure 1.5c displays this dialog with an


opened edit field for the fuzzy description file named
DR300.FUZ.

The edit field itself is closed either by the button ’Save’


which stores the content of the edit field to the file or by

Program Operation Speed Control 1-5


Program Operation Laboratory Setup Speed Control DR300

1.6 Menu Run possibly running setpoint generator is reset.

Stop Controller: Switches off any of the selected


The pulldown menu Run in figure 1.6a contains items to controllers.
start and stop a controller, to record measurements and to
adjust the setpoint. Any controller may be started only Start Measuring opens a window to adjust the measuring
when the accompanying parameter file could be loaded time and to assign trigger conditions to start recording the
previously with success. An active controller is indicated measurements. Figure 1.6b shows this window. The
by a check mark left to the menu item. measuring time in seconds is entered to the right to the
title ’Total Time [s]:’. When ’Slope’ is set to ’no trigger’
measurement recording is started directly after closing the
window using the ’Ok’ button.

The trigger signal for conditional measuring (’Slope:’ is


set ’positive’ or ’negative’) is selected below the title
’Trigger Channel:’. The measurement recording starts
after this signal raises above or falls below, depending on
the settings of ’Slope’, the limit value ’Trigger Value:’.
Figure 1.6a: The sub menu ’Run’
In addition ’Prestore:’ allows for adjustment of a time
PI Controller: Starts directly the PI controller. A range for recording measurements before the trigger
possibly running setpoint generator is reset only when no condition is valid. This time has always to be shorter than
controller was active previously. the adjusted measuring time.

Fuzzy Controller: Starts directly the fuzzy controller The adjustment of the setpoint, Setpoint Generator
defined by its fuzzy description file (*.FUZ). A possibly opens a dialog (see figure 1.6c ) for adjusting two
running setpoint generator is reset only when no independent signal generators for the motor as well as for
controller was active previously. the load (generator). The adjustments of the upper
generator are assigned either to the speed setpoint signal
Open Loop Control: Starts directly the open loop control [rpm] (PI, fuzzy controller or no controller is active) or to
of the motor meaning that the servos for the motor as well the control signal [V] (open loop control is active) of the
as for the generator are controlled directly by the control motor. The settings of the lower generator define the
signals from the Setpoint Generator (see below). A

Figure 1.6b: The ’Setup Measuring Function’ dialog

1-6 Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

1.7 Menu View

The pulldown menu View (see figure 1.7a) provides


functions for graphic representations of recorded
measurements, of data from a documentation file (*.PLD)
as well as 3D-characteristics of a selectable fuzzy
controller. Timing data may be displayed in addition.

Figure 1.6c: The ’Speed Setpoint Generator’ dialog


control signal [V] for the load (generator) in any
controller case.

Any signal shape (constant, rectangle, triangle, ramp,


sine) together with an offset, an amplitude and a timing
period is adjustable. The period is meaningless in case of
Figure 1.7a: The sub menu ’View’
a constant signal shape. The real signal is always formed
by the sum of offset and amplitude. The selected signals
become valid after terminating the dialog with ’Ok’.
The menu item Plot Measured Data is enabled only after
the first measurement acquisition is started. It opens a
dialog window (see figure 1.7b) to select the data which
are to be displayed in a graphic representation.
Terminating this dialog with ’Ok’ will display the graphic
window automatically on the screen. An example is
shown in figure 1.7c.

The menu item Plot File Data is enabled only when a


documentation file (*.PLD) was recently loaded by
means of the menu item ’Load Recorded Data’. The data
of the documentation file are selected and displayed in a
graphic representation as with the menu item ’Plot
Measured Data’.

Figure 1.7b: The ’Select Plot Data’ dialog

Program Operation Speed Control 1-7


Program Operation Laboratory Setup Speed Control DR300

Figure 1.7c: Example of a ’Plot Window’


The menu item Parameter From *.PLD File generates The fuzzy controller is referenced by its fuzzy description
an information box displaying the controller type and file. The X-axis and the Y-axis of the graphic represent
parameters read from the currently selected the two inputs of a fuzzy controller while the Z-axis
documentation file (*.PLD). This menu item is enabled represent its output. The dimensions, that means the
only when such a file was loaded successfully. ranges of the input and output signals, of the resulting
cube are displayed in a static field below the selector box
The menu item Fuzzy 3D opens a dialog (see figure 1.7d) for the fuzzy description file. The middle of the cube is
displaying the controller characteristic of a selectable indicated by a blue point while the minimum value for all
fuzzy controller in a three-dimensional graphic. axes is indicated by a red point.

Figure 1.7d: The ’Show Fuzzy 3D’ dialog

1-8 Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

The group of check boxes allows for manipulating the vertical axis 0...100%) displays the frequency occurrence
layout of the graphic: of the sampling period values. The number labelled ’N’
is the number of sampling periods used for the current
With ’Grid’ marked a grid with either a higher or lower calculations.
resolution depending on the setting of ’Low resolution’ is
displayed along the surface of the characteristic. The measurements are taken by means of the timer
components of the PC adapter card.
The surface itself is displayed in a grey scale (darker areas
indicate higher values along the Z-axis) when ’Surface’
is marked. The surface will be coloured if ’Colour’ is
marked in addition (increasing values along the Z-axis are
indicated by colour changes from red to blue).

The margins of the cube are displayed only when


’Coordinate box’ is marked. The same is valid for the
three axes depending on the setting of ’Coordinate
system’. Figure 1.7e: The ’DR300 Timing’ dialog

The check box ’Mark’ is selectable only when a fuzzy Warning:


controller is active. If ’Mark’ is set the current operating Starting another Windows task with too much file
point of the active fuzzy controller is indicated by a small accesses while the controller program is running may
green area. Its dimension correspond to the currently cause a reset of the output stage release for the servo
selected grid width. amplifier !!!

The scroll bars labelled ’Rotate a:’ and ’Rotate b:’ allow The calculation of the minimum and maximum values of
for rotating the graphic with respect to the X-axis and the the sampling period may be restarted by resetting the
Y-axis respectively. The crossing point of these axes is values by means of the button ’Reset’
the middle of the cube. Alternatively the rotation is
achieved by moving the mouse in the cube area The dialog will be terminated by pressing the button
accordingly. ’Hide’.

The button ’Print’ starts a hardcopy output to the currently Remark: Due to the obvious variation of the sampling
selected printer device. period values, the calculation of speed variables has to be
done with respect to real time intervals obtainable from
The dialog is terminated by pressing the button ’Close’. the timer components of the PC adapter card.

Activating the menu item Timing will present a window


(see figure 1.7e) displaying a statistic graphic as well as
the minimum and maximum values of the sampling
period in milli seconds measured (with a resolution of
500ns) since the last start of a controller. While its mean
value is normally close to the nominal value of 5 ms, the
maximum value may differ significantly from the
nominal value especially in the case another Windows
task with time consuming file accesses was started in the
mean time. The statistic graphic (horizontal axis 0..20 ms,

Program Operation Speed Control 1-9


Program Operation Laboratory Setup Speed Control DR300

1.8 Menu Help 1.9 Description of the File


Formats
The pulldown menu Help as shown in figure 1.8a
provides functions to control the Windows help function 1.9.1 The Format of the Fuzzy
and to obtain general information about the program. Description File (*.FUZ)

The menu item Contents displays the contents of the help The fuzzy description file with the extension FUZ is a file
file DR300.HLP, while Search for Help On ... searches to configure a fuzzy controller. The file format is
developed by the amira GmbH and is used by several
products of the amira.

The fuzzy description file is used to configure a fuzzy


object, which i.e. may operate as a fuzzy controller.

The fuzzy description file is a simple ASCII file, which


can be edited by a text editor. The length of a line is limited
to 255 characters. Single assignments are separated by
Figure 1.8a: The sub menu ’Help’
spaces or tabulators.
for keywords contained in this help file. The item How to
Use Help opens the Use Help Dialog of Windows. It contains four types of elements, which are described in
the following sections:
Activating the menu item About opens an information
box displaying the program version, the copyright and the
IO-adapter card requirements (see figure 1.8b). Comments [optional]

The file can include a comment in classical C-style (’/*’


at the beginning and ’*/’ at the end) at every position
except for the definition part of label. At least one space
has to separate the comment string from the ’keywords’
’/*’ and ’*/’.

The Definition of a Label [optional]

The definition of a label is limited to one line. It starts with


the statement ’#define’. The next statement contains the
label name and the last statement contains the label
definition. Thus a label can be defined as follows:

Figure 1.8b: The ’About’ dialog


#define name
This_is_the_definition_of_the_label_name

1-10 Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

The Definition of Fuzzy Sets and Variables the premise and the conclusion. Both parts are separated
by the statement ’then’. The premise and the conclusion
The definition of fuzzy sets is only allowed within the are built by a series of expressions which are combined
definition of variables. It is ignored in the other case. The by operators (further details are shown in the chapter of
definition of a variable starts with the statement ’var’. The the theoretical backgrounds of a fuzzy controller).
next statement can hold two different names, either Permitted operators of the premise are ’and’
’input’ in case an input variable is to be defined or ’output’ (Min-Operator) and ’or’ (Max-Operator) whereas the
in case an output variable is to be defined. The third conclusion requires no operator to separate the
statement of a variable definition is its name. Now the expressions. An expression is the linkage of a fuzzy
definition of the fuzzy set follows. It begins with the variable with one of its sets using the statement ’is’.
statement ’set’ followed by the name of the fuzzy set. The
name is followed by the x/y values as base points for a The formulation of a fuzzy rule requires that all the
polygonal line. Similar to the statements the numbers are variables in use are defined previously since the fuzzy
separated by spaces or tabulators. The definition of the description file is interpreted only once from top to
fuzzy set ends with the statement ’endset’. The definition bottom. The syntax check of a fuzzy object tests whether
of a variable ends with the statement ’endvar’ after all the the variables are defined, whether the used sets really
fuzzy sets of the fuzzy variable are defined. Such a belong to the variable and if the expressions are used
definition may look like the following: correctly (input variables with the premise and output
variables with the conclusion). A simple definition of a
var input temperature fuzzy rule may look like the following:
set cold 10 1 20 0 endset
set medium 10 0 20 1 30 0 endset if temperature is cold then heating is high end
set warm 20 0 30 1 endset
endvar

Fuzzy-Var: "temperature" Table of the valid commands (keywords) and their


explanation:
medium
1
cold warm
Membership

Command Explanation

#define NAME TEXT Defines a NAME, which is usable in the


following statements and will be
replaced by the definition TEXT
automatically by the preprocessor.
/* Begin of comment, ignored by the fuzzy
controller kernel.
0 */ End of comment.
10 20 30 in degree Celsius
var Begin of linguistic variable definition.
The statements "input" or "output" and
the name of the variable must follow this
Figure 1.9: The fuzzy variable ’temperature’ keyword. Fuzzy sets are definable only
in the following. The definition of the
variable is terminated with the statement
"endvar".
input Defines the direction input for a variable.
output Defines the direction output for a
variable.
The Definition of Fuzzy Rules endvar End of definition of a variable.
set Begin of fuzzy set definition. A set
name and a series of pairs of values must
The definition of a fuzzy rule is recognized from its first follow this keyword. The pairs of values
statement ’if’. The last statement of a fuzzy rule is named are the base points of the set.
’end’. The definition of a fuzzy rule contains two parts, endset End of set definition.

Program Operation Speed Control 1-11


Program Operation Laboratory Setup Speed Control DR300

Command Explanation 1.9.3 Format of the Fuzzy Description


if Begin of fuzzy rule definition. One or
File for the Laboratory
multiple premises separated by Experiment DR300 (*.FUZ)
operators, the statement "then" and one
or multiple conclusions must follow this
keyword. The rule definition is The fuzzy description file DR300.FUZ looks like the
terminated by the statement "end". A following:
premise consists of a name of an input
variable, the statement "is" and the name
of the set belonging to this input
variable. The conclusion is built in a
/* Standard Fuzzy Controller for DR300,
similar way but the input variable is 19-October-2000*/
replaced by the output variable.
/* SpeedError is the control error signal of the control loop
is Separates variable and set in a premise
or conclusion. */
then Separates the condition and the
assignment part of a fuzzy rule.
and Is the Minimum-Operator. var input SpeedError
or Is the Maximum-Operator. set negativ -600 1 0 0 endset
end End of rule definition. set null -500 0 0 1 500 0 endset
set positiv 00 600 1 endset
Remark endvar

The status and error messages which occur during the /* Acceleration is the differentiated SpeedError */
interpretation of the fuzzy description file are written to
the file ERROR.OUT or appear on the screen. var input Acceleration
set negativ -14300 1 00 endset
1.9.2 Format of the Error Output File set null -2860 0 01 2860 0endset
ERROR.OUT set positiv 00 14300 1 endset
endvar
During loading and interpreting of a fuzzy description file
status and possible error messages are written to the file var output ControlSignal
ERROR.OUT. This file has the following format: set negativ -200 1 -190 0 endset
set null -20 0 0 1 20 0 endset
Fuzzy Parser Version 1.04 (07-DEC-94) set positiv 190 0 200 1 endset
endvar
Fuzzy-Set <set_name> is already defined.
Fuzzy-Set <set_name> expects numerical value. if SpeedError is null and Acceleration is null then
Unknown variable specification <string>. ControlSignal is null end
Variable <var_name> is already defined. if SpeedError is null and Acceleration is positiv then
Rule error, fuzzy variable <var_name> not found. ControlSignal is positiv end
Rule error, fuzzy variable <var_name> is an if SpeedError is null and Acceleration is negativ then
output variable. ControlSignal is negativ end
Rule error, fuzzy variable <var_name> is an input
variable. if SpeedError is positiv and Acceleration is null then
Rule syntax error, missing is. ControlSignal is positiv end
Rule error, fuzzy set <set_name> is not member if SpeedError is positiv and Acceleration is positiv then
of <var_name>. ControlSignal is positiv end
Rule syntax error, unknown Operator <string>. if SpeedError is positiv and Acceleration is negativ then
<label_name>isalreadydefined. ControlSignal is null end
<n>Errorsdetected.

1-12 Program Operation Speed Control


Laboratory Setup Speed Control DR300 Program Operation

if SpeedError is negativ and Acceleration is null then 1.9.5 The Format of the
ControlSignal is negativ end Documentation File *.PLD
if SpeedError is negativ and Acceleration is positiv then
ControlSignal is null end Measured data stored in a data file are reloadable and may
if SpeedError is negativ and Acceleration is negativ then be output in a graphic representation. In addition the
ControlSignal is negativ end system settings (CTRLSTATUS) which were active
during the start of the data acquisition are stored in this
file. They are displayable in a separate window.
1.9.4 Format of the PI Controller File
for the Laboratory Experiment The data file contains data in binary format stored in the
DR300 (*.PI) following order:

This file contains all parameters of the PI controller for The structure PROJEKT PRJ. (60 bytes)
the laboratory experiment DR300. Each entry consists of The structure CTRLSTATUS. (96 bytes)
two lines, an information block in square brackets in the The structure DATASTRUCT. (8 bytes)
first line and a data block in the second line. Further The data array with float values (4 bytes per value).
comments or empty lines are not allowed. The
information block describes sufficiently the function and The size of the data array is defined in the structure
number of data inside the data block. Please change this DATASTRUCT. With the DR300 speed control system
file only using corresponding functions of the DR300 the number of the stored channels is always 8 (the length
controller software. of the measurement vector is 8, i.e. equal to 32 bytes).

The PI controller file DR300.PI looks like the following: the speed setpoint of the motor in [rpm],
the control signal for the generator in [V],
[Sampling Period] the motor speed measured by tacho in [rpm],
0.005 the motor speed measured by encoder in [rpm],
[KR] the measured motor current in [A],
0.1 the measured generator current in [A],
[TR] the output signal for the motor in [V],
0.06 the output signal for the generator in [V],

The number of the stored measurement acquisitions


(vectors) depends on the adjusted values for the sampling
period and the measuring time. The maximum number of
measurings is 1024. The time distance between two
successive acquisitions is an integral multiple of the
sampling period used by the controller.

The structures mentioned above are defined as follows:

struct PROJECT{
char number[10]; // P340 for speed control
char name[10]; // DR300
char Titel[10]; // SPD CTRL
char Version[10]; // last version

Program Operation Speed Control 1-13


Program Operation Laboratory Setup Speed Control DR300

char Date[10]; // last modification 1.10 The DEMO Version


char Dummy[10]; // reserved
};
The demo version of the program DR300W16.EXE is
struct CTRLSTATUS { indicated by the title "Speed Control Monitor
short controller; // type of controller (fuzzy or PI ..) (Demo-Version)" in the monitor window. It operates with
double ta_ms; // sampling period of controller a nonlinear mathematical model of the plant instead of
char fuznam[80]; // name of ’fuzzy-controller’ file reading sensor signals from the IO-adapter card or writing
short dummy; control signals to this card. Besides the functions to select
long timeofmeasure; // date and time of the the IO-interface and to view timing values the
measurement
}; IO-interface all of the menu items are available.

struct DATASTRUCT { Remark:


short nchannel; // number of components of the Because the program names of the demo version and the
measurement-vector standard version are the same the programs must reside
short nvalues; // number of measurement-vectors in different subdirectories including the accompanying
(samples) drivers and dynamic link libraries. Furthermore the
float deltatime; // time period between samples dummy driver DUMMY.DRV must reside in the same
}; directory as the demo version of the program.

1-14 Program Operation Speed Control


Laboratory Setup Speed Control DR300 The PC Plug-in Card DAC98

The PC Plug-in Card DAC98

Date: 31. October 2000

The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Table of Contents

1 The PC Plug-in Card DAC98 (PCA902) 1-1

1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.3 Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.4 Installation of the DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.4.1 Adjustment of the Base Address . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.4.2 Adjustment of the Interrupt Channel . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.4.3 The Operation Modes of the 16 Bit Timer/Counter . . . . . . . . . . . . . . . . . 1-3

1.4.4 Adjustment of the Analog Output Signal Range . . . . . . . . . . . . . . . . . . . 1-3

1.4.5 Pin-Reservations of the DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

1.4.6 Installation of the Card in the PC . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.5 Programming of the DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.5.1 The Registers of the DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

1.5.2 Configuration of the DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.5.3 Reading the Identification String . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.5.4 A/D Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.5.5 D/A Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

1.5.6 Programming the Timer Chip 8253 . . . . . . . . . . . . . . . . . . . . . . . . 1-7

1.5.7 Reading the Digital Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

1.5.8 Setting the Digital Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

1.5.9 Internal Digital Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

1.5.10 Reading an Incremental Encoder Input Channel . . . . . . . . . . . . . . . . . . 1-8

1.5.11 Interrupt / Clock Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

2 DAC98 Adapter Card 2-1

2.1 Adapter Card EXPO-DAC98 (Opt. 902-01) . . . . . . . . . . . . . . . . . . . . . . 2-1

3 Operating Instructions for the Test Program 3-1

The PC Plug-in Card DAC98 i


Table of Contents Laboratory Setup Speed Control DR300

3.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1

3.2 Program Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1

3.3 Menu ’File’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1

3.4 Menu ’IO-Interface’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2

3.5 Menu ’Test’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3

3.6 Menu ’Measure’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

3.7 Menu ’Help’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

4 Source Files of the DAC98 Driver 4-1

4.1 The Class DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1

DAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

GetAdress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

GetInterrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3

GetClock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7

WriteAllDigital . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8

ReadDigital . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8

ReadAllDigital . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9

SetCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9

GetCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10

WaitCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10

TestCounterJMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11

GateCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11

SetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12

SetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12

GetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13

GateTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13

SetINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14

GetINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14

ResetDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15

ii The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Table of Contents

ResetAllDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15

ReadDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16

ReadAllDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16

ReadAnalogVolt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17

WriteAnalogInt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18

ReadDigitalInputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19

4.2 The Class DIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19

DIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20

~DIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20

GetDigitalOut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21

GetAnalogOut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21

GetDDMCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22

GetDDMTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22

GetDDMStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23

FilterINC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23

TimerDirINC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24

SetINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24

SetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25

GetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25

GateTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26

4.3 The Class PCIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26

PCIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27

~PCIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27

DigitalOutStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28

ReadAnalogVoltMean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29

ResetHCTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29

ReadHCTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30

SetINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30

The PC Plug-in Card DAC98 iii


Table of Contents Laboratory Setup Speed Control DR300

5 Windows Drivers for DAC98, DAC6214 and DIC24 5-1

OpenDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1

SendDriverMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

CloseDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4

iv The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 The PC Plug-in Card DAC98 (PCA902)

Resolution: 12 bit
1 The PC Plug-in Card Programmable input
DAC98 (PCA902) signal range : 5V
10V
+/- 5V
1.1 Introduction +/- 10 V

Analog resolution: max. 1.22mV


The DAC98 is a card for general purpose on an IBM-AT
Low-pass filter: 10nF
compatible PC. The different analog and digital inputs
Input resistance: 10k
and outputs allow for a variance of applications in
automatic measurement and control.
Analog Outputs:
Number of outputs: 2
1.2 Features Converter: 2 AD 7545
Resolution: 12 bit
Output signal range: 10V
• 8 analog inputs with a programmable input signal
+/- 10 V
range for each channel
Analog resolution: max. 2.44mV

• 1 12 bit A/D converter: MAX197


Encoder inputs:
Number of inputs: 3 (quadrature signals)
• 2 bipolar/unipolar analog outputs
Decoder: CPLD (DDM) developed
by amira
• 2 12 Bit D/A converter: AD 7542
Input signal level: RS422
Counter width: 16 bit
• 3 quadrature incremental encoder inputs

Digital Inputs:
• 16 bit counter for incremental encoder signals:
Number of inputs: 8
DDM
Level: TTL compatible

• 8 TTL compatible inputs


Digital Outputs:
Number of outputs: 8
• 8 TTL compatible outputs
Level: TTL compatible

• 32 bit timer/counter for interrupt control or time 1.4 Installation of the DAC98
measurement

• 16 bit timer/counter for interrupt control or time 1.4.1 Adjustment of the Base Address
measurement
One of 8 possible base addresses (0x300..0x370) is
adjustable by means of a DIP switch providing a 3 bit
1.3 Specifications coding. The meaning of the switch positions is as follows

1 = Switch position on
Analog Inputs:
0 = Switch position off
Number of inputs: 8
(*) = Default configuration
Converter: 1 MAX197

The PC Plug-in Card DAC98 1-1


The PC Plug-in Card DAC98 (PCA902) Laboratory Setup Speed Control DR300

Note: The base address is the start address of the I/O 1.4.2 Adjustment of the Interrupt
address range which must not be used by any other PC Channel
plug-in card.
In case the interrupt feature of the DAC98 is to be used,
The enclosed driver software requires the card with the a free interrupt channel of the PC hardware has to be
base address 300 ( hex ). If you want to use this software identified. This channel number is then adjusted by means
without any changes please assure that none of the other of the jumpers JP4 to JP12 (see table). The default
PC plug-in cards in your PC uses the same base address. interrupt channel setting is IRQ7. As for the base address
Otherwise you may change the base address in the it is to be assured that none of the other PC plug-in cards
software as well as for the PC plug-in card accordingly. uses the same interrupt channel.

I/O Address 3 2 1 JP 4 5 6 7 8 9 10 11 12
(Hex) IRQ 3 4 5 7 9 10 11 12 15
300(*) 1 1 1
310 0 1 1 The PC hardware may be damaged when more than one
320 1 0 1 jumper is installed or in case the selected interrupt channel
330 0 0 1 is in use by another card.
340 1 1 0
350 0 1 0
360 1 0 0
370 0 0 0

Jumpers of the DAC98

1-2 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 The PC Plug-in Card DAC98 (PCA902)

1.4.3 The Operation Modes of the 16 1.4.5 Pin-Reservations of the DAC98


Bit Timer/Counter
The DAC98 is plugged in the PC with its slot connector
The 16 bit counter either counts external events or it and fixed with a screw at the rear of the PC casing. All of
counts the timer clock. The jumper JP3 adjusts the the input and output channels are accessible at the rear by
corresponding operation mode. a 50-polar D-Sub female connector.

ST1: 50-polar D-SUB connector

The default setting is timer clock counting mode.

1.4.4 Adjustment of the Analog


Output Signal Range

Two different output voltage ranges (-10 V to +10 V or 0


V to +10 V) are selectable for each D/A converter. The
jumpers JP1 (analog out 0) and JP2 (analog out 1) provide
this selection for each channel.

The PC Plug-in Card DAC98 1-3


The PC Plug-in Card DAC98 (PCA902) Laboratory Setup Speed Control DR300

PC-Connector (DAC98) PC-Connector (DAC98)


Pin- Pin- Reservation Pin- Pin- Reservation
No. Descr. No. Descr.
1 CHA0 incremental encoder signal A 0 30 n.c. n.c.
2 CHB0 incremental encoder signal B 0 31 AGND AGND
3 CHA1 incremental encoder signal A 1 32 AIN2 analog input 2
4 CHB1 incremental encoder signal B 1 33 AIN3 analog input 3
5 CHA2 incremental encoder signal A 2 34 Dout0 digital output 0
6 CHB2 incremental encoder signal B 2 35 Dout1 digital output 1
7 CHA3 incremental encoder signal A 3 36 Dout2 digital output 2
8 CHB3 incremental encoder signal B 3 37 Dout3 digital output 3
9 DIN0 digital input 0 38 Dout4 digital output 4

10 DIN1 digital input 1 39 Dout5 digital output 5


40 Dout6 digital output 6
11 DIN2 digital input 2
41 Dout7 digital output 7
12 DIN3 digital input 3 42 DGND digital ground
13 n.c. n.c. 43 DGND digital ground
14 n.c. n.c. 44 AIN6 analog input 6
15 AGND analog ground 45 AIN7 analog input 7
16 AIN0 analog input 0 46 Timer input for external events
/Clk
17 AIN1 analog input 1
47 Aout0 analog output 0
18 /CHA0 inverted incremental encoder signal A0
48 Aout1 analog output 1
19 /CHB0 inverted incremental encoder signal B0
49 AIN4 analog input 4
20 /CHA1 inverted incremental encoder signal A1
50 AIN5 analog input 5
21 /CHB1 inverted incremental encoder signal B1
22 /CHA2 inverted incremental encoder signal A2
23 /CHB2 inverted incremental encoder signal B2 Note:
24 /CHA3 inverted incremental encoder signal A3
All the analog inputs which are not in use have to be
25 /CHB3 inverted incremental encoder signal B3 connected to the analog ground.
26 DIN4 digital input 4

27 DIN5 digital input 5

28 DIN6 digital input 6

29 DIN7 digital input 7

1-4 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 The PC Plug-in Card DAC98 (PCA902)

1.4.6 Installation of the Card in the PC (r) = read the DATR, (w) = write to the DATR

a) Switch off the power to the PC and all other connected HWADR
peripheral devices, e.g. monitor, printer. (r/w)

b) Disconnect all cables of your PC. 0x00(r) read the identification string
0x08(r/w) initialize A/D converter
c) Remove the top cover of your PC. (For details please A/D converter low-byte
refer to the manual of your PC). 0x09(r) A/D converter high-byte
0x10(w) D/A converter channel 0
d) Choose a free add-on slot (16 bit ISA) and remove the 0x18(w) D/A converter channel 1
corresponding slot cover at the rear. 0x20 Counter No. 0 of the 8254 timer
0x21 Counter No. 1 of the 8254 timer
e) Plug in the DAC98 in the chosen slot and tighten the 0x22 Counter No. 2 of the 8254 timer
screw to hold the card’s retaining bracket. 0x23 Mode of the 8254 timer
0x28 PortA of the 8255 IO-interface
f) Replace the PC’s top cover and fasten the screws. digital outputs
Connect all cables. 0x29 PortB of the 8255 IO-interface
digital inputs
The card is now ready for operation. To test the function 0x2A PortC of the 8255 IO-interface
please install the software (ref. chapter 3.1). digital outputs/inputs used internally
0x2B Mode of the 8255
0x30 DDM No. 0 high-byte during read operation
1.5 Programming of the DAC98 of the 16 bit increment counter,
chip reset during write operation
0x31 DDM No. 0 low-byte of the
Initialization and programming of the PC plug-in card 16 bit increment counter
DAC98 is described in the following to give a better 0x38 DDM No. 1 high-byte during read operation
understanding of its functions. The functions itself are of the 16 bit increment counter,
realized by the drivers (see also chapter 4) included in the chip reset during write operation
shipment. 0x39 DDM No. 1 low-byte of the
16 bit increment counter
1.5.1 The Registers of the DAC98 0x78 DDM No. 2 high-byte during read operation
of the 16 bit increment counter,
Mainly two ports are used to program the DAC98. One chip reset during write operation
hardware address register (HWADR) for addressing the 0x39 DDM No. 2 low-byte of the
individual components of the card, and one data register 16 bit increment counter
(DATR). The access mode of the HWADR at the base 0xBA CSDDMALL
address (BADR) is write only. 0xBB all of the DDM chips are reset 0xF8
interrupt/clock signal
The DATR is addressable by BADR + 4 and can either
be read or written, depending on the chosen HWADR.

The following table contains all hardware addresses of the


card. The first column is the address ( in Hex ), the
following column is the function of the DATR.

The PC Plug-in Card DAC98 1-5


The PC Plug-in Card DAC98 (PCA902) Laboratory Setup Speed Control DR300

1.5.2 Configuration of the DAC98 are to be read until this bit is reset to "0" to detect the end
of the conversion. The read operation for the digital inputs
The PC plug-in card DAC98 contains programmable chip is described in section 1.5.7.
devices which have to be initialized before using the
functions of the card. Now the result of the A/D conversion may be read:

At first the digital inputs and outputs are to be configured At first a value of 0x08 (address of low-byte) is written
by programming the 8255 chip containing 3 digital ports into the HWADR. Reading the DATR in the following
(PortA, PortB, PortC) either operating as inputs or outputs will result with the low-byte. Writing then a value of 0x09
with 8 bits for each port. PortC is used internally and is to (address of high-byte) into the HWADR will result with
be programmed such that its bits 0...3 operate as inputs the high-byte after the next reading of the DATR. The
and its bits 4...7 operate as outputs. PortA has to operate described sequence of operations is to be obeyed
as an output whereas PortB has to operate as an input. absolutely during reading the converter.

The programming of the chip is performed in two steps. Bit Pattern Selected Channel
At first a value of 0x2B (address of the 8255 mode D2 D1 D0
register) is written into the HWADR. Writing then a data 0 0 0 0
value of 0x8A into DATR will program the input/output 0 0 1 1
functions as described above. 0 1 0 2
0 1 1 3
1 0 0 4
At next the frequency to control the timer is to be
1 0 1 5
programmed which will be described in section 1.5.11 .
1 1 0 6
1 1 1 7
1.5.3 Reading the Identification String
Bit Pattern Selected Range
Reading the identification string (a preassigned bit map) D4 D3
is performed in two steps. At first a value of 0x00 (address 0 0 0..5V
of the identification string) is written into the HWADR. 0 1 0..10V
Reading then the DATR should result in a value of 0x55 1 0 -5..+5V
when the card is installed correctly. 1 1 -10..+10V

1.5.4 A/D Conversion


1.5.5 D/A Conversion
This section describes the procedures required for an A/D
This section describes the sequence of operations required
conversion. At first the channel which is to be read as well
for a D/A conversion. After writing the address value of
as its input signal range are to be selected. To do this a
the selected D/A converter (0x10 for No. 0 or 0x18 for
value of 0x08 (address of the A/D converter) is written
No. 1) to the HWADR only one further write operation
into the HWADR. Then a value determining the channel
to the DATR is required to start the conversion
and its signal range is sent to the DATR. As described in
the following table the bits 0...2 define the selected immediately. The lower right 12 bits of the DATR
represent the value which is to be converted.
channel and the bits 3 and 4 define the selected input
signal range. Writing to the DATR in this case will be
followed automatically by starting the conversion. The
end of the conversion is indicated by the digital input No.
8 or by the interrupt channel 2. Since a running conversion
is indicated by a "1" in digital input No. 8 the digital inputs

1-6 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 The PC Plug-in Card DAC98 (PCA902)

1.5.6 Programming the Timer Chip means 0x88 is written in the register DATR at first.
8253 Afterwards the high byte (0x13 in our case) is written in
the register DATR. With this the programming of the 32
Since this chip offers a lot of features it is recommended bit timer is completed.
to use its hardware manuals i.e. "Intel Microprocessor and
Peripheral Handbook, Volume II Peripheral". Only a You will find an application of this programming
simple application example will be described in the instruction in the "C++" respective "C" files in the
following. functions SetTimer, SetCounter. When using the 8253
timer/counter to program interrupts a minimum sampling
The 16 bit timer 0 and 1 of this chip are wired by hardware period should be regarded. This minimum sampling
such that they operate as a cascaded 32 bit timer. This 32 period depends on the available computing power, the
bit timer counts the clock signal provided by a quartz base used operating and bus system etc.. With a standard PC
with a programmable divisor. The remaining timer 3 (80386 DX40, operating system DOS, ISA-Bus) this
operates as a single 16 bit timer/counter either counting minimum sampling period is about 0.5 ms, in case the
the clock signal mentioned above or external events. On interrupt service routine has a very short execution time.
counter overflow an interrupt may be requested in case
this feature is enabled. 1.5.7 Reading the Digital Inputs

The following example describes the programming of the Reading the digital inputs requires two steps. At first a
32 bit timer operating as a square wave generator (suitable value of 0x29 (address of digital inputs) is written into the
for interrupt triggering) with a period of 10 seconds. HWADR. Reading the DATR in the following will result
with the state of the digital inputs. The single bits of the
According to the default clock signal with 2 MHz, the 32 data byte correspond to the input channel numbers as
bit timer has to be initialized with a value of 20.000.000. follows:
Since two 16 bit timer operate in a cascade, this value has
to be separated in the product 4000 * 5000 (hexadecimal Data bit Assignment
format: 0x0FA0 * 0x1388). At first the mode register of D0 digital input 0
the 8253 is addressed by writing the value 0x0B3 in the D1 digital input 1
register HWADR. Writing a value of 0x36 in the register D2 digital input 2
DATR will program the mode register such that counter D3 digital input 3
0 is selected, low-byte-first is adjusted and the mode 3 is D4 digital input 4
D5 digital input 5
selected. Then the counter 0 is addressed by writing 0x08
D6 digital input 6
in the register HWADR. Now the low byte of the desired
D7 digital input 7
divisor (in our case the low byte of 0x0FA0 is 0xA0), that
means 0xA0 is written in the register DATR at first. For the digital inputs a 1 means the input has an high level
Afterwards the high byte (0x0F in our case) is written in signal.
the register DATR. With this the programming of the
counter 0 is completed and the similar programming of
1.5.8 Setting the Digital Outputs
the counter 1 will be as follows. The mode register of the
8253 is addressed again by writing the value 0x0B in the Setting the digital outputs requires two steps. At first a
register HWADR. Writing a value of 0x76 in the register value of 0x28 (address of digital outputs) is written into
DATR will program the mode register so that counter 1 the HWADR. Writing a data byte to the DATR in the
is selected, low-byte-first is adjusted and the mode 3 is following will set the digital outputs accordingly. The
selected. Then the counter 1 is addressed by writing 0x09 single bits of the data byte correspond to the output
in the register HWADR. Now the low byte of the desired channel numbers as follows:
divisor (in our case the low byte of 0x1388 is 0x88), that

The PC Plug-in Card DAC98 1-7


The PC Plug-in Card DAC98 (PCA902) Laboratory Setup Speed Control DR300

Data bit Assignment followed by a write operation to the DATR with an


D0 digital output 0 arbitrary value.
D1 digital output 1 b) Now the content of the increment counter is ready for
D2 digital output 2 reading. At first a value of 0x30 (address of high byte of
D3 digital output 3 DDM No. 0) is written into the HWADR. Reading then
D4 digital output 4 the DATR will result with the high byte of the counter
D5 digital output 5
content. The low byte is accessed accordingly by using
D6 digital output 6
the address 0x31.
D7 digital output 7

1.5.11 Interrupt / Clock Signal


1.5.9 Internal Digital Functions
The interrupt register is enabled and the clock signal is
The internal functions are initialized by a write operation selected by the following operations. At first a value of
followed by a read or write operation. At first a value of 0xFA (address of interrupt / clock signal) is written into
0x2A (address of PortC of the 8255). is written into the the HWADR. Writing a data byte to the DATR in the
HWADR. Reading the DATR in the following will result following will enable specific interrupts and select the
in a specific status information whereas writing to the clock signal according to the following table:
DATR will result in specific settings according to the
following table: Data bit Assignment
D0 interrupt of the 32-bit timer
D1 interrupt of the 16-bit timer
Data bit Assignment
D2 interrupt on end of A/D
D0 set the gate of the 32-bit timer
conversion
(output)
D3 not used
D1 set the gate of the 16-bit timer
D4 selected clock signal
(output)
D5 selected clock signal
D2 not used
D6 selected clock signal
D3 not used
D7 not used
D4 busy signal of the A/D
converter (input)
Bit Pattern Selected Clock
D5 not used
D6 D5 D4
D6 not used
0 0 0 8MHz
D7 not used
0 0 1 4MHz
0 1 0 2MHz
0 1 1 1MHz
1.5.10 Reading an Incremental 1 0 0 500kHz
Encoder Input Channel 1 0 1 250kHz
1 1 0 125kHz
This section describes the read procedure of the 1 1 1 62,5kHz
incremental encoder input channel 0 in example. Using
other channels requires the corresponding chip addresses. Note: To maintain any selected clock the corresponding
bits have to be the same in following write operations to
Two steps are required: the interrupt / clock signal register.
a) Any arbitrary write access two a DDM chip results in
changing its internal register sets such that the current data The interrupt / clock signal register may also be read by
are available for reading. To do this a value of 0x31 writing a value of 0xFA (address of interrupt / clock
(address of DDM No. 0) is written into the HWADR signal) into the HWADR followed be reading the DATR.

1-8 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 DAC98 Adapter Card

2 DAC98 Adapter Card

2.1 Adapter Card EXPO-DAC98


(Opt. 902-01)

The adapter card EXPO-DAC98 contains screw terminals


to provide the user with all the input/output signals of the
DAC98. The adapter card is mounted in a aluminium case.

The PC Plug-in Card DAC98 2-1


DAC98 Adapter Card Laboratory Setup Speed Control DR300

2-2 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Operating Instructions for the Test Program

3 Operating Instructions 3.2 Program Start


for the Test Program
After starting the program DAC98TST.EXE the main
menu will appear on the screen as shown in figure 3.1. An
3.1 Installation error message will be displayed at first when the base
address setting of the PC plug-in card does not match the
corresponding address of the program. This address may
The test program requires an IBM compatible PC with
be changed using the menu "IO-Interface"
Microsoft Windows 3.1 or Windows 95.
"Configuration".

Now switch on your computer and start MS Windows.


The first line of the screen contains the menu bar. Its menu
items are described in the following sections.
Insert the DAC98-disk in the 3.5" disk drive of your
computer. Now select the item "Run" from the menu
"File" of the windows program manager from Windows
3.1 resp. the item "Run" of the start menu from Windows
95. Enter the command line

Figure 3.1: The main window of the DAC98 test software


a:\install resp. b:\install

according to the drive assignment. 3.3 Menu ’File’


Prompt the input with "OK" or "Return". The running
installation program now asks for the desired directory. The pull down menu ’File’ only contains the item ’Exit’
The default setting C:\DAC98 may be changed for the to terminate the test software as shown in figure 3.2.
disk drive but without inserting additional
sub-directories.

Attention !

Do not start DAC98TST.EXE directly from the floppy


disk drive! Figure 3.2: The menu ’File’

The PC Plug-in Card DAC98 3-1


Operating Instructions for the Test Program Laboratory Setup Speed Control DR300

3.4 Menu ’IO-Interface’ The test software tries to access the base address to test
the configuration when any selection is prompted using
the OK button. Caution, any fault address setting may
The pull down menu ’IO-Interface’, see figure 3.3, cause hardware conflicts!
provides two functions to manipulate the driver settings
for the DAC98 PC plug-in card.

Figue 3.3: The menu ’IO-Interface’

The function ’Settings’ displays a window with the


current driver settings as shown in figure 3.4. Any setting
may be changed using one of the following sub-menus.

Figure 3.5: The window ’Configuration’

In case of a successfull test the current settings for the base


address, the interrupt channel and the clock rate are stored
in a file automatically. This file will be used during any
start of the test software.

An error message will be displayed (see figure 3.3) when


the PC plug-in card did not respond with the current base
address settings.

Figure 3.4: The window ’Settings’

The function ’Configuration’ opens a window containing


selectable dialogs as shown in figure 3.5.

The sub-menu ’Address of DAC98’ opens a menu to Figure 3.6: The window ’Error’
select one of the valid base addresses of the PC plug-in
card.

The sub-menu ’Interrupt Channel’ opens a menu to select


one of the useable interrupt channels.

The sub-menu ’Clockmode of Timer’ opens a menu to


select the clock rate for the timer devices on the PC
plug-in card.

3-2 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Operating Instructions for the Test Program

3.5 Menu ’Test’ The DDM devices may be reset using the displayed
control buttons.

The pull down menu ’Test’ provides two functions to test The timer resp. the counter decrement the preset value
the DAC98 PC plug-in card. only when the ’Gate’ control button is active. The preset
values may be changed at any time but they will be taken
The menu ’Show all’ opens a window displaying the as start values only when the corresponding control button
value of all signals of the DAC98 PC plug-in card. The is active.
analog signals are displayed in the left part whereas the
digital signals are displayed in the right part of the
window. The analog inputs will show a value of 0V and
the digital inputs will show low level when the external
connector of the PC plug-in card is open.

The input voltage range is selectable for each analog input


left to the displayed measured value.

The analog outputs may be set after entering a valid


number and prompting with ’Return’.

The digital outputs are manipulated by selecting the


corresponding control fields.

Figure 3.7: The window ’Showall’

The PC Plug-in Card DAC98 3-3


Operating Instructions for the Test Program Laboratory Setup Speed Control DR300

The menu item ’Test’ opens a window as shown in figure 3.6 Menu ’Measure’
3.8.

The field "DAC-Info-Box" displays the current The menu ’Measure’ opens a window displaying
configuration settings as well as a specific jumper setting measured data from the analog inputs in a graphic. One
of the PC plug-in card. For the jumper the message or multiple data channels are selectable by corresponding
"intern" means that the timer counts the internal clock. control buttons. The input signal range is +/- 10V for each
The message "extern/undef" means that the timer either analog input. The width of the graphic corresponds to 380
counts external events or that the jumper is missing. samples taken in between a time which depends on the
computing power of the PC.
The following fields allow for selection of single
component tests and display the corresponding results.
But all of these tests are meaningfull only when a special
test adapter from amira is connected to the PC plug-in
card.

The field "TestShowBox" displays the test results of the


single components of the PC plug-in card.

The field "TestConfiguration" provides the selection of


the components which are to be tested. The push button Figure 3.9: The window ’Measure’
’Test’ starts the test immediately. But all of these tests are
meaningfull only when a special test adapter from
amira is connected to the PC plug-in card. 3.7 Menu ’Help’

The pull down menu ’Help’ only contains the item ’Info’
as shown in figure 3.10. The selection of this item will
display short information about the program version and
the copyright.

Figure 3.8: The window ’Test Components’

Figure 3.10: The window ’Info’

3-4 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

4 Source Files of the int RD_DATA is the offset which is to be added


to the base address to read
DAC98 Driver the data register
int intr is the interrupt channel
double Clock is the timer clock
This chapter describes the contents as well as the
int CounterGate is the state of the counter gate
functions of the driver modules written in C++ (16 bit
version). The driver modules are contained in the file int CounterJMP is the state of the
counter jumper
DAC98.CPP. A short DOS test program using some of
int output_status_DAC98 is the register content
the modules is given by the file TEST.CPP.
of the digital outputs

4.1 The Class DAC98 int input_status_DAC98


is the register content
of the digital inputs
The class DAC98 is used to control the PC plug-in card int intr_status is the content of the interrupt
DAC98 of the company amira in a comfortable way. register

Several cards may be controlled without any problem by


using as many driver objects.

Basic Classes:

none

Public Data:
unsigned int ddm_counterr[3] is an array containing
the increment values
counted by the three DDM
devices.
enum Clkmodes defines the series of
constant values for the
clock rate of the timer device

Private Data:
unsigned char ddm_adr[3] is an array containing
the addresses of the three DDM
devices
unsigned long timer_counter0 is the content of the first timer
unsigned long timer_counter is the content of the second timer
unsigned int timer_counter2 is the content of the third timer
int Base is the base address of the DAC98
int WR_DATA is the offset which is to be added
to the base address to write
to the data register

The PC Plug-in Card DAC98 4-1


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Public Element Functions: Name:


GetAdress
Name:
DAC98
int GetAdress( void );

DAC98( int adress ) Class: DAC98

Class: DAC98
Description:

Description: The function GetAdress returns the variable Base which


is the base address of the PC plug-in card adjusted by the
The constructor requires only the base address of the PC constructor or by the function SetAdress.
plug-in card

Parameters:
Parameter: none
int adress is the base address of the PC plug-in
card in the IO address range of the PC. Return value:
int the adjusted base address of the PC plug-in card.
Return value:
none

4-2 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
SetAdress GetInterrupt

void SetAdress( int adr ); int GetInterrupt( void );

Class: DAC98 Class: DAC98

Description: Description:

The function SetAdress adjusts the current base address The function GetInterrupt returns a flag representing the
to the new value of Base. This value has to match the base number of the interrupt channel which was adjusted by
address which is configured on the hardware of the the function SetInterrupt previously.
DAC98 to guarantee further accesses to the card.
Attention: The jumper configuration on the hardware
Attention: Address conflicts may damage the PC must be same. Interrupt conflicts may damage your
hardware ! hardware.

Parameters: Parameters:
int adr is the new base address of the none
PC plug-in card DAC98.

Return value:
Return value: int number of interrupt channel.
none

The PC Plug-in Card DAC98 4-3


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
SetInterrupt Identifikation

void SetInterrupt( int i ); int Identifikation( void );

Class: DAC98 Class: DAC98

Description: Description:

The function SetInterrupt adjusts the flag representing The function Identifikation checks whether the amira
the number of the interrupt channel which is configured DAC98 responds to the base address of the driver
by a jumper on the hardware. software. Any value unequal to zero is returned when the
PC plug-in card returns a bit string preassigned on its
Attention: The jumper configuration on the hardware hardware.
must be same. Interrupt conflicts may damage your
hardware.
Parameters:
none
Parameters:
int i is the number of the new interrupt Return value:
channel
int Result = 1 indicates that the hardware responded
to the base address, else the result = 0.
Return value:
none

4-4 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
Init Exit

void Init( void ); int Exit( void );

Class: DAC98 Class: DAC98

Description: Description:

The function Init at first calls the function Identifikation. The function Exit adjusts the analog and digital outputs
When this call is successfull the amira DAC98 is to 0, the DDM devices are reset and the counter as well
initialized to the default settings. as the timer are stopped.

Parameters: Parameters:
none none

Return value: Return value:


none int Result is always = 1.

The PC Plug-in Card DAC98 4-5


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
Setup SetClock

int Setup( void ); void SetClock( int mode );

Class: DAC98 Class: DAC98

Description: Description:

The function Setup searches for the amira DAC98 using The function SetClock adjusts the clock rate for the timer
all of the adjustable base addresses. This operation may device to the given value.
cause hardware conflicts when any other card operates in
the same address range, i. e. a network card. So the
function must only be used when this case can be Parameters:
excluded. int mode is the desired clock rate.
See the table for the adjustable values.
Attention: Address conflicts may damage the PC The variable mode may be used or
the string constant from the second
hardware !
column

mode constant clock rate


Parameters: 0 Clk8MHz 8MHz
1 Clk4MHz 4MHz
none
2 Clk2MHz 2MHz
3 Clk1MHz 1MHz
Return value: 4 Clk500kHz 500kHz
int Values unequal to zero indicate a successful 5 Clk250kHz 250kHz
function. 6 Clk125kHz 125kHz
7 Clk62kHz 62,5kHz

Return value:
none

4-6 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
GetClock WriteDigital

double GetClock( void ); void WriteDigital( int channel, int value );

Class: DAC98 Class: DAC98

Description: Description:

The function GetClock returns the adjusted clock rate of The function WriteDigital resets the state of the output
the timer device. channel channel when the parameter value = 0 otherwise
the state is set to 1.

Parameters:
none Parameters:
in channel is the number of the digital output
Return value: channel

double clock rate of the timer device. Channel Assignment


0 digital output 0
1 digital output 1
2 digital output 2
3 digital output 3
4 digital output 4
5 digital output 5
6 digital output 6
7 digital output 7
8 gate of the 32 bit timer
(output 8)
9 gate of the 16 bit timer
(output 9)
10 not used (output 10)
11 not used (output 11)

int value is the new state of the digital output


channel.

Return value:
none

The PC Plug-in Card DAC98 4-7


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
WriteAllDigital ReadDigital

void WriteAllDigital( int value ); int ReadDigital( int channel );

Class: DAC98 Class: DAC98

Description: Description:

The function WriteAllDigital adjusts the state of the 12 The function ReadDigital returns the state (0 or 1) of the
digital output channels according to the lower 12 bits of digital input channel channel.
the parameter value .

Parameters:
Parameters: int channel is the number of the digital input channel.
int value state of the 12 output ports.

Channel Assignment
Data bit Assignment 0 digital input 0
D0 digital output 0 1 digital input 1
D1 digital output 1 2 digital input 2
D2 digital output 2 3 digital input 3
D3 digital output 3 4 digital input 4
D4 digital output 4 5 digital input 5
D5 digital output 5 6 digital input 6
D6 digital output 6 7 digital input 7
D7 digital output 7 8 busy signal of the AD
D8 set the gate of the 32 bit converter
timer (output 8) 9 not used
D9 set the gate of the 16 bit 10 not used
timer (output 9) 11 not used
D10 no function (output 10)
D11 no function (output 11)
Return value:
int state of the digital input channel.
Return value:
none

4-8 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
ReadAllDigital SetCounter

int ReadDigital( void ); void SetCounter( unsigned int count );

Class: DAC98 Class: DAC98

Description: Description:

The function ReadAllDigital returns the state of the 12 The function SetCounter adjusts the initial value of the
digital input channels in the lower 12 bits of the return 16 bit counter to the given parameter count.
value.

Parameters:
Parameters: unsigned int count is the new initial value
none of the counter (will be decremented).

Return value: Return value:


int state of the 12 digital input channels. none

Data bit Assignment


D0 digital input 0
D1 digital input 1
D2 digital input 2
D3 digital input 3
D4 digital input 4
D5 digital input 5
D6 digital input 6
D7 digital input 7
D8 busy signal of the AD
converter
D9 not used
D10 not used
D11 not used

The PC Plug-in Card DAC98 4-9


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
GetCounter WaitCounter

unsigned int GetCounter( void ); int WaitCounter( double time );

Class: DAC98 Class: DAC98

Description: Description:

The function GetCounter returns the current content of The function WaitCounter provides a precise delay time
the 16 bit counter. by counting the internal timer clock. The function returns
1 only when the counter counts the internal timer clock
signal otherwise it returns 0.
Parameters:
none Attention: The delay time is correct only in case the
counter is configured to count the (internal) timer clock.
Return value:
unsigned int is the counter content.
Parameters:
unsigned long time delay time in milli seconds.

Return value:
int Result = 1, when the counter counts the internal
timer clock signal otherwise it returns 0.

4-10 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
TestCounterJMP GateCounter

int TestCounterJMP( void ); void GateCounter( int val );

Class: DAC98 Class: DAC98

Description: Description:

The function TestCounterJMP checks whether the The function GateCounter enables or disables the gate
counter is configured for counting internal or external of the 16 bit counter. The counter is started with val=1.
events.

Parameters:
Parameters: int val is the new value for the counter
none gate.

Return value: Return value:


int Result = 1 indicates that the counter is connected none
to the internal timer clock, result = 0
means that the counter counts external
events or the jumper is missing.

The PC Plug-in Card DAC98 4-11


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
SetTimer SetTimer

void SetTimer( unsigned long time ); void SetTimer( double time );

Class: DAC98 Class: DAC98

Description: Description:

The function SetTimer adjusts the initial value for the 32 The function SetTimer adjusts the initial value for the 32
bit counter ( square wave operating mode). The upper 16 bit counter ( square wave operating mode). The parameter
bit are written into the upper cascade of the timer register time is taken as a period time in milli seconds.
and the lower 16 bit are written into the lower cascade.
The resulting period time is given by the product of the
upper and lower cascade settings multiplied with the Parameters:
period time of the clock signal (default 1/2000000 s). unsigned long time timer value in milli seconds.

Return value:
Parameters: none
unsigned long time is the new time value for the
timer cascade.

Return value:
none

4-12 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
GetTimer GateTimer

unsigned long GetTimer( void ); void GateTimer( int val );

Class: DAC98 Class: DAC98

Description: Description:

The function GetTimer returns the current content of the The function GateTimer enables or disables the gate of
32 bit timer. the 32 bit timer. The timer is started with val=1.

Parameters: Parameters:
none int val is the new value for the timer gate.

Return value: Return value:


unsigned long is the timer content. none

The PC Plug-in Card DAC98 4-13


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
SetINT GetINT

void SetINT( int channel, int val ); int GetINT( void );

Class: DAC98 Class: DAC98

Description: Description:

The function SetINT enables the interrupt channel The function GetINT returns the state of the interrupt
determined by channel when the parameter val is unequal channel register. Any data bit reset to 0 indicates the
to zero. In the other case the interrupt channel is disabled. source which requested the interrupt from the card
previously.

Parameters:
int channel is the DAC98 interrupt channel. Parameters:
Valid channels are: none
0, 32 bit timer overflow
1, 16 bit counter overflow Return value:
2, end of conversion AD converter int state of the interrupt channel:

int val is the interrupt enable flag.


Data bit Assignment
Return value: D0 32 bit timer overflow
none
D1 16 bit counter overflow
D2 end of conversion AD converter
D3 no function

4-14 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
ResetDDM ResetAllDDM

void ResetDDM( int channel ); void ResetAllDDM( void );

Class: DAC98 Class: DAC98

Description: Description:

The function ResetDDM resets a single DDM device The function ResetAllDDM resets all of the DDM
indicated by the parameter channel. devices at once.

Parameters: Parameters:
int channel is the DDM device number. none

Return value: Return value:


none none

The PC Plug-in Card DAC98 4-15


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
ReadDDM ReadAllDDM

unsigned int ReadDDM( int channel ); void ReadAllDDM( void );

Class: DAC98 Class: DAC98

Description: Description:

The function ReadDDM reads the DDM device specified The function ReadAllDDM reads all of the three DDM
by the parameter channel and stores the results to the devices and stores the results to the corresponding public
corresponding public data elements. The increment data elements. Before the read operation all the registers
counter content is returned directly. of the DDM devices are switched at the same time such
that the results belong to the same time.

Parameters:
int channel is the DDM device number. Parameters:
none
Return value:
unsigned int is the 16 bit increment counter Return value:
content of the DDM device. none

4-16 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
ReadAnalogInt ReadAnalogVolt

int ReadAnalogInt( int channel, int mode=3 ); float ReadAnalogVolt( int channel, int mode );

Class: DAC98 Class: DAC98

Description: Description:

The function ReadAnalogInt reads the analog input The function ReadAnalogVolt reads the analog input
channel specified by channel and returns the channel specified by channel and returns the
corresponding integer value with respect to the input corresponding voltage value with respect to the input
signal range given by mode. signal range given by mode.

Parameters: Parameters:
int channel is the number of the analog input channel. int channel is the number of the analog input channel.
int mode is the mode defining the input signal range int mode is the mode defining the input signal range
according to: according to:
0, 0..5V 0, 0..5V
1,0..10V 1,0..10V
2, -5..+5V 2, -5..+5V
3, -10..+10V 3, -10..+10V

Return value: Return value:


int converted analog input value. float converted analog input value in Volt.

The PC Plug-in Card DAC98 4-17


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
WriteAnalogInt WriteAnalogVolt

void WriteAnalogInt( int channel, int value ); void WriteAnalogVolt( int channel, float value );

Class: DAC98 Class: DAC98

Description: Description:

The function WriteAnalogInt sends an analog value to The function WriteAnalogVolt operates similar to
the desired channel (0 or 1). The parameter value has to WriteAnalogInt, but the output value is taken as a
be in a range from 0 to +4095. voltage. Its value has to be in the range from -10(V) to
+10(V).

Parameters:
int channel is the number of the analog output Parameters:
channel. int channel is the number of the analog output
int value is the output value. channel.
int value is the output value in Volt.
Return value:
none Return value:
none

4-18 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Private Element Function: 4.2 The Class DIC


Name:
ReadDigitalInputs The class DIC is established to use existing software,
written for the DIC24 PC plug-in card, now with the
DAC98 PC plug-in card. That means this DIC class
unsigned int ReadDigitalInputs( void );
together with the DAC98 class replaces the "old" DIC
class for the DIC24 PC plug-in card.
Class: DAC98

Since this DIC class only provides a subset of the features


of the DAC98 it is strictly recommended to use only the
Description: DAC98 class for new projects.

The function ReadDigital returns the state of the 12


This DIC class only contains those functions as an
digital input channels (8 external inputs + 4 internal
interface to "old DIC function calls" which are not
states) in the lower 12 bits of the return value (similar to
provided directly by the DAC98 class.
ReadAllDigital but with unsigned return value).

Basic Class:
Parameters:
none DAC98

Return value: Public Data:


unsigned int state of the 12 digital input channels.
unsigned char ddm_status[4] is an array containing
the state register
Data bit Assignment of the three DDM devices.

D0 digital input 0 unsigned int ddm_counter[4] is an array containing


D1 digital input 1 the counted increments
of the three DDM devices.
D2 digital input 2
D3 digital input 3 unsigned long ddm_timer[4] is an array containing
D4 digital input 4 the timer values
of the three DDM devices.
D5 digital input 5
D6 digital input 6 int aout0, aout1 are the values for
D7 digital input 7 the analog outputs

D8 busy signal of the AD private:


converter int ident is the state of the identification
D9 not used
D10 not used
D11 not used

The PC Plug-in Card DAC98 4-19


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
DIC ~DIC

DIC( int adress ); ~DIC();

Class: DIC Class: DIC

Description: Description:

The constructor only requires the base address of the card. The destructor requires no parameters.
The field ddm_counter(3) is reset to 0 because the DAC98
contains only 3 DDM devices instead of 4 on the DIC24.
Parameters:

Parameters: none
int adress is the base address of the adapter
card in the address range of the PC.
Return value:
Return value:
none
none

4-20 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
GetDigitalOut GetAnalogOut

unsigned int GetDigitalOut(void); int GetAnalogOut (int channel);

Class: DIC Class: DIC

Description: Description:

The function GetDigitalOut returns the content of the The function GetAnalogOut returns the integer value
shadow register for the digital outputs. previously transfered to the specified analog channel.

Parameters: Parameters:
none int channel is the analog channel number.

Return value: Return value:


int state of the digital outputs. int the 12 bit value of the previous
analog output.

The PC Plug-in Card DAC98 4-21


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
GetDDMCounter GetDDMTimer

unsigned int GetDDMCounter( int channel ); unsigned long GetDDMTimer( int channel );

Class: DIC Class: DIC

Description: Description:

The function GetDDMCounter returns the last counter The function GetDDMTimer returns a timer value of 0
content (global variable) of the DDM component for any channel because this function is not implemented
specified by the given channel number, which was read in the new DDM device. This dummy function is
by the functions ReadDDM or ReadAllDDM. For established only for compatibility reason.
channel = 3 the return value is always = 0.

Parameters:
Parameters: int channel is the number of the DDM device.
int channel is the DDM device number (0, 1, 2).
Return value:
Return value: unsigned long here always = 0.
unsigned int is the 16 bit increment counter
content of the DDM device.

4-22 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
GetDDMStatus FilterINC

unsigned char GetDDMStatus( int channel ); void FilterINC( int channel, int val );

Class: DIC Class: DIC

Description: Description:

The function GetDDMStatus returns a state value of 0 The function FilterINC is an empty function. This
for any channel because this function is not implemented dummy function is established only for compatibility
in the new DDM device. This dummy function is reason.
established only for compatibility reason.

Parameters:
Parameters: int channel is the number of the DDM device.
int channel is the number of the DDM device. int val is the desired filter state
(0==on, 1 == off)
Return value:
unsigned char here always = 0. Return value:
none

The PC Plug-in Card DAC98 4-23


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
TimerDirINC SetINT

void TimerDirINC( int channel, int val ); void SetINT( int channel, int val );

Class: DIC Class: DIC

Description: Description:

The function TimerDirINC is an empty function. This The function SetINT adjusts the interrupt enable register
dummy function is established only for compatibility of the DAC98.
reason.

Parameters:
Parameters: int channel is the interrupt channel.
int channel is the number of the DDM device. Valid channels are:

int val is the desired count direction state 4, 32 bit timer overflow
(0==increment, 1 == decrement) 5, 16 bit counter overflow
int val is the interrupt enable flag.
Return value:
none Return value:
none

4-24 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
SetTimer GetTimer

void SetTimer ( unsigned long time ); unsigned long GetTimer( void );

Class: DIC Class: DIC

Description: Description:

The function SetTimer adjusts the initial value for the 32 The function GetTimer returns the current content of the
bit counter ( square wave operating mode). The upper 16 32 bit timer.
bit are written into the upper cascade of the timer register
and the lower 16 bit are written into the lower cascade. The identification procedure of the "old" DIC24 is
The resulting period time is given by the product of the simulated in addition.
upper and lower cascade settings multiplied with the
period time of the clock signal (default 1/2000000 s).
Parameters:
The identification procedure of the "old" DIC24 is none
simulated in addition.
Return value:
unsigned long is the timer content.
Parameters:
unsigned long time is the new time value for the
timer cascade.

Return value:
none

The PC Plug-in Card DAC98 4-25


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: 4.3 The Class PCIO


GateTimer

The class PCIO is established to use existing software,


void GateTimer( int val );
written for the DAC6214 PC plug-in card, now with the
DAC98 PC plug-in card. That means this PCIO class
Class: DIC
together with the DAC98 class replaces the "old" PCIO
class for the DAC6214 PC plug-in card.

Description: Since this PCIO class only provides a subset of the


features of the DAC98 it is strictly recommended to use
The function GateTimer enables or disables the gate of
only the DAC98 class for new projects.
the 32 bit timer. The timer is started with val=1.

This PCIO class only contains those functions as an


interface to "old PCIO function calls" which are not
Parameters: provided directly by the DAC98 class.
int val is the new value for the timer gate.

Return value: Basic Class:


none
DAC98

Public Data:
unsigned int ddm_counter[1] is an array containing
the increment count
of the first DDM device.

4-26 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
PCIO ~PCIO

PCIO( int adress ) ~PCIO();

Class: PCIO Class: PCIO

Description: Description:

The constructor only requires the base address of the card. The destructor requires no parameter.

Parameters: Parameters:
int adress is the base address of the adapter none
card in the address range of the PC.

Return value:
Return value: none
none

The PC Plug-in Card DAC98 4-27


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
DigitalOutStatus IsPCIO

unsigned char DigitalOutStatus( void ), int IsPCIO( void );

Class: PCIO Class: PCIO

Description: Description:

The function DigitalOutStatus returns the state of the The function IsPCIO calls the function Identifikation of
digital outputs. the class DAC98 to check whether the DAC98 responds
to the base address of the driver software. Any value
unequal to zero is returned when the PC plug-in card
Parameters: returns a bit string preassigned on its hardware.
none

Return value: Parameters:


unsigned char the state of the digital outputs. none

Return value:
int Result of the test. Values unequal to zero indicate
that the hardware responded to the base address.

4-28 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Source Files of the DAC98 Driver

Name: Name:
ReadAnalogVoltMean ResetHCTL

float ReadAnalogVoltMean(int channel, int repeat); void ResetHCTL(void);

Class: PCIO Class: PCIO

Description: Description:

The function ReadAnalogVoltMean reads the analog The function ResetHCTL calls the function ResetDDM
input specified by channel repeat times and returns the to reset the first DDM device.
mean value as a voltage.

Parameters:
Parameters: none
int channel is the analog input channel.
int repeat is the number of read operations. Return value:
none
Return value:
float mean value of analog input in Volt.

The PC Plug-in Card DAC98 4-29


Source Files of the DAC98 Driver Laboratory Setup Speed Control DR300

Name: Name:
ReadHCTL SetINT

int ReadHCTL(void); void SetINT( int val );

Class: PCIO Class: PCIO

Description: Description:

The function ReadHCTL calls the function ReadDDM The function SetINT adjusts the interrupt enable register
and returns the content of the increment counter of the of the DAC98.
first DDM device.

Parameters:
Parameters: int val is the interrupt enable flag.
none
Return value:
Return value: none
int increment counter content.

4-30 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Windows Drivers for DAC98, DAC6214 and DIC24

5 Windows Drivers for DAC98, DAC6214 and DIC24


The drivers are installable 16-Bit drivers applicable to 16- or 32-Bit programs with Windows 3.1 / 95 / 98. Each
driver may be opened only once meaning that only one PC adapter card may be handled by this driver. To exchange
data with the drivers the following three 16-Bit API functions are used:

OpenDriver
HDRVR hDriver = OpenDriver(szDriverName, NULL, NULL)

Parameters szDriverName is the file name of the driver, valid names are "DAC98.DRV",
"DAC6214.DRV" and "DIC24.DRV" (according to the PC adapter cards) possibly
combined with complete path names.
Description The function OpenDriver initializes the driver and returns a handle for following accesses to this
driver. If this function is called the first time the driver is loaded into the memory. Any further
calls return another handle of an existing driver. The driver handle is valid only when the return
value is unequal to NULL. In case the return value is equal to NULL, the function OpenDriver
failed meaning that further driver accesses by the functions SendDriverMessage or CloseDriver
are invalid. The parameter szDriverName of the function OpenDriver contains the DOS file
name of the driver. The file name may include the disk name as well as the complete path names
according to the 8.3 name convention but it must not exceed 80 characters. When only a single
file name is used, the drivers location is expected in the standard search path of Windows. The
other parameters are meaningless and should be equal to NULL.
The address of the PC adapter card handled by this driver is read from a specific entry of the file
SYSTEM.INI from the public Windows directory. When this entry is missing the default address
0x300 (=768 decimal) will be taken.
Return Valid driver handle or NULL.

The PC Plug-in Card DAC98 5-1


Windows Drivers for DAC98, DAC6214 and DIC24 Laboratory Setup Speed Control DR300

SendDriverMessage
LRESULT result = SendDriverMessage( hDriver, DRV_USER, PARAMETER1,
PARAMETER2 )

Parameters hDriver is a handle of the card driver.


DRV_USER is the flag indicating special commands.
PARAMETER1 is a special command and determines the affected channel number
(see table below).
PARAMETER2 is the output value for special write commands.
Description The function SendDriverMessage transfers a command to the driver specified by the handle
hDriver. The drivers for the adapter cards from amira expect the value DRV_USER for the second
parameter (further commands can be found in the API documentation of SendDriverMessage).
The third parameter PARAMETER1 is of type ULONG specifying the command which is to be
carried-out. The lower 8 bits of this parameter determine the channel (number) which is to be
affected by the given command. The commands are valid for all of the three drivers. But the valid
channel numbers depend on the actual hardware. The last parameter PARAMETER2 is of type
ULONG and is used with write commands. It contains the output value. The return value depends
on the command. Commands and channel names are defined in the file "IODRVCMD.H".
Return Is equal to 0 in case of unsupported commands or special write commands. Otherwise it contains
the result of special read commands.

Table of the supported standard API commands


Command Return Remark
DRV_LOAD 1 loads the standard base address from SYSTEM.INI
DRV_FREE 1
DRV_OPEN 1
DRV_CLOSE 1
DRV_ENABLE 1 locks the memory range for this driver
DRV_DISABLE 1 unlocks the memory range for this driver
DRV_INSTALL DRVCNF_OK
DRV_REMOVE 0,
DRV_QUERYCONFIGURE 1
calls the dialog to adjust the base address and stores
DRV_CONFIGURE 1
it to SYSTEM.INI, i. e. [DAC98] Adress=768
DRV_POWER 1
DRV_EXITSESSION 0
DRV_EXITAPPLICATION 0

5-2 The PC Plug-in Card DAC98


Laboratory Setup Speed Control DR300 Windows Drivers for DAC98, DAC6214 and DIC24

Table of the special commands with the flag DRV_USER:


PARAMETER1
Channel Number Return
Command
DAC98 DAC6214 DIC24
DRVCMD_INIT
initializes the card and has to be the 0
first command
8 for DAC98,
DRVINFO_AREAD
6 for DAC6214,
returns the number of analog inputs
0 for DIC24
DRVINFO_AWRITE
2 for all cards
returns the number of analog outputs
DRVINFO_DREAD 8 for DAC98, DIC24
returns the number of digital inputs 4 for DAC6214
DRVINFO_DWRITE 8 for DAC98, DIC24
returns the number of digital outputs 4 for DAC6214
DRVINFO_COUNT 5 for DAC98
returns the number of counters and 1 for DAC6214
timers 6 for DIC24
16 bit value from -32768 to
DRVCMD_AREAD
0-7 0-5 no inputs 32767 according to the input
reads an analog input
voltage range
DRVCMD_AWRITE
0-1 0-1 0-1 0
writes to an analog output
DRVCMD_DREAD state (0 or 1) of a single input
0-7 or 0-3 or 0-7 or
reads a single digital input or all inputs or states binary coded
ALL_CHAN ALL_CHAN ALL_CHAN
(ALL_CHANNELS) (channel0==bit0)
DRVCMD_DWRITE
0-7 or 0-3 or 0-7 or
writes to a single digital output or to all 0
ALL_CHAN ALL_CHAN ALL_CHAN
outputs (channel0==bit0)
DDM0 DDM0
DDM1 DDM1
DRVCMD_COUNT DDM2 DDM2 counter- / timer-content as an
DDM0
reads a counter / timer DDM3 unsigned 32-bit value
COUNTER COUNTER
TIMER TIMER
DDM0 DDM0
DDM1 DDM1
DRVCMD_RCOUNT
DDM2 DDM2
resets a counter / timer (counter, timer
DDM0 DDM3 0
to the value -1) or all DDM’s
COUNTER COUNTER
(ALL_CHANNELS)
TIMER TIMER
ALL_CHAN ALL_CHAN
DRVCMD_SCOUNT
COUNTER COUNTER
presets a counter / timer to an initial 0
TIMER TIMER
value
CloseDriver

The PC Plug-in Card DAC98 5-3


Windows Drivers for DAC98, DAC6214 and DIC24 Laboratory Setup Speed Control DR300

CloseDriver(hDriver, NULL, NULL)

Parameters hDriver is a handle of the card driver.


Description The function CloseDriver terminates the operation of the driver specified by the handle hDriver.
The driver is removed from the memory when all of its handles are released by the function
CloseDriver.

5-4 The PC Plug-in Card DAC98


Laboratory Experiment DR300 DR300 Speed Control

DR300 Speed Control

Windows Software V1.0

Printed: 16. October 2000

DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

1 Source Files of the DR300W16 Controller Program 1-1

1.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

1.2 Global Data and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

1.3 Dialogs and Windows of the Desktop . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

TMainForm.ShowHint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

TMainForm.FormCreate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

TMainForm.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

TMainForm.FormClose . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

TMainForm.FormDestroy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

TMainForm.FileMenuClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

TMainForm.OpenPIClick . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

TMainForm.SavePIClick . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12

TMainForm.SavePIasClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12

TMainForm.OpenFuzzyClick . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12

TMainForm.LoadPlotData1Click . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

TMainForm.SavePlot1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

TMainForm.Print1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

TMainForm.PrintSetup1Click . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

TMainForm.ExitItemClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

TMainForm.IOInterface1Click . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

TMainForm.DAC98Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

TMainForm.DIC24Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15

TMainForm.DAC6214Click . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15

TMainForm.DACSetupClick . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15

TMainForm.Edit1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

TMainForm.PIControllerSetupClick . . . . . . . . . . . . . . . . . . . . . . . 1-16

TMainForm.FuzzyControllerSetupClick . . . . . . . . . . . . . . . . . . . . . . 1-16

TMainForm.useEncoder1Click . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

DR300 Speed Control Windows Software V1.0 i


Table of Contents Laboratory Experiment DR300

TMainForm.UseTacho1Click . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17

TMainForm.Run1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17

TMainForm.PIController1Click . . . . . . . . . . . . . . . . . . . . . . . . . 1-17

TMainForm.FuzzyController2Click . . . . . . . . . . . . . . . . . . . . . . . . 1-18

TMainForm.OpenLoopControl1Click . . . . . . . . . . . . . . . . . . . . . . . 1-18

TMainForm.StopController1Click . . . . . . . . . . . . . . . . . . . . . . . . 1-18

TMainForm.StartMeasuring1Click . . . . . . . . . . . . . . . . . . . . . . . . 1-19

TMainForm.SetpointGenerator1Click . . . . . . . . . . . . . . . . . . . . . . . 1-19

TMainForm.View1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19

TMainForm.PlotMeasuredData1Click . . . . . . . . . . . . . . . . . . . . . . . 1-19

TMainForm.PlotFileData1Click . . . . . . . . . . . . . . . . . . . . . . . . . 1-20

TMainForm.ParametersfromPLDFile1Click . . . . . . . . . . . . . . . . . . . . 1-20

TMainForm.Fuzzy3D1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20

TMainForm.Timing1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20

TMainForm.Contents1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21

TMainForm.SearchforHelpon1Click . . . . . . . . . . . . . . . . . . . . . . . 1-21

TMainForm.HowtoUseHelp1Click . . . . . . . . . . . . . . . . . . . . . . . . 1-21

TMainForm.About1Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21

TMainForm.Timer1Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22

TMainForm.PaintBox1Click . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22

TMainForm.MeasLabelClick . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22

TSingleInstance.WndProc . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

TAboutBox.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

TShow3DFuzDlg.rescale . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

TShow3DFuzDlg.recalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

TShow3DFuzDlg.calcrot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24

TShow3DFuzDlg.calctrans . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24

TShow3DFuzDlg.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25

TShow3DFuzDlg.FormHide . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25

ii DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

TShow3DFuzDlg.FuzzyCBoxChange . . . . . . . . . . . . . . . . . . . . . . . 1-26

TShow3DFuzDlg.DrawSquare . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26

TShow3DFuzDlg.DrawCoors . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27

TShow3DFuzDlg.DrawCoors2 . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27

TShow3DFuzDlg.DrawMark . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27

TShow3DFuzDlg.PaintBoxPaint . . . . . . . . . . . . . . . . . . . . . . . . . 1-27

TShow3DFuzDlg.ScrollBar1Change . . . . . . . . . . . . . . . . . . . . . . . 1-28

TShow3DFuzDlg.ScrollBar2Change . . . . . . . . . . . . . . . . . . . . . . . 1-28

TShow3DFuzDlg.PaintBoxMouseDown . . . . . . . . . . . . . . . . . . . . . . 1-28

TShow3DFuzDlg.PaintBoxMouseMove . . . . . . . . . . . . . . . . . . . . . . 1-29

TShow3DFuzDlg.PaintBoxMouseUp . . . . . . . . . . . . . . . . . . . . . . . 1-29

TShow3DFuzDlg.KoorsCBoxClick . . . . . . . . . . . . . . . . . . . . . . . . 1-29

TShow3DFuzDlg.Koors2CBoxClick . . . . . . . . . . . . . . . . . . . . . . . 1-30

TShow3DFuzDlg.ColorCBoxClick . . . . . . . . . . . . . . . . . . . . . . . . 1-30

TShow3DFuzDlg.LowResCBoxClick . . . . . . . . . . . . . . . . . . . . . . . 1-30

TShow3DFuzDlg.PrintBBtnClick . . . . . . . . . . . . . . . . . . . . . . . . 1-30

TShow3DFuzDlg.MarkCBoxClick . . . . . . . . . . . . . . . . . . . . . . . . 1-31

TShow3DFuzDlg.Timer1Timer . . . . . . . . . . . . . . . . . . . . . . . . . 1-31

TShow3DFuzDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . 1-31

TFuzzyParameterDlg.Big . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31

TFuzzyParameterDlg.Small . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32

TFuzzyParameterDlg.FormCreate . . . . . . . . . . . . . . . . . . . . . . . . 1-32

TFuzzyParameterDlg.FormDestroy . . . . . . . . . . . . . . . . . . . . . . . . 1-32

TFuzzyParameterDlg.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . 1-32

TFuzzyParameterDlg.Sel1BBtnClick . . . . . . . . . . . . . . . . . . . . . . . 1-33

TFuzzyParameterDlg.Ed1BBtnClick . . . . . . . . . . . . . . . . . . . . . . . 1-33

TFuzzyParameterDlg.CancelEdBBtnClick . . . . . . . . . . . . . . . . . . . . . 1-33

TFuzzyParameterDlg.SaveEdBBtnClick . . . . . . . . . . . . . . . . . . . . . . 1-33

TFuzzyParameterDlg.OKBtnClick . . . . . . . . . . . . . . . . . . . . . . . . 1-34

DR300 Speed Control Windows Software V1.0 iii


Table of Contents Laboratory Experiment DR300

TFuzzyParameterDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . 1-34

TMeasureDlg.OKBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34

TMeasureDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35

TPIParameterDlg.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35

TPIParameterDlg.OKBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35

TPIParameterDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . 1-35

TPLDInfoDlg.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36

TPLDInfoDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36

TPlotDlg.OKBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36

TPlotDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36

TPrintPlotDlg.PrinterBitBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . 1-37

TPrintPlotDlg.OKBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37

TPrintPlotDlg.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37

TPrintPlotDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37

TGeneratorDlg.OKBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38

TGeneratorDlg.FormShow . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38

TGeneratorDlg.HelpBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38

TTimingForm.UpdateData . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39

TTimingForm.HideButtonClick . . . . . . . . . . . . . . . . . . . . . . . . . 1-39

TTimingForm.HelpButtonClick . . . . . . . . . . . . . . . . . . . . . . . . . 1-39

TTimingForm.PaintBox1Paint . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39

TTimingForm.PaintBox2Paint . . . . . . . . . . . . . . . . . . . . . . . . . . 1-40

TTimingForm.ResetBtnClick . . . . . . . . . . . . . . . . . . . . . . . . . . 1-40

FloatToStr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-40

FloatToStr3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-40

FloatToStr4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41

FloatToStr5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41

StrToFloatMinMax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41

StrToFloatStrMinMax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-42

iv DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

MinMaxi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-42

DetectNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-42

1.4 Overview of Classes and DLL Interfaces . . . . . . . . . . . . . . . . . . . . . . . 1-43

1.5 References of the DLL Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46

1.5.1 The DLL Interface DRSRV16 . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48

LibMain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48

WEP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48

LockMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48

SetDriverHandle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-49

DoService . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-49

SetParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-50

GetParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-50

GetData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-50

GetTiming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-51

ReadFuzzy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-51

ReadPIPar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-51

WritePIPar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-52

IsDemo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-52

MeasureStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-52

MeasureLevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-53

MeasureStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-53

OpenFuzzy3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-53

CloseFuzzy3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-53

InfoFuzzy3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-54

CalcFuzzy3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-54

1.5.2 The Class DR300STA in the DRSRV16.DLL . . . . . . . . . . . . . . . . . . . 1-55

DR300STA::DR300STA() . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-55

DR300STA::Calc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-55

DR300STA::Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-56

DR300 Speed Control Windows Software V1.0 v


Table of Contents Laboratory Experiment DR300

DR300STA::Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-56

DR300STA::Save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-56

DR300STA::GetKr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-57

DR300STA::GetTr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-57

DR300STA::GetFileName . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-57

DR300STA::GetId . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-57

DR300STA::geterrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-57

DR300STA::SetTa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-58

1.5.3 The Class DR300FUZ in the DRSRV16.DLL . . . . . . . . . . . . . . . . . . . 1-59

DR300FUZ::DR300FUZ() . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-59

DR300FUZ::~DR300FUZ() . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-59

DR300FUZ::Calc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-60

DR300FUZ::Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-60

DR300FUZ::Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-60

DR300FUZ::Save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-61

DR300FUZ::getname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-61

DR300FUZ::GetFileName . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-61

DR300FUZ::GetId . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-61

DR300FUZ::geterrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-62

DR300FUZ::SetTa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-62

1.5.4 The Class STOREBUF in the DRSRV16.DLL . . . . . . . . . . . . . . . . . . . 1-63

STOREBUF::ResetBufIndex . . . . . . . . . . . . . . . . . . . . . . . . . . 1-64

STOREBUF::STOREBUF . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-64

STOREBUF::~STOREBUF() . . . . . . . . . . . . . . . . . . . . . . . . . . 1-64

STOREBUF::StartMeasure . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-65

STOREBUF::WriteValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-65

STOREBUF::SetOutChan . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-65

STOREBUF::ReadValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-65

STOREBUF::GetBufLen . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-66

vi DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

STOREBUF::GetBufTa . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-66

STOREBUF::GetStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-66

STOREBUF::GetBufferLevel . . . . . . . . . . . . . . . . . . . . . . . . . . 1-66

1.5.5 The Class AFBUF in the DRSRV16.DLL . . . . . . . . . . . . . . . . . . . . . 1-67

AFBUF::AFBUF() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-67

AFBUF::~AFBUF() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-67

AFBUF::NewFBuf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-68

AFBUF::ReadFBuf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-68

AFBUF::WriteFBuf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-68

1.5.6 The Class TWOBUFFER in the DRSRV16.DLL . . . . . . . . . . . . . . . . . . 1-69

TWOBUFFER::TWOBUFFER() . . . . . . . . . . . . . . . . . . . . . . . . . 1-70

TWOBUFFER::New2Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . 1-70

TWOBUFFER::Write2Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . 1-70

TWOBUFFER::Read2Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . 1-70

1.5.7 The Class Signal in the DRSRV16.DLL . . . . . . . . . . . . . . . . . . . . . . 1-71

SIGNAL::SIGNAL( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-71

SIGNAL::InitTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-71

SIGNAL::MakeSignal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-72

SIGNAL::ReadNextValue . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-72

SIGNAL::SetRange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-73

SIGNAL::WriteBuffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-73

SIGNAL::Stuetzstellen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-73

1.5.8 The DLL Interface PLOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-74

ReadPlot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-75

WritePlot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-75

Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-76

GetPlot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-77

PrintPlot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-77

GetPldInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-78

DR300 Speed Control Windows Software V1.0 vii


Table of Contents Laboratory Experiment DR300

2 Driver Functions for DR300W16 2-1

2.1 The Class DICDRV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1

DICDRV::DICDRV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2

DICDRV::~DICDRV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2

DICDRV::ReadASpeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2

DICDRV::ReadISpeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3

DICDRV::ReadTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3

DICDRV::ReadDriveCurrent . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3

DICDRV::ReadLoadCurrent . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

DICDRV::SetControlSignals . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

DICDRV::CheckSystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

DICDRV::CheckFree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

DICDRV::TopSwitch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

DICDRV::StartInterrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

DICDRV::TriggerEndstufe . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

DICDRV::CalcModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

DICDRV::WinDelay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

2.2 The Class WDAC98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6

WDAC98::ReadAnalogVolt . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6

WDAC98::WriteAnalogVolt . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

WDAC98::ReadDigital . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

WDAC98::ReadAllDigital . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

WDAC98::WriteDgital . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

WDAC98::GetCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

WDAC98::SetCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

WDAC98::GetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

WDAC98::SetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

WDAC98::ReadDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

viii DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

WDAC98::ResetDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9

WDAC98::ResetAllDDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9

3 The Fuzzy Library 3-1

3.1 Introduction to the Structure of the Fuzzy Library . . . . . . . . . . . . . . . . . . . . 3-1

3.2 Description of the Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2

3.2.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2

3.2.2 Overview of the Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2

3.2.3 References of the Classes, their Data and Element Functions . . . . . . . . . . . . . . 3-4

3.2.3.1 The Class FuzzySet . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

FuzzySet::FuzzySet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

FuzzySet::FuzzySet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

FuzzySet::FuzzySet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

FuzzySet::FuzzySet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

FuzzySet::~FuzzySet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

FuzzySet::getname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

FuzzySet::cleary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

FuzzySet::getxvector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

FuzzySet::getyvector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

FuzzySet::getstuetzen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

FuzzySet::insert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

FuzzySet::normalize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

FuzzySet::coa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

FuzzySet::crisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

FuzzySet::conclude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

FuzzySet::tout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8

FuzzySet::= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8

FuzzySet::*= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9

FuzzySet::+= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9

DR300 Speed Control Windows Software V1.0 ix


Table of Contents Laboratory Experiment DR300

FuzzySet::<< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9

3.2.3.2 The class FuzzyVar . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

FuzzyVar::FuzzyVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

FuzzyVar::~FuzzyVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

FuzzyVar::getname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11

FuzzyVar::getsetname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11

FuzzyVar::getsetcount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11

FuzzyVar::add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11

FuzzyVar::check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

FuzzyVar::norm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

FuzzyVar::getmode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

FuzzyVar::getmaxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

FuzzyVar::getminx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

FuzzyVar::get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13

FuzzyVar::set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13

FuzzyVar::clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13

FuzzyVar::out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13

FuzzyVar::getval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14

FuzzyVar::setval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14

FuzzyVar::vsort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15

FuzzyVar::<< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15

3.2.3.3 The class FuzzyRule . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16

FuzzyRule::FuzzyRule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16

FuzzyRule::~FuzzyRule . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16

FuzzyRule::getname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16

FuzzyRule::addIn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17

FuzzyRule::addOut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17

FuzzyRule::Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17

FuzzyRule::tout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17

x DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

FuzzyRule::<< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18

3.2.3.4 The Class Fuzzy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19

Fuzzy::Fuzzy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20

Fuzzy::Fuzzy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20

Fuzzy::~Fuzzy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20

Fuzzy::read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21

Fuzzy::write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21

Fuzzy::generate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21

Fuzzy::calc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22

Fuzzy::getinputcount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22

Fuzzy::getoutputcount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22

Fuzzy::geterrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22

Fuzzy::getrulecatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23

Fuzzy::speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23

Fuzzy::Get3DInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24

Fuzzy::getname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24

Fuzzy::tout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24

Fuzzy::parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

Fuzzy::calcsetup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

Fuzzy::gettoken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28

Fuzzy::defvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28

Fuzzy::defset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29

Fuzzy::defrule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29

Fuzzy::deflabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29

Fuzzy::getlabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30

Fuzzy::killstructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30

Fuzzy::killfuzzybase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30

Fuzzy::killlabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30

Fuzzy::out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31

DR300 Speed Control Windows Software V1.0 xi


Table of Contents Laboratory Experiment DR300

Fuzzy::<< . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31

Fuzzy::>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31

3.3 Description of the File Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32

3.3.1 The Format of the Fuzzy Description File (*.FUZ) . . . . . . . . . . . . . . . . . . 3-32

3.3.2 The Format of the Error Output File ERROR.OUT . . . . . . . . . . . . . . . . . 3-34

3.4 A Very Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-35

3.4.1 The Fuzzy Description File of a Temperature Control . . . . . . . . . . . . . . . . 3-35

3.4.2 The C++ Sources of a Temperature Control . . . . . . . . . . . . . . . . . . . . 3-36

4 Functions of the PLOT16.DLL 4-1

Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

CreateSimplePlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

ShowPlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3

ClosePlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4

UpdatePlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4

GetValidPlotHandle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4

AddPlotTitle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4

AddAxisPlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5

AddXData: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6

AddTimeData: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6

AddYData: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6

SetCurveMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7

SetPlotMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7

PrintPlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9

CreateEmptyPlotWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10

5 Interface Functions of the TIMER16.DLL 5-1

LibMain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1

SetService . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

xii DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Table of Contents

SelectDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

StartTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3

IsTimerActive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3

StopTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4

GetMinMaxTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4

GetSimTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4

SetupDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5

6 Windows Drivers for DAC98, DAC6214 and DIC24 6-1

OpenDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1

SendDriverMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2

CloseDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4

DR300 Speed Control Windows Software V1.0 xiii


Table of Contents Laboratory Experiment DR300

xiv DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1 Source Files of the DR300W16 Controller Program

1.1 General

The program is a 16-bit application, which may be started only once by the operating systems Windows 3.1 or
Windows95/98. The desktop is created by means of the program language ’Pascal’, while the actual controller is
realized by a DLL developed with the program language ’C++’. Both program parts are available in source
completely. The program package is completed by

the TIMER16.DLL to handle the cyclic controller calls,


the card drivers DAC98.DRV, DIC24.DRVor DAC6214.DRV to access the PC adapter card,
the PLOT16.DLL for the graphic output,
the help file DR300.HLP,

Generating a new executable program is possible only by means of the development systems ’Delphi’ version 1.0
for the desktop and ’Borland C++’ version 4.52 for the controller-DLL. The last may be generated using another
16-bit-C++ compiler in case a suitable project file can be created.

Prior to generating the program the first time please copy the complete content of the enclosed floppy disk to a new
directory of your harddisk by keeping the directory structure (i.e. using the ’Explorer’ to copy to the new directory
DR300).

You will then find the following subdirectories:


DR300DSK
CONTRDLL
EXE

Where DR300DSK contains the Delphi Project File DR300W16.DPR together with all the accompanying Pascal
source files to generate the desktop, CONTRDLL contains the Borland Project File DR300.IDE with all the
accompanying C++ source files to create the controller-DLL (DRSRV16.DLL). Finally the subdirectory EXE
contains all the additional files required by the executable program as can be seen from the following list:

DAC98.DRV DAC6214.DRV DIC24.DRV


PLOT16.DLL
DR300.HLP
DR300.INI
DRSRV16.DLL
TIMER16.DLL

together with the parameter file and fuzzy description file


DR300.PI
DR300.FUZ
Attention: After creating a new desktop or a new controller-DLL, the new results are to be copied later to the
subdirectory EXE.

DR300 Speed Control Windows Software V1.0 1-1


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

A DEMO version of the program (simulation of the mathematical model of the Speed Control system instead of
accessing the PC adapter card) may be obtained simply by setting the macro __SIMULATION__ in the include file
DRDEFINE.H and generating a new DRSRV16.DLL. Because the resulting DLL has the same name as the DLL
controlling the real system, it should be copied together with all the required files (DUMMY.DRV is recommended
instead of DAC98.DRV, DAC6214 or DIC24.DRV)to a different subdirectory (i.e. DEMO) afterwards.

1.2 Global Data and Functions

The file DRDEFINE.H contains some definitions to clarify the readability of the source code and to adjust the
program mode as well as the fixed sampling period. When __SIMULATION__ is defined all program functions
except for selecting the IO-interface and for viewing timing values are available for a simulated Speed Control
system. The PC adapter card is not required in this program mode. To control the real system the macro
__SIMULATION__ must not be defined!

Used definitions:
#define __FUZZY__
#define __SIMULATION__ //to create Demo version
#define ScopeBufSize 8
#define SIMTIME 0.005

The file DR300DAT.H contains global data structures which are used in different instances of the software. These
structures are saved in the data files used to store measurements.

// Data structures:
struct PROJECT{
char number[10]; // P340 for speed control system
char name[10]; // DR300
char Titel[10]; // SPD CTRL
char Version[10]; // last version
char Date[10]; // last modification
char Dummy[10]; // Reserve
};
CTRLSTATUS {
short controller; // type of active controller
double ta_ms; // adjusted sampling period in [ms]
char fuzname[80]; // "Fuzzy controller" file name
short dummy;
long timeofmeasure; // Date and time of the measurement acquisition
};
struct DATASTRUCT { // Structure to reconstruct the measured data
short nchannel; // Length of the stored measurement vectors (number of channels)
short nvalues; // Number of the measurement vectors (number of samples)
float deltatime; // Time between two samples
};

1-2 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

The Format of the Documentation Data File *.PLD

Measured data stored in a data file are reloadable and may be output in a graphic representation. In addition the
system settings (CTRLSTATUS) which were active during the start of the data acquisition are stored in this file.
They are displayable in a separate window.

The data file contains data in binary format stored in the following order:

The structure PROJEKT PRJ. (60 bytes)


The structure CTRLSTATUS. (96 bytes)
The structure DATASTRUCT. (8 bytes)
The data array with float values (4 bytes per value).

The size of the data array is defined in the structure DATASTRUCT. With the DR300 speed control system the
number of the stored channels is always 8 (the length of the measurement vector is 8, i.e. equal to 32 bytes).

the speed setpoint of the motor in [rpm],


the control signal for the generator in [V],
the motor speed measured by tacho in [rpm],
the motor speed measured by encoder in [rpm],
the measured motor current in [A],
the measured generator current in [A],
the output signal for the motor in [V],
the output signal for the generator in [V],

The number of the stored measurement acquisitions (vectors) depends on the adjusted values for the sampling
period and the measuring time. The maximum number of measurings is 1024. The time distance between two
successive acquisitions is an integral multiple of the sampling period used by the controller.

DR300 Speed Control Windows Software V1.0 1-3


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

1.3 Dialogs and Windows of the Desktop

The programs desktop is written in the program language Pascal. The main window with its menu bar as well as all
of the following dialogs and message boxes are realized by the following files.

The file MAIN.PAS contains the procedures:


ShowHint(Sender : TObject)
FormCreate(Sender : TObject)
FormShow(Sender : TObject)
FormClose(Sender : TObject; var Action : TCloseAction)
FormDestroy(Sender : TObject)
FileMenuClick(Sender : TObject)
OpenPIClick(Sender : TObject)

SavePIClick(Sender : TObject)
SavePIasClick(Sender : TObject)
OpenFuzzyClick(Sender : TObject)
LoadPlotData1Click(Sender : TObject)
SavePlot1Click(Sender : TObject)

Print1Click(Sender : TObject)
PrintSetup1Click(Sender : TObject)
ExitItemClick(Sender : TObject)

IOInterface1Click(Sender : TObject)
DAC98Click(Sender : TObject)
DIC24Click(Sender : TObject)
DAC6214Click(Sender : TObject)
DACSetupClick(Sender : TObject)
Edit1Click(Sender : TObject)
PIControllerSetupClick(Sender : TObject)
FuzzyControllerSetupClick(Sender : TObject)
useEncoder1Click(Sender : TObject)
UseTacho1Click(Sender : TObject)
Run1Click(Sender : TObject)

PIController1Click(Sender : TObject)
FuzzyController2Click(Sender : TObject)

1-4 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

OpenLoopControl1Click(Sender : TObject)
StopController1Click(Sender : TObject)
StartMeasuring1Click(Sender : TObject)
SetpointGenerator1Click(Sender : TObject)
View1Click(Sender : TObject)
PlotMeasuredData1Click(Sender : TObject)
PlotFileData1Click(Sender : TObject)
ParametersfromPLDFile1Click(Sender : TObject)
Fuzzy3D1Click(Sender : TObject)
Timing1Click(Sender : TObject)
Contents1Click(Sender : TObject)
SearchforHelpon1Click(Sender : TObject)
HowtoUseHelp1Click(Sender : TObject)
About1Click(Sender : TObject)

Timer1Timer(Sender : TObject)
PaintBox1Click(Sender : TObject)

MeasLabelClick(Sender : TObject)

The file SINGLEIN.PAS contains the procedures:


WndProc(var Msg : TMessage)

The file ABOUT.PAS contains the procedures:


FormShow(Sender : TObject)

The file FUZ3D.PAS contains the procedures:


rescale
recalc
calcrot

calctrans( ix,iy,iz : double; var ox,oy,oz : double )


FormShow(Sender : TObject)
FormHide(Sender : TObject)

FuzzyCBoxChange(Sender : TObject)
DrawSquare( can : TCanvas; j, i, z0, z1, z2, z3 : Integer )

DrawCoors( can : TCanvas )


DrawCoors2( can : TCanvas )

DR300 Speed Control Windows Software V1.0 1-5


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

DrawMark( can : TCanvas )


PaintBoxPaint(Sender : TObject)
ScrollBar1Change(Sender : TObject)
ScrollBar2Change(Sender : TObject)
PaintBoxMouseDown(Sender : TObject; Button : TMouseButton; Shift : TShiftState; X, Y : Integer);
PaintBoxMouseMove(Sender : TObject; Shift : TShiftState; X, Y : Integer);
PaintBoxMouseUp(Sender : TObject; Button : TMouseButton; Shift : TShiftState; X, Y : Integer);
KoorsCBoxClick(Sender : TObject)
Koors2CBoxClick(Sender : TObject)
ColorCBoxClick(Sender : TObject)
LowResCBoxClick(Sender : TObject)
PrintBBtnClick(Sender : TObject)
MarkCBoxClick(Sender : TObject)
Timer1Timer(Sender : TObject)

HelpBtnClick(Sender : TObject)

The file FUZZYPAR.PAS contains the procedures:


Big
Small

FormCreate(Sender : TObject)
FormDestroy(Sender : TObject)

FormShow(Sender : TObject)
Sel1BBtnClick(Sender : TObject)
Ed1BBtnClick(Sender : TObject)
CancelEdBBtnClick(Sender : TObject)
SaveEdBBtnClick(Sender : TObject)
OKBtnClick(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file MEASURE.PAS contains the procedures:


OKBtnClick(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file PIPAR.PAS contains the procedures:


FormShow(Sender : TObject)

1-6 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

OKBtnClick(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file PLDINFO.PAS contains the procedures:


FormShow(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file PLOT.PAS contains the procedures:


OKBtnClick(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file PRINTPLT.PAS contains the procedures:


PrinterBitBtnClick(Sender : TObject)
OKBtnClick(Sender : TObject)
FormShow(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file SETPOINT.PAS contains the procedures:


OKBtnClick(Sender : TObject)
FormShow(Sender : TObject)
HelpBtnClick(Sender : TObject)

The file TIMING.PAS contains the procedures:


UpdateData
HideButtonClick(Sender : TObject)
HelpButtonClick(Sender : TObject)
PaintBox1Paint(Sender : TObject)
PaintBox2Paint(Sender : TObject)
ResetBtnClick(Sender : TObject)

The file TOOLS.PAS contains the functions:


FloatToStr2( f : Single ) : string
FloatToStr3( f : Single ) : string
FloatToStr4( f : Single ) : string
FloatToStr5( f : Single ) : string

StrToFloatMinMax( s : string; min,max : double ) : double


StrToFloatStrMinMax( s : string; var val : double; min,max : double ) : string
MinMaxi( val, min, max : Integer ) : Integer

DR300 Speed Control Windows Software V1.0 1-7


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

DetectNT : Boolean

The file DLLS.PAS contains besides the global data definitions the interface definitions for the DLL’s DRSRV16
and TIMER16.

Global Data:

type ServiceParameter = record


controller : WORD;
encoder : WORD;
kr : double;
tr : double;
name : array[0..79] of char;
spshape : WORD;
spoffset : double;
spamplitude : double;
spperiod : double;
splshape : WORD;
sploffset : double;
splamplitude :double;
splperiod : double;
PIError : WORD;
fuzzyError : WORD;
end;

type ServiceData = record


sdrive : double;
sload : double;
aspeed : double;
ispeed : double;
curdrive : double;
curload : double;
odrive : double;
oload : double;
acc : double;
state : WORD;
end;

type ServiceTiming = record


n: longint;
min : double;
max : double;
v: array[0..19] of longint;
end;

1-8 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

type Fuzzy3DInfo = record


size : longint;
idx, idy, idz : Integer;
incount, outcount : Integer;
xname : array[0..79] of char;
yname : array[0..79] of char;
zname : array[0..79] of char;
xmin, xmax : double;
ymin, ymax : double;
zmin, zmax : double;
end;

param : ServiceParameter ;
data : ServiceData;
tim : ServiceTiming;
cardNo : WORD;

DR300 Speed Control Windows Software V1.0 1-9


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.ShowHint
ShowHint(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure ShowHint is called, when the object of type TMainForm appears on the screen.

TMainForm.FormCreate
FormCreate(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormCreate creates an instance of an object of type TMainForm. With this another
instance (single) of type SingleInstance is created, which guarantees that this application (the
DR300W16 program) may be started only once. A bitmap for the animation picture is prepared.

TMainForm.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormShow is called, when the object of type TMainForm appears at the screen.
At the same time the application DR300W16 is started with the selection of the controller DLL,
here DRSRV16.DLL, and the driver for the adapter card (the drivers file name is contained in the
file DR300.INI). The check marks below the menu item "IO-Interface" are set accordingly. The
type of the active speed sensor is read from the file DR300.INI and the corresponding check mark
is set in addition. Then the parameter structure param is read from the DRSRV16.DLL. Then the
structure is initialized with default values ( no controller, default PI parameters, speed setpoint to
0, period to 20s) and transferred (SetParameter) again to the controller inside the
DRSRV16.DLL. The program version DEMO is detected, when the function IsDemo returns
TRUE. Only in this case the menu item "IO-Interface" is disabled, the string "(Demo-Version)"
is appended to the title line of the monitor window and the timer for the sampling period of the
controller (StartTimer, TIMER16.DLL) is started directly. When DR300.INI does not contain
a driver file DUMMY.DRV, the timer for the sampling period of the controller is started as for
DEMO version. An error message will appear, when the timer could not be started. At the end
the timer for the periodic update of the monitor window is started in addition.

1-10 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMainForm.FormClose
FormClose(Sender : TObject; var Action : TCloseAction)

Parameters: Sender is a reference to the calling object.


var Action is not used.
Description The procedure FormClose stops the timer for the sampling period of the controller.

TMainForm.FormDestroy
FormDestroy(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormDestroy is called before the object of type TMainForm is removed from the
memory. In this connection the animation picture as well as the application are released.

TMainForm.FileMenuClick
FileMenuClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure FileMenuClick is an event handler activated by clicking once on the menu item
"File". The menu item "Save Recorded Data" is enabled when the memory contains data from a
measurement acquisition. Otherwise this menu item is disabled.

TMainForm.OpenPIClick
OpenPIClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure OpenPIClick is an event handler activated by clicking once on the menu item
"File/Load PI Controller". A Windows system dialog appears allowing for the selection of a file
name (extension *.PI) from which the parameters of a PI controller are to be loaded (ReadPIPar).
An error message appears when a non-existing file is selected.

DR300 Speed Control Windows Software V1.0 1-11


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.SavePIClick
SavePIClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure SavePIClick is an event handler activated by clicking once on the menu item
"File/Save PI Controller". The parameters of the PI controller contained in the memory are written
to that file, from which the same parameters have been read previously (OpenPIClick). After
starting the program this file is DR300.PI. An error message will appear, when the data could not
be written successfully to this file.

TMainForm.SavePIasClick
SavePIasClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure SavePIasClick is an event handler activated by clicking once on the menu item
"File/Save PI Controller as...". A Windows system dialog appears to select a new file name
(extension *.PI) for storing (WritePIPar) the parameters of the PI controller contained in the
memory. An error message will appear, when the data could not be written successfully to this
file.

TMainForm.OpenFuzzyClick
OpenFuzzyClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure OpenFuzzyClick is an event handler activated by clicking once on the menu item
"File/Load Fuzzy Controller". A Windows system dialog appears allowing for the selection of a
file name (extension *.FUZ) of a fuzzy description files from which all the fuzzy variables and
rules are to be read (ReadFuzzy). The selected fuzzy description file name is written to the
parameter structure param. Selecting a file name of a file, which does not exist, will result in an
error message.

1-12 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMainForm.LoadPlotData1Click
LoadPlotData1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure LoadPlotData1Click is an event handler activated by clicking once on the menu
item "File/Load Recorded Data". A Windows system dialog appears allowing for the selection
of a file name of a so-called documentation file (extension *.PLD), from which measured data
are to be read (ReadPlot). Selecting a file, which does not exist will result in an error message.

TMainForm.SavePlot1Click
SavePlot1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure SavePlot1Click is an event handler activated by clicking once on the menu item
"File/Save Recorded Data". A Windows system dialog appears allowing for the selection of a file
name of a so-called documentation file (extension *.PLD), to which measured data contained in
the memory are to be written (WritePlot). An error message will appear, when the data could not
be written successfully to the selected file.

TMainForm.Print1Click
Print1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Print1Click is an event handler activated by clicking once on the menu item
"File/Print". A modal dialog (PrintPlotDlg) appears to select previously created plot windows,
which are to be printed to an output device (i.e. printer).

TMainForm.PrintSetup1Click
PrintSetup1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PrintSetup1Click is an event handler activated by clicking once on the menu item
"File/Print Setup". The standard printer setup dialog of Windows is called to select and adjust the
output device.

DR300 Speed Control Windows Software V1.0 1-13


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.ExitItemClick
ExitItemClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure ExitItemClick is an event handler activated by clicking once on the menu item
"File/Exit" or by pressing Shift+F4. The current application, the program DR300W16 will be
terminated.

TMainForm.IOInterface1Click
IOInterface1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure IOInterface1Click is an event handler activated by clicking once on the menu
item "IO-Interface". The following three menu items to select an adapter card driver for the
DAC98, DIC24 or DAC6214 are enabled only, when the corresponding driver exists in the current
directory. The menu item to select the dialog for adjusting the adapter card address is enabled
only, when one of the above drivers is marked.

TMainForm.DAC98Click
DAC98Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure DAC98Click is an event handler activated by clicking once on the menu item
"IO-Interface/DAC98". The name of the driver file DAC98.DRV is written to the file DR300.INI.
After stopping the timer (StopTimer) controlling the sampling period of the controller the driver
DAC98.DRV is selected for the DRSRV16.DLL (SelectDriver). Error messages will appear,
when stopping the timer or selecting the driver failed. The check marks of the corresponding menu
item are set accordingly and the dialog DACSetupClick to adjust the adapter card address is
called automatically.

1-14 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMainForm.DIC24Click
DIC24Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure DIC24Click is an event handler activated by clicking once on the menu item
"IO-Interface/DIC24". The name of the driver file DIC24.DRV is written to the file DR300.INI.
After stopping the timer (StopTimer) controlling the sampling period of the controller the driver
DIC24.DRV is selected for the DRSRV16.DLL (SelectDriver). Error messages will appear,
when stopping the timer or selecting the driver failed. The check marks of the corresponding menu
item are set accordingly and the dialog DACSetupClick to adjust the adapter card address is
called automatically.

TMainForm.DAC6214Click
DAC6214Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure DAC6214Click is an event handler activated by clicking once on the menu item
"IO-Interface/DAC6214". The name of the driver file DAC6214.DRV is written to the file
DR300.INI. After stopping the timer (StopTimer) controlling the sampling period of the
controller the driver DAC6214.DRV is selected for the DRSRV16.DLL (SelectDriver). Error
messages will appear, when stopping the timer or selecting the driver failed. The check marks of
the corresponding menu item are set accordingly and the dialog DACSetupClick to adjust the
adapter card address is called automatically.

TMainForm.DACSetupClick
DACSetupClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure DACSetupClick is an event handler activated by clicking once on the menu item
"IO-Interface/Setup". After stopping the timer (StopTimer) controlling the sampling period of
the controller the dialog SetupDriver of the TIMER16.DLL appears to adjust the adapter card
address of the corresponding driver. Error messages will be presented, when stopping the timer
failed or when the dialog could not adjust the address correctly. Terminating this dialog will restart
the timer.

DR300 Speed Control Windows Software V1.0 1-15


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.Edit1Click
Edit1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Edit1Click is an event handler activated by clicking once on the menu item "Edit".
The menu items "Use Tacho" and "Use Encoder" for the active speed sensor are enabled according
to the current selection.

TMainForm.PIControllerSetupClick
PIControllerSetupClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure PIControllerSetupClick is an event handler activated by clicking once on the
menu item "Edit/PI Controller Setup". The modal dialog (PIParameterDlg) will appear to display
and adjust the parameters of the PI controller.

TMainForm.FuzzyControllerSetupClick
FuzzyControllerSetupClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure FuzzyControllerSetupClick is an event handler activated by clicking once on the
menu item "Edit/Fuzzy Controller Setup". The modal dialog (FuzzyParameterDlg) will appear
to display and adjust all the parameters of the fuzzy controller.

TMainForm.useEncoder1Click
useEncoder1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure useEncoder1Click is an event handler activated by clicking once on the menu
item "Edit/Use Encoder". The active speed sensor is set to encoder type. This setting is written to
DR300.INI and to the parameter structure param which is transferred to DRSRV16.DLL. Then
the check marks for the active speed sensor are set accordingly.

1-16 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMainForm.UseTacho1Click
UseTacho1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure UseTacho1Click is an event handler activated by clicking once on the menu item
"Edit/Use Tacho". The active speed sensor is set to tacho type. This setting is written to DR300.INI
and to the parameter structure param which is transferred to DRSRV16.DLL. Then the check
marks for the active speed sensor are set accordingly.

TMainForm.Run1Click
Run1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure Run1Click is an event handler activated by clicking once on the menu item "Run".
At first all its sub menu items except for "Stop Controller" are enabled. As long as no controller
is selected the menu items to select the PI controller and the fuzzy controller remain enabled in
case of correct controller parameters and the menu item to stop a controller is disabled. In case
of parameter errors the corresponding menu item will be disabled. The menu item to stop a
controller will be enabled when one of the controllers is active.

TMainForm.PIController1Click
PIController1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PIController1Click is an event handler activated by clicking once on the menu
item "Run/PI Controller" or by pressing "F2". The parameter structure param is read from the
DRSRV16.DLL (GetParameter) and its element for the controller type is set to
PICONTROLLER. The check mark for the selected PI controller is set. The parameters of the
two setpoint/control signal generators are reset only when no controller was active previously.
Then the structure param is transferred (SetParameter) to the DRSRV16.DLL. The timer for the
monitor update is disabled during the last operation.

DR300 Speed Control Windows Software V1.0 1-17


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.FuzzyController2Click
FuzzyController2Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FuzzyController2Click is an event handler activated by clicking once on the menu
item "Run/Fuzzy Controller" or by pressing "F3". The parameter structure param is read from
the DRSRV16.DLL (GetParameter) and its element for the controller type is set to
FUZZYCONTROLLER. The check mark for the selected fuzzy controller is set. The parameters
of the two setpoint/control signal generators are reset only when no controller was active
previously. Then the structure param is transferred (SetParameter) to the DRSRV16.DLL. The
timer for the monitor update is disabled during the last operation.

TMainForm.OpenLoopControl1Click
OpenLoopControl1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure OpenLoopControl1Click is an event handler activated by clicking once on the
menu item "Run/Open Loop Control" or by pressing "F6". The parameter structure param is read
from the DRSRV16.DLL (GetParameter) and its element for the controller type is set to
IDENTIFICATION. The check mark for the selected open loop control is set. The parameters of
the two setpoint/control signal generators are reset. Then the structure param is transferred
(SetParameter) to the DRSRV16.DLL. The timer for the monitor update is disabled during the
last operation.

TMainForm.StopController1Click
StopController1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure StopController1Click is an event handler activated by clicking once on menu
item "Run/Stop Controller" or by pressing "F7". The check marks as well as the corresponding
controller flags of the structure param are reset. This structure is then transferred (SetParameter)
to the DRSRV16.DLL.

1-18 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMainForm.StartMeasuring1Click
StartMeasuring1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure StartMeasuring1Click is an event handler activated by clicking once on the menu
item "Run/Start Measuring" or by pressing "F4". The conditions of a measurement acquisition
are adjusted by means of the following modal dialog MeasureDlg.

TMainForm.SetpointGenerator1Click
SetpointGenerator1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure SetpointGenerator1Click is an event handler activated by clicking once on the
menu item "Run/Setpoint Generator" or by pressing "F5". The conditions for the speed setpoint
or the control signal of the motor as well as the control signal of the generator are adjusted by
means of the following dialog GeneratorDlg.

TMainForm.View1Click
View1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure View1Click is an event handler activated by clicking once on the menu item
"View". The following menu items "Plot Measured Data", "Plot File Data" and "Parameters from
*.PLD File" are enabled only, when the memory contains data either from a previous measurement
acquisition or after selecting a so-called documentation file. The "Timing" menu item is disabled
only, when the program is a DEMO version.

TMainForm.PlotMeasuredData1Click
PlotMeasuredData1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PlotMeasuredData1Click is an event handler activated by clicking once on the
menu item "View/Plot Measured Data". Those curves of a previous measurement acquisition are
selected by means of the following dialog PlotDlg, which are to be presented in a plot window.

DR300 Speed Control Windows Software V1.0 1-19


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.PlotFileData1Click
PlotFileData1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PlotFileData1Click is an event handler activated by clicking once on the menu
item "View/Plot File Data". Those curves of a loaded documentation file are selected by means
of the following dialog PlotDlg, which are to be presented in a plot window.

TMainForm.ParametersfromPLDFile1Click
ParametersfromPLDFile1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure ParametersfromPLDFile1Click is an event handler activated by clicking once


on the menu item "View/Parameters from *.PLD File". The parameters of the documentation file
are displayed in a window by means of the following dialog PLDInfoDlg.

TMainForm.Fuzzy3D1Click
Fuzzy3D1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure Fuzzy3D1Click is an event handler activated by clicking once on the menu item
"View/Fuzzy 3D". The following dialog Show3DFuzDlg will present a plot window containing
the 3-dimensional characteristic of a selectable fuzzy description file.

TMainForm.Timing1Click
Timing1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Timing1Click is an event handler activated by clicking once on the menu item
"View/Timing". The visibility of a timing window (TimingForm) is toggled. It displays a statistic
graphic and the minimum and maximum values of the sampling period in [ms].

1-20 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMainForm.Contents1Click
Contents1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Contents1Click is activated by clicking once on the menu item "Help/Contents"
to display the contents of the help file DR300.HLP.

TMainForm.SearchforHelpon1Click
SearchforHelpon1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure SearchforHelpon1Click is activated by clicking once on the menu item
"Help/Search for Help On..." to start the Windows dialog to search for defined keywords.

TMainForm.HowtoUseHelp1Click
HowtoUseHelp1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure HowtoUseHelp1Click is activated by clicking once on the menu item "Help/How
to Use Help" to start the Windows dialog displaying hints how to use the help function.

TMainForm.About1Click
About1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure About1Click is activated by clicking once on the menu item "Help/About..." to
display a window containing information about the program.

DR300 Speed Control Windows Software V1.0 1-21


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TMainForm.Timer1Timer
Timer1Timer(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Timer1Timer is called every 100 ms by means of a timer. The data structure data
of the controller in the DRSRV16.DLL is read. When the controller type was changed, the
parameter structure param is read in addition and the function StopController1Click is called
when no controller is active. In case the DoService function of the DLL returned an error the flag
for the timer of the sampling period is set to TERR_FAIL and the function StopController1Click
is called. Then the contents of the monitor in the main window are updated. This includes the
current controller type, the speed setpoint, the measured values for the motor speed, the control
signals as well as the measured currents of the motor and the generator, the state of the
measurement acquisition as well as an updated animation picture.

TMainForm.PaintBox1Click
PaintBox1Click(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PaintBox1Click is activated by moving the mouse above the animation picture
and pressing any mouse button. The setpoint generator dialog (by means of
SetpointGenerator1Click) is called directly.

TMainForm.MeasLabelClick
MeasLabelClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure MeasLabelClick is activated by moving the mouse above the area displaying the
progress of the measurement acquisition and pressing any mouse button. The measurement
acquisition dialog (by means of StartMeasuring1Click) is called directly.

1-22 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TSingleInstance.WndProc
WndProc(var Msg : TMessage)

Parameters: var Msg is the current Windows system message received by this virtual window.
Description The procedure WndProc is a Windows message handler for the virtual window of type
SingleInstance, which determines by checking the parameters Msg, wParam and lParam if an
instance of this application was called already. In this case this application is terminated.

TAboutBox.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure FormShow is called, when the object of type TAboutBox is displayed on the
screen. Short information about the program (name, version, copyright, required PC adapter card)
are presented in a window.

TShow3DFuzDlg.rescale
rescale

Description The procedure rescale calculates the scaling factors as well as initial values for the axes X, Y and
Z such that the value ranges of the 3 fuzzy variables may be displayed in a cube with an edge
length of 255.

TShow3DFuzDlg.recalc
recalc

Description The procedure recalc calculates the values of the fuzzy output variable for the complete value
ranges of the fuzzy input variables with respect to the currently selected step width and based on
the fuzzy object contained in the memory. The calculated vales are stored to the byte field dat.

DR300 Speed Control Windows Software V1.0 1-23


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TShow3DFuzDlg.calcrot
calcrot

Description The procedure calcrot calculates the values of the Euler rotation matrix depending on the rotation
angles a and b. The angle a defines the rotation around the X-axis while the angle b defines the
rotation around the Y-axis.

TShow3DFuzDlg.calctrans
calctrans( ix,iy,iz : double; var ox,oy,oz : double )

Parameters: ix x-co-ordinate original point.


iy y-co-ordinate original point.
iz z-co-ordinate original point.
var ox x-co-ordinate after rotation and projection.
var oy y-co-ordinate after rotation and projection.
var oz z-co-ordinate after rotation and projection.
Description The procedure calctrans calculates new co-ordinates for the 3-dimensional Cartesian
co-ordinates of an original point by applying the Euler rotation matrix and calculating the
projection to a fixed Y-plane.

1-24 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TShow3DFuzDlg.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormShow is called, when the object of type TShow3DFuzDlg is displayed on
the screen. The dialog "Show Fuzzy 3D" appears to present the 3-dimensional characteristic of a
fuzzy controller with two input variables and one output variable. The attributes of the
characteristic itself are changeable interactively by setting checkboxes, scrollbars or by moving
the mouse. Initial values are defined for a bitmap of suitable size, the step width for the
characteristic, the co-ordinates of the observer position as well as for the projection plane. The
step width determines the number of partial areas along the X-axis and the Y-axis. The last settings
for the rotation angles around the X-axis and around the Y-axis are read from DR300.INI. The
listbox to select a fuzzy description file is filled with the name of the current "fuzzy-controller"
file. The name of this file is taken from the structure param. The checkbox to mark the current
operating point is enabled only, when the active controller is a fuzzy controller. The characteristic
for the first fuzzy description file is displayed automatically by FuzzyBoxChange as a bitmap in
the left field of the dialog. The mapping of the characteristic is calculated such that an observer
looks in the middle of a cube placed behind the screen, where the cube is surrounding the
characteristic.

TShow3DFuzDlg.FormHide
FormHide(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormHide is called, when the object of type TShow3DFuzDlg has to disappear
from the screen. The checkbox to mark the operating point in the characteristic as well as the
timer are disabled, the bitmap is released. The last settings for the rotation angles around the
X-axis and around the Y-axis are written to DR300.INI.

DR300 Speed Control Windows Software V1.0 1-25


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TShow3DFuzDlg.FuzzyCBoxChange
FuzzyCBoxChange(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FuzzyCBoxChange generates a new fuzzy object with respect to the currently
fuzzy description file, which was selected from the listbox. When the selected file does not exist,
a corresponding error message is presented. The text field below the listbox will contain the
updated names and value ranges of the fuzzy variables belonging to the fuzzy object with two
input variables and one output variable. The fuzzy variables are assigned to the X-, Y- and Z-axis
accordingly. The corresponding characteristic is calculated and displayed as a bitmap. At the end
the fuzzy object is removed again from the memory. A possibly running timer is stopped during
the run-time of this procedure.

TShow3DFuzDlg.DrawSquare
DrawSquare( can : TCanvas; j, i, z0, z1, z2, z3 : Integer )

Parameters: can is an identifier for a device context.


j is the index of the partial area along the X-axis.
i is the index of the partial area along the Y-axis.
z0 is the edge point 1 (Z-value) of the partial area.
z1 is the edge point 2 (Z-value) of the partial area.
z2 is the edge point 3 (Z-value) of the partial area.
z3 is the edge point 4 (Z-value) of the partial area.

Description The procedure DrawSquare draws the partial area defined by its edge points (zo, z1, z2, z3) taken
as base points with respect to the Z-axis and defined by the indexes (j, i) along the X- and Y-axis
as a polygon on the projection plane, which is identified by the device context can. The appearance
of the polygon depends on the setting of further checkboxes. The polygon gets a black coloured
frame, when "Grid" (GridCBox) is set, is displayed as a surface, when "Surface" (SurfaceCBox)
is set, the surface is drawn with a grey scale with decreasing darkness for increasing Z-values or
with a colour changing from red to blue, when "Colour" (ColorCBox) is set in addition.

1-26 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TShow3DFuzDlg.DrawCoors
DrawCoors( can : TCanvas )

Parameters: can is an identifier for a device context.


Description The procedure DrawCoors draws the edges of the cube surrounding the characteristic as black
coloured lines on the projection plane identified by the device context can.

TShow3DFuzDlg.DrawCoors2
DrawCoors2( can : TCanvas )

Parameters: can is an identifier for a device context.


Description The procedure DrawCoors2 draws the 3-dimensional axes crossing in the middle of the cube
surrounding the characteristic as black coloured lines on the projection plane identified by the
device context can.

TShow3DFuzDlg.DrawMark
DrawMark( can : TCanvas )

Parameters: can is an identifier for a device context.


Description The procedure DrawMark draws the partial area, which is nearest to the current operating point
of the fuzzy controller, as a green coloured area on the projection plane identified by the device
context can. The operating point results from the current sensor values or its differentiations (see
parameter structure data) with respect to the currently selected fuzzy description file.

TShow3DFuzDlg.PaintBoxPaint
PaintBoxPaint(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PaintBoxPaint calculates a new bitmap representing a complete characteristic and
copies this bitmap to the screen memory only, when needRedraw is set. The complete
characteristic consists of the partial areas defined by its base points contained in the byte field
dat. The characteristic is completed by the edges of the cube, by the axes crossing or marking of
the operating point, when the checkboxes "Co-ordinate box" (KoorsCBox), "Co-ordinate system"
(Koors2CBox) or "Mark" (MarkCBox) are set accordingly.

DR300 Speed Control Windows Software V1.0 1-27


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TShow3DFuzDlg.ScrollBar1Change
ScrollBar1Change(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure ScrollBar1Change maps the current position of the scroll mark to an angle in the
range from -180 to +180, which is taken as a rotation angle around the X-axis. If the absolute
change of the rotation angle is greater than 18, the characteristic is updated by means of
PaintBoxPaint.

TShow3DFuzDlg.ScrollBar2Change
ScrollBar2Change(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure ScrollBar2Change maps the current position of the scroll mark to an angle in the
range from 0 to 360, which is taken as a rotation angle around the Y-axis. If the absolute change
of the rotation angle is greater than 18, the characteristic is updated by means of PaintBoxPaint.

TShow3DFuzDlg.PaintBoxMouseDown
PaintBoxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);

Parameters: Sender is a reference to the calling object.


Button is the number of the mouse button.
Shift is the state of the shift-key.
X, Y is the position of the mouse.
Description The procedure PaintBoxMouseDown is called, when the mouse is moved above the bitmap field
to display the characteristic and when a mouse button is pressed. If the left mouse button is pressed
the global co-ordinates lastX, lastY are set equal to the mouse position and the variable lastBtn is
set to TRUE.

1-28 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TShow3DFuzDlg.PaintBoxMouseMove
PaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

Parameters: Sender is a reference to the calling object.


Button is the number of the mouse button.
Shift is the state of the shift-key.
X, Y is the position of the mouse.
Description The procedure PaintBoxMouseMove is called, when the mouse is moved above the bitmap field
to display the characteristic. If the variable lastBtn is set at the same time the current mouse
position is mapped to new positions of the scrollbars to define the rotation angles around the
X-axis and the Y-axis. The modified scrollbar positions (be means of ScrollBar1Change,
ScrollBar2Change) will then result in an updated output with a rotated characteristic.

TShow3DFuzDlg.PaintBoxMouseUp
PaintBoxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);

Parameters: Sender is a reference to the calling object.


Button is the number of the mouse button.
Shift is the state of the shift-key.
X, Y is the position of the mouse.
Description The procedure PaintBoxMouseUp is called, when the mouse is moved above the bitmap field to
display the characteristic and when none of the mouse buttons is pressed. The variable lastBtn is
reset.

TShow3DFuzDlg.KoorsCBoxClick
KoorsCBoxClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure KoorsCBoxClick is an event handler activated by clicking once on the checkbox
"Coordinate box". The output of the characteristic is with or without a surrounding cube according
to the new setting of the checkbox.

DR300 Speed Control Windows Software V1.0 1-29


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TShow3DFuzDlg.Koors2CBoxClick
Koors2CBoxClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Koors2CBoxClick is an event handler activated by clicking once on the checkbox
"Coordinate system". The output of the characteristic is with or without an axes crossing according
to the new setting of the checkbox.

TShow3DFuzDlg.ColorCBoxClick
ColorCBoxClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure ColorCBoxClick is an event handler activated by clicking once on the checkbox
"Colour". The output of the characteristic is with grey or coloured partial areas according to the
new setting of the checkbox.

TShow3DFuzDlg.LowResCBoxClick
LowResCBoxClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure LowResCBoxClick is an event handler activated by clicking once on the checkbox
"Low resolution". The updated output displays the characteristic with smaller (step width = 12)
or greater (step width = 25) partial areas according to the new setting of the checkbox.

TShow3DFuzDlg.PrintBBtnClick
PrintBBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PrintBBtnClick is an event handler activated by clicking once on the "Print"
button of the "Show Fuzzy 3D" dialog. The Windows system dialog appears to select an output
device for the hardcopy of the complete "Show Fuzzy 3D" dialog.

1-30 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TShow3DFuzDlg.MarkCBoxClick
MarkCBoxClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure MarkCBoxClick is an event handler activated by clicking once on the checkbox
"Mark". The updated output of the characteristic will contain a partial area indicating the current
operating point according to the setting of the checkbox. The timer state is set equal to the setting
of the checkbox, that means when the operating point is to be indicated the timer will produce an
updated characteristic periodically.

TShow3DFuzDlg.Timer1Timer
Timer1Timer(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure Timer1Timer is called by a timer every 200ms, as long as this timer is enabled.
The state of the timer is set equal to the setting of the checkbox "Mark". The output of the
characteristic is updated.

TShow3DFuzDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the "Show Fuzzy 3D" dialog. The corresponding section of the help file DR300.HLP will be
displayed in a window on the screen.

TFuzzyParameterDlg.Big
Big

Description The procedure Big expands the dialog by another edit field below the dialog and two additional
button. The content of the edit field is erased.

DR300 Speed Control Windows Software V1.0 1-31


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TFuzzyParameterDlg.Small
Small

Description The procedure Small removes the edit field and its accompanying two buttons from the lower
part of the dialog. The content of the edit field is erased. The name of the fuzzy description file
belonging to the edit field is reset to NONAME.FUZ.

TFuzzyParameterDlg.FormCreate
FormCreate(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormCreate creates an instance of type TFuzzyParameterDlg. A string list is
generated to store the names of the fuzzy description files.

TFuzzyParameterDlg.FormDestroy
FormDestroy(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormDestroy is called before the object of type TFuzzyParameterDlg is removed
from the memory. The string list containing the names of the fuzzy is erased.

TFuzzyParameterDlg.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormShow is called, when the object of type TFuzzyParameterDlg is displayed
on the screen. At first only the upper part of the "Fuzzy Controller Parameter" dialog is presented
containing a field with the label "Fuzzy Controller File", and the name of the accompanying fuzzy
description file. This name is read from the structure param. If this file does not exist a
corresponding error message will appear.

1-32 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TFuzzyParameterDlg.Sel1BBtnClick
Sel1BBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure Sel1BBtnClick is an event handler activated by clicking once on one of the
"Select" buttons of the "Fuzzy Controller Parameter" dialog. A Windows system dialog will
appear to select the name of a fuzzy description file (extension *.FUZ). The selected name will
be displayed left to the "Select" button, when an existing file was chosen.

TFuzzyParameterDlg.Ed1BBtnClick
Ed1BBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure Ed1BBtnClick is an event handler activated by clicking once on one of the "Edit"
buttons of the "Fuzzy Controller Parameters" dialog. The dialog will be expanded by an edit field
and two additional buttons ("Save", "Abort"). If the fuzzy description file with the name displayed
at the left side in the field of the activated "Edit" button exists its content is shown in the edit field
(variable Memo1). Typical edit functions are now allowed inside the edit field.

TFuzzyParameterDlg.CancelEdBBtnClick
CancelEdBBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure CancelEdBBtnClick is an event handler activated by clicking once on the "Abort"
button of the dialog extension. The edit field will be removed from the dialog and its content will
be erased.

TFuzzyParameterDlg.SaveEdBBtnClick
SaveEdBBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure SaveEdBBtnClick is an event handler activated by clicking once on the "Save"
button of the dialog extension. The content of the edit field is stored to the open fuzzy description
file. An error message will appear, when the saving procedure fails. Then the edit field will be
removed from the dialog and its content will be erased.

DR300 Speed Control Windows Software V1.0 1-33


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TFuzzyParameterDlg.OKBtnClick
OKBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure OKBtnClick is an event handler activated by clicking once on the "Reload" button
of the "Fuzzy Controller Parameters" dialog. The name of the currently selected fuzzy description
file is written to the structure param. Then this fuzzy description file is reloaded and the
accompanying object is generated. Errors occurred during reloading the description file or errors
generated with the new creation of the fuzzy object are displayed in corresponding error messages.

TFuzzyParameterDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the "Fuzzy Controller Parameters" dialog. The corresponding section of the help file
DR300.HLP will be displayed in a window on the screen.

TMeasureDlg.OKBtnClick
OKBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure OKBtnClick is an event handler for clicking once on the "Ok" button from the
dialog "Setup Measuring Function" to adjust the conditions for the measurement acquisition. The
contents of three input fields are converted to numbers for the total measuring time (time = 0 to
1000 sec), for the time before reaching the trigger condition (prestore = 0 to measuring time) and
for the trigger level (trigger = -3000 to 3000, or -10 to 10 in case of open loop control) only when
none of the numbers exceeds the valid range. Two further groups of radio buttons are used to
determine the trigger channel tchannel as well as the trigger condition slope. The trigger condition
is either not existing or defined as a slope, meaning that the measured value of the trigger channel
has to exceed the trigger level either in positive or in negative direction. The measuring is started
directly after terminating the dialog. Trigger values are the setpoint for the motor speed position,
the measured values for the speed and the current of motor/generator as well as the control signals.

1-34 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TMeasureDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the "Setup Measuring Function" dialog. The corresponding section of the help file DR300.HLP
will be displayed in a window on the screen.

TPIParameterDlg.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure FormShow is called, when the object of type TPIParameterDlg is displayed on
the screen. The edit fields for the PI controller parameters are filled with the strings obtained from
converting the corresponding parameters of the structure param. An exception message will
appear, when the conversions failed.

TPIParameterDlg.OKBtnClick
OKBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure OKBtnClick is an event handler for clicking once on the "Ok" button from the
dialog "PI Controller Parameters". The contents of the edit fields of this dialog are converted to
numbers and stored to the structure param. An exception message will appear, when the
conversions failed.

TPIParameterDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the "PI Controller Parameters" dialog. The corresponding section of the help file DR300.HLP
will be displayed in a window on the screen.

DR300 Speed Control Windows Software V1.0 1-35


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TPLDInfoDlg.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormShow is called, when the object of type TPLDInfoDlg is displayed on the
screen. The controller settings of a loaded so-called documentation file are displayed in a "PLD
Information" window. The controller settings include the controller type (PI controller, fuzzy
controller, open loop control, no controller). the time of the measurement acquisition as well as
the sampling rate of the measurement.

TPLDInfoDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the "PLD Information" dialog. The corresponding section of the help file DR300.HLP will be
displayed in a window on the screen.

TPlotDlg.OKBtnClick
OKBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure OKBtnClick is an event handler for clicking once on the "Ok" button from the
dialog "Select Plot Data" to select the channels of a measuring which are to be represented in a
plot window. The selectable channels are the measured value and setpoint of the motor speed, the
measured speed and current of motor/current as well as the control signals for the two devices.
The selected channel is presented in a graphic on the screen by calling PlotMeas.

TPlotDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the dialog "Select Plot Data" to select the channels of a measuring which are to be represented
in a plot window. The corresponding section of the help file DR300.HLP will be displayed in a
window on the screen.

1-36 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TPrintPlotDlg.PrinterBitBtnClick
PrinterBitBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PrinterBitBtnClick is an event handler for clicking once on the "Printer" button
from the dialog to select previously created plot windows. A modal Windows system dialog
appears that permits the user to select which printer to print to, how many copies to print and
further print options.

TPrintPlotDlg.OKBtnClick
OKBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure OKBtnClick is an event handler for clicking once on the "Ok" button from the
dialog to select previously created plot windows. All of the plot windows selected from the list
box are printed directly to the current output device (by means of the function PrintPlotMeas).
When multiple plot windows are selected an offset of 150 mm (counted from the upper margin
of a DIN A4 page) is added before every second print output and a form feed follows this output.

TPrintPlotDlg.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure FormShow is called, when the object of type TPrintPlotDlg is displayed on the
screen. At first all titles of the previously created plot windows are inserted in a listbox.

TPrintPlotDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure HelpBtnClick is an event handler for clicking once on the "Help" button from the
dialog to select previously created plot windows. The accompanying section of the help file
DR300.HLP will be displayed in a window on the screen.

DR300 Speed Control Windows Software V1.0 1-37


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TGeneratorDlg.OKBtnClick
OKBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure OKBtnClick is an event handler for clicking once on the "Ok" button from the
dialog "Speed Setpoint / Control Signal Generator" to adjust the setpoint for the motor speed and
the control signal for the generator. For the setpoint as well as for the control signal the signal
shape is selectable by radio buttons (constant, rectangle, triangle, ramp, sine) and an offset, an
amplitude as well as a time period are adjustable by input fields. The period is meaningless in
case of a constant signal shape. The real signal is always built by the sum of offset and amplitude.
The valid value ranges are -3000 to +3000 rpm for the setpoint’s offset, -6000 to +6000 rpm for
the its amplitudes. In case of open loop control the valid ranges are -10 to +10 V for the offsets
and amplitudes of the control signals. In both cases 0 - 1000 sec is the valid range for the periods.
Only when none of the corresponding number exceeds the valid value range, the numbers are
stored in the parameter structure param which is then transferred to the controller in the
DRSRV16.DLL. Finally the dialog is terminated and the generators start operating with the next
sampling period.

TGeneratorDlg.FormShow
FormShow(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure FormShow is called, when the object of type TGeneratorDlg is displayed on the
screen. The input fields as well as the radio buttons to adjust the generators for the motor speed
setpoint (or control signal in the open loop case) as well as the control signal for the generator are
preset according to the parameters of the global parameter structure param.

TGeneratorDlg.HelpBtnClick
HelpBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure HelpBtnClick is an event handler activated by clicking once on the "Help" button
in the dialog "Speed Setpoint / Control Signal Generator". The corresponding section of the help
file DR300.HLP will be displayed in a window on the screen.

1-38 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

TTimingForm.UpdateData
UpdateData

Description The procedure UpdateData is called periodically with the update rate of the main window (timer
in TMainForm). The structure tim (type ServiceTiming) is read (GetTiming) from
DRSRV16.DLL. Its elements number of sampling periods as well as the minimum and maximum
values of the real sampling period are displayed in the "DR300 Timing" dialog. The graphic with
the statistic values of the sampling periods is updated in addition.

TTimingForm.HideButtonClick
HideButtonClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure HideButtonClick is an event handler activated by clicking once on the "Hide"
button in the "DR300 Timing" dialog. The procedure TMainForm.Timing1Click will reset the
visibility of the "DR300 Timing" dialog.

TTimingForm.HelpButtonClick
HelpButtonClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure HelpButtonClick is an event handler activated by clicking once on the "Help"
button in the dialog "DR300 Timing". The corresponding section of the help file DR300.HLP
will be displayed in a window on the screen.

TTimingForm.PaintBox1Paint
PaintBox1Paint(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PaintBox1Paint is activated by every paint message of the system or indirectly
by UpdateData in case of a visible "DR300 Timing" dialog. Twenty bars (rectangles) are painted
along the head line (axis with values from 0 to 19 [ms])with a height according to the statistic
values of the structure tim.

DR300 Speed Control Windows Software V1.0 1-39


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TTimingForm.PaintBox2Paint
PaintBox2Paint(Sender : TObject)

Parameters: Sender is a reference to the calling object.


Description The procedure PaintBox2Paint is activated by every paint message of the system in case of a
visible "DR300 Timing" dialog. The head line (axis with values from 0 to 19 [ms]) for the statistic
graphic of the frequency of values of the sampling period is painted.

TTimingForm.ResetBtnClick
ResetBtnClick(Sender : TObject)

Parameters: Sender is a reference to the calling object.

Description The procedure ResetBtnClick is an event handler activated by clicking once on the "Reset" button
in the "DR300 Timing" dialog. The number of sampling periods in the structure tim is reset to -1
which in advance will reset the minimum and maximum as well as the statistic values by calling
UpdateData and with this calling GetTiming.

FloatToStr2
FloatToStr2( f : Single ) : string

Parameters: f is the floating point value, which is to be converted.


Description The function FloatToStr2 converts a floating point value (4 bytes for single) to its string
representation with a maximum of 7 significant digits and 2 digits behind the decimal point.
Return Is the string representation of the floating point value.

FloatToStr3
FloatToStr3( f : Single ) : string

Parameters: f is the floating point value, which is to be converted.


Description The function FloatToStr3 converts a floating point value (4 bytes for single) to its string
representation with a maximum of 7 significant digits and 3 digits behind the decimal point.
Return Is the string representation of the floating point value.

1-40 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

FloatToStr4
FloatToStr4( f : Single ) : string

Parameters: f is the floating point value, which is to be converted.


Description The function FloatToStr4 converts a floating point value (4 bytes for single) to its string
representation with a maximum of 7 significant digits and 4 digits behind the decimal point.
Return Is the string representation of the floating point value.

FloatToStr5
FloatToStr5( f : Single ) : string

Parameters: f is the floating point value, which is to be converted.

Description The function FloatToStr5 converts a floating point value (4 bytes for single) to its string
representation with a maximum of 7 significant digits and 5 digits behind the decimal point.
Return Is the string representation of the floating point value.

StrToFloatMinMax
StrToFloatMinMax( s : string; min,max : double ) : double

Parameters: s is the string representation of a floating point value.


min is the lower limit for a floating point value.
max is the upper limit for a floating point value.
Description The function StrToFloatMinMax converts a string to the corresponding floating point value.
When this value exceeds the lower or upper limit it is set equal to the exceeded limit and a
corresponding message appears on the screen.
Return Is the possibly limited floating point value.

DR300 Speed Control Windows Software V1.0 1-41


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

StrToFloatStrMinMax
StrToFloatStrMinMax( s : string; var val : double; min,max : double ) : string

Parameters: s is the string representation of the floating point value.


var val is on return the possibly limited floating point value.
min is the lower limit for a floating point value.
max is the upper limit for a floating point value.
Description The function StrToFloatStrMinMax converts a string to the corresponding floating point value.
When this value exceeds the lower or upper limit it is set equal to the exceeded limit and a
corresponding message appears on the screen. The possibly limited floating point value is again
converted to its string representation with a maximum of 7 significant digits and 3 digits behind
the decimal point.
Return Is the string representation of the possibly limited floating point value.

MinMaxi
MinMaxi( val, min, max : Integer ) : Integer

Parameters: val is the integer value, which is to be checked.


min is the lower limit for an integer value.
max is the upper limit for an integer value.
Description The function MinMaxi checks if an integer value is inside a limited range. When the integer value
exceeds the lower or upper limit it is set equal to the nearest limit.
Return Is the possibly limited integer value.

DetectNT
DetectNT : Boolean

Description The function DetectNT returns TRUE, when the file NTOSKRNL exists in the Windows system
directory, otherwise it returns FALSE. An error message is presented if the Windows system
directory does not exist. It is assumed that the existence of the file means an operating NT system
and a 16 bit application will not run with a NT system.
Return Returns TRUE, when NTOSKRNL.EXE exists, else FALSE.

1-42 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.4 Overview of Classes and DLL Interfaces

The files DRSRV16.H, DRSRV16.CPP contain:


int CALLBACK LibMain( HINSTANCE hInstance, WORD wDatenSeg, WORD cbHeapSize, LPSTR
lpCmdLine )

int CALLBACK WEP( int nParameter )


BOOL CALLBACK LockMemory( BOOL bStart, HDRVR hDrv )
BOOL CALLBACK SetDriverHandle( HDRVR hDrv )
BOOL CALLBACK DoService( DWORD counter )
BOOL CALLBACK SetParameter( WORD wSize, LPSTR lpData )
BOOL CALLBACK GetParameter( WORD wSize, LPSTR lpData )
BOOL CALLBACK GetData( WORD wSize, LPSTR lpData )
BOOL CALLBACK GetTiming( WORD wSize, LPSTR lpData )

BOOL CALLBACK ReadFuzzy( void )


BOOL CALLBACK ReadPIPar( char* name )
BOOL CALLBACK WritePIPar( char* name )

BOOL CALLBACK IsDemo( void )


int CALLBACK MeasureStart( double time, double trigger, double prestore, int tchannel, int slope )
double CALLBACK MeasureLevel( void )
int CALLBACK MeasureStatus( void )

The files FUZZY.H, FUZZY3D.CPP contain:


int CALLBACK OpenFuzzy3D( char* filename )
int CALLBACK CloseFuzzy3D( void )
Fuzzy3DInfo* CALLBACK InfoFuzzy3D( void )
double CALLBACK CalcFuzzy3D( double x, double y )

The files DR300PI.H, DR300PI.CPP contain the class DR300STA with:


void DR300STA ( void )
void Calc( void )

void Reset( void )


int Load( char* name )
int Save( char* name )
double* GetKr( void )
double* GetTr( void )

DR300 Speed Control Windows Software V1.0 1-43


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

char* GetFileName( void )


char* GetIdName( void )
int geterrors( void )
void SetTa( float ta )

The files DR300FUZ.H, DR300FUZ.CPP contain the class DR300FUZ :


void DR300FUZ ( void )
void ~DR300FUZ ( void )
void Calc( void )
void Reset( void )
int Load( char* name )
int Save( char* name )
char* getname( void )
char* GetFileName( void )

char* GetIdName( void )


int geterrors( void )
void SetTa( float ta )

The files ARINGBUF.H, ARINGBUF.CPP contain:


class STOREBUF
void ResetBufIndex( void )
STOREBUF(int, float *)
~STOREBUF()
void StartMeasure( int, float, float, float, int , float )
void WriteValue( void )
void SetOutChan(int)
float ReadValue( void )
int GetBufLen( void )
float GetBufTa( void )
int GetStatus( void )

The files DRSIGNAL.H, DRSIGNAL.CPP contain:


class AFBUF
AFBUF()
~AFBUF()
int NewFBuf( int )
float ReadFBuf( void )
int WriteFBuf( float )
class TWOBUFFER
TWOBUFFER()

1-44 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

void New2Buffer( int , int, int )


int Write2Buffer( float )
float Read2Buffer( void )
class SIGNAL
SIGNAL()
float InitTime( float )
int MakeSignal( int , float, float, float, int )
float ReadNextValue( void )
void SetRange( float, float )
void WriteBuffer( float )
int Stuetzstellen( float, int )

The file PLOT.CPP contains:


class PLOT
int CALLBACK ReadPlot( char *lpfName )
int CALLBACK WritePlot( char *lpfName )
int CALLBACK Plot( int command, int channel )
int CALLBACK GetPlot( int start, char *lpzName )
int CALLBACK PrintPlot( int idx, HDC dcPrint, int iyOffset )
int CALLBACK GetPldInfo( int &controller, char **s, int &n, int &c, double &d )

DR300 Speed Control Windows Software V1.0 1-45


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

1.5 References of the DLL Interfaces

Global Data:

typedef struct{
WORD controller; // controller type (PI, fuzzy controller, open loop, none)
WORD encoder; // type of active speed sensor (encoder or tacho)
double kr; // proportional coefficient of PI controller
double tr; // integral coefficient of PI controller
char name[80]; // name of active fuzzy description file
WORD spshape; // shape of signal for motor (setpoint/control signal)
double spoffset; // offset of signal for motor (setpoint/control signal)
double spamplitude; // amplitude of signal for motor (setpoint/control signal)
double spperiod; // period of signal for motor (setpoint/control signal)
WORD splshape; // shape of control signal for generator (load)
double sploffset; // offset of control signal for generator (load)
double splamplitude; // amplitude of control signal for generator (load)
double splperiod; // period of control signal for generator (load)
WORD PIError; // error flag of PI controller
WORD fuzzyError; // error flag of fuzzy controller
}ServiceParameter ;

typedef struct{
double sdrive; // speed setpoint or control signal (open loop) for motor
double sload; // control signal for generator
double aspeed; // measured value of motor speed from tacho (analog)
double ispeed; // measured value of motor speed from encoder (incremental)
double curdrive; // measured value of motor current
double curload; // measured value of generator current
double odrive; // control signal for motor
double oload; // control signal for generator
double acc; // calculated acceleration of motor (for fuzzy controller)
WORD state; // state of controller (changed or stopped)
}ServiceData;

typedef struct{
longint n; // number of sampling periods
double min; // minimum value of sampling periods
double max; // maximum value of sampling periods
double v[20]; // array of statistic values of sampling periods
}ServiceTiming;

struct Fuzzy3DInfo{
long size; // current size of this structure
int idx; // index for the first input variable

1-46 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

int idy; // index for the second input variable


int idz; // index for the output variable
char xname[80]; // name of the first input variable
char yname[80]; // name of the second input variable
char zname[80]; // name of the output variable
double xmin; // minimum value of the first input variable
double xmax; // maximum value of the first input variable
double ymin; // minimum value of the second input variable
double ymax; // maximum value of the second input variable
double zmin; // minimum value of the output variable
double zmax; // maximum value of the output variable
};

ServiceParameter par is a global structure of type ServiceParameter (see also DRSRV16.H)


ServiceData dat is a global structure of type ServiceData (see also DRSRV16.H)
ServiceTiming tim is a global structure of type ServiceTiming (see also DRSRV16.H)
HGLOBAL mHnd is a handle for the code memory of the DRSRV16.DLL
UINT mData = 0 is a handle for the data memory of the DRSRV16.DLL
HDRVR hDriver = NULL is a handle for the adapter card driver (*.DRV)
DWORD dwCounter = 0L is a counter for calling the function DoService
WORD encoder = 0 is a flag for the active speed sensor
DICDRV *drv is a pointer to an instance of the class DICDRV (driver interface)
float scopebuf[ScopeBufSize] is the measurement-vector
STOREBUF *scope( ScopeBufSize, scopebuf, 1024)
is a pointer to an object to handle the storage of a maximum of 1024 elements of type scopebuf
SIGNAL *SpDriveGen is a pointer to a setpoint/control signal generator object for the motor
SIGNAL *SpLoadGen is a pointer to a control signal generator object for the generator
DR300STA *PICon is a pointer to a PI controller object
DR300FUZ *FuzzyCon is a pointer to a fuzzy controller object
int stopped is a flag for successful operations in DoService.
int changed is a flag for detecting multiple output stage release errors in DoService.
int locked is a flag for active memory operations (used to return directly from DoService).
Fuzzy* fuzzy3d is a pointer to an instance of the class Fuzzy (fuzzy object served for output of
3-dimensional characteristic).
Fuzzy3DInfo fuzzy3dinfo is a global structure of type Fuzzy3DInfo (see also F3DINFO.H)

DR300 Speed Control Windows Software V1.0 1-47


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

1.5.1 The DLL Interface DRSRV16

LibMain
int CALLBACK LibMain( HINSTANCE hInstance, WORD wDatenSeg, WORD
cbHeapSize, LPSTR lpCmdLine )

Description The function LibMain is the entry function of the 16 bit DRSRV16.DLL. None of the parameters
is used directly. New objects for the driver, the scope buffer, the signal generators and the
controllers are created and assigned to the corresponding global pointers. The elements of the
global structure param for the controllers as well as for the generator are initialized.
Return Is TRUE in case of successful initialization, else FALSE.

WEP
int CALLBACK WEP( int nParameter )

Description The function WEP is the exit function of the 16 bit DRSRV16.DLL. None of the parameters is
used directly. When the code and data memory of the complete DRSRV16.DLL is locked, it will
be unlocked. The objects for the driver, the scope buffer, the signal generators and the controllers
are deleted.
Return Is TRUE in case of successful operations, else FALSE.

LockMemory
BOOL CALLBACK LockMemory( BOOL bStart, HDRVR hDrv )

Parameters bStart is a flag with the meaning:


=TRUE, code and data memory of the DRSRV16.DLL will be locked,
=FALSE, code and data memory of the DRSRV16.DLL will be unlocked.
hDrv is a handle for the IO-adapter card driver (is not used here).
Description The function LockMemory controls the lock status of the code and data memory of the complete
DRSRV16.DLL. With bStart=TRUE this memory is locked. With bStart=FALSE this memory
will be unlocked again.
Attention: This function is to be called only by the TIMER16.DLL !
Return Is equal to TRUE, when the handle of the code memory of the DRSRV16.DLL is valid, else return
is equal to FALSE.

1-48 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

SetDriverHandle
BOOL CALLBACK SetDriverHandle( HDRVR hDrv )

Parameters hDrv is an handle for the IO-adapter card driver.


Description The function SetDriverHandle sets the internal handle for the IO-adapter card driver equal to
the actual parameter.
Attention: This function may only be called by the TIMER16.DLL!
Return Always equal to 0.

DoService
BOOL CALLBACK DoService( DWORD counter )

Parameters counter is a counter for the number of calls.

Description The function DoService is the service routine called with periodic timer events (see also
TIMER16.DLL). Timer events occur with a (nearly) constant sampling period as long as they are
enabled. The following operations are carried-out in sequence:

Return directly, when memory is locked (flag locked),


Set call counter dwCounter=counter and reset stopped,
Check for active controller (pi controller, fuzzy controller, open loop control),
Reset the trigger pulse for the servo and the release counter for the first call or after
changing the controller
Trigger the output stage (rectangle signal) with active controller,
Read setpoint/control signal for motor, control signal for generator current and store to
scopebuf,
Read sensors for motor speed, motor and generator current and store to scopebuf,
Check for top limit switch, set changed accordingly and reset controller to none,
Calculate the motor control signal (pi controller/fuzzy controller/open loop control/none),
Output of control signals for motor and generator,
If PC control is disabled increment release counter, else reset
If release counter is equal to 5 set flag changed,
Store the measurement-vector.
Attention: This function is to be called only by the TIMER16.DLL!
Return Is TRUE in case of successful operations, else FALSE.

DR300 Speed Control Windows Software V1.0 1-49


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

SetParameter
BOOL CALLBACK SetParameter( WORD wSize, LPSTR lpData )

Parameters wSize is the size (in bytes) of the data structure pointed to by lpData.
lpData is a pointer to a data structure of type ServiceParameter.
Description The function SetParameter copies the data structure pointed to by lpData to the global structure
par (type ServiceParameter ) only when the size of the source structure is less than or equal to the
size of the destination structure. In this case the parameters of the PI controller as well as the signal
generators are set accordingly. The flag locked is set during this operation.
Return Is equal to TRUE when the size of the source structure is less than or equal to the size of the
destination structure, else return is equal to FALSE.

GetParameter
BOOL CALLBACK GetParameter( WORD wSize, LPSTR lpData )

Parameters wSize is the size (in bytes) of the data structure pointed to by lpData.
lpData is a pointer to a data structure of type ServiceParameter.
Description The function GetParameter at first copies the current parameters of the PI controller as well as
the name of the fuzzy description file to the global structure par (type ServiceParameter) then it
copies this structure to the destination structure pointed to by lpData. The last copy procedure is
carried-out only, when the size of the source structure par is equal to the size of the destination
structure. The flag locked is set during this operation.
Return Is equal to TRUE when the size of the source structure is less than or equal to the size of the
destination structure, else return is equal to FALSE.

GetData
BOOL CALLBACK GetData( WORD wSize, LPSTR lpData )

Parameters wSize is the size (in bytes) of the data structure pointed to by lpData.
lpData is a pointer to a data structure of type ServiceData.
Description The function GetData at first copies the content of the measurement-vector scopebuf to the global
structure dat (type ServiceData). Then dat is copied to the data structure pointed to by lpData
only when the size of the source structure is less than or equal to the size of the destination
structure. Bit 1 and 2 of the controller state are set according to the settings of stopped and changed.
The flag locked is set during this operation.

Return Is equal to TRUE when the size of the source structure is less than or equal to the size of the
destination structure, else return is equal to FALSE.

1-50 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

GetTiming
BOOL CALLBACK GetTiming( WORD wSize, LPSTR lpData )

Parameters wSize is the size (in bytes) of the data structure pointed to by lpData.
lpData is a pointer to a data structure of type ServiceTiming.
Description The function GetTiming copies the global structure tim (type ServiceTiming) to the data structure
pointed to by lpData only when the size of the source structure is less than or equal to the size of
the destination structure. When on entry the element tim.n, the number of sampling periods, is set
to -1, the complete structure is reset to default values before the copy operation is carried-out.
The flag locked is set during the run-time of this function.
Return Is equal to TRUE when the size of the source structure is less than or equal to the size of the
destination structure, else return is equal to FALSE.

ReadFuzzy
BOOL CALLBACK ReadFuzzy( void )

Description The function ReadFuzzy reads the fuzzy description file and generates the accompanying fuzzy
object. The name of the fuzzy description file is read from the global parameter structure par. The
current controller type in par is set equal to FUZZYCONTROLLER only, when a fuzzy controller
was active previously and the new fuzzy object generation was error-free. In case of a previously
active fuzzy controller but errors occurred during the fuzzy object generation the controller type
is set equal to NOCONTROLLER. In any other case the controller type remains as it has been
before this function was called.
Return Is equal to TRUE when the new fuzzy object generation was successful, else FALSE is returned.

ReadPIPar
BOOL CALLBACK ReadPIPar( char* name )

Parameters name is a pointer to the name of a file from which the parameters of a PI controller are to be
read.
Description The function ReadPIPar reads the parameters of a PI controller from the file with the given name
name. The current controller type in par is set equal to PICONTROLLER only, when a PI
controller was active previously and the loading procedure was successful. In case of a previously
active PI controller but errors occurred during loading the parameters the controller type is set
equal to NOCONTROLLER. In any other case the controller type remains as it has been before
this function was called.

Return Is equal to TRUE, when reloading the parameters of the PI controller was successful, else FALSE
is returned.

DR300 Speed Control Windows Software V1.0 1-51


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

WritePIPar
BOOL CALLBACK WritePIPar( char* name )

Parameters name is a pointer to the name of a file to which the parameters of a PI controller are to be
written.

Description The function WritePIPar writes the parameters of the PI controller to a file with the given name
name. The current controller type in par is set equal to PICONTROLLER only, when a PI
controller was active previously and the writing procedure was successful. In case of a previously
active PI controller but errors occurred during writing the matrices the controller type is set equal
to NOCONTROLLER. In any other case the controller type remains as it has been before this
function was called.
Return Is equal to TRUE, when writing the parameters of the PI controller was successful, else FALSE
is returned.

IsDemo
int CALLBACK IsDemo( void )

Description The function IsDemo returns a 1 only when the DRSRV16.DLL is a DEMO version (generated
with the macro __SIMULATION__ , instead of the IO-adapter card a mathematical model is
accessed). Otherwise the function returns 0.
Return Is equal to 1 in case of a DEMO version, else equal to 0.

MeasureStart
int CALLBACK MeasureStart( double time, double trigger, double prestore, int tchannel, int
slope )

Parameters time is the total measuring time (in sec).


trigger is the trigger level for the trigger channel.
prestore is the time before the trigger condition is reached (in sec).
tchannel is the number of the trigger channel.
slobe is a flag for the direction of the trigger condition.
float taint is the sampling period of the service routine.
Description The function MeasureStart calls the function scope.StartMeasure to start a measuring. In
advance the controller settings are copied to the global structure measctrlstatus.
See also STOREBUF::StartMeasure

1-52 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

The functions

MeasureLevel
double CALLBACK MeasureLevel( void )
MeasureStatus
int CALLBACK MeasureStatus( void )

Description call directly the corresponding functions scope.GetBufferLevel, scope.GetStatus of the class
STOREBUF.

See also STOREBUF::GetBufferLevel, STOREBUF::GetStatus

OpenFuzzy3D
int CALLBACK OpenFuzzy3D( char* filename )

Parameters filename is a pointer to the name of a fuzzy description file.


Description The function OpenFuzzy3D opens the fuzzy description file with the name filename and
generates the accompanying fuzzy object (fuzzy3d serving for the output of its 3-dimensional
characteristic). The output file for state and error messages is FUZZY3D.OUT.
Return Error state:
=0, no error,
=-1, invalid pointer to fuzzy object,
=-2, syntax error in the fuzzy description file,
=-3, errors during fuzzy object generation.

CloseFuzzy3D
int CALLBACK CloseFuzzy3D( void )

Description The function CloseFuzzy3D removes an existing fuzzy object (fuzzy3d serving for the output of
its 3-dimensional characteristic) from the memory and resets its pointer to NULL.
Return Always 0.

DR300 Speed Control Windows Software V1.0 1-53


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

InfoFuzzy3D
Fuzzy3DInfo* CALLBACK InfoFuzzy3D( void )

Description The function InfoFuzzy3D returns the structure of type Fuzzy3DInfo belonging to an existing
fuzzy object (fuzzy3d serving for the output of its 3-dimensional characteristic).

Return Structure of type Fuzzy3DInfo of an existing fuzzy object.

CalcFuzzy3D
double CALLBACK CalcFuzzy3D( double x, double y )

Parameters x is the value of the first input variable of a fuzzy object.


y is the value of the second input variable of a fuzzy object.
Description The function CalcFuzzy3D calculates the output variable (index fuzzy3dinfo.idz) of a fuzzy object
(fuzzy3d) with the two input variables x and y (indexes fuzzy3dinfo.idx, fuzzy3dinfo.idy). The
return value is the output variable, when the fuzzy object exists and the indexes are within a valid
range.

Return Output variable of an existing fuzzy object with two given values for its input variables or 0.0.

1-54 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.5.2 The Class DR300STA in the DRSRV16.DLL

The class DR300STA provides functions to calculate the PI controller and to handle its parameters. It inherits from
the basic class CONTROLLER.

Public Data:
double time sampling period (class CONTROLLER)

Private Data:

int errors error counter for file loading (class CONTROLLER)


char filename[MAXPATH] current name of the parameter file (class CONTROLLER)
char *id pointer to the controller id string (class CONTROLLER)
double kr proportional coefficient of PI controller
double tr integral coefficient of PI controller
int start flag: reset of the controller

DR300STA::DR300STA()
void DR300STA ( void ) : CONTROLLER( )

Description The constructor of the class DR300STA initializes values for the internal error, the sampling
period, the parameters of the PI controller as well as for the controller identification string. The
name of the current parameter file is set to DR300.PI. When this file could be read successfully
the parameters of the PI controller are set accordingly. The flag for resetting the controller is set.

DR300STA::Calc
void Calc( void )

Description The function Calc is the main function of this class. It carries-out the calculation of the PI
controller. The speed setpoint as well as the measured speed are read from the global scope buffer
scopebuf. Where the last operation depends on the type of the active speed sensor. The measured
speed is then limited to the range +/-3000 rpm. With reset flag start set, the PI controller output
signal as well as the measured speed from the previous sampling period are reset to zero. Then
the output of a sampled-data controller (approximated digital PI controller with respect to the
coefficients of an analog PI controller) is calculated. This output will be limited to the range
+/-1000 and stored as the control signal to the measurement-vector.

DR300 Speed Control Windows Software V1.0 1-55


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

DR300STA::Reset
void Reset( void )

Description The function Reset sets the flag start to reset the initial values of the PI controller.

DR300STA::Load
int Load( char* name )

Parameters name is a pointer to the name of a file from which the parameters of the PI controller are to be
read.
Description The function Load copies the given name to filename and tries to open the corresponding file.
When the file cannot be opened, an error message is presented, the internal error errors is set to
1 and the function returns ERROR (-1) immediately. Otherwise all the parameters are read from
the file and stored in the corresponding parameters of the PI controller. The file must match a
predefined format and the sequence of the parameters separated by comment lines with a closing
"]" character. The internal error errors is reset to 0.

Return A value of 0 with a successful read operation from the file, else -1.

DR300STA::Save
int Save( char* name )

Parameters name is a pointer to the name of a file to which the parameters of the PI controller are to be
written.
Description The function Save copies the given name to filename and tries to open the corresponding file.
When the file cannot be opened, an error message is presented, the internal error errors is set to
1 and the function returns ERROR (-1) immediately. Otherwise all the parameters (sampling
period, proportional and integral coefficient) of the PI controller are written to the file with
additional comment lines. The internal error errors is reset to 0.
Return A value of 0 with a successful write operation to the file, else -1.

1-56 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

DR300STA::GetKr
double* GetKr( void )

Description The function GetKr returns a pointer to the proportional coefficient of the PI controller kr.
Return A pointer to proportional coefficient of the PI controller kr.

DR300STA::GetTr
double* GetTr( void )

Description The function GetTr returns a pointer to the integral coefficient of the PI controller tr.
Return A pointer to proportional coefficient of the PI controller tr.

DR300STA::GetFileName
char* GetFileName( void )

Description The inherited element function GetFileName returns a pointer to the current parameter file name.

Return The a pointer to the current parameter file name filename.

DR300STA::GetId
char* GetId( void )

Description The inherited element function GetId returns a pointer to the current controller identification
string.
Return The a pointer to the current controller identification string id.

DR300STA::geterrors
int geterrors( void )

Description The inherited element function geterrors returns the value of the internal error errors. This
variable is set during file accesses (see also Load, Save).
Return The value of the internal error errors.

DR300 Speed Control Windows Software V1.0 1-57


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

DR300STA::SetTa
void SetTa( float ta )

Parameters ta is the value of the real sampling period of the controller.


Description The inherited element function SetTa sets the internal sampling period of the PI controller equal
to the given value ta. This value has to be the same as the sampling period for the controller set
by the TIMER16.DLL. Otherwise the calculation of the controller coefficients fails.

1-58 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.5.3 The Class DR300FUZ in the DRSRV16.DLL

The class DR300FUZ provides functions to apply a fuzzy controller. It serves as an interface to the fuzzy
algorithms contained in Fuzzy.lib. It inherits from the basic class CONTROLLER.

Public Data:
double time sampling period (class CONTROLLER)
double acc acceleration of the motor.

Private Data:

int errors error counter for file loading (class CONTROLLER)


char filename[MAXPATH] current name of the parameter file (class CONTROLLER)
char *id pointer to the controller id string (class CONTROLLER)
Fuzzy *Controller fuzzy controller
int start flag: reset of the controller

DR300FUZ::DR300FUZ()
void DR300FUZ ( void ) : CONTROLLER

Description The constructor of the class DR300FUZ sets the internal sampling period to SIMTIME and
initializes the identification string to "FUZZYCONTROLLER". It assigns NULL to the pointer
to the fuzzy object, reads the "fuzzy-controller" file DR300.FUZ (see also Load) and generates
the accompanying fuzzy object. The controller reset flag start is set in addition.

DR300FUZ::~DR300FUZ()
void ~DR300FUZ ( void )

Description The destructor of the class DR300FUZ removes the fuzzy object from the memory.

DR300 Speed Control Windows Software V1.0 1-59


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

DR300FUZ::Calc
void Calc( void )

Description The function Calc is the main function of this class to calculate the fuzzy controller. The speed
setpoint as well as the measured speed are read from the global scope buffer scopebuf. Where the
last operation depends on the type of the active speed sensor. The measured speed is then limited
to the range +/-3000 rpm. With reset flag start set, the fuzzy controller output signal as well as
the control error from the previous sampling period are reset to zero. The approximation of the
acceleration of the control error is then taken as a backward difference approximation. The fuzzy
controller with the two input signals control error and its approximated derivative is calculated
only, when the fuzzy object could be generated without any error. The control signal is calculated
by integrating (rectangle approximation) the fuzzy controller output and limiting the result to the
range +/-1000. At the end the control signal is stored to the measurement-vector.

DR300FUZ::Reset
void Reset( void )

Description The function Reset sets the flag start to reset the fuzzy controller output signal as well as the
control error from the previous sampling period.

DR300FUZ::Load
int Load( char* name )

Parameters name is a pointer to the name of a "fuzzy-controller" file.


Description The function Load at first searches for the extension "FUZ" in the given file name. When this
extension is missing, the internal error errors is set to 1 and the function returns -1 immediately.
The output log file name is equal to the given file name after replacing its extension by "OUT".
If the file with the given name cannot be opened an error message is presented, the internal error
errors is set to 1 and the function returns -1 immediately. Now a possibly existing fuzzy object
is deleted. Then the fuzzy description file is read with a syntax check. In case of no errors the
accompanying fuzzy object is generated. If the generation was successful the mean calculation
time for the fuzzy object is determined. The given file name is copied to the internal parameter
file name filename only, when the mean calculation time did not exceed 65% of the controller’s
sampling period, otherwise the internal error errors is set to 1. To this end the controller reset flag
is set.
Return A -1 in case of an internal errors else 0.

1-60 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

DR300FUZ::Save
int Save( char* name )

Parameters name is a pointer to the name of a "fuzzy-controller" file.


Description The function Save copies the given name to filename, when the internal error errors is not set. If
the file with the given name can be opened the function returns 0, otherwise it returns -1.
Return When file exists 0, else -1.

DR300FUZ::getname
char* getname( void )

Description The function getname returns the name of the current "fuzzy-controller" file, meaning the content
of filename.

Return A pointer to the name of the current "fuzzy-controller" file from filename.

DR300FUZ::GetFileName
char* GetFileName( void )

Description The inherited element function GetFileName returns a pointer to the current parameter file name.
Return The a pointer to the current parameter file name filename.

DR300FUZ::GetId
char* GetId( void )

Description The inherited element function GetId returns a pointer to the current controller identification
string.
Return The a pointer to the current controller identification string id.

DR300 Speed Control Windows Software V1.0 1-61


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

DR300FUZ::geterrors
int geterrors( void )

Description The inherited element function geterrors returns the value of the internal error errors. This
variable is set during file accesses (see also Load, Save).

Return The value of the internal error errors.

DR300FUZ::SetTa
void SetTa( float ta )

Parameters ta is the value of the real sampling period of the controller.


Description The inherited element function SetTa sets the internal sampling period of the fuzzy controller
equal to the given value ta. This value has to be the same as the sampling period for the controller
set by the TIMER16.DLL. Otherwise the calculation of the difference quotient fails.

1-62 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.5.4 The Class STOREBUF in the DRSRV16.DLL

The instance of the class STOREBUF realizes the function of data buffering. The data buffer created dynamically
looks like a matrix with a maximum of assignable rows, where each row contains an adjustable number of
components (i.e. float values from measurements). The storage in the data buffer is performed row by row, where
each row is represented by a data vector, which was filled by another routine from an upper level. In this case it is
the interrupt service routine which fills the data vector, i.e. with the setpoint value, measurements and control
signals, in every sampling period. An element function (StartMeasure) of STOREBUF starts and controls the
storage (WriteValue) of this data vector in the data buffer. With respect to the measuring time at first those
sampling periods are determined in which storage is to be performed (number of store operations * sampling
periods = measuring time). Where the number of store operations is calculated at first such that it is always less than
the maximum number of measurement vectors (= number of rows of the memory matrix). At the end of the
measuring time the store operation is terminated in case no additional trigger conditions are set. In case of an
activated trigger condition, a signal crosses a given value with a selected direction, the store operation is continued
until the end of the measuring time after the trigger condition was met. In case the signal does not meet the trigger
condition, the store operation is performed endless in a ring until the user interactively terminates this operation. In
addition a time before the trigger condition (prestore time) is adjustable in which storage in the data buffer is
performed. The time after the trigger condition is met is then the measuring time reduced by the prestore time. The
mentioned data vector will be named measurement-vector in the following.

Private Data:

float taplt is the sampling period of the interrupt service routine.


int trigger_channel is the channel (index) of the measurement-vector used for triggering.
int startmessung flag for starting new measuring.
int gomessung flag for measuring is started.
int storedelay is the number of sampling periods in between the storage of values.
int storedelayi is the counter for storedelay.
int MaxVectors is the maximum number of storable measurement-vectors.
int anzahl is the number of stored measurement-vectors.
int anzahli is the counter for anzahl.
int stopmeasureindex is the index for normal end of measuring.
int triggerindex is the trigger index..
int prestoreoffset is the number of stored measurement-vectors previous to the trigger.
int nchannel is the number of float values in the measurement-vector.
int outchannel is the channel (index) of the component of the measurement-vector, which is to be read (for
output).
int bufindex is an internal index for the next storage location in the data buffer.
int trigged flag for trigger condition is met.
int stored_values number of measurement-vector storages since the start of the measuring.
float trigger_value trigger float value.

DR300 Speed Control Windows Software V1.0 1-63


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

float *fptr is a pointer to the start address of the dynamic data buffer.
float *sourceptr is a pointer to the measurement-vector.
float *inptr is a pointer to the actual data buffer location.
int aktiv flag for status of the dynamic data buffer.
int status flag for storage control.

STOREBUF::ResetBufIndex
void ResetBufIndex( void )

Description The private element function ResetBufIndex sets bufindex to 0 and inptr equal to fptr meaning
that the start conditions for the data buffer are set.

STOREBUF::STOREBUF
STOREBUF( int nchannel, float *indata, int maxvectors )

Parameters int nchannel is the number of float values of the external measurement-vector.
float *indata is the pointer to the start address of the measurement-vector.
int maxvectors is the maximum number of measurement-vectors.

Description The constructor of this class initializes flags (gomessung, startmessung, aktiv = FALSE) to control
the storage as well as a pointer to the measurement vector (sourceptr = indata. The maximum
number of the measurement-vectors is set ( MaxVectors = maxvectors ) where the minimum value
is limited to 1.

STOREBUF::~STOREBUF()
void ~STOREBUF( void )

Description The destructor of this class frees the dynamically allocated memory fptr in case it was created.

1-64 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

STOREBUF::StartMeasure
void StartMeasure( float meastime, float triggervalue, float prestoretime, int triggerdir,
float taint )

Parameters triggerchannel is the number of the trigger channel.


meastime is the measuring time in seconds.
triggervalue is the trigger level of the trigger channel.
prestoretime is the time of storage previous to the trigger (in sec).
triggerdir is the flag for direction (below/above) of the trigger condition.
taint is the sampling period of the interrupt service routine.
Description The function StartMeasure initializes a new storage operation. To a maximum of maxvectors
measurement-vectors are stored. In case the adjusted measuring time meastime is longer than
maxvectors * taint (sampling period) the number of interrupt executions without data storage is
calculated. The arguments of this function are all the parameters required for the storage.

STOREBUF::WriteValue
void WriteValue( void )

Description The function WriteValue stores nchannel float values from the array indata
(measurement-vector) to the current address of the dynamically allocated array.

STOREBUF::SetOutChan
void SetOutChan(int in)

Parameters int in references the component of the measurement vector which is to be read (output).
Description The inline function SetOutChannel sets the channel number (index in the measurement-vector)
of the signal which is to be returned by the function ReadValue.

STOREBUF::ReadValue
float ReadValue( void )

Description The function ReadValue returns the value of the next storage location belonging to the channel
selected by SetOutChannel.
Return Value (float) read from measurement-vector.

DR300 Speed Control Windows Software V1.0 1-65


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

STOREBUF::GetBufLen
int GetBufLen( void )

Description The function GetBufLen interrupts a current storage operation and returns the number of stored
measurement-vectors.

Return Number (int) of stored measurement-vectors.

STOREBUF::GetBufTa
float GetBufTa( void )

Description The inline function GetBufTa returns the time between storage, which was calculated with
respect to the measuring time and the sampling period.
Return Time (float) between storage depending on measuring time and sampling period.

STOREBUF::GetStatus
int GetStatus( void )

Description The function GetStatus returns the status of the store operation.

Return Status (int) of store operation


0 not initialized
1 storage before trigger
2 waiting for trigger condition
4 storage operation
5 storage complete
6 storage interrupted

STOREBUF::GetBufferLevel
double GetBufferLevel( void )

Description The function GetBufferLevel returns the percentage of the former measurement time with respect
to the given trigger condition (= filling ratio or level of the data buffer). The return value will stay
at 0% until the valid trigger condition is reached even when prestoretime is unequal to zero. That
means the return value will start with an initial value of prestoretime / meastime in % at the time
of a valid trigger condition.
Return The percentage of the filling ratio (double) of the data buffer.

1-66 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.5.5 The Class AFBUF in the DRSRV16.DLL

An instance of the class AFBUF is an object that creates dynamically a data array for an assignable number of float
values. Data can be stored in this array and can be read afterwards when the data array is filled completely. The
array is handled like a ring buffer.

Private data:

float *fptr is the pointer to the start of the dynamically created data array.
float *inptr is the pointer to the current storage location ready to store a value (input).
float *outptr is the pointer to the current storage location ready to read a value (output).
int aktiv flag: dynamic memory is initialized.
int filled flag: data array is filled.
int abuflen is the number of float values in the data array.
int inbufindex is the index of the current input position.
int outbufindex is the index for the current output position.

AFBUF::AFBUF()
void AFBUF( void )

Description The constructor of this class resets the flag aktiv, which indicates a dynamically created data array.

AFBUF::~AFBUF()
void ~AFBUF( void )

Description The destructor of this class frees the initialized data memory in case it was created dynamically.

DR300 Speed Control Windows Software V1.0 1-67


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

AFBUF::NewFBuf
int NewFBuf( int anzahl )

Parameters anzahl is the size of the data array in float values.


Description The function NewFBuf initializes a data array with anzahl float values. A value of 1 is returned
after a successful initialization, otherwise 0 is returned.
Return Status (int) of data array:
= 0, data array is not initialized,
= 1, data array is initialized.

AFBUF::ReadFBuf
float ReadFBuf( void )

Description The function ReadFBuf returns the float value of the next storage location of the dynamically
created data array in case this array was filled previously.
Return Value (float) from data array.

AFBUF::WriteFBuf
int WriteFBuf( float fvalue )

Parameters float fvalue is the value, which is to be stored.


Description The function WriteFBuf stores the float value to the storage location.
Return Number (int) of stored values (=0 in case no data array initialized).

1-68 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.5.6 The Class TWOBUFFER in the DRSRV16.DLL

The class TWOBUFFER handles two instances of the class AFBUF. One instance (write-instance) can be used to
store data while the other is used to read out data (read-instance). In case the data array of the write-instance is filled
it is handled as a read-instance in the following. This condition guarantees that the interrupt service routine has
always access to valid data.

Private objects:

AFBUF Buf1 is an instance of the class AFBUF


AFBUF Buf2 is an instance of the class AFBUF

Private data:

int readbuffer flag: data array is ready for read operation.


int buffer1 flag: 0 = Buf1 write,
1 = Buf1 read.
int buffer2 flag: 0 = Buf2 write,
1 = Buf2 read.
int newbuffer flag: 0 = not a new output buffer,
1 = Buf1 is a new output buffer,
2 = Buf2 is a new output buffer.
int buf1len length of the data array of the instance Buf1
int buf1leni index of the instance Buf1.
int buf2len length of the data array of the instance Buf2.
int buf2leni index of the instance Buf2.
int inbufindex index for input data array.
int repw1 number of repeated values in Buf1
int repw1i index of repeated values in Buf1
int repw2 number of repeated values in Buf2
int repw2i index of repeated values in Buf2
int repb1 number of data array outputs of the instance Buf1.
int repb1i index of the array outputs of the instance Buf1.
int repb2 number of data array outputs of the instance Buf2.
int repb2i index of the array outputs of the instance Buf2.

DR300 Speed Control Windows Software V1.0 1-69


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

TWOBUFFER::TWOBUFFER()
void TWOBUFFER( void )

Description The constructor of this class initializes flags and counters as follows:
readbuffer = FALSE, buffer cannot be read,
buf1len = 1, length of the buffer Buf1,
buf2len = 1, length of the buffer Buf2,
buffer1 = 1, buffer Buf1 for read operation,
buffer2 = 0, buffer Buf2 for write operation,
newbuffer = 0, no buffer for read or write operation available.

TWOBUFFER::New2Buffer
void New2Buffer( int anzahl , int repeatwert, int repeatbuf )

Parameters int anzahl is the number of float values of the new array.
int repeatwert defines how often a value is to be repeated during a read operation by
Read2Buffer.
int repeatbuf defines how often the array is to be sent to the output.

Description The function New2Buffer creates data arrays dynamically with anzahl float values. With buffer1
= 0 Buf1 is created and with buffer2 = 0 Buf2 is created.

TWOBUFFER::Write2Buffer
int Write2Buffer( float wert )

Parameters float wert is the value, which is to be stored.

Description The function Write2Buffer writes the argument value to the data array. In case the end of the
array is reached, the array is used as a source for the function Read2Buffer.
Return Total number (int) of stored (written) values.

TWOBUFFER::Read2Buffer
float Read2Buffer( void )

Description The function Read2Buffer returns the values of the read-array handling like a ring. In case the
argument repeatbuf of the function New2Buffer was equal to x, the array is read x times. After x
read operations zero is returned. In case repeatbuf is equal to 0, the read operation is cyclic.
Return Value (float), which is read from the array.

1-70 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

1.5.7 The Class Signal in the DRSRV16.DLL

An instance of the class SIGNAL is an object to create a data array, which represents a given signal shape in case it
is read out with constant time intervals. To do this an instance of the class TWOBUFFER is used. Adjustable
signal shapes are rectangle, triangle, sawtooth and sine. In addition the amplitude, an offset and the time period is
adjustable.

Private Data:

float abtastzeit sampling period to read out values.


float stuetzst number of base points of a signal period.
float signaloffset offset of the signal.
float signalamplitude amplitude of the signal.
float minrange minimum available return value.
float maxrange maximum available return value.

Private objects:

TWOBUFFER sign is an instance of the class TWOBUFFER

SIGNAL::SIGNAL( )
void SIGNAL( void )

Description The constructor of this class initializes the variables abtastzeit, minrange and maxrange.

SIGNAL::InitTime
float InitTime( float settime )

Parameters float settime is the sampling period of the read routine (in sec.)
Description The function InitTime sets the sampling time, which is used to read out the values from the
interrupt routine, equal to the given controller sampling period.
Return Adjusted sampling period (float) in seconds.

DR300 Speed Control Windows Software V1.0 1-71


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

SIGNAL::MakeSignal
int MakeSignal( int form, float offset, float ampl ,float periode , int repeatbuf)

Parameters int form is the signal shape indicator


konstform (constant) 0
rectform (rectangle) 1
triform (triangle) 2
saegeform (sawtooth) 3
sinusform (sine) 4
float offset offset value of the signal.
float ampl amplitude of the signal.
float periode period of the signal (in sec).
int repeatbuf defines how often the signal is to be read out (0 = continuously).
Description The function MakeSignal The function MakeSignal generates a data array with a maximum of
1024 float values, in which the values of the selected signal shape are stored. The signal shape is
adjusted by the argument form. The absolute value of the signal f(t) is given by the sum offset +
amplitude * f(t). In case the number of base points determined by the division periode / sampling
period is greater than 1024 the number of base points is halved and the repeat value repw1 or
repw2 is doubled until the number is less than 1024.
After the generation of a data array it is assigned as a source to the function ReadNextValue (see
class TWOBUFFER).
Return Error status:
=0, no error
=1, illegal signal shape.

SIGNAL::ReadNextValue
float ReadNextValue( void )

Description The function ReadNextValue reads the data from the assigned array. The value is internally
limited to the range minrange to maxrange. It is called by the interrupt service routine. Due to
the locking mechanism in TWOBUFFER, new signal shapes can be created even in case the
active interrupt outputs another one.
Return Value (float) read from the data array.

1-72 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

SIGNAL::SetRange
void SetRange( float min, float max )

Parameters float min is the minimum return value of the function ReadNextValue.
float max is the maximum return value of the function ReadNextValue.
Description The function SetRange adjusts the range of the base points forming the signal, i.e. the minimum
and maximum values returned by the function ReadNextValue.

SIGNAL::WriteBuffer
void WriteBuffer( float value )

Parameters float value is the value which has to be stored.


Description The private element function WriteBuffer writes the argument value to the data array of the
instance TWOBUFFER.

SIGNAL::Stuetzstellen
int Stuetzstellen( float Periodenzeit, int form)

Parameters float Periodenzeit is the time period of the signal.


int form is the indicator for the adjusted signal shape.
Description The private element function Stuetzstellen calculates the number of base points and with this the
length of the data arrays of the instance TWOBUFFER depending on the time period and the
signal shape. The number of the base points is determined by the division Periodenzeit / sampling
period. In case of a constant signal shape the minimum number of base points is 1.
Return Calculated number (int) of base points.

DR300 Speed Control Windows Software V1.0 1-73


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

1.5.8 The DLL Interface PLOT

Included in the DRSRV16.DLL, the functions of the file PLOT.CPP provide the interfaces for graphic output of
measured data and for displaying information about the contents of documentation files (*.PLD).

Global Data:

HWND handlelist[100] is an array to store the handles of plot windows.


PROJECT project is a structure with data for the project identification.
CTRLSTATUS measctrlstatus is a structure containing the controller state, controller parameters as well as
the measuring time at the time a measuring is started.
CTRLSTATUS ctrlstatus is a structure containing the controller state, controller parameters as well as the
measuring time at the time a controller is started.
DATASTRUCT datastruct is structure containing the number of measurement-vectors, the number of its
components as well as the sampling period of a measuring.
char FileName[60] is a string containing the name of a documentation file (*.PLD).
double **ppData is a pointer to a buffer containing measurements loaded from a documentation file (*.PLD).
int NumberOfCurvesInChannel is the number of curves of a plot depending on the "plot channels" (= se-
lected groups of components of the measurement vector).
int ChannelToScope is the relation between curves (index) of the measurement buffer scope or the pointer
**ppData and the "plot channels" (= selected groups of components of the measurement vector).
char *ScopeNames contains the curve descriptions (strings) for the linestyle table of the plot.
char *TitleNames contains the drawing titles for different "plot channels".
char *YAxisNames contains the description of the Y-axis for different "plot channels".
char *XAxisName contains the description of the X-axis for different "plot channels".

1-74 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

ReadPlot
int CALLBACK ReadPlot( char *lpfName )

Parameters *lpfName is a pointer to the name of a documentation file, from which measurements are to be
read.

Description The function ReadPlot reads the structures project, ctrlstatus and datastruct as well as the
measurements from the documentation file with the given name lpfName and stores the
measurements to a new global data array pointed to by **ppData. Up to 59 characters of the file
name lpfName are copied to the global file name FileName.
Return The state of the file access:
=0, measurements read successfully,
=-1, file with the given name could not be opened,
=-2, the PROJECT structure from the file contains a wrong project number.

WritePlot
int CALLBACK WritePlot( char *lpfName )

Parameters *lpfName is a pointer to the name of a documentation file, to which measurements are to be
written.
Description The function WritePlot writes the global structures project, measctrlstatus, the local structure
DATASTRUCT mydatastruct as well as the content of the global measurement buffer scope to
a documentation file with the given name lpfName. The local structure mydatastruct contains the
number of measurement-vectors, the number of its components as well as the sampling period of
a measuring.
Return The state of the file access:
=0, measurements written successfully,
=-1, file with the given name could not be created.

DR300 Speed Control Windows Software V1.0 1-75


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

Plot
int CALLBACK Plot( int command, int channel )

Parameters command defines the data source:


=1, data from the global measurement buffer scope,
=2, data from the global array **ppData
channel defines the curves related to "plot channels":
=0, Measured speed with setpoint [rpm] (2 curves),
=1, Speed measured by tacho [rpm] (1 curve),
=2, Speed measured by encoder [rpm] (1 curve),
=3, Measured motor current [A] (1 curve),
=4, Measured generator current [A] (1 curve),
=5, Output to motor [V] (1 curve),
=6, Output to generator [V] (1 curve).

Description The function Plot represents the curves specified by channel with accompanying descriptions in
a graphic inside a plot window. The data sources are the global measurement buffer scope or the
global array **ppData depending on the parameter command.
Return The state of the graphic output:
=0, successful graphic output of measured curves,
=-1, invalid values for command,
=-2, invalid values for channel,
=-3, length of the global array **ppData is 0,
=-4, length of the global measurement buffer scope is 0.
See also CreateSimplePlotWindow, SetCurveMode, AddAxisPlotWindow, AddXData,
AddPlotTitle, ShowPlotWindow.

1-76 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Source Files of the DR300W16 Controller Program

GetPlot
int CALLBACK GetPlot( int start, char *lpzName )

Parameters start is a flag indicating the first plot window.


*lpzName is a pointer to the title of the plot window, the Windows handle of which was found.
Description The function GetPlot determines the Windows handle of an existing plot window referenced by
a local index index. The Windows handle is copied to the global list handlelist and the index is
incremented. If the Windows handle is unequal to 0 up to 60 characters of the title of the
corresponding plot window are copied to lpzName. With start=TRUE the Windows handle of the
plot window with index=0 is determined.
Return The state of the handle determination:
=0, handle = 0, plot window with current index could not be found,
=1, handle determined for current index, title copied.
See also GetValidPlotHandle.

PrintPlot
int CALLBACK PrintPlot( int idx, HDC dcPrint, int iyOffset )

Parameters idx is the index for the global list of handles referencing existing plot windows.
dcPrint is the device context of the output device.
iyOffset is the beginning of the printout in vertical direction as a distance in [mm] from the
upper margin of a page.
Description The function PrintPlot prints the content of the plot window with the Windows handle from the
global list handlelist[idx] to the device with the device context dcPrint. The printout has a width
of 180 mm and a height of 140 mm. It is located at the left margin with a distance of iyOffset mm
from the upper margin of a (i.e. DIN A4) page.
Return Is always equal to 0.
See also PrintPlotWindow.

DR300 Speed Control Windows Software V1.0 1-77


Source Files of the DR300W16 Controller Program Laboratory Experiment DR300

GetPldInfo
int CALLBACK GetPldInfo( int &controller, char **s, int &n, int &c, double &d )

Parameters &controller is a reference to the controller structure (PI controller, fuzzy controller, none).
**s is a (double) pointer to the string containing date and time of the measuring.
&n is a reference to the number of samples of each measured signal (curve).
&c is a reference to the number of measured signals.
&d is a reference to the sampling period of the measuring.
Description The function GetPldInfo reads selected elements of the structures ctrlstatus as well as datastruct
and stores these elements to the mentioned parameter references. It is assumed that the structures
were filled previously with data from a loaded documentation file (*.PLD).
Return Is the result:
=0, the structure elements have been copied,
=-1, the global data array **ppData does not exist, length = 0.
See also ReadPlot.

1-78 DR300 Speed Control Windows Software V1.0


Laboratory Setup DR300 Driver Functions for DR300W16

2 Driver Functions for DR300W16

2.1 The Class DICDRV

The class DICDRV provides the interface between the DR300W16 controller program and the driver functions of
the PC plug-in card. The class WDAC98 containing the driver functions is the basic class of DICDRV. In addition
this class contains the mathematical model of the speed control system when it is compiled with ’#define
__SIMULATION__’ (see file DRDEFINE.H). With this all program functions except for the calibration can be
carried-out for a simulated plant of the speed control system. The PC plug-in card is no longer required in this case.
This program version will be called ’DEMO-Version’ in the following.

Basic Class:

WDAC98 driver functions of the PC adapter card (file WDAC98.CPP)

The files DICDRV.H, DICDRV.CPP contain the class DICDRV with the functions:
DICDRV( void )
~DICDRV(){}
double ReadASpeed( void )

double ReadISpeed( void )


double ReadTime( void )
double ReadDriveCurrent( void )
double ReadLoadCurrent( void )
void SetControlSignals( double DriveControl, double LoadControl )

int CheckSystem( void )


int CheckFree( void )
int TopSwitch( void )
virtual void StartInterrupt( void )
virtual void TriggerEndstufe( void )

The files MODEL.H, MODEL.CPP contain the function:


void CalcModel( int reset )

The files TOOLS.H, TOOLS.CPP contain the function:


void WinDelay( int ms )

DR300 Speed Control Windows Software V1.0 2-1


Driver Functions for DR300W16 Laboratory Setup DR300

Public Data:

double lastdt is the duration of the last sampling period.


double Speed is the motor speed.
double DriveCurrent is the motor current.
double LoadCurrent is the generator current.
double DriveForce is the motor control signal.
double LoadForce is the generator control signal.

DICDRV::DICDRV
DICDRV( void )

Description The constructor of the class DICDRV initializes an object of the class WDAC98 and sets an
initial value for the timer device of the PC adapter card. The two analog outputs are reset to 0.
With the DEMO-version initial values are set for the motor speed and the two control signals of
the mathematical model.

DICDRV::~DICDRV
~DICDRV( void )

Description The destructor of the class DICDRV resets the real control signal to 0.

DICDRV::ReadASpeed
double ReadASpeed( void )

Description The function ReadASpeed reads the analog input connected to the tacho, converts this value to
[rpm] and stores the result to Speed. The same variable is returned.
With the DEMO-version the motor speed Speed calculated by the mathematical model is returned.
Return The speed of the motor measured by the tacho in [rpm].

2-2 DR300 Speed Control Windows Software V1.0


Laboratory Setup DR300 Driver Functions for DR300W16

DICDRV::ReadISpeed
double ReadISpeed( void )

Description The function ReadISpeed determines the real duration of the previous sampling period (lastdt
from ReadTime) and reads the incremental encoder signal to measure the speed of the motor.
The increments are limited to a range of +/-2047. Then the increments are used to calculate the
motor speed with respect to the real duration of the previous sampling period. The result is stored
in Speed and returned.
With the DEMO-version the motor speed Speed calculated by the mathematical model is returned.
Return The speed of the motor measured by the encoder in [rpm].

DICDRV::ReadTime
double ReadTime( void )

Description The function ReadTime determines the real duration of the previous sampling period by reading
the timer of the PC adapter card. The real duration in [sec] is calculated by scaling the difference
between the current timer reading and the timer reading from the previous call. In addition the
result is converted to [msec] and used to determine the minimum or maximum value of the
previous sampling periods since the first call of this function. The last values are stored to the
global structure tim of type ServiceTiming. Its number of sampling periods is incremented and
the nearest integer to the duration value is used as an index to increment the corresponding array
element as long as this index is positive and less than 20. The elements of the global structure tim
are initialized only for the first call of this function.
With the DEMO-version the nominal sampling period is returned.
Return The real duration of the previous sampling period in [sec].

DICDRV::ReadDriveCurrent
double ReadDriveCurrent( void )

Description The function ReadDriveCurrent reads the analog input connected to the current monitor of the
motor, converts this value to [A] and stores the result to DriveCurrent. The same variable is
returned.
With the DEMO-version the motor current DriveCurrent calculated by the mathematical model
is returned.
Return The current of the motor in [A].

DR300 Speed Control Windows Software V1.0 2-3


Driver Functions for DR300W16 Laboratory Setup DR300

DICDRV::ReadLoadCurrent
double ReadLoadCurrent( void )

Description The function ReadLoadCurrent reads the analog input connected to the current monitor of the
generator, converts this value to [A] and stores the result to LoadCurrent. The same variable is
returned.
With the DEMO-version the generator current LoadCurrent calculated by the mathematical
model is returned.
Return The current of the generator in [A].

DICDRV::SetControlSignals
void SetControlSignals( double DriveControl, double LoadControl )

Parameters DriveControl is the control signal for the motor in [V].


LoadControl is the control signal for the generator in [V].
Description The function SetControlSignals limits the control signals in [Volt] to the range of +/-10V and
transfers the limited values to the D/A-converters.
The D/A-conversion is omitted for the DEMO-version. The given control signals are assigned to
the variables DriveForce and LoadForce. Then the mathematical model of the speed control
system is calculated (CalcModel).

DICDRV::CheckSystem
int CheckSystem( void )

Description The function CheckSystem checks if the two system identification signals are equal to the mask
for a speed control system. When this condition is reached at least five times in ten successive
readings the return value is 1, else it is 0 (system lead not connected or defect?, wrong
lead/system).
Return A value of 1 for a positive system check, else 0.

DICDRV::CheckFree
int CheckFree( void )

Description The function CheckFree returns a value of 1, when the control by the PC (PCREADY) is enabled
at least five times in ten successive readings, else it returns 0.

Return Enable state of the PC control (0/1).

2-4 DR300 Speed Control Windows Software V1.0


Laboratory Setup DR300 Driver Functions for DR300W16

DICDRV::TopSwitch
int TopSwitch( void )

Description The function TopSwitch is a dummy function reserved for future use.
Return Always 0.

DICDRV::StartInterrupt
void StartInterrupt( void )

Description The function StartInterrupt activates the output stage release by sending a trigger pulse and
starting a rectangle signal. Any interrupt is left unchanged.

DICDRV::TriggerEndstufe
void TriggerEndstufe( void )

Description The function TriggerEndstufe toggles the level of the rectangle signal for the output stage release.

DICDRV::CalcModel
void CalcModel( int reset )

Parameters reset is the reset flag for the model calculation.


Description The function CalcModel calculates the approximated model of the speed control system with the
DEMO-version when the flag reset is FALSE, otherwise the model output is reset to zero before
the calculation is carried-out. The model output is stored to the motor speed Speed.

DICDRV::WinDelay
void WinDelay( int ms )

Parameters ms is the delay time in milliseconds.


Description The function WinDelay uses the multi media timer to produce a delay time of ms milliseconds.
The delay time is limited to the range from 1 to 100 milliseconds and incremented by one to reach
at least a delay time of 1 ms.

DR300 Speed Control Windows Software V1.0 2-5


Driver Functions for DR300W16 Laboratory Setup DR300

2.2 The Class WDAC98

The class WDAC98 realizes the interface between the class DICDRV and the driver functions (DIC24.DRV,
DAC98.DRV) of the PC adapter card. Calling the DRV-functions is carried-out by "SendMessage"-functions using
commands and parameters as described with the driver software (see also IODRVCMD.H).

The files WDAC98.CPP and WDAC98.H contain the class WDAC98 with the functions:

double ReadAnalogVolt( int channel )


void WriteAnalogVolt( int channel, double val )

int ReadDigital( int channel )


int ReadAllDigital( void )
void WriteDigital( int channel, int value )
unsigned int GetCounter( void )
void SetCounter( unsigned int val )

unsigned long GetTimer( void )


void SetTimer( unsigned long val )
unsigned int ReadDDM( int channel )

void ResetDDM( int channel )


void ResetAllDDM( void )

WDAC98::ReadAnalogVolt
double ReadAnalogVolt( int channel )

Parameters channel is the number of the analog input channel, which is to be read.
Description The function ReadAnalogVolt reads the analog input channel specified by channel and returns
the corresponding voltage value. The value is in the range from -10.0 to +10.0 with the assumed
unit [Volt].

Return: The input voltage of the analog channel in the range from -10.0 to +10.0.

2-6 DR300 Speed Control Windows Software V1.0


Laboratory Setup DR300 Driver Functions for DR300W16

WDAC98::WriteAnalogVolt
void WriteAnalogVolt( int channel, double val )

Parameters channel is the number of the analog output channel, to which a value is to be written.
val is the value for the analog output.
Description The function WriteAnalogVolt writes the value val in the range from -10.0 to +10.0 (with the
assumed unit [Volt]) as an analog voltage to the specified analog output channel. Values outside
of the mentioned range are limited internally.

WDAC98::ReadDigital
int ReadDigital( int channel )

Parameters channel is the number of the digital input channel, which is to be read.
Description The function ReadDigital reads the state (0 or 1 ) of the specified digital input channel and returns
this value.

Return: The state (0 or 1) of the specified digital input.

WDAC98::ReadAllDigital
int ReadAllDigital( void )

Description The function ReadAllDigital reads the state of all input channels and returns this value.
Return: The state of all digital input channels.

WDAC98::WriteDgital
void WriteDgital( int channel, int val )

Parameters channel is the number of the digital output channel, to which a value is to be written.
value is the new state of the digital output.
Description The function WriteDgital writes the value val (0 or 1) to the specified digital output channel and
with this sets its state.

DR300 Speed Control Windows Software V1.0 2-7


Driver Functions for DR300W16 Laboratory Setup DR300

WDAC98::GetCounter
unsigned int GetCounter( void )

Description The function GetCounter returns the content of the 16-bit-counter register.
Return: The content of the 16-bit-counter register.

WDAC98::SetCounter
void SetCounter( unsigned int val )

Parameters val is the new value for the 16-bit-counter register.


Description The function SetCounter writes the given value to the 16-bit-counter register.

WDAC98::GetTimer
unsigned long GetTimer( void )

Description The function GetTimer returns the content of the 32-bit-timer register.

Return: The content of the 32-bit-timer register.

WDAC98::SetTimer
void SetTimer( unsigned long val )

Parameters val is the new value for the 32-bit-timer register.


Description The function SetTimer writes the given value to the 32-bit-timer register.

WDAC98::ReadDDM
unsigned int ReadDDM( int channel )

Parameters channel is the number of the DDM device, which is to be read.


Description The function ReadDDM returns the content of the counter register of the specified DDM device
(incremental encoder).
Return: The content of the specified DDM counter register.

2-8 DR300 Speed Control Windows Software V1.0


Laboratory Setup DR300 Driver Functions for DR300W16

WDAC98::ResetDDM
unsigned int ResetDDM( int channel )

Parameters channel is the number of the DDM device, which is to be reset.


Description The function ResetDDM resets the content of the counter register of the specified DDM device
(incremental encoder).

WDAC98::ResetAllDDM
void ResetAllDDM( void )

Description The function ResetAllDDM resets the contents of the counter register of all DDM devices
(incremental encoders) at the same time.

DR300 Speed Control Windows Software V1.0 2-9


Driver Functions for DR300W16 Laboratory Setup DR300

2-10 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

3 The Fuzzy Library

3.1 Introduction to the Structure of the Fuzzy Library

The fuzzy library Fuzzy.lib is constructed with a strict hierarchical structure. Since an object oriented programming
language supports this, the library was programmed using the programming language "C++".

As described in "Backgrounds of the Fuzzy Controller", the fuzzy set is the lowest level of this hierarchy. A
separate class with the name FuzzySet was defined for the fuzzy set. Since nearly all run time operations use the
class FuzzySet, the design was carried out with respect to the optimization of the run time and a definition range as
wide as possible. As these aspects compete with each other, a compromise had to be found between run time and
flexibility. The number representation "double" was chosen, because this is supported directly by the arithmetic
coprocessors. But it is recommended to use a 486DX computer, which has a good performance even with this
number representation. Without an arithmetic coprocessor the fuzzy library can only be applied to slow processes or
off-line calculations, e.g. of a lookup table. The number representation "double" provides a nearly unlimited
definition range for the fuzzy sets. The definition range of a fuzzy set should be between 0 and 1 to achieve a good
overall view, but the correct function of the library does not require this range. The class FuzzySet represents a
fuzzy set by a polygonal line. This polygonal line is stored in form of a corresponding number of x/y values. An
object of type FuzzySet could hold theoretically up to 32768 of those values. But this number will never be
reached, since the available memory is limited. The next level in the hierarchy of the fuzzy library is represented
by the linguistic variable. This variable is included in the class FuzzyVar. A linguistic variable combines a group of
fuzzy sets which have the same definition range. The purpose of the class FuzzyVar is to prepare and handle its
data elements of the type FuzzySet. The x/y values of the objects of type FuzzySet of the class FuzzyVar are
expanded automatically so that all of the fuzzy sets contain the same number of x/y values (normalizing of the sets).
The x co-ordinates of the x/y values are identical. With respect to the run time it is therefore meaningful to use as
few x/y values as possible (usually 3-5 are sufficient) and to use the same x co-ordinates in the x/y values of sets
which are grouped to one linguistic variable.

The fuzzy rules are built by object types of the class FuzzyRule. The class FuzzyRule combines the input and
output linguistic variables together with their sets with respect to the syntax of a fuzzy rule. A separate object has to
be generated for every rule. The class FuzzyRule includes functions to interpret the rules.

The class Fuzzy holds the top of the hierarchy of the fuzzy library. Functions of this class are able to read a fuzzy
description file, to detect syntax errors and to a certain extent logical errors, to generate an executable rule base by
means the above mentioned classes and to compute the mean run time for this base. The class Fuzzy is the only one
of the mentioned classes of the library, which the user calls in his program. An object of the type Fuzzy is a
complete rule base, which is configured by a fuzzy description file. It is problem-free to handle multiple objects of
type Fuzzy, which are stored together in the memory. After reading the fuzzy description file it is recommended to
check by means of corresponding functions if errors occurred during the read and interpret operations. In case of no
error a fuzzy control base can then be generated. A built-in function for computing the mean run time of the
controller in one sampling period should be called before using this control base. The controller run time strongly
depends on the rule base, the number of linguistic variables and the used computer system. The control base should
only be called from an interrupt service routine in case the run time is about 50% shorter than the sampling period
(time between two interrupts).

DR300 Speed Control Windows Software V1.0 3-1


The Fuzzy Library Laboratory Experiment DR300

3.2 Description of the Classes


3.2.1 General

The library Fuzzy.lib at hand is compiled using the Borland C++ compiler version 4.2. The compiler switches code
optimization for the 386 processor as well as 16 bit, large memory model, were set.

3.2.2 Overview of the Classes


class FuzzySet
FuzzySet( char *name, int p )
FuzzySet( char *name, int p, double *x )
FuzzySet( char *name, int p, double *x, double *y )
FuzzySet( const FuzzySet& org)
~FuzzySet()
char *getname(void)
void cleary( void )
double *getxvector( void )
double *getyvector( void )
int getstuetzen( void )
void insert( double x, double y )
void normalize( int p, double *x )
double coa( void )
double crisp( double x )
void conclude( FuzzySet *a, double weight )
FuzzySet& operator = ( const FuzzySet& org )
FuzzySet& operator *= ( double factor )
FuzzySet& operator += ( const FuzzySet& org )
FuzzySet& operator << (ostream& o, const FuzzySet& s)
void tout( void )
class FuzzyVar
FuzzyVar( char *name, int c, int m )
~FuzzyVar()
char *getname( void )
char *getsetname( int i)
int getsetcount( void )
void add( int index, FuzzySet *set)
void check( void )
void norm( void )
int getmode( void )
double getmaxx( void )
double getminx( void )
double get( int SetNo )
void set( int SetNo, double weight )
void clear( void )

3-2 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

double out( void )


double getval( void )
void setval( double v )
void tout( void )
int vsort( int c, double *x )
FuzzyVar& operator << (ostream& o, const FuzzyVar& v)
class FuzzyRule
FuzzyRule( char *name, int i, int o )
~FuzzyRule()
char *getname( void )
void addIn( FuzzyVar *inv, int set, int op )
void addOut( FuzzyVar *outv, int set )
int Do( void )
void tout( void )
FuzzyRule& operator << (ostream& o, const FuzzyRule& r)
class Fuzzy
Fuzzy()
Fuzzy( char *, ostream& eout = cout )
~Fuzzy()
int read( char *n = NULL, ostream& eout = cout )
int write( char *n = NULL )
void generate( void )
void calc( double *, double * )
int getinputcount( void )
int getoutputcount( void )
int geterrors( void )
int getrulecatch( int i )
double speed( long count = 1000 )
int Get3DInfo( Fuzzy3DInfo *info )
char *getname( void )
void tout( void )
friend ostream& operator<<( ostream&, const Fuzzy& )
friend istream& operator>>( istream&, Fuzzy& )
int parser( istream&, ostream&)
void calcsetup( void )
char *gettoken( istream&, int mode=0 )
int defvar( istream&, ostream& )
int defset( VarDes*, istream&, ostream& )
int defrule( istream&, ostream& )
int deflabel( istream&, ostream& )
char *getlabel( char *)
void killstructures( void )
void killfuzzybase( void )
void killlabel( void )
void out( ostream& ) const

DR300 Speed Control Windows Software V1.0 3-3


The Fuzzy Library Laboratory Experiment DR300

3.2.3 References of the Classes, their Data and Element Functions

3.2.3.1 The Class FuzzySet


The class FuzzySet is a digital representation of a fuzzy set. The class is designed as a data element of the class
FuzzyVar which is a representation of a fuzzy linguistic variable.

Basic Class:

none

Public Data:

none

Public Element Functions

FuzzySet::FuzzySet
FuzzySet( char *name, int p )

Parameters char *name is a pointer to the name of the fuzzy set.


int p is the number of x/y values for which memory is to be
allocated.
Description The function is a constructor for an empty fuzzy set, but with a defined memory allocation for
the given number of x/y values.

FuzzySet::FuzzySet
FuzzySet( char *name, int p, double *x #following lines)

Parameters char *name is a pointer to the name of the fuzzy set.


int p is the number of x/y values for which memory is to be
allocated.
double *x is a vector of p double numbers, which represent
the x values of the p x/y values.
Description The function is a constructor for a fuzzy set with a defined X vector. The elements of the Y vector
are set to 0.

3-4 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

FuzzySet::FuzzySet
FuzzySet( char *name, int p, double *x, #following linesdouble *y )

Parameters char *name is a pointer to the name of the fuzzy set.


int p is the number of x/y values for which memory is to be
allocated.
double *x is a vector of p double numbers, which represent
the x values of the p x/y values.
double *y is a vector of p double numbers, which represent
the y values of the p x/y values.
Description The function is a constructor for a fuzzy set with defined X and Y vectors.

FuzzySet::FuzzySet
FuzzySet( const FuzzySet& org)

Parameters const FuzzySet& org is a reference to the fuzzy set, which


is to be copied.
Description The function is a copy constructor.

FuzzySet::~FuzzySet
~FuzzySet()

Description The function is the destructor.

FuzzySet::getname
char *getname(void)

Description The function getname returns a pointer to the name of the fuzzy set.
Return The pointer (char *) to the name of the fuzzy set.

DR300 Speed Control Windows Software V1.0 3-5


The Fuzzy Library Laboratory Experiment DR300

FuzzySet::cleary
void cleary( void )

Description The function cleary sets all elements of the Y vector to 0.

FuzzySet::getxvector
double *getxvector( void )

Description The function getxvector returns a pointer to the data array of the X vector.

Return The pointer (double *) to the X vector.

FuzzySet::getyvector
double *getyvector( void )

Description The function getxvector returns a pointer to the data array of the Y vector.
Return The pointer (double *) to the Y vector.

FuzzySet::getstuetzen
int getstuetzen( void )

Description The function getstuetzen returns the number of the x/y values.

Return The number (int) of the x/y values in the set.

FuzzySet::insert
void insert( double x, double y )

Parameters double x is the x value to be inserted.


double y is the y value to be inserted.
Description The function insert inserts a x/y value in the fuzzy set in case the new value is not redundant.

3-6 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

FuzzySet::normalize
void normalize( int p, double *x )

Parameters int p is the new number of x/y values.


double *x is the new x vector with p co-ordinates.
Description The function normalize normalizes the fuzzy set such that it contains p x/y values with the x
co-ordinates from the given x vector. The fuzzy set will not loose information only in case its old
x co-ordinates are a subset of the new x co-ordinates.

FuzzySet::coa
double coa( void )

Description The function coa calculates a modified centre of area of the fuzzy set.
Return The value (double) of the centre of area point.

FuzzySet::crisp
double crisp( double x )

Parameters double x is the x value for which the crisp value is to be


calculated.
Description The function crisp calculates the y crisp value belonging to the given x value.

Return The calculated crisp value (double).

FuzzySet::conclude
void conclude( FuzzySet *a, double weight )

Parameters FuzzySet *a is the fuzzy set overlay.


double weight is the weighting coefficient.
Description The function conclude overlays the set with the given fuzzy set *a evaluated by the weighting
coefficient weight (Maximum/Product method).

DR300 Speed Control Windows Software V1.0 3-7


The Fuzzy Library Laboratory Experiment DR300

FuzzySet::tout
void tout( void )

Description The function tout provides online-debugging. Its output is a representation of the set in readable
text on the screen. This function is still available only to guarantee compatibility with older version
of the fuzzy library. Please use instead the operator <<.

Private Data:
char *SetName is a pointer to the name of the fuzzy set.
double *xval is a pointer to the x vector.
double *yval is a pointer to the y vector.
int sizeis the reserved number of x/y values.
int ss is the actual number of the x/y values.

Private Element Functions:

none

Operators:

FuzzySet::=
FuzzySet& operator = ( const FuzzySet& org )

Parameters const FuzzySet& org is a reference to the set, which is to be copied.


Description The assignment operator only operates in case the sets are of the same size. The actual set will be
a copy of the set given by its reference.

Return FuzzySet& is a reference to the copied set.

3-8 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

FuzzySet::*=
FuzzySet& operator *= ( double factor )

Parameters double factor is the scaling factor.


Description The scaling operator is used to weight the set according to the Maximum/ Product method. The
format of the weighting coefficient is double.
Return FuzzySet& is a reference to the set.

FuzzySet::+=
FuzzySet& operator += ( const FuzzySet& org )

Parameters FuzzySet& org is a reference to the set, which is to be added.

Description The summation operator only operates in case the two sets have the same size. The set given by
its reference is added to the actual set.
Return FuzzySet& is a reference to the sum of the sets.

FuzzySet::<<
FuzzySet& operator<< (ostream& o, const FuzzySet& s)

Parameters ostream& o is a reference to the output stream.


FuzzySet& s is a reference to the fuzzy set, which is to be
written to the output stream.
Description The operator writes the state of the fuzzy set to the given stream using readable text format.
Return A reference to the output stream.

DR300 Speed Control Windows Software V1.0 3-9


The Fuzzy Library Laboratory Experiment DR300

3.2.3.2 The class FuzzyVar


The class FuzzyVar is the digital representation of a fuzzy linguistic variable. The class is used as a data element of
the class Fuzzy.

Basic Classes:

none

Public Data:

none

Public Element Functions:

FuzzyVar::FuzzyVar
FuzzyVar( char *name, int c, int m )

Parameters char *name is the name of the linguistic variable.


int c is the number of fuzzy sets, which can be inserted.
int m is the operation mode of the variables.
Description The constructor of a linguistic variable requires 3 parameters, the variable name, the number of
sets and the mode. The mode defines the direction of the variable i.e. input (bit0 = 0) or output
(bit0 = 1).

FuzzyVar::~FuzzyVar
~FuzzyVar()

Description The destructor not only erases the data defined by the constructor but also all the fuzzy sets, which
were assigned to the linguistic variable by the function add. Therefore a fuzzy set can only be
assigned to one fuzzy variable.

3-10 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

FuzzyVar::getname
char *getname( void )

Description The function returns a pointer to the name of the linguistic variable.
Return The pointer (char *) to the variable name.

FuzzyVar::getsetname
char *getsetname( int i)

Parameters int i is the index of the fuzzy set.


Description The function returns a pointer to the name of a fuzzy set of the variable. The index of the set is
given by the parameter i.

Return The pointer (char *) to the name of the fuzzy set.

FuzzyVar::getsetcount
int getsetcount( void )

Description The function returns the number of the fuzzy sets assigned to this variable.
Return The number (int) of sets assigned to the variable.

FuzzyVar::add
void add( int index, FuzzySet *set)

Parameters int index is the index of the fuzzy set.


FuzzySet *set is the pointer to the fuzzy set, which will be inserted.
Description The function add assigns the fuzzy set, referenced by its pointer (*set), to the linguistic variable.
The position of the set assigned to the variable is defined by the value index. The calling function
has to take care about the index. The fuzzy sets have to be created dynamically since they will be
deleted by the destructor of the linguistic variable. Calling the function add will transfer the
handling of the fuzzy set completely to the class FuzzyVar.

DR300 Speed Control Windows Software V1.0 3-11


The Fuzzy Library Laboratory Experiment DR300

FuzzyVar::check
void check( void )

Description The function check checks the logic structure of the linguistic variable. This function is not
implemented at the moment. It is intended for a future expansion of the class.

FuzzyVar::norm
void norm( void )

Description The function norm normalizes the linguistic variable. That means every set of the variable has
the same number of x/y values at the same x co-ordinates. This is required for calculations with
the fuzzy sets.

FuzzyVar::getmode
int getmode( void )

Description The function getmode returns the operation mode of the variable i.e. its direction input (bit0= 0)
or output (bit0 = 1).
Return The operation mode (int) of the variable.

FuzzyVar::getmaxx
double getmaxx( void )

Description The function getmaxx determines the maximum X value of the definition range of the normalized
fuzzy variable.
Return The maximum value (double) of the x vector of the variable.

FuzzyVar::getminx
double getminx( void )

Description The function getminx determines the minimum X value of the definition range of the normalized
fuzzy variable.
Return The minimum value (double) of the x vector of the variable.

3-12 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

FuzzyVar::get
double get( int SetNo )

Parameters int SetNo is the index of the fuzzy set.


Description The function get returns the crisp value of the set referenced by its index SetNo. The input value
of the set is identical to the input value of the variable (see also function setval).
Return The determined crisp value (double).

FuzzyVar::set
void set( int SetNo, double weight )

Parameters int SetNo is the index of the fuzzy set, which is to be overlaid.
double weight is the weighting factor.
Description The function set overlays the output set, referenced by its index SetNo, of the variable. The overlay
is weighted by the given weighting coefficient. This function is applicable only to linguistic
variables generated as output variables.

FuzzyVar::clear
void clear( void )

Description The function clear erases the output set of the variable. This is required at the beginning of every
sampling period (control period), but not for every rule. This function is only applicable to output
variables (see also the constructor).

FuzzyVar::out
double out( void )

Description The function out returns the centre of area of the output set of the variable. This function is only
applicable to output variables (see also the constructor).
Return The centre of area (double) of the output set of the variable.

DR300 Speed Control Windows Software V1.0 3-13


The Fuzzy Library Laboratory Experiment DR300

FuzzyVar::getval
double getval( void )

Description The function getval returns the current input value of the variable.
Return The input value (double) of the variable.

FuzzyVar::setval
void setval( double v )

Description The function tout provides online-debugging. Its output is a representation of the linguistic
variable in readable text on the screen. This function is still available only to guarantee
compatibility with older version of the fuzzy library. Please use instead the operator <<.

Private Data:
char *VarName is the pointer to the name of the linguistic variable.
int SetCount is the number of fuzzy sets assigned to this variable.
FuzzySet **d is the pointer to the array of fuzzy sets.
double *normx is the pointer to the normalized x vector.
double value is the input value of the variable.
int mode is the operation mode of the variable:
Bit 0: =0, input variable
= 1, output variable
Bit 1-15 reserved for future expansions.

3-14 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Private Element Functions:

FuzzyVar::vsort
int vsort( int c, double *x )

Parameters int c is the number of elements in the x vector.


double *x is the given x vector.
Description The help function vsort sorts the c elements of the given x vector. The vector is sorted with
ascending order, double elements are deleted. The new number of elements is returned. This
function is used in case of the normalization of the linguistic variable.

Return The new number (int) of elements in the x vector.

Operators:

FuzzyVar::<<
FuzzyVar& operator<< (ostream& o, const FuzzyVar& v)

Parameters ostream& o is a reference to the output stream.


FuzzyVar& v is a reference to the fuzzy variable, which is to be written to the output stream.
Description The operator writes the state of the fuzzy variable to the given stream using readable text format.
Return A reference to the output stream.

DR300 Speed Control Windows Software V1.0 3-15


The Fuzzy Library Laboratory Experiment DR300

3.2.3.3 The class FuzzyRule


The class FuzzyRule is the digital representation of a fuzzy rule. The class is used as a data element of the class
Fuzzy.

Basic Classes:

none

Public Data:

none

Public Element Functions:

FuzzyRule::FuzzyRule
FuzzyRule( char *name, int i, int o )

Parameters char *name is the pointer to the name of the rule.


int i is the number of input combinations.
int o is the number of output combinations.
Description The constructor generates a fuzzy rule. Three parameters are required, the name of the rule
(*name), the number of input combinations (i) and the number of output combinations (o).

FuzzyRule::~FuzzyRule
~FuzzyRule()

Description The destructor erases the memory allocated by the constructor.

FuzzyRule::getname
char *getname( void )

Description The function getname returns the pointer to the name of the rule.
Return The pointer (char *) to the name of the rule.

3-16 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

FuzzyRule::addIn
void addIn( FuzzyVar *inv, int set, int op )

Parameters FuzzyVar *inv is the referenced variable of an input combination.


int set is the set index of an input combination.
int op is the operator of an input combination.
Description The function addIn adds an input combination to the fuzzy rule. Therefore the pointer to an input
fuzzy variable, the set index and the combination operator has to be given.

FuzzyRule::addOut
void addOut( FuzzyVar *outv, int set )

Parameters FuzzyVar *inv is the referenced variable of an output combination.


int set is the set index of an output combination.
int op is the operator of an output combination.
Description The function addOut adds an output combination to the fuzzy rule. Therefore the pointer to an
output fuzzy variable, the set index and the combination operator have to be given.

FuzzyRule::Do
int Do( void )

Description The function Do interprets a fuzzy rule. A value has to be assigned to the input variables
previously. The defuzzification of the output sets of the output variables is not performed since
this is only meaningful in case all the rules are interpreted. The operators of the input use the
MIN/MAX (and/or) method. The interference is carried out using the Maximum/Product method.
Return Status (int) is 0 in case the rule is not applicable.

FuzzyRule::tout
void tout( void )

Description The function tout provides online-debugging. Its output is a representation of the fuzzy rule in
readable text on the screen. This function is still available only to guarantee compatibility with
older version of the fuzzy library. Please use instead the operator <<.

DR300 Speed Control Windows Software V1.0 3-17


The Fuzzy Library Laboratory Experiment DR300

Private Data:
char *RuleName is the pointer to the name of the rule.
int incount is the number of input combinations of the rule.
FuzzyVar **invars is the pointer to an array of pointers to input variables.
int *inset is the pointer to an array of index of the sets.
int *operators is the pointer to an array of operators.
int outcount is the number of output combinations of the rule.
FuzzyVar **outvars is the pointer to an array of pointers to output variables.
int *outset is the pointer to an array of index of the sets.
int iidx, oidx are index variables.

Private Element Functions:

none

Operators:

FuzzyRule::<<
FuzzyRule& operator << (ostream& o, const FuzzyRule& r)

Parameters ostream& o is a reference to the output stream.


FuzzyVar& r is a reference to the fuzzy rule, which is to be written to the output stream.
Description The operator writes the state of the fuzzy rule to the given stream using readable text format.
Return A reference to the output stream.

3-18 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

3.2.3.4 The Class Fuzzy


The class Fuzzy is the digital representation of a fuzzy controller. The class provides methods to handle, to
read/write, to interpret and to execute fuzzy control bases. The class Fuzzy has no basic class but it requires data
elements which are objects of the following classes:

FuzzySet,

FuzzyVar,

FuzzyRule,

Basic Classes:

none

Public Data:

struct Fuzzy3DInfo{
long size; // current size of this structure
int idx; // index for the first input variable
int idy; // index for the second input variable
int idz; // index for the output variable
char xname[80]; // name of the first input variable
char yname[80]; // name of the second input variable
char zname[80]; // name of the output variable
double xmin; // minimum value of the first input variable
double xmax; // maximum value of the first input variable
double ymin; // minimum value of the second input variable
double ymax; // maximum value of the second input variable
double zmin; // minimum value of the output variable
double zmax; // maximum value of the output variable
};

DR300 Speed Control Windows Software V1.0 3-19


The Fuzzy Library Laboratory Experiment DR300

Public Element Functions:

Fuzzy::Fuzzy
Fuzzy()

Description The constructor prepares the fuzzy control base. All of the pointers are initialized and a mechanism
to supervise the ’new’ operator is installed. The control base can be used only after a call to the
functions parser and generate.

Fuzzy::Fuzzy
Fuzzy( char *name, ostream& eout = cout )

Parameters char *name is the name of the fuzzy description file.


ostream& eout is the reference to an output stream, which is to be used for status/error
messages (default: cout).

Description Alternatively to the a. m. standard constructor the control base can be generated using a data file
name. In this case the function read is executed besides the operations of the standard constructor.
The function read reads the file referenced by its name (*name) and prints out status/error
messages to the given stream (eout). Attention: The constructor does not return any error
information. Therefore it is strongly required to test the error status by using the function geterrors
before the program is continued.

Fuzzy::~Fuzzy
~Fuzzy()

Description The destructor has the task to free the memory, which was allocated by this object. To do this the
operator uses several help functions (see killstructures, killbase, killlabel).

3-20 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Fuzzy::read
int read( char *name = NULL, ostream& eout = cout #following lines)

Parameters char *name is the name of the fuzzy description file (default: NULL)
ostream& eout is the reference to an output stream, which is to be used for status/error
messages (default: cout).

Description The function read opens the fuzzy description file referenced by its file name (*name) and
interprets its data using the function parser. Status and error messages are sent to the given stream
(eout).
Return int, is the number of errors occurred.

Fuzzy::write
int write( char *n = NULL )

Parameters char *n is the name of the fuzzy description file to be created (default: NULL)

Description The function write creates a fuzzy description file on the mass storage depending on the structure
of the fuzzy control base stored in the memory of the computer. This file is readable later on by
the function read. Its name is the given file name (*name).
Return The error status (int) (=0, no error).

Fuzzy::generate
void generate( void )

Description The function generate creates the fuzzy control base using the tree of structures generated by the
function parser. Doing this objects of type FuzzySet, FuzzyVar and FuzzyRule are created.
Existing rule bases are deleted previously (be careful in case of online calls).

DR300 Speed Control Windows Software V1.0 3-21


The Fuzzy Library Laboratory Experiment DR300

Fuzzy::calc
void calc( double *in, double *out )

Parameters double *in is the vector with the values of the input variables.
double *out is the vector with the values of the output variables.
Description The function calc executes the controller function. An array of input values (format: double) is
referenced by its pointer (*in). The pointer (*out) points to an array, which is to be used to store
the output values (format: double). A sufficient size of the arrays has to be regarded. The array
sizes of the control base are known from the fuzzy description file. The order of the array items
is according to the order of their definitions in the description file.

Fuzzy::getinputcount
int getinputcount( void )

Description The function getinputcount returns the number of input variables.

Return The number (int) of input variables.

Fuzzy::getoutputcount
int getoutputcount( void )

Description The function getoutputcount returns the number of output variables.


Return The number (int) of output variables.

Fuzzy::geterrors
int geterrors( void )

Description The function geterrors returns the number of errors occurred during the last call to the function
parser.
Return The number (int) of errors occurred.

3-22 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Fuzzy::getrulecatch
int getrulecatch( int i )

Parameters int i is the index of the rule.


Description The function getrulecatch detects whether the rule i was activated during the last controller
execution. The parameter i is the index of the rule inside the rule base. In case of an illegal rule
index the value -1 is returned.
Return Status (int) is equal to 1 in case the rule was activated during the last pass.

Fuzzy::speed
double speed( long count = 1000 )

Parameters long count is the number of test passes ( default: 1000 ).

Description The function speed provides run time analysis (available only for DOS and Windows). It
determines the definition range of the input variables, generates random input values belonging
to this definition range and calculates the mean run time of the function calc. The number of passes
through the function calc, which is to be used to determine the mean value, is given by the
parameter count. The mean run time is returned in milli seconds. The function requires an
executable rule base. The longest possible run time cannot be determined, since the run time
depends on the number of the active rules and with that on the input values. Attention:
Manipulations of the timer interrupt (i.e. for the sampling period) falsify the result.
Return The mean run time (double) of the rule base in milli seconds.

DR300 Speed Control Windows Software V1.0 3-23


The Fuzzy Library Laboratory Experiment DR300

Fuzzy::Get3DInfo
int Get3DInfo( Fuzzy3DInfo *info )

Parameters Fuzzy3DInfo *info is a pointer to a structure of type Fuzzy3DInfo.


Description The function Get3DInfo copies the names and range values of those fuzzy variables referenced
by their indexes. The indexes idx, idy and idz are taken from the Fuzzy3DInfo structure pointed
to by info. For valid indexes the names, minimum and maximum values of the referenced variables
are copied to this structure. When the index idy is invalid (less than 0 or greater than the number
of input variables of this fuzzy object) only, its value is set equal to the valid value of idx. This
allows for a three-dimensional representation of the characteristic area of a fuzzy object containing
only one input variable.
Return Status (int) of operations:
0, no errors
-1, invalid pointer info (=NULL)
-2, size conflict in Fuzzy3DInfo structure
-3, invalid index idx ( < 0 or > number of input variables)
-4, invalid index idz ( < 0 or > number of output variables)

Fuzzy::getname
char *getname( void )

Description The function getname returns a pointer to the name of the rule base.
Return The pointer (char *) to the name of the rule base.

Fuzzy::tout
void tout( void )

Description The function tout provides online-debugging. Its output is a representation of the fuzzy rule base
in readable text on the screen. This function is still available only to guarantee compatibility with
older version of the fuzzy library. Please use instead the operator <<.

3-24 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Private Data:
char *basename is the pointer to the name of the rule base.
int errorcnt is the counter for the errors occurred during run time.
FuzzyVar **vars is the pointer to an array of pointers to fuzzy variables.
int varcount contains the number of fuzzy variables in the a. m. array.
FuzzyRule **rules is the pointer to an array of pointers to fuzzy rules.
int rulecount contains the number of fuzzy rules.
int *rulecatch is the pointer to an integer array (its size is equal to the number rules) containing
information, whether the specified rule was active during the last execution
pass (!=0) or inactive (==0).
Description structures in form of trees and chained lists for loading, saving and interpreting of fuzzy knowledge
bases are described in the following. Each element of the fuzzy rule base is described by its own structure.
struct PointDes{
PointDes *next, is a pointer to the next element.
double x, is the X value of the base point (X/Y-values).
double y, is the Y value of the base point.
} is a description structure (off-line) for the base points of a fuzzy set.
struct SetDes{
SetDes *next, is a pointer to the next set of the variable.
PointDes *first, is a pointer to the first base point.
int pointcount, is the base point counter.
char *setname is a pointer to the name of the set.
} is a description structure (off-line) for the fuzzy sets of a fuzzy variable.
struct VarDes{
VarDes *next, is a pointer to the next variable.
SetDes *first, is a pointer to the first set of the variable.
int setcount, is the set counter.
char *varname, is a pointer to the name of the variable.
int mode is the operation mode of the variable.
} is a description structure (off-line) for a fuzzy variable.
struct PraeDes{
PraeDes *next, is a pointer to the next premise of the rule.
VarDes *var, is a pointer to the variable structure of the premise.
SetDes *set, is a pointer to the set structure of the a. m. variable.
int op is the operator
} is a description structure (off-line) for the premise of a fuzzy rule.
struct ConDes{
ConDes *next, is a pointer to the next conclusion of the rule.
VarDes *var, is a pointer to the variable structure of the conclusion.
SetDes *set, is a pointer to the set structure of the a. m. variable.
} is a description structure (off-line) for the conclusion of a fuzzy rule.

DR300 Speed Control Windows Software V1.0 3-25


The Fuzzy Library Laboratory Experiment DR300

struct RulDes{
RulDes *next, is a pointer to the next rule.
PraeDes *firstPrae, is a pointer to the first premise of the rule.
ConDes *firstCon, is a pointer to the first conclusion of the rule.
char *rulename, is a pointer to the name of the rule.
} is a description structure (off-line) for a fuzzy rule.
struct label{
label *next, is pointer to the next label structure.
char *name, is a pointer to the label name.
char *val, is a pointer to the label definition.
} is a description structure (off-line) for a label definition.
VarDes *Varbase is the base address of the list of variables.
RulDes *Rulebase is the base address of the list of rules.
label *Labelbase is the base address of the list of labels.
int incount is the number of inputs.
int outcount is the number of outputs.
int *invars is a pointer to an index array for the input variables.
int *outvars is a pointer to an index array for the output variables.

3-26 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Private Element Functions:

Fuzzy::parser
int parser( istream& in, ostream& out)

Parameters istream& in is the reference to the stream from which the fuzzy description file is read.
ostream& out is the reference to the stream to which error messages are written.
Description An input stream and an output stream are given to the function parser. The function reads
characters from the input stream (in) and interprets it as a fuzzy description file for a fuzzy rule
base. Status and error messages are sent to the output stream (out). To describe the rule base a
tree structure containing chained lists is generated with respect to the description file for a fuzzy
rule base. Syntax errors and to a certain extent logical errors are detected during the interpretation
of the description file. The number of errors is returned by the function but it can be inquired
alternatively by the function geterrors. In case a tree structure for describing the fuzzy rule base
is existing before the function parser is called, this structure is deleted automatically. To interpret
the fuzzy description file the function parser uses the following help functions:
gettoken() to read ’words’ (separated by spaces)
defvar() to read and handle a variable definition
defrule() to read and handle a rule definition
deflabel() to read and handle a label definition
Return The number (int) of errors occurred.

Fuzzy::calcsetup
void calcsetup( void )

Description The function calcsetup prepares a complete rule base for calculation of its values. To do this index
arrays of inputs and outputs are installed. This function is called automatically by the function
generate.

DR300 Speed Control Windows Software V1.0 3-27


The Fuzzy Library Laboratory Experiment DR300

Fuzzy::gettoken
char *gettoken( istream& in, int mode=0 )

Parameters istream& in is the reference to the stream from which the token is to be read.
int mode is the operation mode, see above (default = 0).
Description The function gettoken reads a character string from the given input stream (in) and returns it. The
character strings are separated by white spaces (i.e. spaces, tabs etc.). Comments starting with
’/*’ and ending with ’*/’ are ignored. Labels belonging to the list of labels are replaced
automatically by their definition. The second parameter of the function is assignable to the legal
values 0 or 1:
mode = 0, an arbitrary string (without spaces etc.) is read.
mode = 1, a numerical value (incl. dec. point etc.) is read,
in case of an error in the numerical input the first characters of the returned string
is -1.
Return The pointer (char *) to the token read.

Fuzzy::defvar
int defvar( istream& in, ostream& out)

Parameters istream& in is the reference to the stream from which the description of the linguistic variable
is read.
ostream& out is the reference to the stream to which the status and error messages are written.

Description The function defvar reads and handles a fuzzy linguistic variable. It is called as a help function
by the function parser. The input stream (in) for reading and the output stream (out) to which
error and status messages are written is given to the function. The function returns the number of
errors which occurred during the definition of the linguistic variable.
Return The number (int) of errors occurred.

3-28 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Fuzzy::defset
int defset( VarDes *v, istream& in , ostream& out)

Parameters VarDes *v is the pointer to the descriptive structure of the linguistic variable from the higher
level.
istream& in is the reference to the stream from which the description of the fuzzy set is read.
ostream& out is the reference to the stream to which status and error messages are written.
Description The function defset reads and handles a fuzzy set. It is called as a help function by the function
defvar which reads and handles a linguistic variable. The arguments given to the function are the
descriptive structure of the linguistic variable from the higher level (*v), the input stream (in)
from which is read and the output stream (out) to which error and status messages are written.
The function returns the number of errors which occurred during the definition of the fuzzy set.
Return The number (int) of errors occurred.

Fuzzy::defrule
int defrule( istream& in, ostream& out)

Parameters istream& in is the reference to the stream from which the description of the rule is read.
ostream& out is the reference to the stream to which status and error messages are written.
Description The function defrule reads and handles a fuzzy rule. It is called as a help function by the function
parser. The arguments of the function are the input stream (in) from which is read and the output
stream (out) to which error and status messages are written. The function returns the number of
errors which occurred during the definition of the rule.
Return The number (int) of errors occurred.

Fuzzy::deflabel
int deflabel( istream& in, ostream& out )

Parameters istream& in is the reference to the stream from which the description of the label is read.
ostream& out is the reference to the stream to which status and error messages are written.
Description The function deflabel reads and handles the definition of a label. It is called as a help function
from the function parser. The arguments of the function are the input stream (in) from which is
read and the output stream (eout) to which error and status messages are written. The function
returns the number of errors which occurred during the definition of the label. Attention: This
function does not operate with gettoken (compare with numerical input)!
Return The number (int) of errors occurred.

DR300 Speed Control Windows Software V1.0 3-29


The Fuzzy Library Laboratory Experiment DR300

Fuzzy::getlabel
char *getlabel( char *s)

Parameters char *s is the pointer to the name of the label to be searched.


Description The function getlabel searches the list of label definitions for the string referenced by *s. In case
this string is found in the list, a pointer to its definition in the list is returned. This pointer is NULL
in the other case. This function is called as a help function from the function gettoken.
Return The pointer (char *) to the label found in the list (=NULL not found).

Fuzzy::killstructures
void killstructures( void )

Description The function killstructures erases the tree of structures which was used to generate the rule base.
The rule base itself is left unchanged.

Fuzzy::killfuzzybase
void killfuzzybase( void )

Description The function killfuzzybase erases the rule base. Further calls to the function calc are no longer
permitted.

Fuzzy::killlabel
void killlabel( void )

Description The function killlabel erases a list of definitions which were constructed according to ’#define’
assignments from the description file. The rule base and its description by a tree of structures are
left unchanged.

3-30 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

Fuzzy::out
void out( ostream& o) const

Parameters ostream& o is the reference to the stream to which the fuzzy


description file is written.
Description The function out writes the fuzzy rule base in readable text (format of fuzzy description file) to
the referenced stream. The basic representation is the tree of structures of the fuzzy rule base
stored in the memory of the computer. The function is called as an elementary function by the
functions write, tout and the operator <<.

Operators:

Fuzzy::<<
friend ostream& operator<<( ostream& o, const Fuzzy& f)

Parameters ostream& o is the reference to the stream to which the fuzzy description file is to be written.
const Fuzzy& f is the object of type Fuzzy, which is to be written.
Description The operator << writes the fuzzy rule base in readable ASCII text to the referenced stream.
Return ostream& is the reference to the stream to which the fuzzy description

Fuzzy::>>
friend istream& operator>>( istream& i, Fuzzy& f)

Parameters istream& i is the reference to the stream from which the fuzzy description file is to be read.
const Fuzzy& f is the object of type Fuzzy, which is to be read.
Description The operator >> reads the ASCII text of the fuzzy rule base from the referenced stream.
Information about syntax or logical errors are to be detected by the function geterrors.
Return ostream & is the reference to the stream from which the fuzzy description

DR300 Speed Control Windows Software V1.0 3-31


The Fuzzy Library Laboratory Experiment DR300

3.3 Description of the File Formats


3.3.1 The Format of the Fuzzy Description File (*.FUZ)

The fuzzy description file with the extension FUZ is a file to configure a fuzzy controller. The file format is
developed by the amira GmbH and is used by several products of the amira.

The fuzzy description file is used to configure a fuzzy object, which i.e. may operate as a fuzzy controller.

The fuzzy description file is a simple ASCII file, which can be edited by a text editor. The length of a line is limited
to 255 characters. Single assignments are separated by spaces or tabulators.

It contains four types of elements, which are described in the following sections:

Comments [optional]

The file can include a comment in classical C-style (’/*’ at the beginning and ’*/’ at the end) at every position
except for the definition part of label. At least one space has to separate the comment string from the ’keywords’
’/*’ and ’*/’.

The Definition of a Label [optional]

The definition of a label is limited to one line. It starts with the statement ’#define’. The next statement contains the
label name and the last statement contains the label definition. Thus a label can be defined as follows:

#define name This_is_the_definition_of_the_label_name

The Definition of Fuzzy Sets and Variables

The definition of fuzzy sets is only allowed within the Fuzzy-Var: "temperature"
definition of variables. It is ignored in the other case. The
medium
definition of a variable starts with the statement ’var’. The 1
next statement can hold two different names, either ’input’ cold warm
Membership

in case an input variable is to be defined or ’output’ in case


an output variable is to be defined. The third statement of a
variable definition is its name. Now the definition of the
fuzzy set follows. It begins with the statement ’set’
followed by the name of the fuzzy set. The name is
followed by the x/y values as base points for a polygonal 0
10 20 30 in degree Celsius
line. Similar to the statements the numbers are separated
by spaces or tabulators. The definition of the fuzzy set
Figure 3.1: The fuzzy variable ’temperature’
ends with the statement ’endset’. The definition of a
variable ends with the statement ’endvar’ after all the

3-32 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

fuzzy sets of the fuzzy variable are defined. Such a definition may look like the following:

var input temperature


set cold 10 1 20 0 endset
set medium 10 0 20 1 30 0 endset
set warm 20 0 30 1 endset
endvar

The Definition of Fuzzy Rules

The definition of a fuzzy rule is recognized from its first statement ’if’. The last statement of a fuzzy rule is named
’end’. The definition of a fuzzy rule contains two parts, the premise and the conclusion. Both parts are separated by
the statement ’then’. The premise and the conclusion are built by a series of expressions which are combined by
operators (further details are shown in the chapter of the theoretical backgrounds of a fuzzy controller). Permitted
operators of the premise are ’and’ (Min-Operator) and ’or’ (Max-Operator) whereas the conclusion requires no
operator to separate the expressions. An expression is the linkage of a fuzzy variable with one of its sets using the
statement ’is’.

The formulation of a fuzzy rule requires that all the variables in use are defined previously since the fuzzy
description file is interpreted only once from top to bottom. The syntax check of a fuzzy object tests whether the
variables are defined, whether the used sets really belong to the variable and if the expressions are used correctly
(input variables with the premise and output variables with the conclusion). A simple definition of a fuzzy rule may
look like the following:

if temperature is cold then heating is high end

Table of the valid commands (keywords) and their explanation:


Command Explanation

#define NAME Defines a NAME, which is usable in the following statements and will be replaced by the
TEXT definition TEXT automatically by the pre-processor.
/* Begin of comment, ignored by the fuzzy controller kernel.
*/ End of comment.
var Begin of linguistic variable definition. The statements "input" or "output" and the name of
the variable must follow this keyword. Fuzzy sets are definable only in the following. The
definition of the variable is terminated with the statement "endvar".
input Defines the direction input for a variable.
output Defines the direction output for a variable.
endvar End of definition of a variable.
set Begin of fuzzy set definition. A set name and a series of pairs of values must follow this
keyword. The pairs of values are the base points of the set.
endset End of set definition.

DR300 Speed Control Windows Software V1.0 3-33


The Fuzzy Library Laboratory Experiment DR300

Command Explanation

if Begin of fuzzy rule definition. One or multiple premises separated by operators, the
statement "then" and one or multiple conclusions must follow this keyword. The rule
definition is terminated by the statement "end". A premise consists of a name of an input
variable, the statement "is" and the name of the set belonging to this input variable. The
conclusion is built in a similar way but the input variable is replaced by the output variable.
is Separates variable and set in a premise or conclusion.
then Separates the condition and the assignment part of a fuzzy rule.
and Is the Minimum-Operator.
or Is the Maximum-Operator.
end End of rule definition.

Remark

The status and error messages which occur during the interpretation of the fuzzy description file are written to the
file ERROR.OUT or appear on the screen.

3.3.2 The Format of the Error Output File ERROR.OUT

During loading and interpreting of a fuzzy description file status and possible error messages are written to the file
ERROR.OUT. This file has the following format:

Fuzzy Parser Version 1.04 (07-DEC-94)

Fuzzy-Set <set_name> is already defined.


Fuzzy-Set <set_name> expects numerical value.
Unknown variable specification <string>.
Variable <var_name> is already defined.
Rule error, fuzzy variable <var_name> not found.
Rule error, fuzzy variable <var_name> is an output variable.
Rule error, fuzzy variable <var_name> is an input variable.
Rule syntax error, missing is.
Rule error, fuzzy set <set_name> is not member of <var_name>.
Rule syntax error, unknown Operator <string>.
<label_name>isalreadydefined.
<n>Errorsdetected.

3-34 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 The Fuzzy Library

3.4 A Very Simple Example


3.4.1 The Fuzzy Description File of a Temperature Control

The simple temperature control of an electrical heating requires two variables, the temperature and the heating
current. Here the temperature is the input variable and the heating current is the output variable. The description of a
fuzzy controller for this system may look like the following:

/* A simple temperature control */


var input temperature /* Temperature in centigrade degrees (Celsius) */
set cold 10 1 20 0 endset
set medium 10 0 20 1 30 0 endset
set warm 20 0 30 1 endset
endvar

var output heating_current /* Current in Ampere (0A - 4A) */


set small 01 20 endset
set medium 0 0 21 40 endset
set high 20 41 endset
endvar

/* now the rules follow: */

if temperature is cold then heating_current is high end


if temperature is medium then heating_current is medium end
if temperature is warm then heating_current is small end

/* End of File */

As can be seen from the file, the heating operates with a heating current between 0A and 4A. The rules shall control
a temperature of 20°C.

As usual the file name of the fuzzy description file ends with the extension ’fuz’. In this example we choose the file
name ’SIMPLE.FUZ’.

DR300 Speed Control Windows Software V1.0 3-35


The Fuzzy Library Laboratory Experiment DR300

3.4.2 The C++ Sources of a Temperature Control

After the fuzzy description file was created according to 3.4.1, it has to be included in a C++ program. The
following example briefly shows the solution:

/* Example Program: SIMPLE.CPP */

/* The program is to be adapted to your */


/* development environment. */

#include "iostream.h"
#include "ferror.h"
#include "fuzzy.h"

double readtemperature( void )


{
/* here is the code to read the temperature sensor */
return temperature;
}

void writeheatingcurrent( double heating_current )


{
/* here is the code to adjust the heating current */
}

void main( void )


{
Fuzzy f; // create the fuzzy object
double in[1]; // only one input variable
double out[1]; // only one output variable
if(f.read("simple.fuz")) // load the description file
error(); // file
f.generate(); // create the rule base
while(1) // endless loop
{
in[0] = readtemperature(); // read input value
f.calc( in, out ); // execute controller
writeheatingcurrent( out[0] ); //write output value
}
}
/* end of file */

With this the programming of a very simple fuzzy controller is terminated.

3-36 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Functions of the PLOT16.DLL

4 Functions of the PLOT16.DLL


List of the functions (all of type far _pascal) of the standard interface:

int Version( void ),


HWND CreateSimplePlotWindow(HWND parentHWnd, WORD NumberOfCurves,
WORD NumberOfPoints, double far** data )
void ShowPlotWindow(HWND HWnd, BOOL bflag )
void ClosePlotWindow(HWND HWnd)
void UpdatePlotWindow(HWND HWnd)
HWND GetValidPlotHandle( int index )
void AddPlotTitle( HWND HWnd, int Position, LPSTR title)
WORD AddAxisPlotWindow( HWND HWnd, WORD AxisID, LPSTR title, WORD Position,
WORD ScalingType, double ScalMin, double ScalDelta, double ScalMax )
void AddXData(HWND HWnd, WORD XCount, double far* XData )

void AddTimeData(HWND HWnd, WORD XCount, double StartTime, double SamplingPeriod )


WORD AddYData(HWND HWnd, WORD nYCount, double far* YData )
void SetAxisPosition( HWND HWnd, WORD AxisID, WORD Position)

int SetCurveMode(HWND HWnd, WORD idCurve, LPSTR title, WORD AxisId, WORD LineStyle,
DWORD Colour , WORD MarkType )
int SetPlotMode( HWND HWnd, WORD TitlePosition, DWORD TitleColour, LPSTR Title, WORD
WithLineStyleTable, WORD WithAxisFrame, WORD WithPlotFrame, DWORD FrameColour,
WORD WithDate, long OldDate, LPSTR FontName, int MaxCharSize )
void PrintPlotWindow( HWND HWnd, HDC printerDC, int xBegin, int yBegin, int xWidth, int yHeight,
BOOL scale )
HWND CreateEmptyPlotWindow(HWND parentHWnd)

DR300 Speed Control Windows Software V1.0 4-1


Functions of the PLOT16.DLL Laboratory Experiment DR300

Table of the macros in use:

Macro Value Meaning

X_AXIS 1 reference AxisID for the X-axis


Y_AXIS 2 reference AxisID for the Y-axis
Y_AXIS 4 reference AxisID for the Y2-axis
AXE_BOTTOM 1 X-axis bottom to axis frame
AXE_LEFT 1 Y/Y2-axis left to axis frame
AXE_RIGHT 2 Y/Y2-axis right to axis frame
AXE_TOP 2 X-axis top to axis frame
AXE_MIDDLE 4 X/Y-axis in the middle of the axis frame
TITLETEXT_TOP 1 drawing title top position
TITELTEXT_BOTTOM 2 drawing title bottom position
TITELTEXT_APPEND 4 drawing title appended to the window title
LINEAR_SCALING 0 linear scaling of the min/max-values of an axis
LOG_SCALING 1 logarithmic scaling of the min/max-values of an axis
INTERN_SCALING 0 automatic internal scaling of the min/max-values of an axis
EXTERN_SCALING 2 external adjustment of the min/max/delta-scaling values of an axis
NO_MARK 0 without marking a Y-curve
CROSS 1 marking by a laying cross
TRIANG_UP 2 marking by a triangle top oriented
TRIANG_DOWN 3 marking by a triangle bottom oriented
QUAD 4 marking by a square
CIRCLE 5 marking by a circle

Version
int Version( void )

Description: The function Version returns the version number (at this time = 19 for the version 1.2 dated 01.
April 1999) of this DLL.
Return The version number of this DLL.

CreateSimplePlotWindow
HWND far _pascal CreateSimplePlotWindow (HWND parentHWnd,
WORD NumberOfCurves, WORD NumberOfPoints, double far** data)

Parameters parentHWnd is the windows handle of the parent window.


NumberOfCurves is the number of curves in the plot object.
NumberOfPoints is the number of points of each curve in the plot object.

4-2 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Functions of the PLOT16.DLL

data is a pointer to the value matrix of the curves.


Description The function CreateSimplePlotWindow creates a window containing a standard plot object. This
plot object contains the value matrix data consisting of NumberOfCurves Y-curves (rows of the
value matrix) with NumberOfPoints points (columns of the value matrix) for each curve with
respect to a common X-axis. The X-axis is interpreted as a time axis with NumberOfPoints steps
to be drawn at the top of the axes frame including labels and a standard axis title. All Y-curves
correspond to one common Y-axis to be drawn left to the axes frame including a standard axis
title and labels determined by an automatic internal scaling. A grid net with dashed lines is added
to the axes frame. A linestyle table is located in the upper part of the window containing a short
piece of a straight line for each Y-curve with the accompanying attributes linestyle, colour and
marking type followed by a short describing text ("Curve #xx"). Each curve is displayed with
attributes according to the following table.

Curve No.: Text Linestyle Colour Marking Type


1 Curve # 1 PS_SOLID BLACK none
2 Curve # 2 PS_DASH RED cross
3 Curve # 3 PS_DOT GREEN triangle top
4 Curve # 4 PS_DASHDOT BLUE triangle bottom
5 Curve # 5 PS_DASHDOTDOT MAGENTA square
6 Curve # 6 PS_SOLID CYAN circle
7 Curve # 7 PS_DASH YELLOW none
8 Curve # 8 PS_DOT GRAY cross

The 5 different linestyles, 6 marking types and 8 colours are repeated serially. The curve handles
(identifiers) are set automatically equal to the curve numbers. A standard drawing title will be
added below the axes frame.
Return The Windows handle of the plot object window for a successful windows creation. Otherwise
NULL is returned.

ShowPlotWindow
void far _pascal ShowPlotWindow(HWND HWnd, BOOL bflag );

Parameters HWnd is a Windows handle of a plot object window.


bflag is a flag to control the visibility of a plot object window (=TRUE - visible, else invisible).
Description The function ShowPlotWindow displays a previously created plot object window with the
Windows handle HWnd when the flag bflag is set equal to TRUE. Otherwise the plot object
window is hidden.

DR300 Speed Control Windows Software V1.0 4-3


Functions of the PLOT16.DLL Laboratory Experiment DR300

ClosePlotWindow
void far _pascal ClosePlotWindow(HWND HWnd)

Parameters HWnd is a Windows handle of a plot object window.


Description The function ClosePlotWindow closes a previously created plot object window with the
Windows handle HWnd and removes all the corresponding objects from the memory.

UpdatePlotWindow
void far _pascal UpdatePlotWindow(HWND HWnd)

Parameters HWnd is a Windows handle of a plot object window.


Description The function UpdatePlotWindow updates the drawing of a previously created plot object
window with the Windows handle HWnd.

GetValidPlotHandle
HWND far _pascal GetValidPlotHandle( int index )

Parameters index is an index to reference a plot object window.

Description The function GetValidPlotHandle determines the Windows handle HWnd of that plot object
window which is referenced by the given index. Starting with an index of 0 the handle of each
previously created plot object window is determinable. The function returns the value 0, when a
plot object window with the given index does not exist.
Return The handle HWnd of the plot object window referenced by index if it exists else 0.

AddPlotTitle
void far _pascal AddPlotTitle( HWND HWnd, int Position, LPSTR title)

Parameters HWnd is a Windows handle of a plot object window.


Position is the position of the drawing title (TITLETEXT_TOP or
TITLETEXT_BOTTOM + possibly TITLETEXT_APPEND).
title is a pointer to the new drawing title with a maximum of 255 characters.
Description: The function AddPlotTitle inserts a new drawing title title at the position Position in a previously
created plot object window with the Windows handle HWnd. The position is either the upper part
of the drawing frame (TITLETEXT_TOP) or the lower part (TITLETEXT_BOTTOM). If the
macro TITLETEXT_APPEND is defined in addition the title is appended also to the windows

4-4 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Functions of the PLOT16.DLL

title. However the overall length of this windows title is limited to 79 characters. The drawing
title must not exceed 255 characters. Line wrapping is carried-out automatically if necessary but
the drawing title will be truncated if it exceeds a third of the drawing height.

AddAxisPlotWindow
WORD far _pascal AddAxisPlotWindow( HWND HWnd, WORD AxisID, LPSTR title,
WORD Position, WORD ScalingType, double ScalMin, double ScalDelta, double ScalMax
)

Parameters HWnd is a Windows handle of a plot object window.


AxisID is a reference to the axis (X-axis = X_AXIS, Y_axis = Y_AXIS, second Y-axis =
Y2_AXIS).
title is a pointer to the new axis title with a maximum of 255 characters.
Position is the position of the axis inside the axes frame:
X-axis at the bottom (AXE_BOTTOM), at the top (AXE_TOP) or in the middle
(AXE_MIDDLE), a Y-axis left (AXE_LEFT), right (AXE_RIGHT) or in the middle
(AXE_MIDDLE) of the frame.
ScalingType is the scaling mode for the new axis:
= LINEAR_SCALING | INTERN_SCALING - internal, linear
= LINEAR_SCALING | EXTERN_SCALING - external, l
= LOG_SCALING | INTERN_SCALING - internal, logarithmic
= LOG_SCALING | EXTERN_SCALING - external, logarithmic
ScalMin is the minimum external scaling value for the axis.
ScalDelta is the external scaling step for the axis.
ScalMax is the maximum external scaling value for the axis.
Description The function AddAxisPlotWindow adds a new axis with the reference AxisID (X_AXIS,
Y_AXIS or Y2_AXIS) to a previously created plot object window with the Windows handle
HWnd. Any existing axis in this plot object with the same reference will be replaced by the new
one. The axis title title , the position Position inside the axes frame (AXE_BOTTOM /
AXE_LEFT, AXE_RIGHT / AXE_TOP or AXE_MIDDLE) as well as the scaling mode
ScalingType (LOG_SCALING / LINEAR_SCALING and EXTERN_SCALING /
INTERN_SCALING) are to be defined for the new axis. The scaling values ScalMin, ScalDelta
and ScalMax are considered only when the macro EXTERN_SCALING is defined for the scaling
mode. Otherwise the scaling values are determined automatically.
Return The axis reference AxisID when the axis was created successfully, else 0.

DR300 Speed Control Windows Software V1.0 4-5


Functions of the PLOT16.DLL Laboratory Experiment DR300

AddXData:
void far _pascal AddXData(HWND HWnd, WORD XCount, double far* XData )

Parameters: HWnd is a Windows handle of a plot object window.


XCount is the number of points for the X-axis in the plot object.
*Xdata is a pointer to the data of the X-axis in the plot object.
Description: The function AddXData adds new data XData with a number of XCount values for the X-axis
to a previously created plot object window with the Windows handle HWnd. Any existing data
of a X-axis in this plot object are replaced by the new data.

AddTimeData:
void far _pascal AddTimeData(HWND HWnd, WORD XCount, double StartTime,
double SamplingPeriod )

Parameters: HWnd is a Windows handle of a plot object window.


XCount is the number of points (time values) for the X-axis in the plot object.
StartTime is the initial value for the time axis (=X-axis).
SamplingPeriod is the sampling period, the time distance between two successive values for
the time axis (=X-axis).

Description: The function AddTimeData adds new data with a number of XCount time values for the X-axis
to a previously created plot object window with the Windows handle HWnd. The time values start
with StartTime and end with (XCount - 1) * SamplingPeriod. Any existing data of a X-axis in
this plot object are replaced by the new data.

AddYData:
WORD far _pascal AddYData(HWND HWnd, WORD nYCount, double far* YData )

Parameters: HWnd is a Windows handle of a plot object window.


nYCount is the number of points for the Y-curve in the plot object.
*Ydata is a pointer to the data for the Y-curve in the plot object.
Description: The function AddYData adds a new Y-curve given by the data YData with a number of YCount
values to a previously created plot object window with the Windows handle HWnd. The function
returns an automatically generated reference (handle) for the Y-curve when a valid plot object
window exists. The standard values for the curve-attributes linestyle, colour, marking type and
describing text ("Curve #xx") are set automatically as described with the function
CreateSimplePlotWindow with respect to the returned reference value. In case no data are
defined for a X-axis, a standard time axis from 1.0 to nYCount*1.0 is generated in addition.

4-6 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Functions of the PLOT16.DLL

Return Is equal to the automatically generated reference (idCurve) of the added Y-curve, when the plot
object window exists, else equal to 0.
See also CreateSimplePlotWindow.

SetCurveMode
int far _pascal SetCurveMode( HWND HWnd, WORD idCurve, LPSTR title,
WORD AxisId, WORD LineStyle, DWORD Colour, WORD MarkType)

Parameters HWnd is a Windows handle of a plot object window.


idCurve is the reference (handle) of the Y-curve.
title is a pointer to the new describing text of the Y-curve used for the linestyle table with a
maximum of 255 characters. The current describing text is retained when the length of this
string is equal to 0.
AxisId is the assignment to the Y-axis (Y_AXIS) or Y2-axis (Y2_AXIS).
LineStyle is the linestyle of the Y-curve (see CreateSimplePlotWindow). The current linestyle
is retained when this parameter is equal to 0xFFFF.
Colour is the (RGB-) colour of the Y-curve. The current colour is retained when this
parameter is equal 0xFFFFFFFFL.
MarkType is the marking type of the Y-curve. The current marking type is retained when this
parameter is equal 0xFFFF.

Description The function SetCurveMode changes the attributes of a Y-curve referenced by idCurve
belonging to a previously created plot object window with the Windows handle HWnd. The
describing text title for the linestyle table, the assignment AxisId to the Y- or Y2-axis, the linestyle
LineStyle, the colour Colour as well as the marking type MarkType are assignable.
Remark: When a Y2-axis is not existing but a curve is assigned to this axis the linestyle table
demonstrates this fact by displaying only the describing text for this curve without the short piece
of a straight line. The number of characters in the describing text should be short with respect to
the number of curves.

Return Is equal to 1, when the Y-curve with idCurve exists, else equal to 0.

SetPlotMode
int far _pascal SetPlotMode( HWND HWnd, WORD TitlePosition, DWORD TitleColour,
LPSTR Title, WORD WithLineStyleTable, WORD WithAxisFrame,
WORD WithPlotFrame, DWORD FrameColour, WORD WithDate, long OldDate,
LPSTR FontName, int MaxCharSize )

Parameters HWnd is a Windows handle of a plot object window.

DR300 Speed Control Windows Software V1.0 4-7


Functions of the PLOT16.DLL Laboratory Experiment DR300

TitlePosition is the position of the drawing title (TITLETEXT_TOP or


TITLETEXT_BOTTOM + possibly TITLETEXT_APPEND).
TitleColour is the (RGB-) colour for the drawing title. The current colour is retained when this
parameter is equal 0xFFFFFFFFL.
Title is a pointer to the new drawing title with a maximum of 255 characters. The current
drawing title text is retained when the length of this string is equal to 0.
WithLineStyleTable enables (=TRUE) or disables (=FALSE) the display mode of the linestyle
table.
WithAxisFrame is a flag determining if a frame is to be drawn around the axes crossing
(=TRUE) or not (=FALSE).
WithPlotFrame is a flag determining if a frame is to be drawn around the drawing (=TRUE) or
not (=FALSE) only during output to a Windows Meta File or a raster device.
FrameColour is the (RGB-) colour for the axes frame. The current colour is retained when this
parameter is equal 0xFFFFFFFFL.
WithDate is a parameter determining if no date (=FALSE), the current date (=NEW_DATE) or
a given ’old’ date (=OLD_DATE) is to be inserted in the upper left part of the drawing.
OldDate is the ’old’ date, which is considered only when WithDate is set to OLD_DATE.
FontName is the font name of the character set used for all text outputs (titles, date, linestyle
table, labels). If the length of this name is equal to 0, the default character set will be used.
MaxCharSize is the maximum character height for all text outputs used with a maximum
window size. Reducing the plot window size will scale down the character height to a
minimum of 12 pixels. If this parameter is equal to 0xFFFF, the default maximum
character size will be used.

Description: The function SetPlotMode changes the general layout of a plot object window with the Windows
handle HWnd previously created i.e. by CreateSimplePlotWindow.
As described with the function AddPlotTitle a new drawing title title is inserted at the position
Position . The position is either the upper part of the drawing frame (TITLETEXT_TOP) or the
lower part (TITLETEXT_BOTTOM). If the macro TITLETEXT_APPEND is defined in addition
the title is appended also to the windows title. However the overall length of this windows title
is limited to 79 characters. The drawing title must not exceed 255 characters. Line wrapping is
carried-out automatically if necessary but the drawing title will be truncated if it exceeds a third
of the drawing height. The drawing title is displayed using the colour TitleColor and the character
set FontName with a maximum character height MaxCharSize (for a maximum size of the plot
window). The character set as well as the maximum character height are also used for the other
text outputs.
If the flag WithLineStyleTable is set to TRUE a linestyle table is inserted above the axes frame
containing a short piece of a straight line for each Y-curve with the accompanying attributes
linestyle, colour and marking type followed by a short describing text in the standard form "Curve
#xx" or defined by the function SetCurveMode.
When the flag WithAxisFrame is set to TRUE, a frame is drawn around the axes crossing using
the colour FrameColour only at those margins, which are not occupied by an axis.
When the flag WithPlotFrame is set to TRUE, an additional frame is drawn around the complete

4-8 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Functions of the PLOT16.DLL

drawing using the colour FrameColour only in case the plot window is output to a Windows Meta
File or to a raster device.
The parameter WithDate determines the display mode of the date in the upper left part of the
drawing. With WithDate set to FALSE the date output is missing. With WithDate set to
NEW_DATE the current date (day, month, year and time during drawing the plot) is inserted
while WithDate set to OLD_DATE will display the date given by the parameter OldDate.
Return Is equal to 1, when the plot window with the handle HWnd exists, else equal to 0.
See also CreateSimplePlotWindow, AddPlotTitle, SetCurveMode.

PrintPlotWindow
void far _pascal PrintPlotWindow( HWND HWnd, HDC printerDC, int xBegin, int yBegin,
int xWidth, int yHeight, BOOL scale )

Parameters HWnd is a Windows handle of a plot object window.


printerDC is the device context of the output device.
xBegin is the left margin of the hardcopy (mm/Pixel)
yBegin is the upper margin of the hardcopy (mm/Pixel)
xWidth is the width of the hardcopy (mm/Pixel)
yHeight is the height of the hardcopy (mm/Pixel)
scale =TRUE, position and size of the hardcopy in [mm],
else position and size of the hardcopy in pixels.

Description: The function PrintPlotWindow generates an output (typically a hardcopy) of a previously created
plot object window with the Windows handle HWnd. The output device is defined by its device
context handle printerDC. The position and the size of the hardcopy are determined by the
parameters xBegin, yBegin, xWidth and yHeight. These parameters are interpreted as [mm], when
the parameter scale is set to TRUE. Otherwise these parameters are taken as pixel numbers.

DR300 Speed Control Windows Software V1.0 4-9


Functions of the PLOT16.DLL Laboratory Experiment DR300

CreateEmptyPlotWindow
HWND far _pascal CreateEmptyPlotWindow(HWND parentHWnd)

Parameters parentHWnd is the windows handle of the parent window.


Description: The function CreateEmptyPlotWindow creates a window with an ’empty’ plot object. This plot
object only contains the current date, an empty axes frame as well as a standard drawing title
above this frame.
Return The Windows handle of the plot object window for a successful windows creation. Otherwise
NULL is returned.

4-10 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Interface Functions of the TIMER16.DLL

5 Interface Functions of the TIMER16.DLL


The TIMER16.DLL supports the cyclic call of specific functions of the "Service"-DLL which realizes a sampled
data control with a constant sampling period (The recent version of this DLL is 1.1).

The interface of the TIMER16.DLL contains the following functions:

UINT SetService( LPSTR lpServiceName )


UINT SelectDriver( LPSTR lpDriverName )
UINT StartTimer( double Time)
UINT StopTimer( void )
UINT IsTimerActive( void )
void GetMinMaxTime( DWORD &min , DWORD &max, BOOL res)
float GetSimTime( void )
UINT SetupDriver( void )

LibMain
int LibMain( HINSTANCE , WORD, WORD, LPSTR )

Parameters All parameters will be left out of consideration.


Description The function LibMain only resets the addresses of the functions of the "Service" to NULL and
returns 1.

Return Is always equal to 1.

DR300 Speed Control Windows Software V1.0 5-1


Interface Functions of the TIMER16.DLL Laboratory Experiment DR300

SetService
UINT SetService( LPSTR lpServiceName )

Parameters lpServiceName is a pointer to the name of the "Service"-DLL which contains the controller
and is to be called periodically.

Description The function SetService stores the given name (including the extension "DLL") to the variable
szServiceName and tries to load the DLL with this name. In case a DLL with the given name
cannot be loaded, an error message ("SetService ’ServiceName’ LoadLibrary failed!") is
presented and the function returns 0 immediately. Otherwise the addresses of the functions
DoService, SetParameter, GetData, LockMemory, IsDemo and SetDriverHandle which
should be contained in the DLL are determined. If one of these addresses cannot be determined
an error message ("SetService - GetProcAddress ’function name’ failed!") appears on the screen
and the function returns 0 immediately.

Attention: It is strongly recommended to call this function as the first function of the
TIMER16.DLL. Furthermore it has to be called before any function of the "Service"-DLL is
called!

Return Is equal to 1 in case of successful loading the "Service"-DLL and correct address determination,
else equal to 0.

SelectDriver
int SelectDriver( LPSTR lpDriverName)

Parameters lpDriverName is a pointer to the name of the new driver for the PC adapter card.

Description The function SelectDriver stores the given name (including the extension "DRV") to the variable
szDRiverName, which determines the driver for the PC adapter card, only when no timer is
running and no other card driver is open.

Attention: It is strongly recommended to call this function for the first time directly after calling
SetService!
Return Error state :
TERR_OK (0) on successful operations,
TERR_RUNNING (1), when a timer is still running,
TERR_FAIL (99), when another card driver is open.

5-2 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Interface Functions of the TIMER16.DLL

StartTimer
UINT StartTimer( double Time)

Parameters Time is the sampling period in seconds (minimum 0.001 s).


Description The function StartTimer opens and initializes the PC adapter card driver with the name given
by the global variable szDriverName (see also SelectDriver). The code and data memory of this
DLL as well as that of the "Service"-DLL is locked (no longer moveable because of the function
start addresses). A multi-media timer is programmed according to the given sampling period. A
value of 0 (TERR_OK) is returned only when all of the operations were carried-out successfully.
Return Error state :
TERR_OK (0) on successful operations,
TERR_RUNNING (1), when a timer is still running,
TERR_TOOFAST (2), when the selected sampling period is too small
TERR_DRV_LOAD_FAIL (5), when the card driver opening fails
TERR_MEM_LOCK_FAIL (6), when locking the memory of the
TIMER16.DLL and the "Service"-DLL fails.

IsTimerActive
UINT IsTimerActive( void )

Description The function IsTimerActive returns the state of the timer controlling the sampling period.

Return Timer state :


0: timer is not running,
1: timer is running.

DR300 Speed Control Windows Software V1.0 5-3


Interface Functions of the TIMER16.DLL Laboratory Experiment DR300

StopTimer
UINT StopTimer( void )

Description The function StopTimer stops the currently running multi-media timer, unlocks the memory of
this DLL as well as of the "Service"-DLL and closes the current adapter card driver.

Return Error state:


TERR_OK (0) on successful operations,
TERR_RUNNING (1), when no timer is running

GetMinMaxTime
GetMinMaxTime( DWORD &min , DWORD &max, BOOL res)

Parameters &min is a reference to the minimum sampling period/calculation time in ms. If this value is
equal to 0 at entry the calculation time of DoService function is returned, else the sampling
period.
&max is a reference to the maximum sampling period/calculation time in ms.
res is a flag to reset the minimum and maximum value of the sampling period/calculation time.
Description The function GetMinMaxTime returns the minimum and maximum value of the real sampling
period or the calculation time during the sampling period (when min=0 at entry) determined up
to this time. With res=1 the minimum and maximum value are set to the nominal sampling period
or a calculation time of 0.

GetSimTime
float GetSimTime( void )

Description The function GetSimTime returns the (simulation) time passed since the last start of a multi-
media timer. This value is calculated by the product of the nominal sampling period and the
number of calls of the function DoService.
Return Time in seconds since the last call of StartTimer.

5-4 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Interface Functions of the TIMER16.DLL

SetupDriver
UINT SetupDriver( void )

Description The function SetupDriver opens the PC adapter card driver with the name given by the global
variable szDriverName (see also SelectDriver) and starts the dialog to adjust the base address
only when no multi-media timer is running and in case no card driver is open. The driver is closed
again at the end of the dialog. If opening or closing the driver or carrying-out the dialog fails
corresponding messages will appear on the screen.
Return Error state :
TERR_OK (0) on successful operations,
TERR_RUNNING (1), when a timer is still running,
TERR_FAIL (99), when a driver is open or opening and closing the driver fails.

DR300 Speed Control Windows Software V1.0 5-5


Interface Functions of the TIMER16.DLL Laboratory Experiment DR300

5-6 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Windows Drivers for DAC98, DAC6214 and DIC24

6 Windows Drivers for DAC98, DAC6214 and DIC24


The drivers are installable 16-Bit drivers applicable to 16- or 32-Bit programs with Windows 3.1 / 95 / 98. Each
driver may be opened only once meaning that only one PC adapter card may be handled by this driver. To exchange
data with the drivers the following three 16-Bit API functions are used:

OpenDriver
HDRVR hDriver = OpenDriver(szDriverName, NULL, NULL)

Parameters szDriverName is the file name of the driver, valid names are "DAC98.DRV",
"DAC6214.DRV" and "DIC24.DRV" (according to the PC adapter cards) possibly
combined with complete path names.
Description The function OpenDriver initializes the driver and returns a handle for following accesses to this
driver. If this function is called the first time the driver is loaded into the memory. Any further
calls return another handle of an existing driver. The driver handle is valid only when the return
value is unequal to NULL. In case the return value is equal to NULL, the function OpenDriver
failed meaning that further driver accesses by the functions SendDriverMessage or CloseDriver
are invalid. The parameter szDriverName of the function OpenDriver contains the DOS file
name of the driver. The file name may include the disk name as well as the complete path names
according to the 8.3 name convention but it must not exceed 80 characters. When only a single
file name is used, the drivers location is expected in the standard search path of Windows. The
other parameters are meaningless and should be equal to NULL.
The address of the PC adapter card handled by this driver is read from a specific entry of the file
SYSTEM.INI from the public Windows directory. When this entry is missing the default address
0x300 (=768 decimal) will be taken.
Return Valid driver handle or NULL.

DR300 Speed Control Windows Software V1.0 6-1


Windows Drivers for DAC98, DAC6214 and DIC24 Laboratory Experiment DR300

SendDriverMessage
LRESULT result = SendDriverMessage( hDriver, DRV_USER, PARAMETER1,
PARAMETER2 )

Parameters hDriver is a handle of the card driver.


DRV_USER is the flag indicating special commands.
PARAMETER1 is a special command and determines the affected channel number
(see table below).
PARAMETER2 is the output value for special write commands.
Description The function SendDriverMessage transfers a command to the driver specified by the handle
hDriver. The drivers for the adapter cards from amira expect the value DRV_USER for the second
parameter (further commands can be found in the API documentation of SendDriverMessage).
The third parameter PARAMETER1 is of type ULONG specifying the command which is to be
carried-out. The lower 8 bits of this parameter determine the channel (number) which is to be
affected by the given command. The commands are valid for all of the three drivers. But the valid
channel numbers depend on the actual hardware. The last parameter PARAMETER2 is of type
ULONG and is used with write commands. It contains the output value. The return value depends
on the command. Commands and channel names are defined in the file "IODRVCMD.H".
Return Is equal to 0 in case of unsupported commands or special write commands. Otherwise it contains
the result of special read commands.

Table of the supported standard API commands


Command Return Remark
DRV_LOAD 1 loads the standard base address from SYSTEM.INI
DRV_FREE 1
DRV_OPEN 1
DRV_CLOSE 1
DRV_ENABLE 1 locks the memory range for this driver
DRV_DISABLE 1 unlocks the memory range for this driver
DRV_INSTALL DRVCNF_OK
DRV_REMOVE 0,
DRV_QUERYCONFIGURE 1
calls the dialog to adjust the base address and stores
DRV_CONFIGURE 1
it to SYSTEM.INI, i. e. [DAC98] Adress=768
DRV_POWER 1
DRV_EXITSESSION 0
DRV_EXITAPPLICATION 0

6-2 DR300 Speed Control Windows Software V1.0


Laboratory Experiment DR300 Windows Drivers for DAC98, DAC6214 and DIC24

Table of the special commands with the flag DRV_USER:


PARAMETER1
Channel Number Return
Command
DAC98 DAC6214 DIC24
DRVCMD_INIT
initializes the card and has to be the 0
first command
8 for DAC98,
DRVINFO_AREAD
6 for DAC6214,
returns the number of analog inputs
0 for DIC24
DRVINFO_AWRITE
2 for all cards
returns the number of analog outputs
DRVINFO_DREAD 8 for DAC98, DIC24
returns the number of digital inputs 4 for DAC6214
DRVINFO_DWRITE 8 for DAC98, DIC24
returns the number of digital outputs 4 for DAC6214
DRVINFO_COUNT 5 for DAC98
returns the number of counters and 1 for DAC6214
timers 6 for DIC24
16 bit value from -32768 to
DRVCMD_AREAD
0-7 0-5 no inputs 32767 according to the input
reads an analog input
voltage range
DRVCMD_AWRITE
0-1 0-1 0-1 0
writes to an analog output
DRVCMD_DREAD state (0 or 1) of a single input
0-7 or 0-3 or 0-7 or
reads a single digital input or all inputs or states binary coded
ALL_CHAN ALL_CHAN ALL_CHAN
(ALL_CHANNELS) (channel0==bit0)
DRVCMD_DWRITE
0-7 or 0-3 or 0-7 or
writes to a single digital output or to all 0
ALL_CHAN ALL_CHAN ALL_CHAN
outputs (channel0==bit0)
DDM0 DDM0
DDM1 DDM1
DRVCMD_COUNT DDM2 DDM2 counter- / timer-content as an
DDM0
reads a counter / timer DDM3 unsigned 32-bit value
COUNTER COUNTER
TIMER TIMER
DDM0 DDM0
DDM1 DDM1
DRVCMD_RCOUNT
DDM2 DDM2
resets a counter / timer (counter, timer
DDM0 DDM3 0
to the value -1) or all DDM’s
COUNTER COUNTER
(ALL_CHANNELS)
TIMER TIMER
ALL_CHAN ALL_CHAN
DRVCMD_SCOUNT
COUNTER COUNTER
presets a counter / timer to an initial 0
TIMER TIMER
value
CloseDriver

DR300 Speed Control Windows Software V1.0 6-3


Windows Drivers for DAC98, DAC6214 and DIC24 Laboratory Experiment DR300

CloseDriver(hDriver, NULL, NULL)

Parameters hDriver is a handle of the card driver.


Description The function CloseDriver terminates the operation of the driver specified by the handle hDriver.
The driver is removed from the memory when all of its handles are released by the function
CloseDriver.

6-4 DR300 Speed Control Windows Software V1.0

You might also like