Finite State Machine Data Acquisition at Fermilab
D.A. Herrup, B. Lublinsky, J. Wang
Fermi National Accelerator Laboratory*ABSTRACT
Modern Accelerator control requires the collection and manipulation of large quantities of data in
response to accelerator-related operations and timing events. We have implemented a system at Fermilab
based on a set of finite state machines which allows state-by-state definition of the data collection
parameters and the storage of up to 100 KB of data in an easily accessible set of circular buffers. Initiallythe system will digitize beam position detectors and provide tune information. We will describe some of theother uses for this system.

INTRODUCTION
One of the important problems in accelerator control concerns the ability to synchronize andcollect data describing various processes, and eventually to provide control information for these processes.
An example of these problems in the Fermilab Tevatron concerns the control of the tune during the various(energy, low-β squeeze, etc.) ramps. These ramps are initiated by global timing signals which start ramps
on various magnetic circuits. The quadrupole currents throughout the ramp are set at breakpoints which areseparated by several seconds. All control is open loop and the currents at the breakpoints are initiallydetermined from beam measurements. Typically, a satisfactory table describing the current in the circuits asa function of time is established once and is only changed when accelerator conditions change enough sothat a "global retuning" is needed.
For reasons which are not well understood (but are the subject of intensive study), the Tevatron
operating conditions drift. As a result, a ramp which is optimized one day may not be optimal at anothertime. The "global retuning" mentioned in the previous paragraph is extremely labor-intensive and cannot bedone during ordinary operations but requires dedicated accelerator time. The system we have built (GFSDAfor Generic Finite State Data Acquisition) eliminates these problems by providing flexible, large-scale dataacquisition which will make correction of tune and other parameters much simpler.
The hardware system we have built initially is VME-based with a Motorola MVME 162-223
processor card with a 68040 processor, a single Omnibyte 4-channel, 12-bit, fast digitizer with onboard
memory for 65536 digitizations, and hardware for reading Tevatron clock events. The microprocessor runs
VXWorks. Additional ADC cards can be added. The final configuration will be based on a 68060 processor
and will have an external shared memory card with 64MB of memory for data storage.
The software system consists of one (or more) Tevatron clock-event-driven Finite State Machines(FSM), a set of states each with its own data acquisition properties, and a set of circular buffers for thestorage of the large amounts of data (100s of KB) which the system stores. In addition, the microprocessor
will have sufficient computing power to do sophisticated data analysis such as Fast Fourier Transforms(FFT), peak-finding, and closed loop control, if desired.

SOFTWARE IMPLEMENTATIONThe Tevatron operations follow the FSM paradigm quite closely. One can envision each ramp inthe Tevatron as corresponding to a specific state with its own set of breakpoints for the open loop control,* Operated by the Universities Research Association under contract with theU.S. Department of Energy.

FSMSTATE

Event
BufferTOD
Buffer012Periodic
Buffer00121

2

