This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Synchronisation with advertisement

Hello,

Im trying to create a synchronisation method for sensors using BLE. At the moment i can synchronise them within 10ms accuracy, in theory it should be within 2ms and i can not find this 7ms extra delay. This is my current synchronisation method:

At the sensor(using S110) i'm using the 16 bit timer1 with a resolution of 4us. I'm using a compare match to increment a variable(uint16 msec) within the time it overflows in this case 125ms. Just before the radio gets active(radio notification) i'm reading the current timer1 register and put this in another variable(uint16 usec) and set these time values in the manufacturer specific advertise data. So i'm now sure each time before the radio gets active a new value will be advertised. The advertising interval is set to 1s.

Now at the S120 device im scanning 100% so almost each second it will receive the timing of the sensor. I've measured this with the oscilloscope by setting a pin high when sending at sensor and receiving at S120 device. I've seen a variable delay of Δt 2ms this is noticed as the S120 scans on channel 37,38,39 (1ms inbetween these channels). Immediately after i've received the timing value from the sensor I read the timer1 register of the S120 device and calculate the difference between the S120 and sensor(S110). Now at the next compare event of the S120 device i'm setting a new compare register at timer1: normal compare register + difference (i've calculated the min / max of difference and this is within the timers resolution).

Now in theory i would expect to see a constant delay + Δt 2ms from scanning on 3 different channels. In fact i see the Δt differ within 10ms. Is there anything im missing? Hope someone can help me with this. I've attached some pictures showing the sensor and S120 device timer compare interrupt and zooms.

Regards, Pascal

2014-04-25 11.39.06.jpg

2014-04-25 11.39.57.jpg

IMAG0624.jpg

Advertise.jpg

Parents
  • In the above method at each compare IRQ i cleared the timer and restart counting from 0 towards 31250. I thought maybe the clear task is not being executed exactly at count value 31250. If a bluetooth event comes at IRQ the timer will not be cleared and for example counts toward 3250 and gets cleared.

    So now instead of clearing the timer at each compare IRQ im just setting new compare value with: CC[0] += 31250. I use CC[1] to capture the timervalue and put it in currentvalue. I calculate the time needed towards a new interrupt as follow:

    NRF_TIMER1->TASKS_CAPTURE[1] = 1; //capture timer value
    currentvalue = (NRF_TIMER1->CC[1]); //value in us
    if(currentvalue>NRF_TIMER1->CC[0])
    {
        currentvalue = 65535-currentvalue + NRF_TIMER1->CC[0];
    }
    else
    {
    currentvalue = NRF_TIMER1->CC[0] - currentvalue;
    }
    

    At the S120 device i calculate his time value towards next IRQ. At the next IRQ of the S120 device i update the compare register with: NRF_TIMER1->CC[0] += TIMER1_CC_DELAY - difference;

    In theory i would expect the IRQs to be executed at exactly the same time. Still i'm getting the same results as my first test: Δt = 10ms jitter instead of 2ms jitter. Does someone know what causes this unexpected delay? All help will be appreciated!

Reply
  • In the above method at each compare IRQ i cleared the timer and restart counting from 0 towards 31250. I thought maybe the clear task is not being executed exactly at count value 31250. If a bluetooth event comes at IRQ the timer will not be cleared and for example counts toward 3250 and gets cleared.

    So now instead of clearing the timer at each compare IRQ im just setting new compare value with: CC[0] += 31250. I use CC[1] to capture the timervalue and put it in currentvalue. I calculate the time needed towards a new interrupt as follow:

    NRF_TIMER1->TASKS_CAPTURE[1] = 1; //capture timer value
    currentvalue = (NRF_TIMER1->CC[1]); //value in us
    if(currentvalue>NRF_TIMER1->CC[0])
    {
        currentvalue = 65535-currentvalue + NRF_TIMER1->CC[0];
    }
    else
    {
    currentvalue = NRF_TIMER1->CC[0] - currentvalue;
    }
    

    At the S120 device i calculate his time value towards next IRQ. At the next IRQ of the S120 device i update the compare register with: NRF_TIMER1->CC[0] += TIMER1_CC_DELAY - difference;

    In theory i would expect the IRQs to be executed at exactly the same time. Still i'm getting the same results as my first test: Δt = 10ms jitter instead of 2ms jitter. Does someone know what causes this unexpected delay? All help will be appreciated!

Children
No Data
Related