This model shows CAN I/O communication using the First-In, First-Out (FIFO) mode of the Softing CAN-AC2-PCI board and shows how to use acceptance filters. The objective is to filter any CAN messages with an identifier larger than 127. To accomplish this, the acceptance filter parameter of CAN port 2 in the FIFO Setup block must be set as follows:
[2047-127, 0, 0, 0]
Important: This legacy example uses standard data types for message storage. Use CAN_MESSAGE data types instead.
For this example, the CAN network consists of a single physical connection between CAN port 1 and CAN port 2 (loop-back configuration). To test this model:
Install the CAN-AC2-PCI board in the target computer.
Use a serial 9-pin/9-pin cable (directly wired) to connect CAN port 1 and CAN port 2.
Set the switches on the board's backplane to terminate both ports.
Boot the target computer as an xPC Target™ machine.
At the MATLAB command prompt, type xpccanpcififo6demo to download and run the model on the target computer.
Figure 1: CAN IO Model Using FIFO Write and FIFO Read
Message generation (encoding) is contained in the Encode Messages subsystem illustrated in Figure 2.
As described in FIFO mode example 3, the matrix entering the FIFO Write block has size [2,5]. Namely, 2 of 3 messages are being sent to the CAN bus every 1 millisecond. In this example however, one of the message identifiers was changed from 114 to 188 (value larger than 127) so the second standard message out of the FIFO Write block toggles between 112 and 188.
Figure 2: The Encode Messages Subsystem
Message extraction (decoding) is contained in the Decode Messages subsystem illustrated in Figure 3.
Notice that one of the FIFO Read Filter blocks is setup to detect messages with identifier 188. However, since acceptance filtering was enabled and all messages containing identifiers greater than 127 are filtered, message 188 will never enter the receive FIFO.
Figure 3: The Decode Messages Subsystem
set_param(mdl,'RTWVerbose','off'); rtwbuild(mdl); +tg; pause(3); -tg;
### Starting xPC Target build procedure for model: xpccanpcififo6 Warning: This model contains blocks that do not handle sample time changes at runtime. To avoid incorrect results, only change the sample time in the original model, then rebuild the model. ### Successful completion of build procedure for model: xpccanpcififo6 ### Looking for target: TargetPC2 ### Download model onto target: TargetPC2
The model uses several xPC Target™ scope blocks (see Figure 4) to output different types of data on the target computer display. In this example, notice the report of message 3 (identifier 188) in Scope 6. Since the acceptance filter removes this message before it enters the receive FIFO, message 3 is always empty. Messages with identifier 188 are sent over the CAN bus every other simulation update so in Scope 3 Read Filter-NoNewEvent and Read Level-MsgsInFIFO will toggle between the following:
NoNewEvent = 1, MsgsInFIFO = 1 (when message 188 is sent)
NoNewEvent = 0, MsgsInFIFO = 2 (when message 112 is sent)
Scopes for this example are as follows:
Scope 1 (graphical) plots the data of all received CAN messages.
Scope 2 (numerical) displays the FIFO Write block status vector [transmit message write status].
Scope 3 (numerical) displays the number of NE messages, the FIFO Read block status vector [lost-message-counter, bus state], and the number of messages in the receive FIFO.
Scopes 4-6 (numerical) display the FIFO Read block info for each received CAN message [port, identifier, event type, data length, timestamp].
Figure 4: Target Scopes
close_system(mdl,0); % EOF xpccanpcififo6_script.m