, right.
```matlab
%% Simulation parameters
v = 1e-3; % Scanning velocity [m/s or rad/s]
Ts_pepu = 60e-6; % Sampling time of PEPU [s] i.e. time to get a new encoder value
Ts_ctrl = 1e-4; % Sampling time of controller [s]
t_sim = 10*Ts_ctrl; % Total simulation time [s]
t = 0:1e-6:t_sim; % Time vector used for simulation [s]
x = v*t; % Suppose linear position [m, rad]
%% Compute position stored in PEPU as every time step
x_pepu = Ts_pepu*floor(t/Ts_pepu)*v;
%% Compute position get on the controller at each control period
t_ctrl = 0:Ts_ctrl:t_sim; % Time vector [s]
x_ctrl = zeros(size(t_ctrl)); % Position stored on the controller [m]
x_error = zeros(size(t_ctrl)); % Position error due to "jitter" [m]
for i = 1:length(t_ctrl)
[~, i_t] = min(abs(t - t_ctrl(i))); % Find the stored encoder value in the PEPU at the time of the controller period
x_ctrl(i) = x_pepu(i_t);
x_error(i) = x_pepu(i_t) - x(i_t);
end
```
{{< figure src="/ox-hugo/jitter_error_example.png" caption="Figure 2: Measurement error due to Jitter. 1mm/s velocity scan, Ts_pepu is 60us and Ts_ctrl is 100us" >}}
## Expected error induced by "jitter" {#expected-error-induced-by-jitter}
Th "position jitter" depends on:
- \\(T\_{s,\text{pepu}}\\): the "sampling time" of the encoder on the PEPU
- \\(v\\): the scan velocity in [unit/s]
The obtain "jitter" can be as large as (expressed in the same units as \\(v\\)):
\begin{equation}
dx = v \cdot T\_{s,\text{pepu}}
\end{equation}
Let's make a numerical example:
```matlab
%% Simulation parameters
v = 1e-3; % Scanning velocity [m/s or rad/s]
Ts_pepu = 60e-6; % Sampling time of PEPU [s] i.e. time to get a new encoder value
```
```text
dx = 60 [nm] with v = 1.0 [mm/s] and Ts_pepu = 60 [us]
```
## Is there an optimal PEPU acquisition rate? {#is-there-an-optimal-pepu-acquisition-rate}
Changing the readout time of the PEPU (its clock for instance) changes the jitter amplitude as well as its "pattern":
```matlab
%% Longer simulation than before to better see the pattern
t_sim = 50*Ts_ctrl; % Total simulation time [s]
t = 0:1e-6:t_sim; % Time vector used for simulation [s]
x = v*t; % Suppose linear position [m, rad]
t_ctrl = 0:Ts_ctrl:t_sim; % Time vector [s]
%% Large Ts_pepu to try to match with controller sampling time
Ts_pepu = 95e-6; % Sampling time of PEPU [s] i.e. time to get a new encoder value
x_pepu = Ts_pepu*floor(t/Ts_pepu)*v;
x_error_1 = zeros(size(t_ctrl)); % Position error due to "jitter" [m]
for i = 1:length(t_ctrl)
[~, i_t] = min(abs(t - t_ctrl(i))); % Find the stored encoder value in the PEPU at the time of the controller period
x_error_1(i) = x_pepu(i_t) - x(i_t);
end
%% Small Ts_pepu as possible to reduce jitter amplitude
Ts_pepu = 30e-6; % Sampling time of PEPU [s] i.e. time to get a new encoder value
x_pepu = Ts_pepu*floor(t/Ts_pepu)*v;
x_error_2 = zeros(size(t_ctrl)); % Position error due to "jitter" [m]
for i = 1:length(t_ctrl)
[~, i_t] = min(abs(t - t_ctrl(i))); % Find the stored encoder value in the PEPU at the time of the controller period
x_error_2(i) = x_pepu(i_t) - x(i_t);
end
%% Small Ts_pepu as possible to reduce jitter amplitude
Ts_pepu = 10e-6; % Sampling time of PEPU [s] i.e. time to get a new encoder value
x_pepu = Ts_pepu*floor(t/Ts_pepu)*v;
x_error_3 = zeros(size(t_ctrl)); % Position error due to "jitter" [m]
for i = 1:length(t_ctrl)
[~, i_t] = min(abs(t - t_ctrl(i))); % Find the stored encoder value in the PEPU at the time of the controller period
x_error_3(i) = x_pepu(i_t) - x(i_t);
end
```
{{< figure src="/ox-hugo/jitter_errors_effect_Ts_pepu.png" caption="Figure 3: Measurement errors due to Jitter. Effect of the refresh rate on the PEPU, different \"patterns\" can appear. Velocity scan is 1mm/s" >}}
For high velocity / high precision scans, it is important to reduce the timing jitter of the measured position (i.e. "position jitter").
Ideally, this is the control system (i.e. where the feedback controller is implemented) that triggers the readout of all the sensors.
Having a intermediate electronic device (here the PEPU) that triggers the readout of the encoders not in sync with the controller can affect quite negatively the quality of the motion.
## Bibliography {#bibliography}