BAT32G1x9 user manual | Chapter 22 CAN control
948 / 1149
Rev.1.02
22.14
Timestamp function
CAN is an asynchronous serial protocol. All nodes connected to the CAN bus have local autonomous
clocks. Therefore, the clocks of the nodes have no relationship (that is, the clocks are asynchronous and
may have different frequencies).
However, in some applications, a public timebase needs to be established over the network (= global
timebase). In order to establish a global time base, the timestamp function is required. The basic mechanism
of the timestamp function is to capture the timer value triggered by the signal on the CAN bus.
22.14.1
Timestamp function
The CAN controller supports capturing timer values triggered by specific frames. In addition to the CAN
controller, an on-chip 16-bit capture timer unit in a microcontroller system is used. The 16-bit capture timer
unit captures the timer value based on the trigger signal (TSOUT) and is used to capture the timer value
output when receiving a data frame from the CAN controller. The CPU can retrieve the time of occurrence
of the capture event by reading the captured value, that is, the timestamp of the message received from the
CAN bus. The TSOUT signal can be selected from the following two event sources and specified by the
TSSEL bit of the CnTS register.
- SOF event
(frame start) (TSSEL=0).
- EOF event
(last bit of the end frame) (TSSEL=1).
TSOUT signal enable requires setting the TSEN bit of the CnTS register to 1.
Figure 22-59. Timing diagram of the capture signal TSOUT
PURE
PURE
PURE
TSOUT
t
The TSOUT signal switches its level when a selected event occurs during data frame reception (in the
sequence diagram above, the SOF is used as the trigger event source). To use the TSOUT signal capture
timer value, the runtime must detect the capture signal on the rising and falling edges.
This timestamp function is controlled by the TSLOCK bit of the CnTS register. When TSLOCK is
cleared to 0, the TSOUT bit switches when the selected event occurs. If the TSLOCK bit is set to 1, TSOUT
will switch when the selected event occurs, but the switch will stop because the TSEN bit is automatically
cleared to 0 when the message is stored in the message buffer 0. This will suppress subsequent switching
of TSOUT in order to save the timestamp value of the last switch (= last capture) as the timestamp value of
the received data frame in the packet buffer 0.