Security System Based on CAN Bus in Accelerator Control
Cui Yonggang
Department of Engineering Physics, Tsinghua University
Beijing 100084, China
Email: cuirr@thinker.ep.tsinghua.edu.cn
Abstract
Controller Area Network (CAN) is widely used inindustrial control. In this paper, as an item of R&D ofShanghai Synchronous Radiation Facility (SSRF), a PC
board which works as the interface between the PC-bus
and CAN bus has been designed. CAN control module, akind of electronic-magnetic lock, has been developed
successfully. The software, written in C++ and assemble
language, gives a friendly user interface. Under control ofthis software the PC board working together with a few
sets of control modules installed on the doors, makes up asecurity system. The system can be used to control all theentrance for the accelerator hall to ensure accelerator
radiation safety. The system has been tested in thelaboratory environment. The PC machine responds to the‘open door’ requirements from the doors in time andrecords the ‘open door’ events on the disk. It can also lockall the doors when the accelerator is running. The numberof entrance in the system can extend to 16 under thecurrent design. High performance of CAN bus can beevaluated with the system.
1 Introduction
The Controller Area Network (CAN) was developed byBosch and Intel for automobile communication as a serialbus. It is a serial network that efficiently supports
distributed real-time control with a very high level of data
integrity. It provides high-speed but low cost multiplex
wiring between nodes, automatic bus arbitration, and error
definition. Because of these advantages, it is a rightselection in real-time control, such as accelerator control.
In this paper, as the R&D of Shanghai Synchronous
Radiation Facility (SSRF), a security system based on theCAN bus has been built to test the performance of theCAN bus. In such a system, any person can only enter thecontrolled area with a registered magnetic card. Thesystem can control all the doors connected to the CAN bus,
respond to the In/Out requirements from the doors in timeand save the information of In/Out events on the disk of PCmachine. The security system is also one part of theinterlock system for the accelerator. When the accelerator
is going to run, the disable signals are sent to every door’s
control module through CAN bus.
2 Hardware description
The security system consists of a PC with a CAN network
adapter used as the control host, and several magnetic

locks with control modules embedded in every lock. The
block diagram of the whole system can be seen in figure 1.
As one part of the whole accelerator control system the PC
can also join the LAN net with TCP/IP or other protocols tocommunicate with other control hosts.
Door Status

Door1
Address

ID-reader

OutputControl

Ethernet

MCUPC
CAN Driver

Door2

LEDCAN Adapter

Door16

Fig. 1 Topology Diagram of Security System
2.1 PC computer and CAN Bus adapter
The PC computer is the system core of control anddatabase management. It has a CAN bus adapter in it
which is designed as the interface between the PC’s ISA
bus and CAN bus.
On this board, there are two driving circuits forselection. The first one uses a 82C200 from PHYLIPS as
the peripheral IC and 82C250 of PHYLIPS as the CAN bus
transceiver IC. Between them, an optical isolator is used toreduce the interfere between two ICs. In another circuits,
discrete components are employed to replace thetransceiver IC and optical isolator. This network is simple
and cheap. The same driving circuits are used in thecontrol modules on locks.
2.2 Control module in magnetic lock
The control module in the magnetic lock is the sensor andactor of the whole system. It reads out the ID of magnetic
card and sends In/Out requisitions to PC machine. It also
executes the command sent by PC machine.
The main chip of the control module is a MC68HC05X4
Microcontroller Unit (MCU) of MOTOROLA, which has
the CAN control module, MCAN, embedded in it. Aroundthe MCU, there are CAN driver module, ID-reader module,and output control module. The CAN driver module uses
discrete components mentioned previously. The ID-reader
module has a magnetic card reader to read out the card ID.
The output control module controls the mechanical lock-up
mechanism through a relay.

There are also some other circuit on the control moduleboard, such as door status module, address module, andLED module. Door status module gives out the current
Open/Close status of the door. Address module offers aaddress to identify a specified lock. LED module uses LEDand bells to give users information prompt.
3 Software of the system
Software of the system has two parts. One is the program
working with the control module and the other one is thecontrol software running on the PC computer.
3.1 Program of MCU

Fig. 3 Logical Structure of PC Software
3.2.1 Device driver
The Device Driver offers a DLL library to Windows 3.1.
This library includes the functions, which are needed toaccess the CAN adapter, described as following.
void ReadCanData(char FAR * DataBuf); //fetch data fromthe message queue defined in device driver
void WriteCanData(char FAR * DataBuf); //write data totransmit buffer
void TransmitData(); //send out the data onto the CAN bus
void Initialize();//initialize the CAN adapter

