1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
classdef (StrictDefaults) RxClock < serdes.SerdesAbstractSystemObject
% RxClock Receiver clock generator
% obj = RxClock returns a System Object, obj, that generates a
% multiphase clock.
%
% RxClock methods:
% step - Generates a multiphase clock. Example usage:
% ClockOut = stepImpl(obj,PhaseControl)
%
% RxClock properties:
% MaxTimingMismatch - Maximum timing mismatch in UI between the 1st
% and 2nd clock phases.
% NumberOfClocks - Number of output clock phases
% SymbolTime - Symbol time of the system
% SampleInterval - Uniform time step of the system
% Copyright 2021 The MathWorks, Inc.
%#codegen
properties (Nontunable)
%Max Timing Mismatch (UI)
MaxTimingMismatch = 0.0
%Number of output clock phases
NumberOfClocks = 4
%Symbol Time Multiplier Factor
SymbolTimeMultiplier = 1;
end
properties (Hidden, SetAccess=private)
Frequency % Clock frequency, Hz
Period % Clock period, seconds
PhaseInitial % Initial core phase
PhaseIncrement % Phase increment per sampling interval
PhaseCore % Clock core phase
PolyPhaseOffset % Array of VCO phase offsets
PhaseOutput % Output phases
ClockRate % Clock rate w.r.t. baud rate
InterPhaseOutput
end
properties (SetAccess = immutable, Nontunable, Hidden)
IsLinear = true;
IsTimeInvariant = true;
end
properties (Nontunable,Hidden)
%Input Waveform Type
% Set the input wave type as one of 'Sample' | 'Impulse' |
% 'Waveform'. The default is 'Sample'.
WaveType = 'Sample';
end
properties(Hidden, Constant)
WaveTypeSet = matlab.system.StringSet({'Sample','Impulse','Waveform'});
end
methods
% Constructor
function obj = RxClock(varargin)
% Support name-value pair arguments when constructing object
obj.BlockName = 'RxClock';
setProperties(obj,nargin,varargin{:})
end
end
methods (Hidden)
% The below methods, getAMIParameters, getAMIInputNames and
% getAMIOutputNames are for use only within the serdesDesigner App
% and will not influence the AMI parameters in Simulink whatsoever.
function amiParameters = getAMIParameters(~)
amiParameters = {};
end
function names = getAMIInputNames(~)
names = {};
end
function names = getAMIOutputNames(~)
names = {};
end
end
methods (Access = protected, Hidden)
function val = isSample(obj)
val = strcmpi(obj.WaveType,'Sample');
end
end
methods(Access = protected)
%% Common functions
function setupImpl(obj)
% Derived parameters
fb = 1/(obj.SymbolTime*obj.SymbolTimeMultiplier);
obj.ClockRate = 1/obj.NumberOfClocks;
obj.Frequency = fb * obj.ClockRate ;
obj.Period = 1 / obj.Frequency ;
obj.PhaseIncrement = obj.SampleInterval / obj.Period ;
% Multi-phase clock setup, poly phase. Inject an offset
% between the 1st and 2nd clocks.
v = zeros(obj.NumberOfClocks,1);
v(1) = obj.MaxTimingMismatch;
obj.PolyPhaseOffset = (0:-1:-(obj.NumberOfClocks-1))' / obj.NumberOfClocks + ...
v(mod(0:obj.NumberOfClocks-1,3)+1);
% Initialize clock core and output phases
obj.PhaseCore = -obj.PhaseIncrement;
obj.PhaseOutput = obj.PhaseCore + obj.PolyPhaseOffset;
obj.InterPhaseOutput = 0;
end
function validateInputsImpl(~,waveIn)
validateattributes(waveIn,{'numeric'},{'finite'},'','waveIn');
end
function [ck_out] = stepImpl(obj,ctrl_ph,initial_ph)
%ck_out = stepImpl(obj,ctrl_ph)
%ctrl_ph_const = -0.125;
if isSample(obj)
% Update clock core and output phases
obj.PhaseCore = mod(obj.PhaseCore + obj.PhaseIncrement, 1);
obj.InterPhaseOutput = obj.PhaseCore - ctrl_ph - initial_ph / obj.Period;
obj.PhaseOutput = obj.InterPhaseOutput + obj.PolyPhaseOffset;
end
% Update output clock
ck_out = sin(2*pi*obj.PhaseOutput);
end
function releaseImpl(obj)
fprintf('[CDR] Phase Offset: %6.32f\n', obj.InterPhaseOutput);
end
function [out1] = getOutputSizeImpl(obj)
% Return size for each output port
out1 = [obj.NumberOfClocks 1];
end
function [dt1] = getOutputDataTypeImpl(~)
dt1 = "double";
end
function [out1] = isOutputComplexImpl(obj)
% Return true for each output port with complex data
out1 = false;
% Example: inherit complexity from first input port
% out = propagatedInputComplexity(obj,1);
end
function [out1] = isOutputFixedSizeImpl(obj)
% Return true for each output port with fixed size
out1 = true;
% Example: inherit fixed-size status from first input port
% out = propagatedInputFixedSize(obj,1);
end
function resetImpl(~)
% Initialize / reset discrete-state properties
end
%% Simulink functions
function icon = getIconImpl(~)
% Define icon for System block
icon = sprintf("Rx\nClock");
end
function [name1, name2] = getInputNamesImpl(~)
name1 = 'Ctrl Ph';
name2 = 'Initial Ph';
end
function [name1] = getOutputNamesImpl(~)
name1 = 'Clock';
end
function num = getNumInputsImpl(~)
num = 2;
end
end
methods(Static, Access=protected)
function group = getPropertyGroupsImpl(~)
% Define property section(s) for System block dialog
group = matlab.system.display.SectionGroup(...
'Title','Main',...
'PropertyList',{'MaxTimingMismatch','NumberOfClocks',...
'SymbolTime','SymbolTimeMultiplier','SampleInterval'});
end
end
end
|