Figure 1. Relationship between the FSM, state, and the various buffers.
its own needs for data acquisition, analysis, and possible closed loop control. The FSM itself simplycontrols the flow of states, which can be quite complicated as there is not a unique time sequence ofoperations (for instance, the number of proton injections can vary, certain operations may be omitted, etc.).
Transitions between various states are controlled by events (or event + delay) on the global Tevatron clock,by simple time-outs, or by "soft" clock events (a control system parameter). Transitions are allowed to up
to 8 different states.
The states control the data acquisition through two types of interrupt rules: event-driven rules andperiodic rules. An event rule can be specified as a global Tevatron clock event (or event + delay) or a
specified time interval after the start of the state. A given clock event can occur many times during aparticular instance of a state. Each event rule has its own specification for data acquisition, including thenumber of digitizations to be collected and the particular set of ADC channels to collect. Each state can also
have a single periodic rule which consists of a frequency for data acquisition as well as the number ofdigitizations and the ADC channels to be collected.
The data to be collected usually consist of 2 or 4 ADC channels and at least 1024 digitizations.
The number of digitizations is determined by the resolution needed for the FFT. The digitization frequency
is 62.5KHz (determined by the available internal frequencies for the Omnibyte ADC. Eventually it will bethe beam revolution frequency of about 47.713 KHz), so 1024 points gives a frequency resolution of 62(48) Hz, which is barely adequate for a Tevatron diagnostic. The number of points will be increased once theshared memory is installed. In any case, each event record will be at least 2024 bytes, and possibly muchlarger. In addition, there can be up to 64 separate events in a given instance of a state, leading to a possible
data size for an instance of 131 KB. We also store header information such as the actual event trigger, thetime into the state, the ADC channels collected, the number of points collected, etc., in the event record.
An intelligent buffering scheme is needed to ensure that these data can be accessed in a simple manner.
The method of data storage we have devised consists of a series of circular buffers. Each state has 3of these buffers: one each for the time-of-day (TOD) stamps, event-driven data and periodic data. We havedesigned this system so that the data for many instances of a state can be saved in memory and will beoverwritten in a circular fashion. The instances are identified by the TOD stamp, a 28 byte label whichgives the date and time of day at which the particular instance was initiated. The periodic and event buffers
are assigned at the same time the TOD buffer is assigned. The relationship between the three buffers is suchthat once a TOD buffer is selected (either for writing by the microprocessor or for accessing from theFermilab control system), access to the accompanying event and periodic buffers is guaranteed. The
relationships are illustrated in Figure 1.
The FSM system is flexible and thus extremely complicated. We have provided a high-levelapplication program running in the Fermilab control system to program the FSM
dynamically. It will allow the user to download configurations from a preset menu and create new
configurations as the uses of the system evolve. It also enables one to start the FSM and force transitions
between states.
Access to the ADC data also occurs through a high-level program which dynamically mirrors theconfiguration of the FSMs. Currently, the application allows the user to select a particular buffer and do
rudimentary FFT analysis and peak-finding.

STATUS OF THE PROJECT
A preliminary version of this system has been completed and is working in the Tevatron as a tune
measurement system. The analog inputs are the signals from a set of resonant Schottky detectors. Since
these detectors are resonant and have a 1.5µs time constant, they are not really well matched to thedigitization and data acquisition capabilities of GFSDA, but nonetheless can be used to measure the tune.
This simple system already provides equal accuracy and more flexibility (the ability to capture and store data
in real time) than the set of HP 3561A Dynamic Signal Analyzers that have been used for the past 7 years.
An illustration of the data we have obtained is shown in Fig. 2. This represents a single digitization of thesignals from the vertical Schottky detector.
We intend to make significant improvements to this system. Our initial implementation has aminimum amount of processing in the microprocessor. Data analysis will be done using the Fermilab
console system. Once we have developed accurate FFT and peak-finding algorithms we will move them into
the microprocessor. This will of course require an expansion of the circular buffer system, but we intend tobuild upon what we have by maintaining the raw data buffers and adding a set of buffers with FFT and peakdata.
In collider operations the Tevatron stores both protons and antiprotons simultaneously. The 2
species see different accelerator lattices and thus can have different tunes, etc. and it is important to measure
the tunes separately. The Schottky system in use allows for independent tune measurement with the use of
2 detectors in each plane separated by λ/4 at the resonant frequency of 21.4 MHz. This separation provides a
directionality of at best 20 dB when the analog circuitry is tuned up. In practice, due to drifts, the rejection
is closer to 10 dB. GFSDA can be used to record the 4 detectors individually and do the directional rejection
in software. This may have several advantages over the analog method now in use: it may be more stable,
and it should be possible to do regular (daily) calibrations with only 1 species of particle in the accelerator,
ensuring that the rejection is updated.
A more powerful method of measuring proton and antiproton tunes is to use a wideband pickup
and gate in time at the instances when the particles pass the pickup. The Tevatron has several stripline
detectors and these are being instrumented with sample-and-hold circuits and precise bucket-by-bucket gates
which will allow GFSDA to measure the tune of an individual proton or antiproton bunch in the Tevatron.
One of the problems which led to the design and construction of GFSDA was the ill-understooddrift in the operating conditions of the Tevatron, leading to changes in tune and other beam parameters. If
we can implement a peak-finding algorithm inside the microprocessor, it will be straightforward for us todevelop a real-time feedback mechanism through the quadrupole power supplies and control the tune in realtime. This has already been done in a simpler prototype system[1].

REFERENCES[1] D.A. Herrup et. al., Nuclear Instruments and Methods in Physics Research A329 (1993) 470.

Figure 2. Tune spectrum obtained with GFSDA.