CAN and FPGA Communication Engineering AWS

Diplomica Verlag. CAN and FPGA. Communication Engineering. Implementation of a CAN Bus based. Measurement System on an. FPGA Development Kit. Yu Zhu. Diplomica Verlag ...
58KB Größe 4 Downloads 211 Ansichten
Yu Zhu

CAN and FPGA Communication Engineering Implementation of a CAN Bus based Measurement System on an FPGA Development Kit

Diplomica Verlag

Yu Zhu CAN and FPGA Communication Engineering: Implementation of a CAN Bus based Measurement System on an FPGA Development Kit ISBN: 978-3-8366-4925-4 Herstellung: Diplomica® Verlag GmbH, Hamburg, 2010

Dieses Werk ist urheberrechtlich geschützt. Die dadurch begründeten Rechte, insbesondere die der Übersetzung, des Nachdrucks, des Vortrags, der Entnahme von Abbildungen und Tabellen, der Funksendung, der Mikroverfilmung oder der Vervielfältigung auf anderen Wegen und der Speicherung in Datenverarbeitungsanlagen, bleiben, auch bei nur auszugsweiser Verwertung, vorbehalten. Eine Vervielfältigung dieses Werkes oder von Teilen dieses Werkes ist auch im Einzelfall nur in den Grenzen der gesetzlichen Bestimmungen des Urheberrechtsgesetzes der Bundesrepublik Deutschland in der jeweils geltenden Fassung zulässig. Sie ist grundsätzlich vergütungspflichtig. Zuwiderhandlungen unterliegen den Strafbestimmungen des Urheberrechtes. Die Wiedergabe von Gebrauchsnamen, Handelsnamen, Warenbezeichnungen usw. in diesem Werk berechtigt auch ohne besondere Kennzeichnung nicht zu der Annahme, dass solche Namen im Sinne der Warenzeichen- und Markenschutz-Gesetzgebung als frei zu betrachten wären und daher von jedermann benutzt werden dürften. Die Informationen in diesem Werk wurden mit Sorgfalt erarbeitet. Dennoch können Fehler nicht vollständig ausgeschlossen werden und der Verlag, die Autoren oder Übersetzer übernehmen keine juristische Verantwortung oder irgendeine Haftung für evtl. verbliebene fehlerhafte Angaben und deren Folgen. © Diplomica Verlag GmbH http://www.diplomica-verlag.de, Hamburg 2010

Preface

The Controller Area Network (CAN), invented by Bosch in 1983, is a serial field bus protocol which was originally used in road vehicles and now is widely applied in other industrial fields. Since its birth automotive electronic engineers have been using Microcontrollers (MCU) to control the CAN bus. Today, as the Field-programmable Gate Array (FPGA) has become very advanced, this book introduces a new method which uses an FPGA and a MCU jointly instead of a single MCU to design a CAN bus based measurement system. Furthermore the designed system works at the fastest possible speed. This book first introduces the CAN protocol in detail. Next it studies the maximum effective data transmission rate and ratio of the CAN bus communication and compares them with those properties of the serial Universal Asynchronous Receiver and Transmitter (UART) communication. Then this book demonstrates an example of designing a CAN bus communication system using a modern FPGA and MCU. Finally, this book implements testing experiments and verifies the measurement results before coming to a conclusion.

Yu Zhu Berlin, August 2010

Contents 1

2

Introduction ......................................................................................................................... 5 1.1

Background ............................................................................................................ 5

1.2

Objective................................................................................................................ 5

1.3

Outline ................................................................................................................... 7

CAN Introduction ................................................................................................................ 8 2.1

Background ............................................................................................................ 8

2.2

Architecture Layers ............................................................................................... 9

2.3

3

2.2.1

Physical Layer ............................................................................................... 9

2.2.2

Data Link Layer .......................................................................................... 11

2.2.3

Higher Layer ............................................................................................... 11

Frame Structure ................................................................................................... 12 2.3.1

Data Frame .................................................................................................. 12

2.3.2

