-
Notifications
You must be signed in to change notification settings - Fork 3
/
Untitled1
119 lines (105 loc) · 3.34 KB
/
Untitled1
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
module MandelbrotGen(
input Clk_100M,
output reg [18:0] addrA,
output reg [11:0] dinA,
output reg wea
);
reg [10:0] C_real = 11'b000_00000000; // real value of first x coordinate
reg [10:0] real_factor = 11'b000_00000001; // scaling faactor C_re = C_re + re_factor(x_coordinate) -- decimal point @ 9th place
reg [10:0] imag_factor = 11'b000_00000001; // scaling faactor C_im = C_im + im_factor(y_coordinate) -- decimal point @ 9th place
reg [10:0] C_imag = 11'b000_00000000; // 0.935546875 imaginary value of first y coordinate
reg [7:0] dec_pointNew = 8; //holds decimal place value for Z
reg [11:0] iterations = 0;
reg [10:0] Z_real = 0;
reg [10:0] Z_imag = 0;
//not sure if three most significant bits get truncated
reg [21:0] Temp_Z_real2 = 0; //place holders for the squared real value.
reg [21:0] Temp_Z_imag2 = 0; // place holders for the squared imaginary value.
reg [21:0] tT_Z_im_re = 0; // place holders for the squared value.
reg [10:0] tZ_im_re = 0; // place holders for the squared value.
reg [10:0] Z_real2 = 0; //place holders for the squared real value.
reg [10:0] Z_imag2 = 0; // place holders for the squared imaginary value.
reg [21:0] temp = 0;
reg [1:0] calculating = 1'b1;
reg ce =0;
reg [10:0] a =0;
reg [10:0] b =0;
wire [21:0] p = 0;
reg Count=0;
multiplier m1_11x11(Clk_100M, ce, a, b, p);
always @(posedge Clk_100M) begin
if (&Count) begin
if (addrA > 307199) begin
addrA<=0;
C_imag <= 10'b0000000_000;
C_real <= 10'b0000000_000;
end
else begin
if (calculating == 1) begin //stage 1
/////
ce <=1;
if (ce ==1) begin
a<= Z_real;
b<= Z_real;
Z_real2 <= p[18:7];
ce <=0;
end
calculating <= calculating + 1'b1; //start stage 2
end // end stage 1
/////
if (calculating == 2) begin //stage 2
ce <=1;
if (ce ==1) begin
a<= Z_im;
b<= Z_im;
Z_imag2 <= p[18:7];
ce <=0;
end
calculating <= calculating + 1'b1; //start stage 3
end //end stage 2
//////////////
if (calculating == 3) begin
if (((Z_re2 + Z_im2) > (4<<p_dec_pointNew)) || (iterations == 4095)) begin // shift to the right to drop decimal (may lose resolution, but can fix it l8er)
calculating <= 0;
wea <= 1;
dinA <= iterations;
//dinA <= iterations;
//p_dec_pointNew<=p_dec_point;//reseting decimal position.
Z_re2 <=0;
Z_im2<=0;
Z_im<=0;
Z_re<=0;
end else begin
//////////
// ce <=1;
//a<= Z_re;
//b<= Z_im;
//temp <= p;
//ce <=0;
//temp <= temp <<1;
//tT_Z_im_re <= temp;
//////////
Z_im <= tT_Z_im_re[18:7] + C_im; //yNew = (2*xT*yT) + yC;
Z_re <= Z_re2 - Z_im2 + C_re;// xNew = (xT^2 - yT^2) + xC;
iterations <= iterations + 1'b1;
//p_dec_pointNew <= (p_dec_pointNew)<<1;// binary multiplication of the same number yeilds in a 2x shift in dec.point
end
end else if ((calculating == 0)) begin
wea <=0;
C_re <= C_re + re_factor; //increment x coordinate by 1/256 /////////THIS WAS CHANGED FROM + to -
if (C_re == 11'b010_01111111) begin
C_im <= C_im + im_factor;
C_re<= 11'b000_00000000;
if (C_im == 11'b001_11011111) begin // goes 1 past end of frame
C_im <= 11'b000_00000000;
end
end
addrA <= addrA +1'b1;
calculating <=1;
iterations <= 0;
end
end
Count <=0;
end else Count <= Count+ 1;
end
endmodule