Ssds

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

CAN SCICOS CAN200 Example

ScicosLab and CANopen

Ing. Roberto Bucher

Scuola Universitaria Professionale della Svizzera Italiana (SUPSI)

Manno - July 1. 2009


CAN SCICOS CAN200 Example

Objectives

See how CANopen devices can be integrated in a Scicos block


diagram
Learn how to implement new CANopen devices
Introduce the CAN200 interface dongle
CAN SCICOS CAN200 Example

Outline

1 CAN and CANopen

2 Scicos and CANopen

3 The CAN200 card

4 Example
CAN SCICOS CAN200 Example

CAN

Controller Area Network

Controller area network (CAN or CAN-bus) is a vehicle bus


standard designed to allow microcontrollers and devices to
communicate with each other within a vehicle without a host
computer.
It was designed specifically for automotive applications but is
now also used in other areas.
Development of the CAN-bus started originally in 1983 at
Robert Bosch GmbH.
CAN SCICOS CAN200 Example

CAN

Interface
CAN SCICOS CAN200 Example

CANopen

CANopen

CANopen is a communication protocol and device profile


specification for embedded systems used in automation.
In terms of the OSI model, CANopen implements the layers
above and including the network layer.
The lower level protocol implementing the data link and
physical layers is usually Controller Area Network (CAN).
CAN SCICOS CAN200 Example

Device model

Device model

Every CANopen device must implement:


A Communication unit (protocol for messaging)
A state machine (Initialization, Pre-operational, Operational,
Stopped)
An object dictionary used for configuration and non-realtime
communication with the device.
The application part
CAN SCICOS CAN200 Example

Communication objects

Communication objects
CAN SCICOS CAN200 Example

Protocol

Network management (NMT) protocol

The NMT protocols are used to issue state machine change


commands (ie. to start and stop the devices), detect remote device
bootups and error conditions.
CAN SCICOS CAN200 Example

Protocol

Service Data Object (SDO) protocol


The SDO protocol is used to set and read values from the object
directory of a remote device.
CAN SCICOS CAN200 Example

Protocol

SDO
Master (PC) CAN dev 1 CAN dev 2

CMD

ACK

REQ

DATA

CMD

ACK

REQ

DATA
CAN SCICOS CAN200 Example

Protocol

Process Data Object (PDO) protocol

Process Data Object protocol is used to process real time data


among various nodes.
Synchronous
On change
TX and RX PDO’s
More values in the same message
CAN SCICOS CAN200 Example

Protocol

PDO

ENCODER CURRENT SPEED


CAN SCICOS CAN200 Example

Protocol

PDO
Master (PC) CAN dev 1 CAN dev 2

SYNC

PDO’s

SYNC

PDO’s

SYNC

PDO’s

SYNC

PDO’s
CAN SCICOS CAN200 Example

Protocol

Others

Synchronization Object (SYNC) protocol


Time Stamp Object (TIME) protocol
Emergency Object (EMCY) protocol
CAN SCICOS CAN200 Example

Integration in Scicos

Integration in Scicos

CANopen
device
CAN SCICOS CAN200 Example

Integration in Scicos

Integration in Scicos

CAN
Initialization

CANopen
device
CAN SCICOS CAN200 Example

Integration in Scicos

Integration in Scicos

CAN
Initialization

CANopen
device
Receive
Thread
CAN SCICOS CAN200 Example

The “canopen.c” file

canopen.c

Initializes the RTDM driver


Contains a function to register the TX PDO
Starts a high priority thread for receiving the CAN messages
Handles TX PDO1 and TX PDO2, but can be easy extended
to handle more PDO’s
CAN SCICOS CAN200 Example

The “canopen.c” file

canopen.c

The canopen.c file


CAN SCICOS CAN200 Example

The “canopen.c” file

PDO handling

.....

127 for TX PDO1

.....

127 for TX PDO2


CAN SCICOS CAN200 Example

The “canopen.c” file

PDO handling

.....

127 for TX PDO1

.....

127 for TX PDO2


CAN SCICOS CAN200 Example

The “canopen sync” file

The “canopen sync.c” file

Simply sends a SYNC (0x80) message to all CANopen devices


All the devices handle the SYNC message as follow:
Devices with configured TX PDO’s send the requested values
to the master
Devices with configured RX PDO’s set the last received value
CAN SCICOS CAN200 Example

Reading PDO’s

Reading from the CAN Bus

