source: trunk/MultiChannelUSB/histogram.v@ 87

Last change on this file since 87 was 84, checked in by demin, 15 years ago

improve timings in all components

File size: 2.9 KB
Line 
1module histogram
2 #(
3 parameter W = 32 // bin resolution
4 )
5 (
6 input wire clk, reset,
7 input wire data_ready,
8 input wire [11:0] data, address,
9 output wire [W-1:0] q
10 );
11
12 // signal declaration
13 reg [3:0] state_reg, state_next;
14 reg wren_reg, wren_next;
15 reg [11:0] addr_reg, addr_next;
16 reg [W-1:0] data_reg, data_next;
17
18 wire [W-1:0] q_a_wire, q_b_wire;
19
20 altsyncram #(
21 .address_reg_b("CLOCK0"),
22 .clock_enable_input_a("BYPASS"),
23 .clock_enable_input_b("BYPASS"),
24 .clock_enable_output_a("BYPASS"),
25 .clock_enable_output_b("BYPASS"),
26 .indata_reg_b("CLOCK0"),
27 .intended_device_family("Cyclone III"),
28 .lpm_type("altsyncram"),
29 .numwords_a(4096),
30 .numwords_b(4096),
31 .operation_mode("BIDIR_DUAL_PORT"),
32 .outdata_aclr_a("NONE"),
33 .outdata_aclr_b("NONE"),
34 .outdata_reg_a("CLOCK0"),
35 .outdata_reg_b("CLOCK0"),
36 .power_up_uninitialized("FALSE"),
37 .read_during_write_mode_mixed_ports("OLD_DATA"),
38 .widthad_a(12),
39 .widthad_b(12),
40 .width_a(W),
41 .width_b(W),
42 .width_byteena_a(1),
43 .width_byteena_b(1),
44 .wrcontrol_wraddress_reg_b("CLOCK0")) hst_ram_unit(
45 .wren_a(wren_reg),
46 .clock0(clk),
47 .wren_b(1'b0),
48 .address_a(addr_reg),
49 .address_b(address),
50 .data_a(data_reg),
51 .data_b(),
52 .q_a(q_a_wire),
53 .q_b(q_b_wire),
54 .aclr0(1'b0),
55 .aclr1(1'b0),
56 .addressstall_a(1'b0),
57 .addressstall_b(1'b0),
58 .byteena_a(1'b1),
59 .byteena_b(1'b1),
60 .clock1(1'b1),
61 .clocken0(1'b1),
62 .clocken1(1'b1),
63 .clocken2(1'b1),
64 .clocken3(1'b1),
65 .eccstatus(),
66 .rden_a(1'b1),
67 .rden_b(1'b1));
68
69 // body
70 always @(posedge clk)
71 begin
72 if (reset)
73 begin
74 wren_reg <= 1'b1;
75 addr_reg <= 12'd0;
76 data_reg <= 32'd0;
77 state_reg <= 4'b1;
78 end
79 else
80 begin
81 wren_reg <= wren_next;
82 addr_reg <= addr_next;
83 data_reg <= data_next;
84 state_reg <= state_next;
85 end
86 end
87
88 always @*
89 begin
90 wren_next = wren_reg;
91 addr_next = addr_reg;
92 data_next = data_reg;
93 state_next = state_reg;
94 case (state_reg)
95 0:
96 begin
97 // nothing to do
98 wren_next = 1'b0;
99 addr_next = 12'd0;
100 data_next = 32'd0;
101 state_next = 4'd0;
102 end
103
104 1:
105 begin
106 // write zeros
107 if (&addr_reg)
108 begin
109 wren_next = 1'b0;
110 state_next = 4'd2;
111 end
112 else
113 begin
114 addr_next = addr_reg + 12'd1;
115 end
116 end
117
118 2:
119 begin
120 wren_next = 1'b0;
121 if (data_ready)
122 begin
123 addr_next = data;
124 state_next = 4'd3;
125 end
126 end
127
128 3:
129 begin
130 state_next = 4'd4;
131 end
132
133 4:
134 begin
135 if (&q_a_wire)
136 begin
137 state_next = 4'd0;
138 end
139 else
140 begin
141 wren_next = 1'b1;
142 data_next = q_a_wire + 32'd1;
143 state_next = 4'd2;
144 end
145 end
146
147 default:
148 begin
149 wren_next = 1'b0;
150 addr_next = 12'd0;
151 data_next = 32'd0;
152 state_next = 4'd0;
153 end
154 endcase
155 end
156
157 // output logic
158 assign q = q_b_wire;
159endmodule
Note: See TracBrowser for help on using the repository browser.