Code covered by the BSD License  

Highlights from
Measuring Clock Jitter with xPC Target

image thumbnail

Measuring Clock Jitter with xPC Target

by

Doug Jones (view profile)

 

14 Dec 2007 (Updated )

Explains how to measure PC clock jitter using xPC Target.

xpcJitterTestScript.m
% XPCJITTERTEST: Tested using TCP/IP connection with No Graphics.
close all; clear all; clc;                  % Start with a clean environment
MICRO = 1e-6; NANO = 1e-9;                  % Parameter constants
MEGA  = 1e6;  GIGA = 1e9;                   % Parameter constants
tClkFrq = 2.8*GIGA;                         % Theoretical clock frequency (Hz)
tSampleRate = 250*MICRO;                    % Theoretical sample rate (sec)
tg=xpc;                                     % Create target object
tg.load('xpcJitterTest');                   % Download model to target PC
tg.SampleTime = tSampleRate;                % Set sample rate (sec)
tg.StopTime = 11;                           % Set stop time (sec)
+tg;                                        % Start jitter model
pause(12)                                   % Wait until the run ends.
tStart = 1;                                 % Start computing statistics at 1 sec
tOffSet = tStart/tg.SampleTime+1;           % Index for time offset
t = tg.TimeLog(tOffSet:end)-tStart;         % Simulation Time
pJitterCnt = tg.OutputLog(tOffSet:end,1);   % Clock Jitter (Counts)
ccJitterCnt = tg.OutputLog(tOffSet:end,2);  % Clock Jitter (Counts)
mClkFrq = tg.OutputLog(tOffSet:end,3);      % Clock Frequency (Hz)
pJitter = pJitterCnt/mean(mClkFrq)/MICRO;   % Period Jitter (usec)
ccJitter = ccJitterCnt/mean(mClkFrq)/MICRO; % Cycle-Cycle Jitter (usec)
if mean(mClkFrq)* NANO < 1.0                % Determine clock scale (GHz or MHz)
    clkScale = MICRO; clkFrqLabel = 'MHz';
else
    clkScale = NANO;  clkFrqLabel = 'GHz';
end

% Display statistics.
disp(['Clock Frequency (' clkFrqLabel ')         : ' num2str(mean(mClkFrq)*clkScale,'%8.3f')]);
disp(['Period Jitter Mean (usec)     : ' num2str(mean(pJitter),'%8.3f')]);
disp(['Period Jitter SDev (usec)     : ' num2str(std(pJitter),'%8.3f')]);
disp(['Period Jitter Max  (usec)     : ' num2str(abs(max(pJitter)),'%8.3f')]);
disp(['Cycle-Cycle Jitter Mean (usec): ' num2str(mean(ccJitter),'%8.3f')]);
disp(['Cycle-Cycle Jitter SDev (usec): ' num2str(std(ccJitter),'%8.3f')]);
disp(['Cycle-Cycle Jitter Max  (usec): ' num2str(abs(max(ccJitter)),'%8.3f')]);

% Plot jitter signals.
figure(1); clf;
subplot(2,1,1); plot(t,pJitter,'b',[t(1) t(end)],[tSampleRate tSampleRate]/MICRO,'r','LineWidth',2); 
legend('Measured','Ideal','Location','SouthEast');
set(gca,'XLim',[t(1) t(end)]); set(gca,'YLim',[248 252]);
grid on; xlabel('Time (sec)'); ylabel('\musec'); title('Period Jitter');
subplot(2,1,2); plot(t,ccJitter,'b',[t(1) t(end)],[0 0],'r','LineWidth',2); 
legend('Measured','Ideal','Location','SouthEast');
set(gca,'XLim',[t(1) t(end)]); set(gca,'YLim',[-2 2])
grid on; xlabel('Time (sec)'); ylabel('\musec'); title('Cycle-Cycle Jitter2');

% Plot jitter statistics.
figure(2); clf;
subplot(2,3,[1 4]); axis([0 10 0 10]); set(gca,'Visible','off');
h=text(-2,   9,'Period Jitter MEAN (\musec):');       set(h,'FontSize',12); h=text(7,   9,num2str(mean(pJitter),     '%12.3f')); set(h,'FontSize',12);
h=text(-2,   8,'Period Jitter STD (\musec):');        set(h,'FontSize',12); h=text(7,   8,num2str(std(pJitter),      '%12.3f')); set(h,'FontSize',12);
h=text(-2,   7,'Period Jitter MAX (\musec):');        set(h,'FontSize',12); h=text(7,   7,num2str(abs(max(pJitter)), '%12.3f')); set(h,'FontSize',12);
h=text(-2, 3.5,'Cycle-Cycle Jitter MEAN (\musec):');  set(h,'FontSize',12); h=text(7, 3.5,num2str(mean(ccJitter),    '%12.3f')); set(h,'FontSize',12);
h=text(-2, 2.5,'Cycle-Cycle Jitter STD (\musec):');   set(h,'FontSize',12); h=text(7, 2.5,num2str(std(ccJitter),     '%12.3f')); set(h,'FontSize',12);
h=text(-2, 1.5,'Cycle-Cycle Jitter MAX (\musec):');   set(h,'FontSize',12); h=text(7, 1.5,num2str(abs(max(ccJitter)),'%12.3f')); set(h,'FontSize',12);
subplot(2,3,[2 3]); hist(pJitter,1000);  ylabel('Period Jitter')
subplot(2,3,[5 6]); hist(ccJitter,1000); ylabel('Cycle-Cycle Jitter')

% figure(2); clf;
% subplot(2,1,1); hist(pJitter,1000);  xlabel('\musec'); ylabel('Period Jitter')
% subplot(2,1,2); hist(ccJitter,1000); xlabel('\musec'); ylabel('Cycle-Cycle Jitter')

% Plots the cycle-cycle jitter PSD.
figure(3); clf;
psd(spectrum.periodogram,ccJitter,'Fs',1/tSampleRate);  

Contact us