A real-time thread scheduled with SCHED FIFO and priority


“1” is responsible to get the messages from the CAN bus.
The receiving procedure runs using the interrupt of the CAN
bus RTDM driver.
The registered PDO’s are saved into the two PDO matrices.
8 procedures allow to extract the values from the PDO
messages (1,2,4 bytes, signed, unsigned)
CAN SCICOS CAN200 Example

The palette

Additional palettes

Epos Epos Analog INIT ENC


canopen 0x08 1s
sync 1 0

Epos Epos signal means


encoder motX out.txt
0x08 0x08

Epos
Switch
motor I
0
0x08
1

Pport_out Pport_in
2 15
0x378 0x378
CAN SCICOS CAN200 Example

Implementing a new block

The interface

1 Epos
canopen
sync

Epos Epos INIT ENC


motor I encoder 0.01s 1 1
1 0x08 0
0x08
gain_x
CAN SCICOS CAN200 Example

Implementing a new block

The interface

1 Epos
canopen
sync

Epos Epos INIT ENC


motor I encoder 0.01s 1 1
1 0x08 0
0x08
gain_x
CAN SCICOS CAN200 Example

Implementing a new block

The implementation

The Implementation file


CAN SCICOS CAN200 Example

The card

The CAN200 dongle


CAN SCICOS CAN200 Example

The card

Details

based on the SJA1000 chip


Little modifications on the original CAN200 board
16 Mhz quarz
Scmhitt trigger chip instead of a nand
Quite simple
PCB and scheme are provided
CAN SCICOS CAN200 Example

Hardware

The CAN200 dongle - Scheme

VCC
470 LED1
X4-1
R6
C3 C6

+
100n 47uF
470
X4-2
R4
GND

VCC
GND

23 22
AD0 VDD1
1 IC1A
3 24 8
AD1 VSS1
2
74HC132 25
AD2
12
VDD3
26
AD3
4 IC1B 15
VSS3
6 27

3
AD4
5 13 8 5
TX0 RS

VCC
74HC132 28 1 7 4 9
AD5 TXD CANH
14 4 6 3 8
TX1 RXD CANL

GND
1 5 2 7
AD6 VREFOUT
19 1 6
X2 RX0
2
AD7

2
14 1 20 X1
RX1 R1
15 2
16 3 3 21
ALE/AS VSS2 47k R5
17 4
18 5 4 18
CS VDD2 120
270
R3

19 6
10

20 7 5

2
1
9

RD/E

JP1
VCC

21 8 17
RESET
22 9 6
WR
23 10
74HC132

33p
IC1C

C1
24 11 220p 7
CLK_OUT
8

25 12
10k

C4
R2

13 11 9

2
74HC132 MODE XTAL1
13

8MHz

33p
C2
11 16 10

Q1
INT XTAL2

1
12
IC1D

GND
GND

6/23/2009 15:45:44 /home/bucher/eagle/can200/can200.sch (Sheet: 1/1)


CAN SCICOS CAN200 Example

Software

The Driver

RTDM driver
Modified peaks dongle driver
Few lines changed
CAN SCICOS CAN200 Example

Example

The Servo motor


CAN SCICOS CAN200 Example

Example

The Servo motor


CAN SCICOS CAN200 Example

Example

The Servo motor


CAN SCICOS CAN200 Example

Example

Features

Motor Output
Hall sensor+Incremental encoder
2 Analog inputs −10V ÷ +10V
1 Analog output 0V ÷ 10V
10 Digital inputs
5 Digital outputs
CAN SCICOS CAN200 Example

Example

Motor equations

Differential equation

Jm · ϕ̈m = −Dm · ϕ̇m + Kt · I

In Laplace
Kt
Jm
Φ(s) = · I (s)
s 2 + DJmm ·s
CAN SCICOS CAN200 Example

Example

Motor equations

Kt
Jm
Φ(s) = · I (s)
s 2 + DJmm ·s
can be rewritten as

K
Φ(s) = · I (s)
s2 +α·s
where
Kt Dm
K= ,α =
Jm Jm
CAN SCICOS CAN200 Example

Example

Motor equations

With I (s) as step signal we obtain:

K I0
Φ(s) = ·
s2 +α·s s
that in time domain becomes
K · I0 K · I0 K · I0 α·t
ϕ(t) = − 2
+ ·t + ·e
α α α2
CAN SCICOS CAN200 Example

Example

Example

Controller
ScicosLab

You might also like