CHAPTER 9Advanced PIC18 Projects—CANBus ProjectsThe Controller Area Network (CAN) is a serial bus communications protocol developedby Bosch (an electr
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
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
9.5 Bit StuffingThe CAN bus makes use of bit stuffing, a technique to periodically synchronizetransmit-receive operations to prevent timing errors bet
device can have its own different clock frequency. One message bit consists of fournonoverlapping time segments:Synchronization segment (Sync_Seg)Pr
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
In order to compensate for phase shifts between the oscillator frequencies of nodeson a bus, each CAN controller must synchronize to the relevant sign
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
9.9 PIC18F258 MicrocontrollerLater in this chapter the PIC18F258 microcontroller is used in a CAN bus–basedproject. This section describes this microc
The features of the PIC18F258 microcontroller’s CAN module are as follows:Compatible with CAN 1.2, CAN 2.0A, and CAN 2.0BSupports standard and exten
The CAN module in the PIC18F258 microcontroller has six modes of operation:Configuration modeDisable modeNormal operation modeListen-only modeLoo
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,
communicating with each other. The baud rate can be determined by testingdifferent values until valid messages are received. The listen-only mode cann
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
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
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
Baud rate prescaler (BRP) ¼ 4Sync_Seg ¼ 1Prop_Seg ¼ 5Phase_Seg1 ¼ 5Phase_Seg2 ¼ 5SJW ¼ 1Sample point ¼ 68%Error ¼ 0%9.10 mikroC CAN FunctionsThe mikro
bus for PIC microcontrollers having no built-in CAN modules. In this section wewill discuss only the library functions available for PIC microcontroll
CAN_MODE_LISTEN Listen-only mode of operationCAN_MODE_CONFIG Configuration mode of operation9.10.2 CANGetOperationModeThe CANGetOperationMode functi
CAN_CONFIG_SAMPLE_ONCE Sample bus once at sample pointCAN_CONFIG_SAMPLE_THRICE Sample bus three times prior tosample pointCAN_CONFIG_STD_MSG Accept
void CANSetMask(char CAN_MASK, long value, charCAN_CONFIGFLAGS)CAN_MASK can be one of the following:CAN_MASK_B1 Receive buffer 1 mask valueCAN_MASK_
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
a random amount of time before trying to send again. CAN protocol, however, solvesthe collision problem using the principle of arbitration, where only
CAN_TX_PRIORITY_2 Transmit priority 2CAN_TX_PRIORITY_3 Transmit priority 3CAN_TX_STD_FRAME Standard identifier messageCAN_TX_XTD_FRAME Extended id
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
The DISPLAY ProcessorLike the COLLECTOR processor, the DISPLAY processor consists of a PIC18F258microcontroller with a built-in CAN module and an MCP2
The COLLECTOR processor reads the temperature, formats it, and sends to theDISPLAY processor over the CAN busThe DISPLAY processor reads the tempera
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ CAN BUS EXAMPLE - NODE: DISPLAY ======
TRISC = 0; // PORTC are outputs (LCD) TRISB = 0x08; // RB2 is output, RB3 is input//// CAN
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
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ CAN BUS EXAMPLE - NODE: COLLECTOR
//// CAN BUS Timing Parameters// SJW = 1; BRP = 1; Phase_Seg1 = 6; Phase_Seg2 = 7; BRP = 1; Prop_Seg = 6; init_flag = CAN_
// Program loop. Read the temperature from analog temperature// sensor// for(;;) // Endless
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
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
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
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
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
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
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