# time synchronization across different nodes in a mesh network, single hop as well as multi hop.

I am working on time synchronizations between different nodes in a mesh network. I have earlier worked on the radio and the ppi examples given. I wish to generate time stamps at each send and receive events between two different nodes for which i am using the nRF radio along with two crystal oscillators, 16 M XOSC as well as 32.768 KHz XOSC with quartz crystal. Could you let me know that if i am using the ppi with the radio functionality, how do i define the two nodes in my code between which i want to send packets. then can i extend this case for n nodes too.

edit retag close delete

Hi Khosla,

How do you plan to connect your mesh network ? How would the re-transmission between nodes in the network work ?

It you only plan to synchronize between 2 device (or multiple devices but not mesh) you can have a look here.

( 2017-05-16 10:56:59 +0200 )editconvert to answer

Thanks for this. Seems good enough as a guide!!!

I am using the ppi code with radio in segger as seen below. Considering both the the transmit as well as receive cases in the same code. I have to collect the timestamps for each of the send as well as receive events for each of the two crystal oscillators, 16 MHz as well as 32.768 KHz XOSC as i mentioned earlier. Just let me know ur comments on how appropriate the code is. Basically, my task is to synchronize between two neighboring nodes (single hop) as well as then extend this to synchronize between 7-8 nodes.

Lemme know if something can be added in the code. One more thing is that i would be using only hardware clocks as you defined too, the timer and RTC.

Here is the code:

• The ...
(more)
( 2017-05-16 12:36:32 +0200 )editconvert to answer

Sort by » oldest newest most voted

You still haven't described clearly enough what you are planing to do and what the difficulties you have. Please try to follow the tutorial and get back if you have issues.

more

main.c

This is the code i would be using for my work. I looked at the link you gave me. But it would be good if u could see mine and lemme know whether its appropriate enough. As far as the main problem is concerned, my task is synchronizing all events in a mesh network. I need to timestamp the events using hardware timers. Then once i have the time values, i can verify them by sniffing packets on air and seeing results on the Logic Analyzer. Then getting the data out from the board to the pc. Using certain algorithms to estimate the drift and the offset variations with regard to the time events recorded. Hope this will clarify your queries.

( 2017-05-17 12:14:10 +0200 )editconvert to answer

In your code I can't see how the mesh work. You simply send broadcast data. What about the receiver? How does the mesh work ?? Is there any retransmission , rebroadcast ?? I don't see in your code where you put the timestamp into the broadcast data, or maybe I misread it.

( 2017-05-18 14:07:36 +0200 )editconvert to answer

You can find the receiver functionality slightly above the main function. Since i am still experimenting on this, i was earlier thinking to collect the timestamp information (send and receive times) with the help of wireshark and analyser. But this won't be precise enough since there is no idea of the clocks analyser is using and that wireshark receive times can't be relied on. Although this could be done as a verification part only. I now ought to add some more timer functionality to achieve this. But i had another query that if i use the capture functionality in hardware timer, how do i go about it without CPU intervention, as we are normally doing this by calling TASKS_CAPTURE for each capture event in the code. But this involves CPU. What's the other CPU independent way for doing this. Would appreciate your advice!!!

( 2017-05-18 15:42:56 +0200 )editconvert to answer

Yes I can see start_reciever() but I don't see when it's called.

Yes, using wireshark and analyser is for verification. The question is how you are planing to do the actual time synchronization ? Do you have an idea of what you are trying to achieve ?

Basically please explain what you meant here: I wish to generate time stamps at each send and receive events between two different nodes for which i am using the nRF radio

The main point of time synchronization is to calibrate multiple devices to start a timer at the same time. By having the synchronized timer we can add a time stamp on every data we sample or execute a command at the same time.

What we do in the example I pointed you to (which only takes 15 minutes to read and 5 minutes to test ) is to do TASKS_CAPTURE on the timer of the master, add the latency (consistent time delta by using another timer), then put that value in the radio packet.

On the receiver/slave side, when receiving the packet, it uses that timer captured value to update its own timer with that value (includes the delta). After that the timers on both device should be synchronized.

Note that this solution is only for a start network, where one single node can update multiple nodes around it. I don't know how do you plan to do it for a mesh network. That why I keep asking how do you plan to do your mesh.

And yes, we don't have a solution to avoid CPU involve here. We need the CPU to put the captured timer value to radio packet. But we can have a consistent time for doing that by using another timer and PPI to start radio transmission a fixed time after the capture task.

more

01200555.pdf

This is a part of my thesis work basically. I am using the tiny sync algorithm to achieve this. Refer to fig 1 and then section 4 on page 1270. basically i need to collect the three time stamps, t_o, t_b and t_r for each probe message sent. The packet itself would be carrying the timestamp to the destination.