Power On

3.2.2 Application based on Windows 3.1
Initialize Ports, Get address
Initialize M C A N

Initialize RAM

Y

Reading Flag is On ?

Read ID andGenerate a Into
requisition event

N
Check Message RegisterN
Any events ?
Y
Goto Respective Server Routine

Fig. 2 Flow chart of MCU program
The software of the MCU is an event-driven program
written in assemble language. The events driving theprogram can be the In/Out requisitions on a lock, theevents of received message on CAN bus, or therequisitions events of execute commands. The flow chartof main routine of this program is shown in figure 2.
3.2 Software on PC
On the PC machine, control software runs underWindows 3.1. The software includes an application written
in MS VC++ for control and database management and adevice driver written in 80X86 assemble language with
DDK. The structure is described in figure 3.

Windows 3.1&VC++
Application
Assemble language& DDKDevice Driver
CAN Adapter
CAN BUSThe application based on Windows 3.1 has the functions
to monitor the work of the whole system, including thejudgment of a valid card number, the registration of each
In/Out information, retrieve of history information, thedatabase management, and so on. The application is
written in MS VC++. With OOP programming, new data
structure and classes for database management are defined.
struct RegisteredCard { //Structure to define a magnetic
card
char CardID[MAXCARDIDLEN]; //Card ID
char Name[MAXNAME+1]; //Owner’s name of thiscard
struct RegisteredCard * NextCard; //Pointer of nextcard};
struct Record { //Structure to define a piece of information
char Name[MAXNAMELEN+1]; //Namechar DataTime[20]; //Time
int Room; //Where
char CardID[MAXCARDIDLEN+1]; //Card ID
char Comment[MAXEVENTCOMMENTLEN+1];//Some comment about it};class CardLinkList { //Class to define database ofregistered card
int ManyCard; //Number of registered card
struct Card * Room[MAXROOMNUM]; //To store
information of card registered on every lockpublic:…
BOOL Search(char * lpCardID, struct Record *NewRecord, int Belongto = 0); //Search a ID indatabasevoid AddCard(…
);
void DelCard(…
);…
};
class RecordQueue { //Class to define information queue,each node is a piece of information

struct Record Event[MAXEVENTNUM]; //Queue
int Header, Tail; //Header and tail pointer of queue
public:BOOL Empty(); //Queue is empty or not
BOOL Full(); //Queue is full or nor
void Initialize(); //Initialize the queue…
void GetARecord(struct Record * pointer); //Fetch apiece of information from queue
void AddRecord( struct Record AnEvent); //add apiece of information into queue…
};

Fig. 4 Window of Application
Based on these structures and classes, the application isbuilt. It has an interface of Windows style, which is easy touse. Figure 4 shows the main window.
4 Conclusion
The security system is tested in the laboratoryenvironment with several locks connected to the CAN bus.

Some advantages of CAN bus can be seen here.
First is automatic bus arbitration. In such a multimastersystem, several nodes may send messages at same time.
According to the priority of the message, CAN bus
arbitrates them automatically. In the experiment, when therequisitions occur on different doors at same time, the PCmachine can immediately answer them one by one. No
delay time can be felt.
Secondly, CAN bus has a high speed and low cost. In theexperiment, the physical medium is unshielded twist ware
(UTP). The transmission rate can be 667 bits/s with 40m
long ware, limited by the frequency of 8MHz crystal on theCAN adapter. Theoretically, this rate can be 1Mbits/s highwithin such a distance.
Thirdly, like the Ethernet, CAN bus is a network tobroadcast message, not a peer-to-peer network. In theexperiment, the PC machine can send a instruction to lockevery door in the system. Because of this, the control
machine does not have to pole other nodes one by one. It isvery useful in changing parameters in different parts of asystem synchronously, such as to increase the magnetic
fields in every part of store ring.
In addition, according to the driving capability of driving
circuit, the number of nodes in such a system can extend to16 currently. In order to add more nodes, transistors must
be used.
This project only demonstrate the CAN bus. We expect
it to find its right position in system control of SSRF.
Reference[1] MC68HC05 ADVANCE INFORMATION, Motorola
Inc.,1992[2] Techniche Informationen, DESY, 900927