Time sync in CAN

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Time sync in CAN

Shreyas Ravishankar

Hello,

I am trying to implement time sync in CAN. Can anyone help me with the implementation?

Reply | Threaded
Open this post in threaded view
|

Re: Time sync in CAN

heikki saha
Hello,

Please refine, what do you mean with "time sync"?

Best regards,

-H

Heikki Saha, CTO
  M.Sc. Automation
  Dr.Tech. Electronics
TK Engineering Oy
Mail address:  P.O. box 810, FIN-65101 VAASA
Visit address: Yrittäjänkatu 17, FIN-65380 VAASA
+358 (0)50 588 6894
[hidden email]
http://www.tke.fi/
http://www.canopen.fi/

----- Original Message -----
From: "Shreyas Ravishankar" <[hidden email]>
To: [hidden email]
Sent: Thursday, October 22, 2015 3:07:02 PM
Subject: [CANLIST] Time sync in CAN



Hello,

I am trying to implement time sync in CAN. Can anyone help me with the implementation?
--
Archives and useful links: http://groups.yahoo.com/group/CANbus
Subscribe and unsubscribe at www.vector.com/canlist/
Report any problems to <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Time sync in CAN

Shreyas Ravishankar

I am trying to implement a quality of service policy such that old data is not forwarded to the application that is to set a life span. All the ECU's in the network which are providers or consumers are connected via CAN and all have to be synchronized to some master clock because there is a Publish/Subscribe pattern in the communication protocol. So all data sent and received should have timestamps and then after the time sync mechanism, I can compare current time with the timestamps and drop data when specified lifespan expires. Hope you understood. I saw a mechanism which sends SYNC and FollowUp messgaes to provide time sync but I need an implementation. Kindly let me know.

On Oct 22, 2015 14:41, "heikki saha" <[hidden email]> wrote:
Hello,

Please refine, what do you mean with "time sync"?

Best regards,

-H

Heikki Saha, CTO
  M.Sc. Automation
  Dr.Tech. Electronics
TK Engineering Oy
Mail address:  P.O. box 810, FIN-65101 VAASA
Visit address: Yrittäjänkatu 17, FIN-65380 VAASA
<a href="tel:%2B358%20%280%2950%20588%206894" value="+358505886894">+358 (0)50 588 6894
[hidden email]
http://www.tke.fi/
http://www.canopen.fi/

----- Original Message -----
From: "Shreyas Ravishankar" <[hidden email]>
To: [hidden email]
Sent: Thursday, October 22, 2015 3:07:02 PM
Subject: [CANLIST] Time sync in CAN



Hello,

I am trying to implement time sync in CAN. Can anyone help me with the implementation?
--
Archives and useful links: http://groups.yahoo.com/group/CANbus
Subscribe and unsubscribe at www.vector.com/canlist/
Report any problems to <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Time sync in CAN

Stephen Glow
Hi Shreyas;

Depending on how accurate the time synchronization needs to be, I can think of two possible implementations:

- The simplest would be for the time master to send out a CAN message periodically containing it's current time.  All receiving devices use this data to update their clocks.  There will be some error here, because the master can't know exactly when it's message will be sent out when it loads it's time into the message, so the time the slaves receive will always be off by a small and variable amount.  This is probably good enough if you only need millisecond accuracy.

- A slightly more complex method would give higher accuracy.  Periodically the master sends out some sort of sync message.  This doesn't need to contain any data, just an ID that devices can identify.  All receiving devices take a local time stamp of when they received the sync message, and the master keeps a time stamp of when it's sync message actually made it onto the bus.  After the sync, the master broadcasts it's time when the sync message actually got onto the bus.  This corresponds to the time the slaves received it, so they can adjust their clocks accordingly.

If you can capture the time a message is sent/received in hardware, then this should be very accurate.  If you have to capture it in software (i.e. in an ISR), then the accuracy will depending on interrupt latency/jitter.  Still should be pretty accurate for most systems.

The latter method is used by the CANopen protocol and works quite well in my experience.

Rgds,
Steve

On 10/22/2015 08:54 AM, Shreyas Ravishankar wrote:

I am trying to implement a quality of service policy such that old data is not forwarded to the application that is to set a life span. All the ECU's in the network which are providers or consumers are connected via CAN and all have to be synchronized to some master clock because there is a Publish/Subscribe pattern in the communication protocol. So all data sent and received should have timestamps and then after the time sync mechanism, I can compare current time with the timestamps and drop data when specified lifespan expires. Hope you understood. I saw a mechanism which sends SYNC and FollowUp messgaes to provide time sync but I need an implementation. Kindly let me know.

On Oct 22, 2015 14:41, "heikki saha" <[hidden email]> wrote:
Hello,

Please refine, what do you mean with "time sync"?

Best regards,

-H

Heikki Saha, CTO
  M.Sc. Automation
  Dr.Tech. Electronics
