MikroElektronika PIC Microcontrollers PIC18 Manuel d'utilisateur

Naviguer en ligne ou télécharger Manuel d'utilisateur pour PC/postes de travail MikroElektronika PIC Microcontrollers PIC18. Advanced PIC18 Projects—CAN Bus Projects Manuel d'utilisatio

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 40
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 0
CHAPTER 9
Advanced PIC18 Projects—CAN
Bus Projects
The Controller Area Network (CAN) is a serial bus communications protocol developed
by Bosch (an electrical equipment manufacturer in Germany) in the early 1980s.
Thereafter, CAN was standardized as ISO-11898 and ISO-11519, establishing itself as
the standard protocol for in-vehicle networking in the auto industry. In the early days of
the automotive industry, localized stand-alone controllers had been used to manage
various actuators and electromechanical subsystems. By networking the electronics in
vehicles with CAN, however, they could be controlled from a central point, the engine
control unit (ECU), thus increasing functionality, adding modularity, and making
diagnostic processes more efficient.
Early CAN development was mainly supported by the vehicle industry, as it was used in
passenger cars, boats, trucks, and other types of vehicles. Today the CAN protocol is
used in many other fields in applications that call for networked embedded control,
including industrial automation, medical applications, building automation, weaving
machines, and production machinery. CAN offers an efficient communication protocol
between sensors, actuators, controllers, and other nodes in real-time applications, and is
known for its simplicity, reliability, and high performance.
The CAN protocol is based on a bus topology, and only two wires are needed for
communication over a CAN bus. The bus has a multimaster structure where each device
on the bus can send or receive data. Only one device can send data at any time while
all the others listen. If two or more devices attempt to send data at the same time,
the one with the highest priority is allowed to send its data while the others return to
receive mode.
www.newnespress.com
Vue de la page 0
1 2 3 4 5 6 ... 39 40

Résumé du contenu

Page 1 - Bus Projects

