-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharrayout_demo.va
More file actions
57 lines (51 loc) · 1.85 KB
/
Copy patharrayout_demo.va
File metadata and controls
57 lines (51 loc) · 1.85 KB
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
`include "disciplines.vams"
// Enhancement-20 demonstration: array OUTPUT and INOUT arguments to analog
// functions (completing Enhancement-18's input-only array arguments).
//
// * `make_taps` writes a geometric tap array via an OUTPUT array argument.
// * `normalize` scales an array in place via an INOUT array argument.
//
// The gain is the sum of the normalized taps, which is 1 by construction for any
// `ratio`, so V(out) tracks V(in) exactly -- but only if both the output write
// (filling the taps) and the inout write (normalizing them) actually reach the
// caller's array. A broken writeback leaves the taps zero/unnormalized and the
// gain wrong.
module arrayout_demo(in, out);
input in;
output out;
electrical in, out;
parameter real ratio = 0.5 from (0:inf);
// OUTPUT array argument: fill w with 1, ratio, ratio^2, ratio^3
analog function real make_taps;
input r; output w;
real r; real w[0:3];
integer i;
begin
w[0] = 1.0;
for (i = 1; i < 4; i = i + 1) w[i] = w[i - 1] * r;
make_taps = 0.0;
end
endfunction
// INOUT array argument: normalize in place so the elements sum to 1
analog function real normalize;
inout w; real w[0:3];
integer i; real s;
begin
s = 0.0;
for (i = 0; i < 4; i = i + 1) s = s + w[i];
for (i = 0; i < 4; i = i + 1) w[i] = w[i] / s;
normalize = s;
end
endfunction
real taps[0:3];
real g;
real dummy;
integer i;
analog begin
dummy = make_taps(ratio, taps); // fill taps (output arg)
dummy = normalize(taps); // normalize in place (inout arg)
g = 0.0;
for (i = 0; i < 4; i = i + 1) g = g + taps[i]; // = 1.0 for any ratio
V(out) <+ g * V(in);
end
endmodule