source: trunk/Octopus/counter.v@ 192

Last change on this file since 192 was 102, checked in by demin, 15 years ago

initial commit

File size: 2.1 KB
Line 
1module counter
2 (
3 input wire clock, frame, reset,
4
5 input wire [15:0] cfg_data,
6
7 input wire bus_ssel, bus_wren,
8 input wire [1:0] bus_addr,
9 input wire [15:0] bus_mosi,
10
11 output wire [15:0] bus_miso,
12 output wire bus_busy,
13
14 output wire cnt_good
15 );
16
17 wire [3:0] int_ssel_wire;
18 wire [15:0] int_miso_wire;
19
20 reg cnt_good_reg;
21 reg [15:0] int_miso_reg;
22
23 wire [63:0] reg_bits_wire;
24 wire [63:0] cnt_bits_wire;
25
26 integer i;
27 genvar j;
28
29 lpm_counter #(
30 .lpm_direction("DOWN"),
31 .lpm_port_updown("PORT_UNUSED"),
32 .lpm_type("LPM_COUNTER"),
33 .lpm_width(64)) lpm_counter_component (
34 .sload(cfg_data[0]),
35 .sclr(reset),
36 .clock(clock),
37 .data(reg_bits_wire),
38// .cnt_en(frame & cfg_data[1]),
39 .cnt_en((frame) & (|cnt_bits_wire) & (cfg_data[1])),
40 .q(cnt_bits_wire),
41 .aclr(1'b0),
42 .aload(1'b0),
43 .aset(1'b0),
44 .cin(1'b1),
45 .clk_en(1'b1),
46 .cout(),
47 .eq(),
48 .sset(1'b0),
49 .updown(1'b1));
50
51 generate
52 for (j = 0; j < 4; j = j + 1)
53 begin : BUS_OUTPUT
54 lpm_ff #(
55 .lpm_fftype("DFF"),
56 .lpm_type("LPM_FF"),
57 .lpm_width(16)) cfg_reg_unit (
58 .enable(int_ssel_wire[j] & bus_ssel & bus_wren),
59 .sclr(reset),
60 .clock(clock),
61 .data(bus_mosi),
62 .q(reg_bits_wire[j*16+15:j*16]),
63 .aclr(),
64 .aload(),
65 .aset(),
66 .sload(),
67 .sset());
68 end
69 endgenerate
70
71 lpm_mux #(
72 .lpm_size(4),
73 .lpm_type("LPM_MUX"),
74 .lpm_width(16),
75 .lpm_widths(2)) bus_miso_mux_unit (
76 .sel(bus_addr),
77 .data(cnt_bits_wire),
78 .result(int_miso_wire));
79
80
81 lpm_decode #(
82 .lpm_decodes(4),
83 .lpm_type("LPM_DECODE"),
84 .lpm_width(2)) lpm_decode_unit (
85 .data(bus_addr),
86 .eq(int_ssel_wire),
87 .aclr(),
88 .clken(),
89 .clock(),
90 .enable());
91
92 always @(posedge clock)
93 begin
94 if (reset)
95 begin
96 int_miso_reg <= 16'd0;
97 cnt_good_reg <= 1'b0;
98 end
99 else
100 begin
101 int_miso_reg <= int_miso_wire;
102 cnt_good_reg <= (|cnt_bits_wire) & (cfg_data[1]);
103 end
104 end
105
106 // output logic
107 assign bus_miso = int_miso_reg;
108 assign bus_busy = 1'b0;
109 assign cnt_good = cnt_good_reg;
110
111endmodule
Note: See TracBrowser for help on using the repository browser.