CHAPTER 9Advanced PIC18 Projects—CANBus ProjectsThe Controller Area Network (CAN) is a serial bus communications protocol developedby Bosch (an electr

Page 2

9.1.3 Control FieldThe control field is 6 bits wide, consisting of 2 reserved bits and 4 data length code(DLC) bits, and indicates the number of data

Page 3 - CAN BUS

9.1.6 ACK FieldThe ACK field indicates that the frame has been received normally. This fieldconsists of 2 bits, one for ACK slot and one for ACK delim

Page 4

9.5 Bit StuffingThe CAN bus makes use of bit stuffing, a technique to periodically synchronizetransmit-receive operations to prevent timing errors bet

Page 5

device can have its own different clock frequency. One message bit consists of fournonoverlapping time segments:Synchronization segment (Sync_Seg)Pr

Page 6

and the nominal bit rate (NMR) isNBR ¼ 1=TBITð9:2ÞThe time quantum is derived from the oscillator frequency and the programmablebaud rate prescaler, w

Page 7 - 9.1 Data Frame

In order to compensate for phase shifts between the oscillator frequencies of nodeson a bus, each CAN controller must synchronize to the relevant sign

Page 8 - 9.1.2 Arbitration Field

built-in CAN module. The microcontroller is connected to the CAN bus using anexternal MCP2515 CAN controller chip and an MCP2551 CAN bus transceiver c

Page 9 - 1234567891011

9.9 PIC18F258 MicrocontrollerLater in this chapter the PIC18F258 microcontroller is used in a CAN bus–basedproject. This section describes this microc

Page 10 - 9.1.5 CRC Field

The features of the PIC18F258 microcontroller’s CAN module are as follows:Compatible with CAN 1.2, CAN 2.0A, and CAN 2.0BSupports standard and exten

Page 11 - 9.4 Overload Frame

The CAN module in the PIC18F258 microcontroller has six modes of operation:Configuration modeDisable modeNormal operation modeListen-only modeLoo

Page 12 - 9.5 Bit Stuffing

As shown in Figure 9.1, in a typical vehicle application there is usually more than oneCAN bus, and they operate at different speeds. Slower devices,

Page 13

communicating with each other. The baud rate can be determined by testingdifferent values until valid messages are received. The listen-only mode cann

Page 14

The CAN module uses message acceptance filters and masks to determine if amessage in the MAB should be loaded into a receive buffer. Once a valid mess

Page 15

the masks and filters to determine if the message should be accepted. If a maskbit is set to 0, that bit in the identifier is automatically accepted r

Page 16

The Sync_Segment is 1TQ. Choosing 2TQfor the Prop_Seg, and 7TQfor Phase_Seg1leaves 6TQfor Phase_Seg2 and places the sampling point at 10TQat the end o

Page 17 - 9.9 PIC18F258 Microcontroller

Baud rate prescaler (BRP) ¼ 4Sync_Seg ¼ 1Prop_Seg ¼ 5Phase_Seg1 ¼ 5Phase_Seg2 ¼ 5SJW ¼ 1Sample point ¼ 68%Error ¼ 0%9.10 mikroC CAN FunctionsThe mikro

Page 18

bus for PIC microcontrollers having no built-in CAN modules. In this section wewill discuss only the library functions available for PIC microcontroll

Page 19 - 9.9.4 Listen-only Mode

CAN_MODE_LISTEN Listen-only mode of operationCAN_MODE_CONFIG Configuration mode of operation9.10.2 CANGetOperationModeThe CANGetOperationMode functi

Page 20 - 9.9.8 CAN Message Reception

CAN_CONFIG_SAMPLE_ONCE Sample bus once at sample pointCAN_CONFIG_SAMPLE_THRICE Sample bus three times prior tosample pointCAN_CONFIG_STD_MSG Accept

Page 21

void CANSetMask(char CAN_MASK, long value, charCAN_CONFIGFLAGS)CAN_MASK can be one of the following:CAN_MASK_B1 Receive buffer 1 mask valueCAN_MASK_

Page 22

id is the CAN message identifier. Only 11 or 29 bits may be used depending onmessage type (standard or extended). data is an array of bytes up to 8 wh

Page 23

a random amount of time before trying to send again. CAN protocol, however, solvesthe collision problem using the principle of arbitration, where only

Page 24 - 9.10 mikroC CAN Functions

CAN_TX_PRIORITY_2 Transmit priority 2CAN_TX_PRIORITY_3 Transmit priority 3CAN_TX_STD_FRAME Standard identifier messageCAN_TX_XTD_FRAME Extended id

Page 25 - 9.10.1 CANSetOperationMode

The project’s circuit diagram is given in Figure 9.16. Two CAN nodes areconnected together using a two-meter twisted pair cable, terminated with a 120

Page 26 - 9.10.3 CANInitialize

The DISPLAY ProcessorLike the COLLECTOR processor, the DISPLAY processor consists of a PIC18F258microcontroller with a built-in CAN module and an MCP2

Page 27 - 9.10.5 CANSetMask

The COLLECTOR processor reads the temperature, formats it, and sends to theDISPLAY processor over the CAN busThe DISPLAY processor reads the tempera

Page 28 - 9.10.7 CANRead

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ CAN BUS EXAMPLE - NODE: DISPLAY ======

Page 29 - 9.10.8 CANWrite

TRISC = 0; // PORTC are outputs (LCD) TRISB = 0x08; // RB2 is output, RB3 is input//// CAN

Page 30 - Bus Project

Filter 3 for buffer 2 is set to value 3 so that identifiers having values 3 are accepted bythe receive buffer.The operation mode is then set to NORMAL

Page 31 - Temperature

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ CAN BUS EXAMPLE - NODE: COLLECTOR

Page 32 - The COLLECTOR Processor

//// CAN BUS Timing Parameters// SJW = 1; BRP = 1; Phase_Seg1 = 6; Phase_Seg2 = 7; BRP = 1; Prop_Seg = 6; init_flag = CAN_

Page 33 - DISPLAY Program

// Program loop. Read the temperature from analog temperature// sensor// for(;;) // Endless

Page 34 - 508 Chapter 9

removed from the bus, no configuration data needs to be changed (i.e., the bus is“hot pluggable”).CAN bus offers remote transmit request (RTR), which

Page 35 - Figure 9.17: (Cont’d)

node filter is set to accept identifier 500). This is a request to the COLLECTORnode to send the temperature reading. The program then reads the tempe

Page 36

dominant bit state always wins out over a recessive bit state. In the recessive state, thedifferential voltage CANH and CANL is less than the minimum

Page 37 - (Continued)

circuit and a capacitor are used at either end of the bus. This method increases the EMCperformance of the bus (Figure 9.5(c)).Many network protocols

Page 38 - 512 Chapter 9

There are basically four message frames in CAN: data, remote, error, and overload. Thedata and remote frames need to be set by the user. The other two

Page 39

CRC field, which checks whether or not the received bit sequence is corrupted.The ACK field is 2 bits and is used by the transmitter to receive acknow

Page 40 - COLLECTOR Program

The process of arbitration is illustrated in Figure 9.9 by an example consisting of threenodes having identifiers:Node 1: 11100110011 Node 2: 11100111

Commentaires sur ces manuels

Pas de commentaire