Tutorial
v1.10
CANopenNode
Page 1/24
CANopenNode
Tutorial
Janez Paternoster
Cesta v Zajčjo Dobravo 14a
Ljubljana
Slovenia, EU
janez.paternoster@siol.net
1. December 2005
Tutorial
v1.10
CANopenNode
Page 2/24
Copyright (C) 2005 Janez Paternoster, Slovenia
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU
Free Documentation License, Version 1.2 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the file entitled "FDL.txt".
Tutorial
v1.10
CANopenNode
Page 3/24
Contents
1. Introduction......................................................................................................................................4
1.1 Requirements.............................................................................................................................4
1.2 Description.................................................................................................................................4
2. Hardware..........................................................................................................................................6
3. Program microcontrollers.................................................................................................................7
3.1 Source files................................................................................................................................7
3.2 Oscillator and CAN diodes settings...........................................................................................8
3.3 Programming Sensor..................................................................................................................9
3.3.1 Setup Project – CO_OD.h file............................................................................................9
3.3.2 Interface with application – User.c file.............................................................................11
3.3.3 Compile, program and test...............................................................................................12
3.4 Program Power unit.................................................................................................................12
3.4.1 Add variables into Object Dictionary – CO_OD.c file....................................................12
3.4.2 Setup Project – CO_OD.h file..........................................................................................14
3.4.3 Interface with application – User.c file............................................................................16
3.4.4 Electronic Data Sheet – Tutorial_Power.eds file..............................................................17
3.4.5 Compile, program and test...............................................................................................17
3.5 Program Command interface...................................................................................................18
3.5.1 Setup Project – CO_OD.h file..........................................................................................18
3.5.2 Interface with application – User.c file............................................................................19
3.3.3 Compile, program and test...............................................................................................20
4. Connect and test the network..........................................................................................................21
5. User interface with PIC + LCD + Keypad......................................................................................24
6. Ethernet User interface...................................................................................................................24
7. Conclusion......................................................................................................................................24
Tutorial
v1.10
CANopenNode
Page 4/24
1. Introduction
With this tutorial you will make working CANopen network. CANopenNode, Open Source Library
will be used. It will be shown how to: make a generic input/output device, use Process Data objects
(transmission and mapping), use retentive variables in Object Dictionary, make own program for
smart devices, use custom CAN message for NMT master, use emergency message for custom
errors, etc.
In later chapter it will be shown, how to configure network with
panel_with_PIC+LCD+keypad
or
Web_interface_with_SC1x
examples (both are included with CANopenNode) or with standard
commercial configuration tool.
In this tutorial are described most of CANopenNode features. It is quite a lot of them, so many
information is in this tutorial. Source code is tested, so user should not have problems with it. If
there are problems or questions, please contact the author.
1.1 Requirements
1. CANopenNode source v1.10, download from http://sourceforge.net/projects/canopennode/ ;
2. MPLAB IDE (download from http://www.microchip.com, free);
3. MPLAB C18 V3.00+ (download from http://www.microchip.com, free);
4. Three boards with microcontroller PIC18F458 (or other PIC18F with CAN) and CAN
transceiver;
5. PIC programmer (MPLAB ICD2 from http://www.microchip.com works fine).
6. Knowledge of using MPLAB IDE and MPLAB C18.
7. Knowledge of CANopen protocol (online training at “http ://www.can-cia.org/canopen/ ” or
“http://www.esacademy.com/myacademy/”, book: “http://www.canopenbook.com/”).
8. Recommended: CANopen configuration tool like
panel_with_PIC+LCD+keypad
(part of
CANopenNode) or
Web_interface_with_SC1x
(also part of CANopenNode) or any other
commercial CANopen configuration tool.
1.2 Description
Network represents air-condition unit with remote sensor and command interface. It consists from
three CANopen devices (Picture 1.1):
1. Sensor: stand alone temperature sensor:
•
Based on generic Input/Output device profile (CiADS401).
•
Transmit sensed temperature on every change of state and periodically with event timer
(TPDO 1).
•
Produce Heartbeat every second.
2. Power unit: air-condition unit made from heater and cooler:
•
Receive temperature from Sensor (RPDO 0).
Tutorial
v1.10
CANopenNode
Page 5/24
•
TempLo and TempHi variables are in Object Dictionary. They can be accessed and changed
with CANopen configuration tool via SDO communication objects. Variables are retentive
(keep value after power off). Units are [° Celsius].
•
Turn cooler or heater ON or OFF. Decision is based on Temperature from sensor, TempLo and
TempHi. If device is not in operational state, cooler and heater will be powered off.
•
Transmit state of cooler and heater on every change of state and periodically with event timer
(TPDO 0).
•
Produce Heartbeat every second.
•
Monitor heartbeats from sensor and command interface.
3. Command interface: one button and two led diodes, optionally LCD display:
•
Receive temperature from Sensor (RPDO 0) and display it on LCD (optional).
•
Receive state of cooler and heater from Power unit (RPDO 1) and display it on LED diodes.
•
NMT master in connection with button. If button is pressed, all network will be set to pre-
operational, and if button is pressed again, all network will be set to operational NMT state. If
button is pressed for longer time (5 seconds), all nodes on network will reset.
•
Produce Heartbeat every second.
Picture 1.1 – Sample CANopen network
Besides communication objects described above, each node uses also SDO, Emergency and NMT
(slave) communication objects.
Sensor
Node-ID = 6
Run
LED
Error
LED
Temperature
Generic I/O
CiADS401
Heartbeat
1sec
COB 706
TPDO 1
word_0: temp.
COB 286
Heater
.
Cooler
.
Power unit
Node-ID = 7
Run
LED
Error
LED
User program
Heartbeat
1sec
COB 707
TPDO 1
byte 0: state
COB 187
Heartbeat
Consumer
COB 706
Object
Dictionary:
TempLo
TempHi
RPDO 0
word 0: temp.
COB 286
Heater
.indic.
Cooler
indic.
Command
interface
Node-ID = 8
Run
LED
Error
LED
User program,
NMT master
Heartbeat
1sec
COB 708
NMT master
COB 00
RPDO 1
word 0: temp.
COB 286
RPDO 2
byte 0: state
COB 187
Temperature
indication
Button
CAN bus
125kbps
11 bit identifier
recived
objects
transm.
objects
Heartbeat
Consumer
COB 708