Proceedings of the 19th Annual Meeting of Particle Accelerator Society of Japan
October 18 - 21, 2022, Online (Kyushu University)

PASJ2022 WEP009

SOFTWARE DEVELOPMENT FOR INTEGRATED CONTROL SYSTEM OF
DC MAGNET POWER SUPPLY
D. Wang1∗ , Y. Enomoto1 , M. Satoh1
1 KEK, Ibaraki 305-0801, Japan
Abstract
To enhance the system reliability and maintainability, an
integrated DC magnet power supply control board is designed to effectively consolidate several control functions
into a unified whole. A Raspberry Pi Compute Module, a
STM32 micro-controller, an Intel CPLD as well as otherfunctional ICs, such as energy measurement IC, ADCs andDACs, are embedded into a single board. The software implementation handles the control logic and communications
among these ICs. An EPICS IOC runs inside the Raspberry
Pi deals with the EPICS communication towards our main
control network while the micro controller aggregates hardware status information from ICs and reports them to theIOC. The CPLD is mainly used for the interlock signal processing. The communication protocol design between thoseparts and programming practice experiences are introducedin this work.

INTRODUCTION
About 200 power supplies for the steering magnets areused at the KEK injector linac to support a stable beam operation. A newly design of the steering magnet power supply
control system replaces the old PLC based system with a
new Raspberry Pi (RPi) based control system to decrease thedifficulties of the EPICS (Experimental Physics and Industrial Control System) integration as EPICS is the standard
framework of the control system at the injector linac. Thissystem has started to operate since 2020 [1].
The first version of the Raspberry Pi based DC power
supply control system has been reported in paper [1, 2].
Nevertheless, lack of self monitoring feature, high coupling
between different modules and ungraceful cable connections
have become a major concern of the control system during
the long term accelerator operation. The second version isthus developed to address those concerns.
The Raspberry Pi Compute Module (RPi CM), the STM32
micro-controller (MCU), the Intel Complex Programmable
Logic Device (CPLD) as well as other monitoring ICs areembedded into a single PCB board to meet our requirements.
The configuration of those monitoring ICs are controlled bythe STM32 MCU.

The 24-bit ADC (LTC2380) and 20-bit DAC (AD5791) arereused because they are proved to be effective and accurate
to control the magnet power supply during the accelerator
operation.

Figure 1: The layout of new control board.
The main controller is changed to the RPi CM4 whichis specifically designed for industrial and embedded applications. It is built with the same ARM processor as theRaspberry Pi 4 so that the software of the first version control board can be mostly reused. We also benefit from theflexibly of RPi CM4 by deliberately removing unnecessary
IO interfaces, like HDMI and audio ports, to reduce the riskof bus interference.
The Arduino Mega board is substituted by theSTM32G474 device because the MCU can provide more
General-purpose input/output (GPIO) Pins (up to 107),
which makes it possible to monitor many on-board signals.
And the MCU is capable to operate at a frequency of up to170 MHz. The MCU has 512 KB FLASH to storage thedata and 128 KB RAM to run the program [3]. The SPI andUART controller inside the MCU are used to communicate
with other modules.

Figure 2: The change of modules in new design.

CONTROL BOARD
To improve the functionality of the DC power supply
control system, several new modules are introduced in thenew control board. The layout of the control board is shownin Fig. 1 and the change of modules is shown in Fig. 2.
∗ di.wang@kek.jp

The on-board signal monitoring is implemented by using
a 16-channel, 16-bit ADC module (ADS8686S) and two
daisy-chained 16-bit DAC modules (DAC81416) [4, 5]. TheDACs are responsible for outputting the signal threshold
while the ADC monitors whether the on-board signals sit
between the thresholds. Besides that, the ADE9078 power- 526 -

Proceedings of the 19th Annual Meeting of Particle Accelerator Society of Japan
October 18 - 21, 2022, Online (Kyushu University)

PASJ2022 WEP009

metering IC allows the control board to perform a highly
accurate power and energy measurement [6].
The on-board signals act as one kind of interlock signals
and are examined by the MAX V CPLD. The CPLD ensures the flexibility of interlock signal processing because
the modification and upgrade of the interlock logic can beeasily achieved by reprogramming the CPLD rather thanredesigning the control board.

SOFTWARE IMPLEMENTATIONThe systematic diagram of the new architecture is show inFig. 3. The EPICS IOC runs inside the RPi module controls
the magnet power supply the same way as the former design.

Figure 3: The software schematic diagram.

On-board IC configuration
To properly utilize the on-board monitoring IC, several
commands must be transferred to the registers inside theICs via the SPI interface. The Hardware Abstraction Layer(HAL) API provided by the STM company is used to configure the SPI controller and transfer frames between MCU
and ADC/DAC ICs.

