MSc Disertation CANopen IO Card Implementation
-
Upload
mosab-yaseen -
Category
Documents
-
view
224 -
download
0
Transcript of MSc Disertation CANopen IO Card Implementation
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
1/158
i
Implementation of digital I/O module for
communication using CANopen protocol
A thesis submitted to Newcastle University for the degree ofMSc in Automation and control
In the Faculty of Science, Agriculture and Engineering
2010
Mosab Yaseen Mohammed Elamin
SCHOOL OF ELECTRICAL, ELECTRONIC AND COMPUTER ENGINEERING
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
2/158
ii
NEWCASTLE UNIVERSITYSCHOOL OF ELECTRICAL, ELECTRONIC AND COMPUTER ENGINEERING
I, Mosab Yaseen Mohammed Elamin , confirm that this report and the work presented init are my own achievement.
I have read and understand the penalties associated with plagiarism.
Signed: .......................................................Date: ...........................................................
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
3/158
iii
Abstract
Many industrial automation technologies were developed due to the great benefits of
adopting automation in industry, one of these techniques is remote digital Input/Output (I/O)
modules which is widely used with considerable success in automation applications.
These modules communicate with controllers in different types of communication
protocols; CANopen is a field bus protocol which proved to be reliable for more than fifteen
years in automation communication.
This project describes in details the steps of implementing digital I/O module with
CANopen in both hardware and software terms, the module has been tested and verified.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
4/158
iv
ContentsAcronyms .................................................................................................................................................... vii
List of figures ............................................................................................................................................. viii
List of tables ................................................................................................................................................. ix
Chapter 1 ...................................................................................................................................................... 1
Introduction .................................................................................................................................................. 1
1.1 Automation methods ......................................................................................................................... 1
1.2 Benefits of DCS: .................................................................................................................................. 2
1.3 Smart solutions:...................................................................................................................................... 3
1.3.1 Intelligent instrumentation ............................................................................................................. 4
Advantages: ............................................................................................Error! Bookmark not defined.
Disadvantages: .......................................................................................Error! Bookmark not defined.
Recent trends: ........................................................................................Error! Bookmark not defined.
1. 3.2 Remote or field I/O: ..........................................................................Error! Bookmark not defined.
Advantages: ............................................................................................Error! Bookmark not defined.
Disadvantages: .......................................................................................Error! Bookmark not defined.
Recent trends: ...................................................................................................................................... 5
1.4 Communication protocols ...................................................................................................................... 6
1.4.1 Open System Interconnection (OSI) model: ................................................................................... 6
1.4.2 Standard Vs proprietary .................................................................................................................. 8
1.4.2.1 Proprietary protocols ............................................................................................................... 8
1.4.2.2 Standard protocols: .................................................................................................................. 8
1.4.3 Ethernet VS Field bus protocols ...................................................................................................... 8
1.4.3.1 Ethernet .................................................................................................................................... 8
1.4.3.2 Field bus protocols ................................................................................................................... 9
Chapter 2 ................................................................................................................................................ 11
CAN protocol: ......................................................................................................................................... 11
2.1 Historical background: ................................................................................................................. 11
Chapter 3 ................................................................................................................................................ 12
CANopen: ............................................................................................................................................... 12
3.1 Protocol structure: ........................................................................................................................ 12
3.2 CANopen properties:.................................................................................................................... 13
Chapter 4....................................................................................................................................................16
Hardware implementation.........................................................................................................................16
4.1 Implementation description..........................................................................................................16
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
5/158
v
4.2 Overview of the microcontrlloer....................................................................................................16
4.2.2 ECAN module features........................................................................................................17
4.2.3 Module overview.................................................................................................................18
4.2.4 I/O ports.............................................................................................................................18
4.2.5 Data recieving ....................................................................................................................19
4.2.6 Data transmission...............................................................................................................20
4.2.7 Interrupt services.........................................................................................................,.....21
4.2.8 Data rate programming......................................................................................................22
4.3 MCP2551 CAN transciever.............................................................................................................23
4.4 Voltage regulator ..........................................................................................................................24
4.5 Printed Circiut Board.....................................................................................................................25
Chapter 5 ................................................................................................................................................28
Software..................................................................................................................................................28
5.1 Initialization..........................................................................................................................29
5.1.1 Node initilization..................................................................................................29
5.1.1.1 Oscillator initilization...........................................................................29
5.1.1.2 Node ID................................................................................................29
5.1.1.3 Heart beat cycle setting.......................................................................30
5.1.1.4 Port initialization.................................................................................30
5.2 CANopen initilization..........................................................................................................31
5.3 Infinite loop processing......................................................................................................33
5.3.1 Processing functions...........................................................................................34
5.3.2 PDO message recieving......................................................................................34
5.3.3 NMT message group..........................................................................................35
5.3.4 SDO messsage group..........................................................................................35
5.3.5 Object dictionary................................................................................................35
5.3.5.1 Object dictionary entry......................................................................35
5.3.5.2 Reading and writing functions of the dictionary................................37
5.3.6 Message transmission........................................................................................38
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
6/158
vi
5.3.7 DemoProcessEvents function.............................................................................38
5.3.7.1 Input port processing.........................................................................38
5.3.7.2 Output port processing......................................................................39
Chapter 6...............................................................................................................................................40
Tests......................................................................................................................................................40
6.1 Input port test....................................................................................................................40
6.2 State request test..............................................................................................................40
6.3 Output port test................................................................................................................40
6.4 Reading from and writing to object dictionary.................................................................40
6.4 Node state change command...........................................................................................40
Conclusion..........................................................................................................................................41
References:.........................................................................................................................................42
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
7/158
vii
Acronyms
CAN Controller Area NetworkCIA Control In Automation
CPU Central Processing Unit
CSMA/CD Carrier Sense Multiple Access
/Collision Detection
DCS Distributed Control System
IEEE Institute of Electrical and
Electronics Engineers
I/O Input/Output
ISO International Standardization Organization
MAC Medium Access Control
NCS Network Control System
NMT Network Management System
OPC Object Linking and Embedding;
(OLE) forProcess Control
OSI Open System Interconnection
PC Personal Computer
PCB Printed Circuit Board
PDO Process Data Object
PLC Programmable Logic Controller
SDO Service Data Object
http://en.wikipedia.org/wiki/Process_Controlhttp://en.wikipedia.org/wiki/Process_Control -
7/29/2019 MSc Disertation CANopen IO Card Implementation
8/158
viii
List of figures
Figure 1: Typical DCS system [7] ................................................................................................... 2
Figure 2: OSI model ........................................................................................................................ 6
Figure 3: Communication services required for DCS systems ....................................................... 7
Figure 4:CAN definition according to OSI model ........................................................................ 11
Figure 5: CANopen protocol mapped to the OSI model ............................................................... 12
Figure 6: state transitions for a CANopen node............................................................................14
Figure 7: pic18f2585 pin diagram.................................................................................................16
Figure 8: Module circuit layout.....................................................................................................24
Figure 9: Top layer tracks..............................................................................................................25
Figure 10: Bottom layer tracks......................................................................................................25
Figure 11: Top and bottom layers..................................................................................................26
Figure 12: Code flow chart............................................................................................................27
Figure 13: Initialization.................................................................................................................29
Figure 14:Infinite loop processing flow chart..............................................................................34
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
9/158
ix
List of tables
Table 1: Field bus protocols...........................................................................................................9
Table 2: Fieldbus protocols and key factors................................................................................10Table 3: CANopen characteristics................................................................................................13
Table 4: CANopen node states....................................................................................................14
Table 5: PIC18F2585 key features..............................................................................................17
Table 6: Comparison between CAN and ECAN modules..........................................................18
Table 7: Registers associated to receive buffers.........................................................................19
Table 8: Registers associated to transmit buffers.......................................................................20
Table 9: Interrupt registers.........................................................................................................21
Table 10: Bit timing controlling registers...................................................................................23
Table 11: MCP 2551 features.....................................................................................................24
Table 12: Dip switch and baud rates...........................................................................................30
Table 13: Messages groups values..............................................................................................32
Table 14: Messages numbers in message groups.....................................................;;.................32
Table 15: Node states and corresponding value in heartbeat messages......................................33
Table 16: node state change command values............................................................................35
Table 17: object dictionary structure and variable meaning.......................................................36
Table 18: object dictionary.........................................................................................................36
Table 19: transmit functions for message groups.......................................................................38
Table 20: PDO messages............................................................................................................41
Table 21: SDO messages...........................................................................................................42
Table 22: node state change command values...........................................................................43
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
10/158
1
Chapter 1
Introduction
Automation is changing a process or a product to make it work in the best possible manner
without a significant human contribution. [1]
There exists the potential for much benefit and thus applying automation methods has
become important in all industries, some of the reasons are [1, 2]:
Replacing human man power in dangerous and hazardous fields.
Reducing costs in exchange for better product quality, less defective units, fasteroperations, and better utilization of raw materials.
The automation system provides information about processes, which allows defining
weak points and initiating possible improvements.
1.1 Automation methods
Three methods exist in automation:
Control boards for a specific unit.
Programmable Logic Controller (PLC) for a small scale process Distributed Control System (DCS) for a relatively large scale process [3]
Control boards: Early models of automation included the control board, which has a
number of switches, lights, analogue meters and other devices that inform an operator of a unit s
status [3].
PLC: Current models include PLCs, involving a processing unit controller. Under the
command of a set of operation conditions, PLC is operated to govern a sequence of processes[4]. It is often times used to control relatively small systems.
DCS: DCS: is a group of microprocessor based nodes connected in a network
(such as controllers, remote I/O modules, smart measurement devices or smart sensors).
DCS works with a central controlling unit and software packages, including archiving and
analysis tools connected through a communication network [5].
DCS (sometimes referred to as Network Control System (NCS)) was initially used with
industrial processes and factories. However, recently it has been utilized in numerous fields
including the likes of building automation, automotive systems, medical instruments ,airplanes,
amongst others[6], fig(1) [7] shows a typical DCS system, within which PLC and
control boards (machine controller) are labelled.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
11/158
2
Figure 1: Typical DCS system [7]
1.2 Benefits of DCS:
Enables efficient and easy analysis of the system based on data collected from monitoring
devices, this analysis allows improvements to be made to the process.
Increases the speed of failure detection in any device in the system allowing quick failure
detection and correction and in some cases without the need of human interaction.
Allows flexible operation by communicating and controlling all nodes inan acceptable time frame.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
12/158
3
Different control devices from different vendors can exchange data usingObject Linking and Embedding (OLE) for Process Control(OPC) server as shown in
figure(1), the OPC , is a set of standards used to enable plant real-time data
communication between control devices from different manufacturers[8].
It will be possible to connect industrial plants to the internet as shown in figure(1) which
can change the way of plant operation ,however this approach still needs greatresearch efforts.
Additionally [2]:
Since DCS uses a single data bus that connects all nodes, it reduces cost by decreasing
the number and/or length of connection cables.
It allows data buses to run long distances, thus increasing the coverage area.
Expanding DCS systems is easy as new nodes can easily be attached using extension
cable with appropriate communicating ports.
1.3 Smart solutions:Controlling units often connect sensors and actuators through I/O cards used for both
analogue and digital signals. These cards are mounted in the same rack within the cabinet of the
controlling units processor .Many wires connect the I/O cards with the instrument; nevertheless,
there can be some difficulties with this approach [9]:
If there are numerous instruments involved, then the number of wires can become
intolerable for the controller cabinet and difficult for the engineer involved. For large
number of instruments high rates controller processors are required to avoid operation
time delays due to processing time.
If the distance between the controller and instrument is elongated, then there is an excess
cost due to long cabling.
By being utilized for longer distances, the signal may be more vulnerable to noise signals
that can jam the data of interest. Moreover, cable losses may result in erroneous receipt.
It may be extremely difficult to install the processor in a field of harsh conditions
(high temperature, moisture, noise, or high level of gas emission).
Nodes can also be scattered far apart from each other requiring a standalone processor for
each set of neighbouring nodes.
For these reasons a new approach was developed to create moderate processing
capabilities in instrumentation. These new approaches enable a direct connection to data buses
in two different techniques:
http://en.wikipedia.org/wiki/Process_Controlhttp://en.wikipedia.org/wiki/Real-timehttp://en.wikipedia.org/wiki/Real-timehttp://en.wikipedia.org/wiki/Process_Control -
7/29/2019 MSc Disertation CANopen IO Card Implementation
13/158
4
1.3.1 Intelligent instrumentation.
By adding a processor with a small sized memory in addition to built in communication ports to
instruments, dealing with superfluous wires can be avoided as only two communication wires
can connect all instruments in a multi drop fashion to the controller.
1.3.1.1 Advantages:
This technique overcomes the problem of noise picked up by connection wires as well as
power losses in long wires [10].
This unit performs initial processing including data conversion to engineering units, self
testing, initiating alarms according to set limits, or short term archiving. The unit aids
controllers by reducing processing loads [11]. The property of initiating alarms is
advantageous on event based maintenance where instruments can send alarms for improper
operation. These alarms allow maintenance staff to maintain devices before they completely
fail, and this saves money and time compared with cyclic maintenance. The possibility of remote configuration of instruments through data buses.
1.3.1.2 Disadvantages:
Intelligent instruments are more expensive than traditional ones.
With respect to different vendor instruments, interoperability should be considered.
1.3.2.3 Recent trends:
Many studies[12,13,14] support the wireless technology to be adopted in industrial
automation , by using sensors and actuators which communicate wirelessly with
controllers , in [13] the technology of Wireless Sensors Networks (WSN) is described.Standardization efforts are made by number of organization to define and implement
WSN however the real implementation still need time to spread, due to
some design challenges.
Advantages of WSN technology [12, 13]:
Reducing cabling costs
Flexible instruments distribution.
Some applications which require device mobility can be monitored and
controlled wirelessly [15].
Main challenges [12, 13]:
Noise signals.
Propagation losses.
Multipathing ( losses due to reflected waves from several paths).
Time delay, should be kept below certain limits.
Signal interference from other sources.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
14/158
5
1.3.2 Remote or field I/O:
Remote or field I/O (also known as smart I/O) is an input, output module installed remotely
with a low level of intelligence. Examples of intelligence include processing memory,
communication ports , and other physical ports to be connected to instruments.
1.3.2.1 Advantages:
This overcomes the problem of noise picked-up by connection wires as well as power
losses in longer wires.
And this unit makes initial processing such as data conversion to engineering units; this
serves controllers by reducing processing load.
Economically much better than the smart instrumentation approach.
1.3.2.2 Disadvantages:
Remote configuration for instruments is not possible.
More wires are required between instruments and Remote I/O.
Recent trends:
In [12] the Wireless Interface for Sensors and Actuators (WISA) technology is described, it
is adopting I/O modules which communicate with sensors and actuators wirelessly, having
nearly the same advantages and challenges described in 2.1.3 WSN technology.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
15/158
6
1.4 Communication protocols
1.4.1 Open System Interconnection (OSI) model:
The Open System Interconnection Reference Model is a general description of the
communication process by diving it to groups of services and putting these groups in a layer
form, fig (2) shows the OSI model.
This model was made by the standard International Standarization Organization (ISO) to
enable connectivity and interoperability between different vendors communication devices [16].
Figure 2: OSI model
Brief definition for each layer
Application layer: in this layer services of interacting with users are defined, includingapplication addressing, file transfer and others.
Presentation layer: in this layer the required data conversion, processing and encodingservices are defined.
Session layer: in this layer services are defined to link programs in the sending andreceiving devices along the network, it is not a physical link but it is a logical one.
Transport layer: the services here guarantee reliable transfer of a message no matterwhat size is it, over potentially unreliable networks.
Network layer: the services here define the communication path through a widenetwork connection.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
16/158
7
Data link layer: in this layer services responsible for four vital processes are defined,they are:
Error detection and correction: services detect and correcterroneous messages.
Flow control: these services manage the communication load between thetransmitter and receiver, for example if the receiver cant cope with the
transmission rate, these services will slow down the transmitter and buffer
the communication load.
Link management: these services deal with the sequence of rulesrequired for establishing connections between devices; there are certain
rules of communication: request from the transmitter and acknowledgment
from the receiver and some settings for request time out and other
parameters defined by these services.
Medium Access Control (MAC):Since all network nodes shares thesame bus or media , and at any time only one node should be transmitting
and the rest are either receiving or waiting , for a node to access the bus
(i.e. to get control on the bus and start sending) there are set of rules to
decide which node should take hold of the bus first, the services in this
sub layer decide that.
Physical layer: it is the physical interface between a node and the communication media,in here the transmitted signal physical properties are decided such as voltage levels,
power rates as well as physical port properties. Communication services required in DCS
are mainly in the application ,data link, and physical layers fig(3) shows an illustration of
the required layers in industrial applications; and more detailed description can be foundin [2,16].
Figure 3: Communication services required for DCS systems
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
17/158
8
1.4.2 Standard Vs proprietary
A communication protocol is a set of rules governing transmission and receiving of data along with
defining physical properties of communication signals [17], many communication protocols has been
developed.
1.4.2.1 Proprietary protocols
In old DCS systems each company had special communication rules which are called
proprietary or private protocol ,vendors were providing a whole system for a factory or a
manufacturing line, i.e. all communication devices must be from only one vendor this has some
advantageous and disadvantageous [3]
The main advantage is that the system will be especially tailored to the factory so system
consistency and operability will be guaranteed.
Disadvantages:
Any system has some weak points, which do not exist in other systems, if designers have
the possibility to combine different systems, the overall results may be much better.
The customer will be restricted to one vendor in maintenance, spare parts and system
extensions, economically and practically this situation may cause difficulties.
1.4.2.2 Standard protocols:
Standard protocols published or approved by standard organizations and applied by large groupof vendors became more common, designers can select devices from different vendors and
connect them in one network, obviously a more flexible solution and also economically
effective because this standardization generates more competition between vendors allowing
lower prices for customers [6].
1.4.3 Ethernet VS Field bus protocols:
1.4.3.1 Ethernet
There are large numbers of communication standards, some recent studies in DCS system
suggested that in the future Ethernet (IEEE 802.3: Carrier Sense Multible Access (CSMA/CD))will dominate in industrial automation communication [18, 19]
This point of view is based on recent trends of adopting Commercial Off-The-Shelf
(COTS) technologies in DCS systems including Personal Computers (PCs) and Ethernet
networks due to its great achievements in data communication i.e. personal computers
networks[18]
Advantages of Ethernet:
Large capacity of data transmission.
Very high transmission rates.
Compatibility with data networks , this can be very useful, by using appropriate software,field information can be archived in the instruments or controllers, this information can
be send through automation network to the management ,financial, and marketingdepartments or even through internet.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
18/158
9
However Ethernet is not always the best solution in automation applications, because
originally data communication is different from control communication , Ethernet has high
data rates but there are problems with its transmission time determinism , depending on network
size and bus load, transmission time delays are small yet random, these delays have no effects
on data networks, but in automation, small delays in feedback control messages for examplemay result in unstable system. [6]
There are many efforts to improve Ethernet timing properties and to design new versions
called Real Time Ethernet RTE; now more than twenty approaches are available.
More over in some applications with short messages a field bus protocol
Controller Area Network (CAN) was found according to [6] to have better achievements.
This kind of messages is dominant in the lower level in control systems, the communication
between sensors, actuators and controllers, as well as embedded controllers industry like
automotive, medical instruments, aircraft industries and more.
In addition ,some field bus protocols currently have adopted Ethernet facilities such as
Foundation Field bus High Speed Ethernet FF HS1, Modbus TCP, and some others in the way
[12], moreover available in the market gateways between field bus and Ethernet, these gatewaysoffer transparent transmission of field bus protocols from point to point over Ethernet.
One disadvantage of using gateways is that, gateway circuits need time to process the data
flow, this will increase time delays.
1.4.3.2 Field bus protocols
Field bus protocols are a group of protocols for industrial automation, the term bus was
originated from the fact that all devices in the field (e.g. factory, manufacturing line, etc.) are
connected serially through cables, in early automation systems each manufacturer or vendor had
a special protocol, thats why large number of protocols are classified as fieldbuses these days
.Table (1) shows the most common field bus protocols , more information can be
found in[20].
Table 1: Field bus protocols
Field bus Name Technology Developer Year IntroducedProfibus DP/PA Siemens DP: 1994 PA: 1995Interbus Phoenix Contact Interbus Club 1984DeviceNet Allen-Bradley 1994Arcnet Datapoint 1977AS-I AS-I Consortium 1993Foundation Field bus H1 Fieldbus Foundation 1995
Foundation Field bus HSE Fieldbus Foundation2000
Seriplex APC 1990WorldFIP WorldFIP 1988LONWorks Echelon 1991SDS Honeywell 1994ControlNet Allen-Bradley 1996CANOpen CAN in Automation 1995
Modbus Plus Modicon -------
Modbus RTU/ASCII Modicon 1999
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
19/158
10
Comparisons:It is not easy to compare between field bus protocols and decide which one is the best ; this
comparison depends on two issues ,technical specifications and economical feasibility.
First of all application type defines which protocols are applicable , some protocols are
widely used in large processing systems, but not used in smaller scale applications.
Key factors of technical specifications are: Maximum number of nodes in a network segment.
Maximum distance.
Data rate.
Maximum delay time and some other factors.Interestingly some studies [21], suggested an approach to compare protocols and the final
result is a quantitative figure, using a technique called entropy ideal point, this procedure
doesnt only consider technical specifications but also some economical aspects such as
System cost.
Installation cost.
Maintenance cost.However some important economical factors are not included which relates to the currentstatus of the customer such as
Training cost.
Replacement cost if required, and other factors.Still it is a wonderful approach; table (2) shows some field bus protocols
with key properties [20].
Table 2: Field bus protocols and key factors
Fieldbus Name Max Devices Nodes Max Distance
Profibus DP/PA 126DP:100-1,200m/segmentPA: 1,900m/segment
Interbus 512 400m/segmentDeviceNet 64 500mArcnet 255 400/2000 feetAS-I 32 slaves 100-300m
Foundation Fieldbus H1240/segment65,000 segments
1900m
Foundation Fieldbus HSEIP addressingessentially unlimited
100-2000m
Seriplex 500+ devices >500 feet
WorldFIP64 without repeaters 2 km
256 with repeaters 40 kmLONWorks 32,000 per domain 2000mSDS 64 nodes, 126 addresses 500mControlNet 99 250-1000mCANOpen 127 25-1000mModbus Plus 32 per segment, 64 max 500m per segmentModbus RTU/ASCII 250 per segment 350m
.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
20/158
11
Chapter 2
CAN protocol:2.1 Historical background:
CAN is an international serial communication protocol, standardized in ISO 11898-1 and
classified as a field bus, it was originally designed in BOSCH automotive company in 1980 to
achieve in-vehicles communication control, in instead of large number of wires, but after that it
found its way to other applications in industry [2].
CAN protocol only specifies the data link layer and physical layer as shown in fig (4).
Figure 4:CAN definition according to OSI model
There are collection of protocols related to CAN, they are
CAN Application layer CAL, CANopen, DeviceNet, and J1939[22]
CAN Application layer CAL.
CANopen an application layer over CAN bus applied in many automation fields, one of the bestProtocols used in embedded networks in many kinds of machineries especially in Europe.
DeviceNet is a communication protocol based over CAN bus and was developed by
Allen-Bradley Company and mainly used in process automation applications.
J1939 protocol: is an application profile based on CAN originally was developed for in-trucks
communication, after wards had been applied for other fields.
2.2 CAN bus properties: Deterministic i.e. the maximum delay time of transmission is fixed.
The highest priority node always gets hold of the bus first, thus critical nodes are not
affected by time delays. Easy to setup.
Relatively cheap.
Reliable, very effective in error detection and correction.
Was succeeded in dealing with harsh fields conditions in automobiles for long time.
Easy to upgrade[23]
2.3 CAN bus filtering:CAN bus is a message oriented protocol, , there is no sender id or receiver id in a CAN
message , all nodes detects every message on the bus , each node determines whether to
accept and process a message or not based on the message identifier , each message has an
identifier ,which is a particular value , to do this each node need to perform a message filtering,
there are two types of filtering:
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
21/158
12
FULL CAN where message identifiers which the node should receive and process arestatically defined and stored in the node registers , this procedure is fast in processing and
requires smaller programs.
Basic CAN the node manipulates identifiers by software ,requiring larger code , and
some processing time but is more flexible than Full CAN method , more details aboutCAN protocol can be found in[2]
Chapter 3
CANopen:
3.1 Protocol structure:CANopen is a field bus protocol based on CAN bus as shown in fig (5).
Figure 5: CANopen protocol mapped to the OSI model
The reasons why CANopen and CAN dont have specification for four layers i.e.
presentation, session, network, and transport are [2]:
Presentation layer: this layer responsible for encoding data, in CAN there is a defined set of
data types so no need for data encoding or addressing.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
22/158
13
Session layer: CAN adopts real time communication, thus no need for this layer which is
responsible for creating logical links between receiver and transmitter for each
communication transaction.
Network layer: Network layer is responsible for internetworking communication, since in CAN
bus the network can not be such big and complex this layer is not needed.
Transport layer: again because the nature of real time communication and high reliability inCAN networks no need for this layer which deals with semi-unreliable networks.
3.2 CANopen properties:
Table (3) shows some characteristics of CANopen [20].
Table 3: CANopen characteristics
Technology developer CAN In automationYear introduced 1995
Openness 17 chip vendors,300 product vendors, open
Network topology Drop line
Physical media Twisted pair optimal signal & power
Maximum devices (nodes) 127 nodes
Maximum Distance 25-1000m depending on data rate
Communication methods Master/slave, peer-to-peer, multicast, multimaster
Transmission properties 10,20,50,125,250,500& 800Kbps,1 Mbps
Data transfer size 8 byte, variable
CANopen properties are flexible, different choices of data rates and distances are available,even for the limitation of 8 byte message in CAN, CANopen can send longer messages by
breaking a message down to 8 data blocks and recombine them again in the receiver, nodes
number is really competitive.
One of the most powerful characteristics of CANopen that it is an open software, this results
in more flexibility for designers , on the other hand the cost for installing is reduced .
More field bus protocols can be found in [6] to be compared with CANopen.
Control In Automation (CIA) organization, publishes device profiles for CANopen in
different industrial fields, there are many profiles for specific applications such as I/O modules,
train machines, building room control and more.
Profiles help designers to access devices functionalities using CAN bus [2], there are many
published device profiles and other new fields are in progress [22].
3.3 CANopen services:3.3.1 Object dictionary:
CANopen specification defines a data base in each node from which all node information can
be accessed through the network this data base is called object dictionary, each entry in the
dictionary is addressed by an index and sub-index.
3.3.2 Communication objects:
There are four types of communication objects ( messages with specific identifiers and formats)
in CANopen network
SDO Service data objects
These objects are used to read from or write in the object dictionary.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
23/158
14
PDO Process data objectsThese objects are used to transfer the process information e.g. the states of the outputs
inputs of the device.
NMT Network management objectsThese objects are used by the network master node to change the state of a slave node,
the node states defined in the standard are shown in table 4, and figure 6 shows thecommands used to change the states, these commands are sent through NMT objects.
Table 4: CANopen node states
State Communication capabilities
Preoperational SDO communication is
possible to read and write
from the object dictionary,
heart beat messages are sent,
no PDO messaging is
possible
Operational All messages are available
Stop Only heart beat messages are
available
Figure 6: state transitions for a CANopen node[27]
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
24/158
15
Node guard or heartbeat objectsThese are two ways to make a CANopen node send a periodic signal in the bus , this
signal serves two purposes:
o This signal is a sign that the node is up and working.
o And it contains the current state of the node thus the network master will get acurrent view of the status of all nodes on the network.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
25/158
16
Chapter 4
Hardware Implementation
4.1 implementation description:
The module implemented in this project has the following features:
4 inputs and 4 output.
Node id programmable through dip switch.
Programmable baud rate through dip switch.
Asynchronous message sending in case of port change.
Immediate port change in case of receiving operation request.
Full can implementation.
Standard identifiers communication.
Power supply 24V DC.
Reading and writing to/from the object dictionary.
The mode of operation can be controlled
( stop , preoperational, operational, reset command).
Send a heart beat in 2000 ms periods.
4.2 Overview of the microcontroller
The microcontroller used in this implementation is PIC18F2585 which is part of the
PIC18F2585/2680/4585/4680 family , these devices combine high processing capabilities and
low prices, along with some enhanced functions in memory and communication ports which help
improving the over all performance, table 5 shows the main features of PIC18F2585, and figure
7 shows the PIC18F2585 pin diagram [24] .
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
26/158
17
Table 5: PIC18F2585 key features
Manufacturer Microchip
Data EEPROM (bytes) 1024
RAM Bytes 3,328
Flash memory KB 48
CPU Speed
(Million Instructions Per Second )10
Embedded communication
controllerECAN
Temperature Range (C) -40 to 150
Operating Voltage Range (V) 2 to 5.5
Pin Count28
Figure 7 pic18f2585 pin diagram[24]
4.2.2 ECAN Module Features:
ECAN is an enhanced CAN module developed by Microchip , with ECAN there are more
resources available in terms of buffers and filters.
ECAN is fully compatible with legacy CAN modules table 6 shows a comparison between
CAN and ECAN modules :
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
27/158
18
Table 6: comparison between CAN and ECAN modules
CAN ECAN
Number of filters 6 16
Message buffers 2 recieve + 3 transmit buffers 2 recieve + 3 transmit
buffers+6 programmable
buffers(can be programmed to
be either receive or transmit)
Processing time Much less
Code size Larger
ECAN module can be operated in one of these three modes:
Legacy mode (mode 0) in this mode the module will operate as an ordinary CAN module .
Enhanced Legacy (mode 1) operates with the enhancements enabled.
FIFO mode (mode2) in this mode 2 or more buffers can be used to form a FIFO First In
First Out buffer in which no one to one filter to buffer link is available , suitable for applications
requiring large data bursts handling.
ECAN (mode 1) module is recommended for CANOPEN networks which normally require
large number of message handling [25].
4.2.3 Module Overview
The module consists of protocol engine , memory buffers and special function registers that
control the data flow.
4.2.4 I/O ports
This microcontroller has three I/O ports PORTA PORTB and PORTC, each port has three
registers controlling the port operation:
PORT register which reads the level of port pins.
TRIS register used to define each bit of the port as an input or output, if a bit in this register is
set to 0 the corresponding bit in the port will operate as an output and if set to 1 the
corresponding pin will be an input.
LAT it is an output latch used as a second alternative for reading or writing the port value.
Each pin in the port is protected from Vs and Vg by diodes.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
28/158
19
4.2.5 Data receiving:
The microcontroller when connected to a network bus will load every message into a
temporary buffer called the MAB Message Assembly Buffer, the message id will be
compared with the filters, if the massage ID matches one filter then the data will be loaded to
one of the receive buffer for further processing, for each receive buffer there is a control register
RXBnCON in which the information of which filter enabled the reception of the message is
stored , the processor will be informed by an interrupt flag in PIR3 register see
(section 4.6 interrupt services ) table 7 shows the registers associated with a receive buffer.
Table 7: registers associated to receive buffers
No. Register name Description Function
1 RXBnCon (n=0 or 1) Receive buffer
control register
bits 0-4 shows which
filter enabled the
message reception
2 RXBnSIDL used If
standard identifiers
are implemented in
the network (n=0 or 1)
Recieve buffer
Standard Identifier
Low byte
The low byte of the
standard identifier is
stored here
3 RXBnSIDH used If
standard identifiers
are implemented in
the network (n=0 or 1)
Recieve buffer
Standard Identifier
High byte
The High byte of the
standard identifier is
stored here
4 RXBnEIDL used If
extended identifiers
are implemented in
the network(n=0 or 1)
Recieve buffer
extended Identifier
Low byte
The low byte of the
extended identifier is
stored here
5 RXBnEIDH used If
extended identifiers
are implemented in
the network(n=0 or 1)
Recieve buffer
extended Identifier
High byte
The High byte of the
standard identifier is
stored here
6 RXBnDLC Recieve buffer data
length count
The data length in the
message received is
stored here
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
29/158
20
7 RXBnDm (n=0 or 1)
(m=0 to 7)
Recieve buffer data Eight registers in
which the eight data
bytes of the message
can be stored
4.2.6 Data transmission
In case of transmission the data to be send is loaded to one of the transmit buffers , the
processor is informed by setting bit 3 of the transmit buffer control register , after the
transmission is successfully finished bits 2 and 3 in the PIR3 register see
(section 4.6 interrupt services ) will inform the processor that the transmit buffer is ready to be
reloaded, table 8 shows registers associated to transmit buffers.
Table 8: registers associated to transmit buffers
No. Register name Description Functions
1 TXBnCON (n=0 or 1) Transmit buffer n
control register
Bit7 is a transmit
buffer flag set when
the transmission starts
and is not cleared till
the transmission finish
Bit 3 Transmit request
status bit informing
the processor that the
data in the buffer is
ready to be sent,
cleared if the
transmission was
successful
2 TXBnSIDH (n=0 or 1) Transmit buffer n
standard identifier
high byte
The High byte of the
standard identifier is
stored here
3 TXBnSIDL (n=0 or 1) Transmit buffer n
standard identifier
low byte
The low byte of the
standard identifier is
stored here
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
30/158
21
4 TXBnEIDH (n=0 or 1) Transmit buffer n
extended identifier
high byte
The High byte of the
extended identifier is
stored here
5 TXBnEIDL (n=0 or 1) Transmit buffer n
extended identifier
low byte
The low byte of the
extended identifier is
stored here
6 TXBnDm
(n=0 or 1)(m=0 to 7)
Transmitt data buffer Eight registers in
which the eight data
byte of the message
can be stored
7 TXBnDLC (n=0 or 1) Transmit buffer data
length count
The data length in the
message to be
transmitted is stored
here
8 TXERRCNT Transmit error count
register
contains a value of the
rate of transmission
errors , if it overflows
then the module will
enter bus off state
4.2.7 Interrupt services:
In case of receiving or transmitting a message interrupt scheme should be available PIR3
peripheral interrupt register 3 is responsible for raising the interrupt flag in case of a message
received or transmitted table 9 shows registers which deal with message communication
interrupts:
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
31/158
22
Table 9: interrupt registers
No. Register name Description Function
1 PIR3 Peripheral interrupt
request register 3
Bit 3 and bit2 are set
to inform the
processor that the
transmission is
completed and the
number of the
buffer is ready to be
reloaded
Bit1 and bit 0 are set
to inform the
processor that a
message have been
received and by the
number of the buffer
2 PIE3 Peripheral interrupt
enable register
Used to enable or
disable interrupts
3 IPR3 Peripheral interrupt
priority register
Used to set the
priority of buffers
4.2.8 Data rate programming
This module can be programmed to operate in one of the eight baud rates defined in the
standard , all time parameters are defined in terms of a time quantity called Time quanta TQ,
The value of TQ is derived from the oscillator frequency and a programmable value called
baud rate pre scalar BRP (0-63) by equation 1
TQ = (2 * (BRP + 1))/oscillator frequency...................1
Each of the four bit time segments defined in CAN specification is defined in multiples of TQ
thus the bit time is calculated by equation 2
Bit Time= TQ * (Synchronization segment + Propagation segment +Phase segment1 + Phase segment2).......................2
Finally the baud rate is calculated by equation 3Baud rate = 1/Bit Time......................3
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
32/158
23
Table 10 shows the three registers controlling these values.
Table 10: Bit timing controlling registers
No. Register name Description Function
1 BRGCON1 Baud rate control
register 1
Bit7-6 define the
value of
synchronization
segment
Bit5-0 define the
value of BRP
2 BRGCON2 Baud rate control
register 2
Bit 5-3 define the
value of phase
segment1
Bit2-0 define the
value of propagation
segment
3 BRGCON3 Baud rate control
register 3
Bit 2-0 define the
value of phase
segment2
4.3 MCP2551 transceiver
MCP2551 is a CAN transceiver, to raise the voltage level of the signals sent and to protect the
microcontroller from overvoltage in the bus, key features are displayed in table 11 [26]
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
33/158
24
Table 11: MCP 2551 features
Manufacturer Microchip
Speed 1 Mb/s operation
Standard ISO-11898
standard physical layer
Voltage supply Max. 7 volts
Protection Protection against damage due to short-circuit
conditions (positive or negative battery voltage)
Protection against high-voltage transients
High noise immunity due to differential bus
implementation
Temperature ranges -40C to +85C
4.4 Voltage regulator
78l05 regulator is used to transform the 24 V DC supply to 5 volts.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
34/158
25
4.5 Printed circuit board:
For designing the PCB two software packages were used Multisim to draw the layout of the
circuit as shown in figure 8.
Figure 8: Module circuit layout
Ultiboardto specify the
Physical dimensions of the components.
The copper tracks on the two sides of the board. The vias (a via is a connection between the two sides of the board).
Figure 9 shows the top layer tracks, figure 10 shows the bottom layer tracks, and figure 11
shows the two layers.
U1
pic18f2585
1
2
3
4
5
6
7
8
9
10
11
12
13
14 15
16
17
18
19
20
21
22
23
24
25
26
27
28
U2
MCP2551
1
2
3
4 5
6
7
8
J2
DSUB9F
R1
1k
R2
1k
R3
1k
R7
1k
R10
1k
R4
1k
R5
1k
R6
1k
R8
1k
R9
1k
J1
HDR1X2
R11
10.0k
J6
C1
15pF
2%C2
15pF
2%
X120MHz
U378L05
LINE VREG
COMMON
VOLTAGE
J3
HDR1X4
J7
HDR1X5
J4
HDR1X5
J5
R12
1k
R13
1k
J8
HDR1X6
J9
HDR1X2
J10
HDR1X2
J11
Key = SpaceR14
390
R15390
C3
330nF
2%
C4
0.01F
2%LED
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
35/158
26
Figure 9 Top layer tracks
Figure 10 Bottom layer tracks
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
36/158
27
Figure 11 Top and bottom layers
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
37/158
28
Chapter 5.
Software
Microchip developed a CANOPEN stack [27] that includes most of the functions defined by
the standard, these functions need to be tailored for the application required, and most of these
functions were used in this project to program the microcontroller.
The program developed in this project handles both CAN and CANOPEN functions along
with continuously monitoring the input ports for any change, a description of the code in general
is introduced first , details for each service are mentioned afterwards.
Figure 12 shows a flow chart of the code.
Figure 12: Code flow chart
Power on
Continuous
monitoring
Processing
Change
detected?
Initialization
NO
Yes
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
38/158
29
5.1 Initialization:
Module initialization consists of two parts as shown in figure 13.
Figure 13: initialization
5.1.1 Node initialization:
In this stage the oscillator and timer setting, node ID and baud rate are determined
dip switches are used for this purpose, and the ports are initialized according to requirements.
5.1.1.1 Oscillator initialization:
Since there are several options for the oscillator source in PIC18F2585 either internal or
external and different frequencies can be selected , in this mode the source of oscillator and
frequency value are selected.
The mode selected here is HS High speed external oscillator for this the register config1H was
set to 0b00000010 and the frequency 20 MHZ.
5.1.1.2 Node ID:
For node id 3 bits from port A were used to be connected to the 4 way dip switch (only
three ways are used and one reserved) , in initializing these pins must be configured as in puts
thus register TRISA see( section 4.1.4 ) is set to TRISA=0xFF; ( the rest of the pins are set as
inputs but are not used , still they are connected to a header for future use).
As per the standard it is not allowed for a node to have an ID of 0, thus a conditional
statement has been put in the code to avoid this
if(node0 == 0) node = 1; else node = node0;
mCO_SetNodeID (node) // Set the Node ID
Initialaization
Node
initialization
CANOPEN
initialization
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
39/158
30
Similarly for baud rate two pins of PORTB are connected to a two way dip switch ,thus
PORTB is set to operate as an input port TRISB= 0xFF , the dip switch enable the operation in
one of four rates(1 Mbit, 500Kbit, 250Kbit,125Kbit per second) , in fact CANbus standard
defines eight rates , the remaining four are (800Kbit,50 Kbit,20Kbit, 10Kbit per second) but
because of the tester used in our case here for testing this module see( section ) only the above
mentioned rates are available.
For each dip switch selection the registers BRGCON1 BRGCON2 and BRGCON3 are set to
yield one value as shown in table 12.
Table 12: dip switch and baud rates
Dip switch value Registers values Baud rate
0 BRGCON1 = 0x00
BRGCON2 = 0x92
BRGCON3 = 0x82
1Mbit
1 BRGCON1 =0x01
BRGCON2 = 0x92
BRGCON3 = 0x82
500kbits
2 BRGCON1 = 0x03;
BRGCON2 = 0x92
BRGCON3 = 0x82
250kbits
3 BRGCON1 = 0x07
BRGCON2 = 0x92
BRGCON3 = 0x82
125kbits
5.1.1.3 Heart beat cycle setting
The heartbeat rate set in this stage , defining the cycle in milliseconds , by this function
mNMTE_SetHeartBeat (cycle), whereas cycle is in milliseconds.
5.1.1.4 Port initialization:
In this implementation PORTC pins 0-3 are used as inputs and PORTC pins 4-7 are used as
outputs , thus TRISC=0x0F.
There are two variables defined to store ports values:
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
40/158
31
uLocalRcvBuffer to store the data received by messages to deal with output port PORTC 4-7.
uLocalXmtBuffer to store the state of the input port PORTC 0-3 to be send to CAN bus.
change is used to detect any changes in the input port.
These variables are set to zero in this initialization stage..
Since the standard defines message identifiers to include the node id:
PDO transmit id and PDO receive id are defined in this stage by the following
PDO transmit cob id is 384+node id which is the equivalent of 0x180+ node id.
PDO receive cob id is 512+node id (0x200+node id).
PIC18F microcontrollers are designed to handle identifiers in a reverse order, the id of
0b10001110 is handled with filters in this order 0b01110001 , so any id must be stored in
microchip format.
This is what the function mTOOLS_CO2MCHP (CO_COB) do, converts the MCHP COB
format to the CANopen format.
5.2 CANOPEN initialization
In this stage the CANOPEN services are enabled by these functions
_CO_COMM_NMT_Open (); Starts network management
_CO_COMM_SDO1_Open (); Starts the default SDO
_CO_COMM_NMTE_ Open (); Starts the heartbeat
_CO_COMM_PDO1_Open (); Start the pdo1
In this function there are another two functions:
The first one is mTOOLS_CO2MCHP which is responsible for setting the cob id for the
end point and transforming it from CANopen format to Microchip format
The second function is mCANOpenMessage this function uses a variable called handler ,
each end point has its own handler , addressing endpoints with handlers improves the data flow
and speeds up the message processing, messages are classified to three major groups:
Network control message group
SDO message group
PDO message group
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
41/158
32
Each group is assigned a value as shown in table 13
Table 13: messages groups values
Message group Name value
Network control COMM_MSGGRP_NETCTL 0x00
SDO COMM_MSGGRP_SDO 0x40
PDO COMM_MSGGRP_PDO 0x80
Each group includes number of messages as shown in table 14.
Table 14: messages numbers in message groups
Message Message value Message group
COMM_NETCTL_NMT 1 COMM_MSGGRP_NETCTL
COMM_NETCTL_NMTE 4 COMM_MSGGRP_NETCTL
COMM_SDO_1 0 COMM_MSGGRP_SDO
COMM_PDO_1 0 COMM_MSGGRP_PDO
Thus each message is uniquely addressed by the group number and subgroup number e.g.
PDO1 is addressed by 0x80 and 0 and so on.
mCANOpenMessage function has two inputs and one return value:
mCANOpenMessage (MsgTyp, COBID, hRet)
MsgTyp= message type which is the group number in binary digitally (ored) with subgroup
number e.g. PDO1 message type = 0x80 | 0 = 0x80 and so on.
COBID is stored in a buffer _uCANRxIDRes[n], after wards this buffer is copied to filter
register RXFnSIDH (n= 0 to 15 in ECAN mode1)
hRet is a handle which indicates that the COBID was copied to one filter register.
Then the function mCANOpenComm is called to put CANCON register to zero,
CANCON CAN control is a special register in PIC18F2585 which is used to set the status of
the CAN controller in one of the following modes
Configuration mode
Listen only mode
Loopback mode
Disable mode
Normal mode
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
42/158
33
CANCON=0 will put the controller to normal mode.
According to the standard a CANOPEN node should send a message informing the network
that the node has initialized, this message is called boot up message, and the COB ID for this
message is the same of heart beat with one data byte containing zero value.
This message is sent using the function of_CO_COMM_NMTE_TXEvent.
mCANSendMessage function is used to inform the processor that a message is ready to be
sent.
Then the node will enter preoperational mode as described by the standard , where the heart
beat message will be send every N milliseconds (N is decided by the programmer) with the
COB ID of 0x700 + Node ID with one data byte , this byte shows the state of the node as shown
in table15.
Table 15: node states and corresponding value in heartbeat messages
Data byte value State Communication capabilities
0x7F Preoperational SDO communication is
possible to read and write
from the object dictionary,
heart beat messages are sent,
no PDO messaging is
possible
0x05 Operational All messages are available
0x04 Stop Only heart beat messages are
available
5.3 Infinite loop processing:
Figure 14 shows the data flow chart after initialization, which is implemented by an infinite
loop while (1), as long as the node is powered this loop should be followed.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
43/158
34
Figure 14: infinite loop processing flow chart
5.3.1 Processing functions:
_CO_COMMRXEventManager this function deals with all received messages
In this function bit1 of register PIR3 is continuously monitored if it raises then this function
forwards a handle of the associated buffer , this handle is checked to determine which group this
message belongs to , then the relevant receiving function is called,
5.3.2 PDO message receiving.
For PDO group then the function _CO_COMM_PDO1_RXEvent is called , this function will
store the data field and data length in buffers for further processing.
After that the function mCANReadMessage is called to reset bit7 (RXFULL) of the buffer to
indicate that the message was successfully received.
5.3.3 NMT message group
For a state change command which belongs to NMT group the function
_CO_COMM_NMT_RXEvent is called, This function will check first that the data length is 2
Then it reads data byte zero , according to the value the node state
will change as shown in table 16.
Continuous
monitoring
Processing
Change
detected?
NO
Yes
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
44/158
35
Table 16 : node state change command values
Data bytre0 value The state Functionality available
0x01 Start node , operational mode All messaging is available
0x02 Stop node No communication except
the heart beat
0x80 Preoperational mode SDO messaging and
heartbeat only
0x82 Reset communication The node will restart as if it
was powered off and
powered on again
5.3.4. SDO message group
For SDO messages then the function _CO_COMM_SDO1_RXEvent is called to determine
whether the message is an upload or download and respond accordingly.
5.3.5 Object dictionary
5.3.5.1 Object dictionary entry
The implementation of the object dictionary is achieved through using structures , each entry
in the dictionary is represented by a structure that contains all necessary information.
typedef struct _DICTIONARY_OBJECT_TEMPLATE
{
unsigned int index;
unsigned char subindex;
unsigned char ctl;
unsigned int len;
rom unsigned char * pROM;
}DICT_OBJECT_TEMPLATE;
Table 17 shows the function of each variable in the structure, and table 18 shows the object
dictionary implemented by this code.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
45/158
36
Table 17: object dictionary structure and variable meaning
Variable Function
Ctrl a variable that defines whether the entry is
writable or readable both
Len the length in bytes of the object
* pROM a pointer to the object
Table 18: object dictionary
Index Sub-
index
Object R/W Meaning
0x1000 0 Device type R Contains a code that
represent the type , reading
this value will return
0x111111
0x1017 0 NMTE_HeartBeatAccessEvent R This entry allows reading
the heart beat message
cycle
0x1018 4 Device serial number R Reading this object will
return device serial number
0x87654321
0x1200 1 SDO1_CS_COBIDAccessEvent R Reading this entry will
return the Client to Server
COB ID 0x600+node ID
0x1200 2 SDO1_SC_COBIDAccessEvent R Reading this entry will
return the Server to client
COB ID 0x580+node ID
0x1400 1 RPDO1_COBIDAccessEvent R Reading this entry will
return the Recieve PDO
OB ID 0x200+node ID
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
46/158
37
0x1600 1 RPDO1Map R Reading this entry will
return the index and sub-
index of the object that
store the data sent by
RPDO
0x62000
0x1800 1 TPDO1_COBIDAccessEvent R Reading this entry will
return the Transmit PDO
COB ID 0x180+node ID
0x1800 2 TPDO1_TypeAccessEvent R Reading this entry will
return the Transmit PDO
type 255
0x1A00 1 TPDO1Map R Reading this entry will
return the index and sub-
index of the object that
store the data sent by
TPDO
0x60000
0x6000 0 uLocalXmtBuffer R Reading this entry will
return the state of the input
ports PORTC bits 0-3
0x6200 0 uLocalRcvBuffer R/W This entry allows reading
and writing to the output
ports PORTC bits 4-7
5.3.5.2 Reading and writing functions of the dictionary
There are two functions to access the dictionary:
_CO_DictObjectRead this function is used to read from the dictionary which in turn
manipulate two functions
CO_MEMIO_CopyRomToRam used if a data stored in ROM
need to be read .
CO_MEMIO_CopySram used for reading from RAM.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
47/158
38
_CO_DictObjectWrite this function is used to write in the dictionary ,in this function
only CO_MEMIO_CopySram is used, because it is not possible to modify ROM contents
in the run time.
5.3.6 Message transmission
_CO_COMMTXRdyEventManager() , this function is where all transmission requests are
dispatched , this function is continuingly checking these flags, each group has a variable called
transmit flag as shown below
COMM_NETCTL_TF Network control Transmit Flag
COMM_SDO_TF SDO transmit flag
COMM_SDO_TF PDO transmit flag
Whenever a message is ready to be sent the corresponding flag is raised , once one flag is
raised the associated transmit function is called, table 19 show the transmit function of each
group
Table 19 transmit functions for message groups
Message group Transmit function
NMTCTL _COMM_NMTE_TXEvent
PDO _CO_COMM_PDO1_TXEvent.
SDO _CO_COMM_SDO1_TXEvent
All these functions operate in the same way, they all set COBID , data length and put the
required data into the data filed of the message.
5.3.7 DemoProcessEvents function:
This function is the application defined and it has two parts:
Part 1 dealing with the input port.
Part 2 dealing with the output port.
5.3.7.1 Input port processing
The function keeps reading the input port (PORTC 0-3) storing the port value in a variable
called uLocalXmtBuffer and comparing this variable with the last state stored in the variable
uIOinDigiInOld , once a change is detected that means at least on pin was changed , then the
transmit flag of PDO1 is raised, there is a pointer linking the variable uLocalXmtBuffer with
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
48/158
39
the transmit buffer thus when the transmit flag is raised the contents of uLocalXmtBuffer will be
sent , the stored state is updated to have the latest values , and the comparison starts again.
5.3.7.2 Output port processing
There is a pointer linking the variable uLocalRcvBuffer with the receive buffer, thus when a
PDO message is received the data field will be copied to this variable.
In addition LATC which is the value of the output port is assigned to uLocalRcvBuffer
(since PORTC0-3 are programmed as inputs only PORTC4-7 will change with LATC)
Thus any value sent in byte 0 of a PDO message will be forwarded to LATC4-7, also it is
possible to change the output port status through writing in the object dictionary.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
49/158
40
Chapter 6
Tests
The monitor software used is CANbus demo board [28] which include two CAN nodes each
is equipped by USB board that can communicate with a PC and display CAN messages in the
associated interface, the masks of these nodes are all set to one to enable receiving every CAN
message in the bus , the interface allow to form and send CAN messages as well.
6.1 Input port test
According to the implementation if one input changed state then an asynchronous PDO
message will be sent with the current state of the switches.
The COB ID should be 0x180+node ID; the first byte in the data field will reflect the state of the
inputs as shown in table () , if an input is connected then the corresponding bit should be one ,
otherwise should be zero, the test was successfully completed.
6.2 Output port test
A message is sent to trigger a signal through output port.
The COBID should be 0x200+node ID , byte0 of the data bytes should have the state
requested on the output port , for every bit set to one in bits4-7 in byte0 the corresponding port
should forward five volt signal , making the connected LED lit .
The test was successfully done as shown in table()
Another way is to lit the LEDs by writing in correspondent object in the object dictionary , this
was done as well as shown in table ()
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
50/158
41
Table 20 PDO messages
6.3 Reading from object dictionary test:
Reading any entry in the object dictionary, this was successfully done as shown in table 21
Message
identifier
Data
length
D0 D1 D2 D3 D4-D7
Transmit PDO
Input port
change
0x180 +
node ID
8 Bits 0-3 the 4
ports status
00 00 00 00
Receive PDO
Output signal
command
0x200 +
node ID
8 Bits 4-7 the value
for each port
0x01 firs port0x02 second
0x04 third
0x08 forth
And combinations
e.g. value 0xC
means port3 and 4
00 00 00 00
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
51/158
42
Table 21 SDO messages
6.4 State request test
The state of the inputs should be read on request, by reading the value of the input port from
the object dictionary the test was successfully completed .
Message
identifier
Data
length
D0 D1 D2 D3 D4-D7
Read from the
dictionary
0x600+
node ID
8 0x40 Index
low
Index
high
Sub
index
zeros
Read response 0x580+
node ID
8 0x43 for
four bytes
object
0x47 forthree bytes
objects
0x4B for
two bytes
object
0x4F for
one byte
object
Index
low
Index
high
Sub
index
The object
D7 most
significant
D4 least
significant
Write to the
dictionary
0x600+
node ID
8 0x2F
(for one
byte only)
Index
low
Index
high
Sub
index
D4 the data
to be
written
Write response 0x580+
node ID
8 0x60 Index
low
Index
high
Sub
index
zeros
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
52/158
43
6.5 node state change commands:
These commands were successfully tested as shown in table 22.
Start remote node
Stop remote node
Enter preoperational mode
Node reset
Table 22 node state change command values
Message
identifier
Data
length
Data
bytre0
value
Data
byte1
value
The state Function Response
0x01 02 0x01 Node ID Start node ,
operational
mode
All messages are
available
The heart
beat data
byte 0 is
0x05
0x01 02 0x02 Node ID Stop node No
communication
except the heartbeat
The heart
beat data
byte 0 is0x04
0x01 02 0x80 Node ID Preoperational
mode
SDO messaging
and heartbeat
only
The heart
beat data
byte 0 is
0x7F
0x01 02 0x82 Node ID Reset
communication
The node will
restart as if it was
powered off and
powered on again
The boot up
message
will be sent
again data
byte 0 is 0
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
53/158
44
Conclusion
The field of Industrial automation is developing rapidly , new technologies have appeared to
reduce costs and to increase efficiency in industry ,recent trends in automation are to useintelligent and wireless instruments , some researchers are even working to make
communication with DCS systems through internet a safe and feasible solution ,in this field
Remote I/O modules with CANopen have competitive characteristics.
In this project the implementation for digital I/O module has been described in details in
terms of hardware and software, and finally the module has been successfully tested.
-
7/29/2019 MSc Disertation CANopen IO Card Implementation
54/158
45
References:[1] Friedmann, Paul G. (2006). Automation and Control Systems Economics.
(2nd Edition) [Online]. Available: http://www.knovel.com
[2] Farsi, Mohammed Barbosa Manuel, CANopen implementation, application to industrialnetworks, Research Studies Press Ltd, 2000, pp 1
[3] Whitt, Michael.(2004). Successful Instrumentation and Control Systems Design.
[Online]. Available: http://www.knovel.com
[4] Bolton, W. (2006). Programmable Logic Controllers. (4th Edition).
[Online]. Available: http://www.knovel.com
[5] McMillan, G.K.; Considine, D.M.(1999). Process/Industrial Instruments and Controls... . Handbook. (5th Edition) [Online]. Available: http://www.knovel.com.
[6] Feng-Li Lian; Moyne, J.R.; Tilbury, D.M.; Performance evaluation of control networks:
. Ethernet, ControlNet, and DeviceNet, in Control Systems Magazine, IEEEVolume 21,
. Issue 1, , pp:6683, Feb. 2001
[7] Process Control Security Requirements Forum (PCSRF)working group, Generic
composite industrial control system network architecture-DCS,NIST National Institute
of Standards and Technology U.S,[ONLINE] Available:
http://www.isd.mel.nist.gov/projects/processcontrol/members/documents/diagram_DCS.gif
[8] Adnan Salihbegovi ,Zoran Cico, Vlatko Marinkovi, Elvedin Karavdi,
software engineering approach in the design and development of the industrial
automation systems, proceedings of the 2008 international workshop on Software
Engineering in east and south Europe, 2008, in technical presentations, pp:15-22.
[9] Daniel, R.A.,Ethernet-a natural evolution for remote I/O,in:WESCON/96,
, 1996, pp 610616
[10] Palls-Areny, Ramon; Webster, John G.(2001). Sensors and Signal Conditioning.,
. (2nd Edition) [Online]. Available: http://www.knovel.com
[11] D. W. Clarke,Intelligent instrumentation,
... Transactions of the Institute of Measurement and Control, vol. 22: pp. 327, Mar 2000;
[12] Jimmy Kjellsson, Anne Elisabeth Vallestad, Richard Steigmann, and DacfeyDzung,Integration of a wireless I/O Interface for PROFIBUS and PROFINET for
Factory Automation,Industrial Electronics, IEEE Transactions on Volume 56, Issue
10,pp:4279 - 4287 ,Oct. 2009.
http://c/xpl/RecentCon.jsp%3fpunumber=4110http://c/xpl/RecentCon.jsp%3fpunumber=4110http://c/xpl/RecentCon.jsp%3fpunumber=4110http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/tocresult.jsp%3fisnumber=5238769http://c/xpl/tocresult.jsp%3fisnumber=5238769http://c/xpl/tocresult.jsp%3fisnumber=5238769http://c/xpl/tocresult.jsp%3fisnumber=5238769http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/RecentCon.jsp%3fpunumber=4110 -
7/29/2019 MSc Disertation CANopen IO Card Implementation
55/158
46
[13] Gungor, V.C.; Hancke, G.P,Industrial Wireless Sensor Networks: Challenges, Design
Principles, and Technical Approaches,Industrial Electronics, IEEE Transactions on
Volume 56, Issue 10, Page(s):42584265, Oct. 2009.
[14] Gnad, A.; Kratzig, M.; Rauchhaupt, L.; Trikaliotis, S,Relevant influences in wireless
automation, WFCS 2008. IEEE International Workshop on Page(s):341348, 21-23
May 2008.
[15] Ando, B.; Savalli, N, instrumentationnotes - CANBUS Networked Sensors Use in
Orientation Tools for the Visually Impaired Wired versus Wireless Technology,
Instrumentation & Measurement Magazine, IEEE,Volume 11, Issue 1, pp:4952, Feb.
2008.
[16] Halsall, Fred:Title Data communications, computer networks, and open systems, ... (4th Edition),1996,pp 15-18.
[17] American Society of Heating, Refrigerating and Air-Conditioning Engineers.(2009).
ASHRAE Handbook - Fundamentals. [Online]. Available: http://www.knovel.com.
[18] Jasperneite, J.; Imtiaz, J.; Schumacher, M.; Weber, K.;A Proposal for a Generic Real-
. Time Ethernet System, Industrial Informatics, IEEE Transactions on Volume 5, Issue 2
, pp: 7585, May 2009.
[19] Bob Yeager, President Emerson Power & Water Solutions,Distributed Control . .
. Technology: From A Decade of Progress to an Era of New Possibilities, presented at
. 2008POWID Conference PO44, [ONLINE] Available: . . . . . . . .
. http://www.isa.org/filestore/Division_TechPapers/GlassCeramics/POW08-P044Final.pdf
[20] Strothman, Jim.(2006).Handbook of Measurement Equations and Tables.
(2nd Edition).[Online]. Available: http://www.knovel.com
[21] Wei-ming Tong; Hong-wei Gao; A Fieldbus Comprehensive Evaluation and Selection
Method Based on Entropy-Ideal Point,ISDA '08. Eighth International Conference on ,
Volume 2, pp: 564568, 26-28 Nov. 2008.
[22] Cia Control in automation,CAN history [Online]. Available:
http://www.can-cia.org/index.php?id=161 , http://www.can-cia.org/index.php?id=48
& http://www.can-cia.org/index.php?id=49
[23] Ando, B.; Baglio, S.; La Malfa, S.; Marletta, V.; Savalli, N.; A distributed sensor
network approach for orientation tasks,Intrumentation and Measurement Technology
Conference, IEEE, pp: 1215, 5-7 May 2009.
[24] Microchip technology Inc. PIC18F2585/2680/4585/4680 Data Sheet, 2007.
http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/RecentIssue.jsp%3fpunumber=41http://c/xpl/tocresult.jsp%3fisnumber=5238769http://c/xpl/RecentCon.jsp%3fpunumber=4629548http://c/xpl/RecentCon.jsp%3fpunumber=4629548http://c/xpl/RecentCon.jsp%3fpunumber=4629548http://c/xpl/RecentIssue.jsp%3fpunumber=5289http://c/xpl/tocresult.jsp%3fisnumber=4449000http://open_window%28%22http//sparky.ncl.ac.uk:80/F/CSLPGQQX1AB18AILJQHG6FKGSHV8YFVB2IJ12NQXHG2CSSBNH2-48513?func=service&doc_number=000264983&line_number=0012&service_type=TAG%22);http://open_window%28%22http//sparky.ncl.ac.uk:80/F/CSLPGQQX1AB18AILJQHG6FKGSHV8YFVB2IJ12NQXHG2CSSBNH2-48513?func=service&doc_number=000264983&line_number=0012&service_type=TAG%22);http://open_window%28%22http//sparky.ncl.ac.uk:80/F/CSLPGQQX1AB18AILJQHG6FKGSHV8YFVB2IJ12NQXHG2CSSBNH2-48514?func=service&doc_number=000264983&line_number=0013&service_type=TAG%22);http://open_window%28%22http//sparky.ncl.ac.uk:80/F/CSLPGQQX1AB18AILJQHG6FKGSHV8YFVB2IJ12NQXHG2CSSBNH2-48514?func=service&doc_number=000264983&line_number=0013&service_type=TAG%22);http://open_window%28%22http//sparky.ncl.ac.uk:80/F/CSLPGQQX1AB18AILJQHG6FKGSHV8YFVB2IJ12NQXHG2CSSBNH2-48514?func=service&doc_number=000264983&line_number=0013&service_type=TAG%22);http://open_window%28%22http//sparky.ncl.ac.uk:80/F/CSLPGQQX1AB18AILJQHG6FKGSHV8YFVB2IJ12NQXHG2CSSBNH2-48515?func=service&doc_number=000264983&line_number=0015&service_type=TAG%22);http://open_window%28%22http//sparky.ncl.