This model shows CAN I/O communication using the First-In, First-Out (FIFO) mode of the Softing CAN-AC2-PCI board and discusses the condition and detection of the "No new event" message.
Important: This legacy example uses standard data types for message storage. Use CAN_MESSAGE data types instead.
Looking at the send/receive behavior of the model, you can observe that at each time step (1 millisecond) the FIFO Write block sends out two events (messages) over the CAN bus through the CAN Port 1 transmit FIFO. However, the FIFO Read block reads three events from the CAN Port 2 receive FIFO. This implies that one of the three events leaving the FIFO Read block is of type "No new event" or NE. You can show this by attaching an additional FIFO Read Filter block that filters on the NE message type.
Having made this observation, you could reduce the read depth of the FIFO Read block from 3 to 2. This does not change the overall behavior of the model. As a positive side effect, the latency of the FIFO Read block becomes smaller and therefore the model's cycle time reduces as well.
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 xpccanpcififo2demo 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 with 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. Only two messages are transmitted for every write because the control elements for the two standard messages are toggled alternately between 0 and 1.
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. Four FIFO Read Filter blocks are connected (in parallel) to the output of the FIFO Read block to extract the data from the incoming CAN messages including the NE messages.
Figure 3: The Decode Messages Subsystem
set_param(mdl,'RTWVerbose','off'); rtwbuild(mdl); +tg; pause(3); -tg;
### Starting xPC Target build procedure for model: xpccanpcififo2 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: xpccanpcififo2 ### 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 NE messages (Read Filter-NoNewEvent) in Scope 3. For each read, there should be 1 NE message.
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 and 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 xpccanpcififo2_script.m