source: trunk/MultiChannelUSB/oscilloscope.v@ 51

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

first attempt to use normal memory clock

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