Clock synchronization between 2 controllers
1 次查看(过去 30 天)
显示 更早的评论
I am reading data from a microcontroller at 10ms sampling time. The problem is that the data is not exactly 10ms due to the drift in the crystal oscillator of the controller. Hence over time I notice that the outputs vary significantly because of this drift. I am trying to build a time synchronization module, where I periodically(every 1sec) sync the processor clock with a reference clock(ideal clock). Every 1 second, I calculate the slope of the actual clock vs the original clock and apply that value to the next period (1sec). However even with this periodic slope correction, it does not solve my time synchronization problem. Any thoughts or ideas about how to synchronize the clocks in a better and efficient way?
time_sensor_x = time_sensor(1) : 0.01 : length(time_sensor)/100; %i"time_sensor_x" is the ideal clock, "time_sensor" is the actual clock.
%-----Slope calculation------%
k = 1;
for i = 1:100:length(time_sensor_x)
slope_value(k) = time_sensor(i)/time_sensor_x(i);
k = k+1;
t = i;
end
%-----Slope correction and new time calculation------%
k = 1;
for i = 1:length(time_sensor_x)
time_sensor_corrected(i) = (1/slope_value(k))*(time_sensor(i)); %corrected time
if mod(i,100) == 0
k = k+1;
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Clocks and Timers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!