38.10 Timestamping
The CAN Protocol module contains a Time Base Counter (TBC). The TBC is a 32-bit
free-running counter that increments on multiples of SYSCLK 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 C1TBC by clearing TBCEN.
- TEFTSEN (CxTEFCON[5]) has to be set to timestamp messages in the TEF.
- RXTSEN (CxFIFOCONy[5]) has to be set to timestamp messages in the individual RX FIFO.
- The application can read C1TBC 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 timestamped either at the beginning of a frame or at the end, depending
on the TSEOF bit (C1TSCON[17]). Table 38-10
specifies the reference points when the timestamping occurs. At the reference point, the
value of the TBC (C1TBC) is captured and stored into the message object:
- Receive Message Object: The TBC value is stored in the RXMSGTSx bits (see Table 38-8).
- TEF Object: The TBC value is stored in the TXMSGTSx bits (see Table 38-6).
Frame | Reference Point |
---|---|
Start of TX | Sample point of SOF |
Start of RX | Sample point of SOF |
Valid TX | No error till end of EOF |
Valid RX | No error till the last, but one bit of EOF |