Documentation

Synchronize Timestamps Across Data-Gathering Network

This example shows a data acquisition target computer that transmits timestamped data to a second target computer that analyzes the data.

Required Products: Simulink®, Simulink Real-Time™

Other Requirements:

  • One Windows® development computer with an Ethernet card.

  • Two Speedgoat target computers.

  • At least one Intel® 82574 Ethernet card on each target computer

  • One Ethernet card on each target computer dedicated to communication between the development and target computers.

  • One Ethernet switch.

  • Four crossover Ethernet cables.

The real-time applications use Precision Time Protocol blocks to synchronize the Intel 82574 Ethernet card PTP clocks and the kernel clocks for each computer. You can log the PTP timestamps from both computers and use them to associate transmitted data with reference data.

Configure Hardware

Your Speedgoat target machines include at least two Ethernet cards installed, one of them an Intel 82574 Ethernet card. Use the Intel 82574 Ethernet card for the PTP network. Use the other to connect the two target computers through the Ethernet switch to the development computer. The network looks like this figure.

Required Information

To configure the network and your models for this example, collect the following information for each target computer:

  • Identifiers

  • PTP card: Device name, PCI bus and slot numbers, MAC address that you assign to the PTP card that is transmitting non-PTP data

  • COM card: Device name, PCI bus and slot numbers, Ethernet index of the card

You can find the built-in MAC address of the PTP card from a source such as a bill of materials or a label on the hardware. You can find the device name and the PCI bus and slot numbers by using SimulinkRealTime.target.getPCIInfo. You can find the Ethernet index of the communication card by using SimulinkRealTime.getTargetSettings.

Example Information

TargetPC1

Identifier — TargetPC1

PTP card

  • Device name — Intel 82574L

  • PCI bus — 5

  • PCI slot — 0

  • MAC Address — [EEPROM}

COM card

  • Device name — Intel 82579LM

  • Ethernet index — 0

  • PCI bus — 0

  • PCI slot — 25

  • MAC address — N/A

TargetPC2

Identifier — TargetPC2

PTP card

  • Device name — Intel 82574L

  • PCI bus — 0

  • PCI slot — 52

  • MAC Address — 68:05:CA:31:B9:EF

COM card

  • Device name — Intel 82541GI_LF

  • Ethernet index — 0

  • PCI bus — 16

  • PCI slot — 4

  • MAC address — N/A

Hardware Configuration

  1. Connect an Ethernet cable between the PTP card in TargetPC1 and the PTP card in TargetPC2. This connection creates the PTP network. To configure the IEEE 1588 Ethernet blocks in the two real-time applications, you must have the PCI bus and PCI slot of these cards.

  2. Connect an Ethernet cable from the Comm card in TargetPC1 to the Ethernet switch.

  3. Connect an Ethernet cable from the Comm card in TargetPC2 to the switch.

  4. Connect an Ethernet cable from the switch to the development computer. These connections complete the communication network between the development computer and the target computers.

  5. Start the two target computers. Use slrtexplr to connect to them. If you cannot establish communication with a target computer, verify the Ethernet index assigned to the communication port.

Configure Real-Time Applications

In this example, the system contains two real-time applications running on separate target computers. The data acquisition application transmits PTP and non-PTP data to the data analysis application. To configure the data acquisition application, you must have the MAC address of the PTP card that is installed in the data analysis target computer. The data analysis application transmits only PTP data to the data acquisition application. To configure the data analysis application, you can use the MAC address stored in the EEPROM of the PTP card in the data acquisition target computer.

Configure Data Acquisition Application

To configure this application, first perform the steps in Configure Hardware. Collect the PCI bus, PCI slot, and role of the Ethernet cards installed in the target computers.