U mean to say that while using timers too for all events we would always be requiring the CPU. Although timers have the inbuilt functionality to minimize CPU intervention. There are probably some related tasks of Nordic in the SDK itself that have been done without using CPU. But i still need to figure out how to do the capture tasks independent of the CPU.

( 2017-05-19 11:49:31 +0200 )editconvert to answer

Also i would be just using capture events for capturing the event times. So no compare events will be involved.

( 2017-05-19 12:05:02 +0200 )editconvert to answer

Thanks for providing the document. My understanding is that you need to capture time stamp on both side and your approach require time-stamp packet from both direction to do calculation and estimate a12, b12 from that.

Our approach is a little bit different that we only use packet from one direction and try to reset the timer on node 2 to set the offset b12 to zero using the time stamp. We reduce the affect of the drift a12 by keep sending time stamp packet so that the drift create by the timer won't exceed the real time requirement.

You can re-use what we implemented in our example on the transmission side. Use PPI to trigger a TASK_CAPTURE of the free run timer from COMPARE event of another timer (TIMER2) (You can ignore this, and trigger TASK_CAPTURE your way) Then use CPU to put the Captured value of the ...(more)

( 2017-05-19 13:07:11 +0200 )editconvert to answer

Good enough. I will remain in touch with you on this if you don't mind. The CPU intervention problem is solved by using the the PPI itself. But perhaps i need to in initialize it earlier in the process so as to avoid delay. But when we are using timer 0, 1 and 2, are these individual timers present at each of the nodes or these are just separate instances of the same timer on one node. Because as u mentioned we are using one timer and one RTC for each node right.

( 2017-05-19 14:24:14 +0200 )editconvert to answer

Also as per the algorithm, i need to generate a timestamp t_o just when the packet arrives at node 1. So will it be done using a timer itself and if yes, at what point in the code i need to load the timestamp in the packet.

( 2017-05-19 14:44:26 +0200 )editconvert to answer

In our example we use 2 TIMERs to improve accuracy. The time stamp is only taken on one timer (the free runner) the other timer is just to do the task of triggering TASK_CAPTURE and RADIO->TASKS_START. They are individual hardware timers.

I don't understand this "generate a timestamp t_o just when the packet arrives at node 1" . What do you mean by arrive at node 1 ? I thought t_o is when you send the packet from node 1 ?

( 2017-05-19 16:53:21 +0200 )editconvert to answer

ya but if u see fig 1 in the doc, u see t_o as the the time of send event being generated at node 1 interface. t_o being the time just before the packet is sent as labelled. i propose to follow the algorithm but will make some modifications at later stages in this algorithm. you are right. i wrote it the wrong way. sorry!!!! now i will try working on this the coming weekend and then discuss further if required. thanks alot for ur support.

( 2017-05-19 17:48:10 +0200 )editconvert to answer

If I understand you correctly, you want to generate the time stamp at exact moment when it's sent from Node 1 , right ? It's impossible to capture the timer at exact time when the packet is sent and put it into the radio packet at the same time. But we can do calculation and estimate the exact value of the timer when the radio packet is sent. The number of cycles from the time we capture the timer value until the time we trigger TASK_START on the radio is determined (by using the second timer and PPI), so we can calculate the exact time stamp.

( 2017-05-22 12:40:21 +0200 )editconvert to answer

[hide preview]

## Recent blog posts

• ### The complete tutorial for developing and debugging nRF52 applications on a Mac

Posted 2017-05-11 04:13:06 by Mohammad Afaneh
• ### Bluetooth 5 2Mbps Demo with nRF52 Series and Samsung Galaxy S8

Posted 2017-05-09 14:20:22 by John Leonard
• ### Setting up Segger on a mac or pc and debug - step by step for humans

Posted 2017-05-05 14:03:35 by Lola

Posted 2017-04-11 11:49:17 by Radosław Koppel
• ### Taking a deeper dive into Bluetooth 5

Posted 2017-04-07 14:53:51 by John Leonard

## Recent questions

• ### nrf52 sdk12 custom service full example

Posted 2017-05-28 19:34:43 by Remi
• ### Antenna for the beacon

Posted 2017-05-28 18:06:06 by Usman
• ### Gazell nRF51822

Posted 2017-05-28 00:40:13 by Andrew Kohlsmith
• ### Is Zephyr I2c Master Supported pca10040

Posted 2017-05-27 23:21:37 by gidjit
• ### Throughput of ble_app_uart

Posted 2017-05-27 19:14:00 by mansfield