source: trunk/MultiChannelCOM/histogram.v@ 109

Last change on this file since 109 was 2, checked in by demin, 15 years ago

first working version

File size: 2.5 KB
Line 
1module histogram
2 (
3 input wire clk, reset,
4 input wire data_ready,
5 input wire [11:0] data, address,
6 output wire [31:0] q,
7 output wire [3:0] led
8 );
9
10 // signal declaration
11 reg [3:0] state_reg, state_next;
12
13 reg [31:0] led_data_reg [3:0];
14 reg [31:0] led_data_next [3:0];
15
16 reg wren_reg, wren_next;
17 reg [11:0] addr_reg, addr_next;
18 reg [31:0] data_reg, data_next;
19
20 wire [31:0] q_a_wire, q_b_wire;
21
22 ram4096x32 ram4096x32_unit (
23 .address_a(addr_reg),
24 .address_b(address),
25 .clock(~clk),
26 .data_a(data_reg),
27 .data_b(),
28 .wren_a(wren_reg),
29 .wren_b(1'b0),
30 .q_a(q_a_wire),
31 .q_b(q_b_wire));
32
33 // body
34 always @(posedge clk)
35 begin
36 if (reset)
37 begin
38 state_reg <= 4'b1;
39 end
40 else
41 begin
42 state_reg <= state_next;
43 wren_reg <= wren_next;
44 addr_reg <= addr_next;
45 data_reg <= data_next;
46 led_data_reg[0] <= led_data_next[0];
47 led_data_reg[1] <= led_data_next[1];
48 led_data_reg[2] <= led_data_next[2];
49 led_data_reg[3] <= led_data_next[3];
50 end
51 end
52
53 always @*
54 begin
55 state_next = state_reg;
56 wren_next = wren_reg;
57 addr_next = addr_reg;
58 data_next = data_reg;
59 led_data_next[0] = led_data_reg[0];
60 led_data_next[1] = led_data_reg[1];
61 led_data_next[2] = led_data_reg[2];
62 led_data_next[3] = led_data_reg[3];
63 case (state_reg)
64 0: ; // nothing to do
65 1:
66 begin
67 // start reset
68 wren_next = 1'b1;
69 addr_next = 0;
70 data_next = 0;
71 led_data_next[0] = 0;
72 led_data_next[1] = 0;
73 led_data_next[2] = 0;
74 led_data_next[3] = 0;
75 state_next = 4'd2;
76 end
77
78 2:
79 begin
80 // write zeros
81 if (&addr_reg)
82 begin
83 state_next = 4'd3;
84 end
85 else
86 begin
87 addr_next = addr_reg + 12'd1;
88 end
89 end
90
91 3:
92 begin
93 // read
94 wren_next = 1'b0;
95 if (&data_reg)
96 begin
97 state_next = 4'd0;
98 end
99 else if (data_ready)
100 begin
101 // set addr
102 addr_next = data;
103 state_next = 4'd4;
104 end
105 end
106
107 4:
108 begin
109 // increment and write
110 wren_next = 1'b1;
111 data_next = q_a_wire + 32'd1;
112 led_data_next[addr_reg>>10] = q_a_wire;
113 state_next = 4'd3;
114 end
115
116 default:
117 begin
118 state_next = 4'd0;
119 end
120 endcase
121 end
122
123 // output logic
124 assign q = q_b_wire;
125 assign led[0] = led_data_reg[0][23];
126 assign led[1] = led_data_reg[1][23];
127 assign led[2] = led_data_reg[2][23];
128 assign led[3] = led_data_reg[3][23];
129
130endmodule
Note: See TracBrowser for help on using the repository browser.