02 EPICS Database
02 EPICS Database
Kay Kasemir
Jan. 2022
Channel Access
(pvAccess)
• Input/Output
Controller (IOC)
2 2
IOC LAN
“Hard” IOCs run vxWorks and directly interface to A/D, D/A, LLRF,
… hardware.
“Soft” IOCs run on Linux etc. and have no I/O Hardware other than
serial or networked devices (Moxa to motor controller, …)
3 3
IOC Database
4 4
Example: Basic Temperature Control
Task:
1. Read temperature
2. Open/close switch as needed
3. Repeat
Software?
5
One Fishy Database
Analog Input
Record
SCAN Field
Binary Output
Record
6 6
Database = Records + Fields + Links
7
Records are Active
8
Example “first.db”
9
Record Types
10
Common Fields
• Design Time
– NAME: Record name, unique on network!
– DESC: Description
– SCAN: Scan mechanism
– PHAS: Scan phase
– PINI: Process once on initialization?
– FLNK: Forward link
• Runtime
– TIME: Time stamp
– SEVR, STAT: Alarm Severity, Status
– PACT: Process active
– UDF: Undefined? Never processed?
– PROC: Force processing
• Either
– TPRO: Trace processing, set to 1 to debug record processing
11
Record Scanning
• SCAN field:
– When processed by other records:
“Passive” (default)
– Periodically:
“.1 second”, “.2 second”, “.5 second”,
“1 second”, “2 second”, “5 second”, “10 second”
– On event:
“Event” (EVNT field selects the event),
“I/O Intr” (if device support allows this)
• PHAS field
– Adds order to records that are on the same periodic scan
• First PHAS=0, then PHAS=1, …
• PINI
– Set to “YES” to force record once on startup.
Good idea for “operator input” records that are hardly ever changed, so
they have an initial value.
• PROC
– Writing to this field will process a record
12
Database vs. the Rest of the IOC
• Record scanning runs at LAN
higher priority than
Channel Access
or PV Access
– At high CPU load, PVs
IOC Channel Access, PV Access
might not connect while
records are still processed
Database Sequencer
• 0.1 second scan runs at
higher priority than 10
second scan
• PRIO field selects priority Device Support
for async.
completion and
event-scanned record
I/O Hardware
Your mileage might vary
– RTOS or plain Linux?
13 13
Common Input/Output Record Fields
14
Extending “first.db”
# A ramp from 0 to 'limit', were limit
record(ao, "$(S):limit")
Using ‘output’.
{
‘input’ would also work,
field(DRVH, "100")
since there’s no hardware
field(DOL, "10") to read or write, but only
field(PINI, "YES") ‘output’ has DRVH…
}
record(calc, "$(S):ramp")
16
Binary Record Fields
17
Record Links
• Input or Output links may be
– Name of other record’s field: “other”, “other.VAL”, “other.A”
• If other record is in same IOC: “Database link”
• If name not found: “Channel Access link”
– Hardware link
• Details depend on device support
• DTYP field selects device support
• Format examples: “@plc12 some_tag”, “#C1 S4”
• Input links may be
– Constant number: “0”, “3.14”. “-1.6e-19”
• A record’s FLNK field processes another record after
current record is ‘done’
18 18
Database Links
• Example:
field(“INP”, “other_rec.VAL PP MS”)
19
Channel Access Links
• Flags:
– PP: Ignored. Not triggering processing on other IOC
– MS, MSI: Maximize severity (when INVALID)
20
Channel Access Link Flags
21
Forward Links
22
Processing chains
23 23
Which record is never processed?
24 24
How often is Input_1 processed?
25 25
How long will this take?
26 26
Rate Of Change Example
Calculating “Rate-of-Change” of an Input
INPA fetches data that is 1 second old because it does not request processing of the AI
record. INPB fetches current data because it requests the AI record to process. The
subtraction of these two values reflects the ‘rate of change’ (difference/sec) of the
pressure reading.
27
Simulation Mode
When in simulation mode, the AO record does not call device support and the AI record
fetches its input from the AO record.
28
Multiple Scan Triggers
Slow Periodic Scan with Fast Change Response
The AI record gets processed every 5 seconds AND whenever the AO record is changed. This
provides immediate response to an operator's changes even though the normal scan rate is
very slow. Changes to the power supply settings are inhibited by the BO record, which
represents a Local/Remote switch.
29
Device Support
30
Synchronous vs. Asynchronous I/O
32
What could go wrong here?
33
Lock-Sets
• Group of records connected by links
• Processing a record locks its lock-set
– Prevents processing by multiple threads
– Similar but technically separate from PACT
34
Record Locking vs. PACT
Depending on its device support, a record
can “process” for a long time
– Processing sets PACT and triggers driver to fetch
data.
Some time later driver processes the record
again, and clears PACT.
Records in lock-set are locked while
– Processing starts, then again when it completes,
but not in the in-between times
– Reading a field
– Writing a field
35
Alarms
• Common fields:
– SEVR: Alarm Severity
• NONE, MINOR, MAJOR, INVALID
– STAT: Alarm Status
• UDF, READ, WRITE, CALC, HIGH, STATE, …
• Binary records:
– ZSV, OSV: Severity for ‘zero’ and ‘one’ state
• Analog records:
– LOLO, LOW, HIGH, HIHI: Thresholds
– LLSV, LSV, HSV, HHSV: Associated severities
– HYST: Hysteresis
36
Alarm Example
# Raise alarms when temperature near boiling point
record(ai, "$(user):tank")
field(DESC,"Water Temperature")
field(SCAN, "…
field(INP, "…
field(EGU, "C")
field(PREC, "1")
field(HIGH, "90")
field(HSV, "MINOR")
field(HIHI, "100")
field(HHSV, "MAJOR")
37
Monitor Dead-Bands
38
Record Hints
39
Record Hints
41
Record Hints
42
Calcout Record Details
43
Calcout Example
• record(calcout, “Corrector”)
{
field(SCAN, “.1 second”)
field(INPA, “Enable”)
field(INPB, “Setpoint”)
field(INPC, “Readback”)
field(INPD, “17.54”)
field(CALC, “A”)
field(OOPT, “When Non-zero”)
field(DOPT, “Use OCAL”)
field(OCAL, “D*(B-C)”)
field(OUT, ”SteeringMagnet PP”)
}
è CALC to determine if we should do anything,
OCAL for actual computation
44
‘synApps’ Records outside of EPICS base
• MOTOR record
– A whole ecosystem for controlling motors
45
Motor Record Details
• Record of 100+ fields https://epics.anl.gov/bcda/synApps/motor/motorRecord.html
• Basic control
– VAL Desired motor position. Supports put-callback
– RBV Readback value, actual motor position
– DONE Are we done moving the motor?
– HLS, LLS Are we at the high or low limit?
– STOP
• Resolution
– MRES, DIR, OFF, EGU… Turn motor ticks into “mm” or “degrees”
– Is it a stepper motor or servo? Do we have an encoder, how is it calibrated?
• Motion
– VBAS, VMAX, ACCL, HVEL, JVEL, … Speed, acceleration
– HLM, LLM, … Limits of motion range
– BDST, BACC, RTRY, .. Backlash compensation, retries
46
Large or small Records?
47
Time Stamps
48
Linear Conversion
LINR=SLOPE
VAL = (RVAL)*ESLO + EOFF
49
Breakpoint Tables
Analog records can set
LINR= typeKdegC
50
Summary
51