source: trunk/MultiChannelUSB/oscilloscope.v@ 86

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

improve timings in all components

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