Figure 5: Two DACs are connected in daisy-chain.
To save the GPIO pins of the MCU, two on-board monitoring DACs are connected in series to form a daisy-chain
connections. The diagram is shown in Fig. 5. The SPI communication software are also capable to support this kind ofscheme.
Before measuring the power and energy using theADE9078 IC, additional gain calibration is necessary toacquire accurate results because the sampling capacitors inside the ADE9078 vary device to device [6]. By applyinga known nominal voltage to the IC, the measurement value
by the ADE9078 is read via SPI. Then the voltage gain canbe acquired by comparing the expected value and measuredvalue. With the help of KIKUSUI PCR2000WE AC Power
Supply module and HIOKI PW3390 Power Analyzer, thevoltage gain calibration is performed and the experiment
data is recorded in Table 1. Figure 6 shows the parametersof AC power measured by the Power Analyzer. The voltage
gain under such case is 2.023.

Figure 6: The HIOKI PW3390 power analyzer.

CPLDFigure 4: The readout value of ADS8686S via SPI.
The on-board monitoring ADC measures the fan speed,temperature, current and voltage value. The MCU thencollect these data through SPI and convert the raw data toengineering value. The results of converted data are shownin Fig. 4.

There are two major functions of the CPLD. The first is
to implement the interlock logic. The other is to provide theADC sampling clock.
The interlock signals consist of three types, 16 analog
lines, 12 digital lines, and 4 external lines. All signals arelatched inside using the CPLD logic. If one of these signals- 527 -Proceedings of the 19th Annual Meeting of Particle Accelerator Society of Japan
October 18 - 21, 2022, Online (Kyushu University)

PASJ2022 WEP009

Table 1: Voltage Gain Calibration of ADE9078
Nominal Value
100 V RMS
110 V RMS
120 V RMS
130 V RMS
140 V RMS

Expected Value

Measured Value

0.10 V RMS
0.11 V RMS
0.12 V RMS
0.13 V RMS
0.14 V RMS

0.0494 V RMS
0.0544 V RMS
0.0593 V RMS
0.0642 V RMS
0.0692 V RMS

fail, the CPLD triggers a relay which cuts off the output. Theinterlock logic can be reset either by a physical push button
or by a RPi GPIO output.
The LTC-2380 ADC features an average-N conversions
which receives continuously conversion trigger and outputs
the averaged results. Consequently, the synchronization
logic is achieved using 4 4-bit counters inside the CPLD toprovide up to 32768 triggers pulses.
Figure 8: The protocol file for StreamDevice.

EPICS Integration
All the on-board monitored values as well as the latchedinterlock signals should be published through EPICS. The
UART API between EPICS IOC and MCU is designed basedon the EPICS StreamDevice module [7]. The IOC constructs
text-based commands using StreamDevice module and sends
the commands to MCU.
The MCU is set to receive an amount of data in interrupt
mode till either the expected number of data is received oran IDLE event occurs. After checking the start flag anddevice control byte, dedicated commands are analyzed andsent to targeted IC via SPI. Besides of the basic register readand write commands, several special function commands areprovided to reduce the complexity of StreamDevice protocol.
The description of UART command is shown in Fig. 7 andthe example protocol file for ADC is shown in Fig. 8.

Figure 7: The UART API.

SUMMARY
The new software of the new steering magnet power supply control board is developed. Apart from controlling themagnet power supply, it also includes operation status monitoring and energy measurement feature. The STM32 MCU
works as a bridge between RPi IOC and on-board ICs.
The UART API between EPICS IOC and MCU provides
an easy-to-use template for similar projects. This development process expands the usability of EPICS in the embedded system field.

REFERENCES[1] E. Yoshinori, K. Shiro, and U. Shinji, “EPCIS COMPATIBLEBIPOLAR DC MAGNET POWER SUPPLIES USING RASPBERRY PI,” in Proceedings of the 18th Annual Meeting ofParticle Accelerator Society of Japan, Takasaki, Japan, Aug.
2021. https://www.pasj.jp/web_publish/pasj2021/
proceedings/PDF/THP0/THP011.pdf[2] K. Shiro, E. Yoshinori, and U. Shinji, “DEVELOPMENT OF
CONTROL SOFTWARE FOR EPICS COMPATIBLE DC
MAGNET POWER SUPPLY USING RASPBERRY PI,” inProceedings of the 18th Annual Meeting of Particle Accelerator Society of Japan, Takasaki, Japan, Aug. 2021, pp. 918–920. https://www.pasj.jp/web_publish/pasj2021/
proceedings/PDF/THP0/THP039.pdf[3] STM32G474. https : / / www . st . com / en /microcontrollers - microprocessors / stm32g474qe .
html[4] ADS8686S. https://www.ti.com/product/ADS8686S[5] DAC81416. https://www.ti.com/product/DAC81416[6] ADE9078. https : / / www . analog . com / en / products /ade9078.html[7] StreamDevice. https : / / paulscherrerinstitute .
github.io/StreamDevice/- 528 -