-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.v
77 lines (61 loc) · 1.32 KB
/
main.v
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
module main();
reg [7:0] r1 [0:511];
reg [7:0] r2 [0:511];
reg [7:0] r3 [0:511];
reg [10:0] Gx;
reg [10:0] Gy ;
reg [10:0] G [0:510];
reg clk;
reg [31:0] i,done;
reg [7:0] pixel;
reg [7:0] A00, A01, A02,A10,A11,A12,A20,A21,A22;
integer data,scan,final;
`define NULL 0
initial begin
clk=0; i=0;done=0;
data = $fopen("lena_decimal.txt", "r");
if (data== `NULL) begin
$display("data_file handle was NULL");
$finish;
end
final = $fopen(".txt","w");
end
always begin
#1 clk = ~clk;
end
always@(posedge clk) begin
if(i==510) begin
done=done +1;
i=0;
end
if(i<511) begin
r3[i]=r2[i];
r2[i]=r1[i];
scan=$fscanf(data, "%d\n",pixel);
r1[i]= pixel;
end
A00=r3[i-2];
A01=r3[i-1];
A02=r3[i];
A10=r2[i-2];
A11=r2[i-1];
A12=r2[i];
A20=r1[i-2];
A21=r1[i-1];
A22=r1[i];
if(done>1 && i>1) begin
//Gx = {3'b0,A20}+ 1'b1 +A22+ ~{3'b0,A10<<1} + 1'b1 +A12<<1+ ~{3'b0,A00} + 1'b1 + A02;
//Gy = ~{3'b0,A00} + 1'b1+ ~{3'b0,A01<<1} + 1'b1+ ~{3'b0,A02<<1} +1'b1 + A20 +A21<<1 +A22;
//Gx = r3[i] + r3[i-1]*2 + r3[i-2] - r1[i] - r1[i-1]*2 - r1[i-2];
//Gy = r3[i] + r2[i] + r1[i] - r3[i-2] - r2[i-2]*2 - r1[i-2];
Gx = r3[i] + - r3[i-2] + r2[i]*2 - r2[i-2]*2 +r1[i] - r1[i-2];
Gy = r3[i] - r1[i] + r3[i-1]*2 - r1[i-1]*2 + r3[i-2] - r1[i-2];
if(Gx[10] == 1)
Gx = ~Gx +1;
if(Gy[10] == 1)
Gy = ~Gy + 1;
$fwrite(final,"%d\n",Gx+Gy);
end
i=i+1;
end
endmodule