This model shows CAN I/O communication using the First-In, First-Out (FIFO) mode of the Softing CAN-AC2-PCI board.
Important: This legacy example uses standard data types for message storage. Use CAN_MESSAGE data types instead.
A summary of the functional behavior of the model is summarized below:
Send a message with extended identifier 5100 to CAN port 1 updating the data every millisecond.
Send a message with standard identifier 112 to CAN port 1 updating the data every even millisecond.
Send a message with standard identifier 114 to CAN port 1 updating the data every odd millisecond.
Read three events every millisecond from the receive FIFO on CAN port 2.
Display the incoming (received) data of the three messages separately.
Do not use acceptance filtering (all messages are accepted).
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 xpccanpcififo1demo 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.
The matrix signal entering the FIFO Write block consists of three messages each including a control element (sixth component); therefore, the message matrix size is [3,6]. The sample time of the FIFO Write block is set to 1 millisecond. For the standard identifiers that must be sent out every other millisecond, the control element is alternates between 0 and 1 accordingly. You can generate the control elements with a Unit Delay and logical NOT using the corresponding feedback as the control element values.
Figure 2: The Encode Messages Subsystem
Message extraction (decoding) is contained in the Decode Messages subsystem illustrated in Figure 3.
The FIFO Read block has a sample time of 1 millisecond and a read depth of 3. Three FIFO Read Filter blocks are connected (in parallel) to the output of the FIFO Read block to extract/decode the messages from the incoming CAN events.
Figure 3: The Decode Messages Subsystem
set_param(mdl,'RTWVerbose','off'); rtwbuild(mdl); +tg; pause(3); -tg;
### Starting xPC Target build procedure for model: xpccanpcififo1 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: xpccanpcififo1 ### 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:
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 status vector leaving the FIFO Read block [lost-message-counter, bus state].
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 xpccanpcififo1_script.m