Remote Frame ............................................................................................. 15

2.3.3

Error Frame ................................................................................................. 16

2.3.4

Overload Frame ........................................................................................... 17

2.3.5

Interframe Space ......................................................................................... 17

2.4

Frame Coding ...................................................................................................... 18

2.5

Error Detecting and Handling ............................................................................. 19

2.6

Fault Confinement ............................................................................................... 20

CAN and MCU Serial Port Effective Data Study ............................................................. 23 3.1

CAN Effective Data Study .................................................................................. 23

3.2

MCU Serial Port Study ........................................................................................ 26 3.2.1

General 8051 MCU ..................................................................................... 26

3.2.2

Using Timer 2 .............................................................................................. 28

3.2.3

X2 Mode...................................................................................................... 29

1

3.3 4

5

CAN vs. MCU Serial Port................................................................................... 30

Experiment Components and Setup .................................................................................. 33 4.1

Stratix III FPGA Development Kit ..................................................................... 33

4.2

CAN MCU AT89C51CC03 ................................................................................ 36

4.3

5-3.3 V Voltage Level Transistor ........................................................................ 39

4.4

NI CAN USB-8473 ............................................................................................. 41

4.5

PC with NI CAN Driver...................................................................................... 43

4.6

Setup.................................................................................................................... 43

Software Development ...................................................................................................... 44 5.1

FPGA with Quartus II ......................................................................................... 44 5.1.1

DDS Design ................................................................................................ 44

5.1.2

PLL Application .......................................................................................... 46

5.1.3

UART Reception......................................................................................... 50

5.1.4

UART Transmission ................................................................................... 52

5.2

MCU with Keil C51 ............................................................................................ 54 5.2.1

Serial Port Programming ............................................................................ 54

5.2.2

CAN Programming ..................................................................................... 55

5.2.3

Interrupt Management ................................................................................ 61

5.2.4

In-System Programming with FLIP............................................................ 62

5.3 6

7

NI CAN BUS with LabVIEW ............................................................................ 64

Experiments and Results ................................................................................................... 70 6.1

Problem Diagnosis .............................................................................................. 70

6.2

Final Results ........................................................................................................ 73

Conclusion ........................................................................................................................ 76

References ................................................................................................................................ 77 Appendix A:

Microcontroller Source Code ......................................................................... 78

Appendix B:

Figures ............................................................................................................ 81

2

Appendix C:

Tables .............................................................................................................. 83

Appendix D:

Symbols .......................................................................................................... 84

Appendix E:

Abbreviations and Acronyms .......................................................................... 85

3

1 Introduction 1.1

Background

Since the 1980s the application of Controller Area Network (CAN) in the automobile has solved many problems caused by the huge number of wires between different devices. Since its birth automotive electronic engineers have been using Microcontrollers (MCU) to control the CAN bus. As the development of electronic devices progresses, the need for high speed, high safety and low cost has grown rapidly and the limitations of MCUs are made apparent. At this time, the development of Field-programmable Gate Array (FPGA) continues to become more advanced. Compared to the properties of the MCU, the FPGA not only can provide higher standards in the areas of performance, safety, flexibility and reliability but also requires shorter development time and lower cost. Therefore, the FPGA is expected to play a significant role in the future of the automobile industry.

1.2

Objective

This book introduces a new method which uses an FPGA and a MCU jointly instead of a single MCU to design a CAN bus based measurement system. Furthermore the designed system works at the fastest possible speed. Initially, the FPGA (Altera Stratix III) was programmed to simulate four Direct Digital Synthesizers (DDS) for four wave channels. Each DDS contained a 26-bit phase accumulator, of which the highest 12 bits were used for a wave lookup table. The four different waves (sine, cosine, right triangle and rectangle) were output through their corresponding channels by way of serial bit stream to a CAN bus. Owing to the fact that the FPGA itself does not provide any communication interface and the CAN protocol is protected by patents of Robert Bosch GmbH, it is not permitted to program the FPGA with CAN without a license. Therefore, it is

5