The data acquisition application is ex_ptp_sync_src (matlab:open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_ptp_sync_src')))). It runs on TargetPC1. To configure the application:

Set Configuration Parameters

  1. Open ex_ptp_sync_src.

  2. In the Configuration Parameters dialog box, open the Solver pane.

  3. Verify that Type is Fixed-step.

  4. Verify that Fixed-step size (fundamental sample time) is set to an explicit value and not to auto (best practice). Use the same sample time as in the data analysis application.

  5. Verify that Allow tasks to execute concurrently on target is set.

  6. Take the defaults for the other settings.

  7. Open the Simulink Real-Time Options pane.

  8. Verify that Build for default target computer is cleared.

  9. Verify that Specify target computer name is TargetPC1.

  10. Verify that Execution mode is Real-Time.

  11. Take the defaults for the other settings.

Configure PTP Blocks

  1. Open the IEEE 1588 Ethernet block

  2. Open the General pane.

  3. From the information for the TargetPC1 PTP card, enter the values 5 and 0 for PCI bus and PCI slot.

  4. Verify that the IEEE 1588 Ethernet Sample time value is a multiple of the Fixed-step size (fundamental sample time) value.

  5. Verify that Sample time has the same value as in the data analysis model.

  6. Open the Network parameters pane.

  7. From the information for the TargetPC1 PTP card, in the Source MAC address box, select EEPROM.

  8. Verify that Destination MAC address is Standard PTP multicast.

  9. Open the Clock parameters pane.

  10. Verify that Timescale (epoch) is PTP (1970-01-01).

  11. Verify that Delay measurement mechanism is Request-response.

  12. Set the Slave only check box. This setting prevents the software from making this node the master PTP clock node.

  13. Open the Time intervals pane.

  14. Verify that Announce interval (second), Sync interval (second), and Min delay or pdelay request interval (second) are at least three times the Sample time value.

  15. Verify that the intervals are integral multiples of Sample time.

  16. Verify that the intervals have the same settings as in the data analysis model.

  17. In the remaining top-level PTP blocks, verify that the Sample time value matches that in the IEEE 1588 Ethernet block.

  18. Open PTP Clock-Data Subsystem. For each block in the subsystem, verify that the Sample time value matches that in the IEEE 1588 Ethernet block.

Configure Data Communication Blocks

  1. From the information for the TargetPC2 PTP card, in the Create Ethernet Packet block dialog box, set Destination MAC to macaddr('68:05:CA:31:B9:EF').

  2. Set EtherType (use 0 for length) to hex2dec('0010'). Using this type distinguishes the data-specific messages from the PTP-specific messages, which use the same Ethernet card.

  3. In the Ethernet Tx block, verify that the Sample time value matches that in the IEEE 1588 Ethernet block.

  4. Save the updated model in your working folder. You cannot build and run a real-time application in the examples folder.

Configure Data Analysis Application

To configure this application, first perform the steps in Configure Hardware. Collect the PCI bus, PCI slot, and role of the Ethernet cards that are installed in the target computers. To configure the PTP card in the data analysis target computer, use the MAC address that you specified in the Create Ethernet Packet block of the data acquisition application.

The data analysis application is ex_ptp_sync_sink (matlab:open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_ptp_sync_sink')))). It runs on TargetPC2. To configure the application:

Set Configuration Parameters

  1. Open ex_ptp_sync_sink.

  2. In the Configuration Parameters dialog box, open the Solver pane.

  3. Verify that Type is Fixed-step.

  4. Verify that Fixed-step size (fundamental sample time) is set to an explicit value (best practice) and not to auto. Use the same sample time as in the data acquisition application.

  5. Verify that Allow tasks to execute concurrently on target is set.

  6. Take the defaults for the other settings.

  7. Open the Simulink Real-Time Options pane.

  8. Verify that Build for default target computer is cleared.

  9. Verify that Specify target computer name is TargetPC2.

  10. Verify that Execution mode is Real-Time.

  11. Take the defaults for the other settings.

Configure PTP Blocks

  1. Open the IEEE 1588 Ethernet block.

  2. Open the General pane.

  3. From the information for the TargetPC2 PTP card, enter the values 52 and 0 for PCI bus and PCI slot.

  4. Verify that the IEEE 1588 Ethernet Sample time value is a multiple of the Fixed-step size (fundamental sample time) value.

  5. Verify that Sample time has the same value as in the data acquisition IEEE 1588 Ethernet block.

  6. Open the Network parameters pane.

  7. In the Source MAC address box, select Specify.

  8. From the information for the TargetPC2 PTP card, in the Specify source MAC address text box, enter macaddr('68:05:CA:31:B9:EF'). You can enter an arbitrary MAC address in this box, provided it is unique in the PTP network.

  9. Verify that Destination MAC address is Standard PTP multicast.

  10. Open the Clock parameters pane.

  11. Verify that Timescale (epoch) is PTP (1970-01-01).

  12. Verify that Delay measurement mechanism is Request-response.

  13. Verify that Slave only is cleared. This setting allows the software to make this node the master PTP clock node.

  14. Open the Time intervals pane.

  15. Verify that Announce interval (second), Sync interval (second), and Min delay or pdelay request interval (second) are at least three times the Sample time value.

  16. Verify that the intervals are integral multiples of Sample time.

  17. Verify that the intervals have the same settings as in the data acquisition model.

  18. In the remaining top-level PTP blocks, verify that the Sample time value matches that in the IEEE 1588 Ethernet block.

  19. Open PTP Clock-Data Subsystem. For each block in the subsystem, verify that the Sample time value matches that in the IEEE 1588 Ethernet block.

Configure Data Communication Blocks

  1. Open PTP Clock-Data Subsystem

  2. Open the Ethernet Rx block.

  3. Open the Rx pane and verify that the Sample time value matches that in the IEEE 1588 Ethernet block.

  4. Open the Filter pane.

  5. Verify that Filter criteria is Specify types to match.

  6. Verifty that Receive these types (vector of types 0-65535) is [hex2dec('0010')].

  7. Save the updated model in your working folder. You cannot build and run a real-time application in the examples folder.

Build, Download, and Run Real-Time Applications

In this example, the data acquisition application builds and is downloaded to TargetPC1. The data analysis application builds and is downloaded to TargetPC2. To run these applications, first perform the steps in Configure Real-Time Applications. MATLAB® and Simulink Real-Time Explorer must be running in your working folder.

Build, download, and run the applications:

  1. Start TargetPC1 and TargetPC2.

  2. In the Explorer Targets pane, connect to TargetPC1 and TargetPC2.

  3. In your working folder, open ex_ptp_sync_src and ex_ptp_sync_sink.

  4. Build and download ex_ptp_sync_src to TargetPC1.

  5. Build and download ex_ptp_sync_sink to TargetPC2.

  6. In the Explorer Applications pane, for TargetPC1/ex_ptp_sync_src and TargetPC2/ex_ptp_sync_sink, change the property Stop Time to Inf.

  7. In the Explorer Applications pane, start ex_ptp_sync_src and ex_ptp_sync_sink.

  8. For both applications, waveform data starts streaming in the target scopes labeled Data. However, the timestamps displayed as signal Time are not initially valid. The two applications go through the following sequence of Sync Status and State values:

1. Initialization:

  • ex_ptp_sync_src State → 4 (LISTENING)

  • ex_ptp_sync_src Sync Status → 0 (not synchronized)

  • ex_ptp_sync_sink State → 4 (LISTENING)

  • ex_ptp_sync_sink Sync Status → 0 (not synchronized)

2. Master allocation and synchronization

  • ex_ptp_sync_sink State → 6 (MASTER)

  • ex_ptp_sync_sink Sync Status → 1 (synchronized)

3. Slave allocation and synchronization

  • ex_ptp_sync_src State → 9 (SLAVE)

  • ex_ptp_sync_src Sync Status → 1 (synchronized)

For the data acquisition node (the slave node), the final state looks like this figure.

For the data analysis node (the master node), the final state looks like this figure.

For this example, the sensor and reference Sine Wave blocks are set to the same frequency and amplitude, but start at arbitrary times. The difference in start time causes a phase difference between the sine waves. The phase difference appears on the Delta scope as a waveform that settles to a constant amplitude.

The phase difference is constant because the IEEE 1588 Sync Execution blocks synchronize the kernel clocks on the two target computers. If you do not include these blocks, the kernel clocks of the two target computers drift apart. As a result, the Delta waveform shows a beat frequency.

With the IEEE 1588 Sync Execution block, you can make measurements across multiple target computers at a synchronized time step. However, the kernel interrupt clock controller can shorten some time steps up to 10% of the fundamental sample time, resulting in a CPU overload.

See Also

| | | | | | |

Related Topics

Was this topic helpful?