15.12 Timestamping
The CAN FD Protocol Module contains a Time Base Counter (TBC). The TBC is a 32-bit free-running counter that increments on multiples of Fcy and rolls over to zero when:
- TBCPRE[9:0] bits (CxTSCON[9:0]) are used to configure the prescaler for the TBC.
- Setting TBCEN (CxTSCON[16]) enables the TBC.
- Clearing TBCEN disables, stops and resets the TBC.
- The TBC has to be disabled before writing to CxTBC by clearing TBCEN.
- TEFTSEN (CxTEFCON[5]) has to be set to time-stamp messages in the TEF.
- RXTSEN (CxFIFOCONx[5]) has to be set to time-stamp messages in the individual RX FIFO.
- The application can read CxTBC at any time. Similar to any multibyte counter, the application has to consider that the counter increments and might roll over while reading different bytes of the counter.
All timestamps are 32 bits, allowing timestamps to be used for system time synchronization with high resolution.
A rollover of the TBC will generate an interrupt if TBCIE is set.
Messages can be time-stamped either at the beginning of a frame or at the
end, depending on the TSEOF bit (CxTSCON[17]). When TSEOF = 0
, TSRES (CxTSCON[18]) specifies if FD frames are time-stamped at SOF or the
reserved bit. Table 15-14 specifies the reference points
when the timestamping occurs. At the reference point, the value of the TBC (CxTBC) is
captured and stored into the message object:
- Receive Message Object: The TBC value is stored in the RXMSGTSx bits (see Receive Message Object).
- TEF Object: The TBC value is stored in the TXMSGTSx bits (see Reading a TEF Object).
Frame | CAN 2.0 | CAN FD |
---|---|---|
Start of TX | Sample point of SOF | Sample point of SOF or the bit after FDF |
Start of RX | Sample point of SOF | Sample point of SOF or the bit after FDF |
Valid TX | No error till end of EOF | No error till end of EOF |
Valid RX | No error till the last, but one bit of EOF | No error till the last, but one bit of EOF |