TK Engineering Oy
Mail address:  P.O. box 810, FIN-65101 VAASA
Visit address: Yrittäjänkatu 17, FIN-65380 VAASA
<a moz-do-not-send="true" href="tel:%2B358%20%280%2950%20588%206894" value="+358505886894">+358 (0)50 588 6894
[hidden email]
http://www.tke.fi/
http://www.canopen.fi/

----- Original Message -----
From: "Shreyas Ravishankar" <[hidden email]>
To: [hidden email]
Sent: Thursday, October 22, 2015 3:07:02 PM
Subject: [CANLIST] Time sync in CAN



Hello,

I am trying to implement time sync in CAN. Can anyone help me with the implementation?
--
Archives and useful links: http://groups.yahoo.com/group/CANbus
Subscribe and unsubscribe at www.vector.com/canlist/
Report any problems to <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Time sync in CAN

Shreyas Ravishankar

Hello,
Thanks for the quick reply. If I use the first method, can you tell me how I can set timestamps for sent and received CAN mesaages. I am using Socketcan now. Kindly let me know.

On Oct 22, 2015 3:12 PM, "Stephen Glow" <[hidden email]> wrote:
Hi Shreyas;

Depending on how accurate the time synchronization needs to be, I can think of two possible implementations:

- The simplest would be for the time master to send out a CAN message periodically containing it's current time.  All receiving devices use this data to update their clocks.  There will be some error here, because the master can't know exactly when it's message will be sent out when it loads it's time into the message, so the time the slaves receive will always be off by a small and variable amount.  This is probably good enough if you only need millisecond accuracy.

- A slightly more complex method would give higher accuracy.  Periodically the master sends out some sort of sync message.  This doesn't need to contain any data, just an ID that devices can identify.  All receiving devices take a local time stamp of when they received the sync message, and the master keeps a time stamp of when it's sync message actually made it onto the bus.  After the sync, the master broadcasts it's time when the sync message actually got onto the bus.  This corresponds to the time the slaves received it, so they can adjust their clocks accordingly.

If you can capture the time a message is sent/received in hardware, then this should be very accurate.  If you have to capture it in software (i.e. in an ISR), then the accuracy will depending on interrupt latency/jitter.  Still should be pretty accurate for most systems.

The latter method is used by the CANopen protocol and works quite well in my experience.

Rgds,
Steve

On 10/22/2015 08:54 AM, Shreyas Ravishankar wrote:

I am trying to implement a quality of service policy such that old data is not forwarded to the application that is to set a life span. All the ECU's in the network which are providers or consumers are connected via CAN and all have to be synchronized to some master clock because there is a Publish/Subscribe pattern in the communication protocol. So all data sent and received should have timestamps and then after the time sync mechanism, I can compare current time with the timestamps and drop data when specified lifespan expires. Hope you understood. I saw a mechanism which sends SYNC and FollowUp messgaes to provide time sync but I need an implementation. Kindly let me know.

On Oct 22, 2015 14:41, "heikki saha" <[hidden email]> wrote:
Hello,

Please refine, what do you mean with "time sync"?

Best regards,

-H

Heikki Saha, CTO
  M.Sc. Automation
  Dr.Tech. Electronics
TK Engineering Oy
Mail address:  P.O. box 810, FIN-65101 VAASA
Visit address: Yrittäjänkatu 17, FIN-65380 VAASA
<a href="tel:%2B358%20%280%2950%20588%206894" value="+358505886894" target="_blank">+358 (0)50 588 6894
[hidden email]
http://www.tke.fi/
http://www.canopen.fi/

----- Original Message -----
From: "Shreyas Ravishankar" <[hidden email]>
To: [hidden email]
Sent: Thursday, October 22, 2015 3:07:02 PM
Subject: [CANLIST] Time sync in CAN



Hello,

I am trying to implement time sync in CAN. Can anyone help me with the implementation?
--
Archives and useful links: http://groups.yahoo.com/group/CANbus
Subscribe and unsubscribe at www.vector.com/canlist/
Report any problems to <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

RE: Time sync in CAN

Bram Kerkhof

With all due respect, that topic is covered in the most basic how-tos and documents for SocketCan and should be easily researchable.

You seem to be either a student learning about CAN with an assignment, or someone who has been assigned a task that is over their level of experience.

 

In both cases, you would be far better off to research this topic on yourself in more detail instead of hoping that other people will feed you bite-sized pieces of information starting at the very base.

I certainly welcome more people getting into CAN networking, as long as they are willing to invest a good amount of time in learning about it just as most of the list members here did. In the case that you don’t have the time to invest, there are quite a few experienced consultants on this list that are willing to do it for you (at a price).

 

Google “linux sockets timestamp” to get started.

 

Best of luck with your project,

Bram

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Shreyas Ravishankar
Sent: donderdag 22 oktober 2015 15:42
To: [hidden email]
Subject: Re: [CANLIST] Time sync in CAN

 

Hello,
Thanks for the quick reply. If I use the first method, can you tell me how I can set timestamps for sent and received CAN mesaages. I am using Socketcan now. Kindly let me know.