Changeset 90 for trunk/MultiChannelUSB/oscilloscope.v
- Timestamp:
- Feb 27, 2010, 10:10:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/oscilloscope.v
r84 r90 1 1 module oscilloscope 2 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 3 input wire clock, frame, reset, 4 5 input wire [16:0] cfg_data, 6 7 input wire trg_flag, 8 9 input wire [47:0] osc_data, 10 11 output wire ram_wren, 12 output wire [19:0] ram_addr, 13 inout wire [17:0] ram_data, 14 15 input wire bus_ssel, bus_wren, 16 input wire [19:0] bus_addr, 17 input wire [15:0] bus_mosi, 18 19 output wire [15:0] bus_miso, 20 output wire bus_busy 9 21 ); 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) 22 23 24 reg [47:0] osc_data_reg, osc_data_next; 25 26 reg [19:0] cfg_cntr_max_reg, cfg_cntr_max_next; 27 reg [19:0] cfg_cntr_mid_reg, cfg_cntr_mid_next; 28 29 reg [2:0] int_case_reg, int_case_next; 30 31 reg int_trig_reg, int_trig_next; 32 reg [19:0] int_trig_addr_reg, int_trig_addr_next; 33 reg [19:0] int_cntr_reg, int_cntr_next; 34 35 reg [15:0] bus_mosi_reg [2:0]; 36 reg [15:0] bus_mosi_next [2:0]; 37 38 reg [15:0] bus_miso_reg, bus_miso_next; 39 reg bus_busy_reg, bus_busy_next; 40 41 reg ram_wren_reg [2:0]; 42 reg ram_wren_next [2:0]; 43 44 reg [17:0] ram_data_reg, ram_data_next; 45 reg [19:0] ram_addr_reg, ram_addr_next; 46 47 wire [17:0] ram_wren_wire; 48 49 assign ram_wren = ~ram_wren_reg[0]; 50 assign ram_addr = ram_addr_reg; 51 52 integer i; 53 genvar j; 54 55 generate 56 for (j = 0; j < 18; j = j + 1) 57 begin : SRAM_WREN 58 assign ram_wren_wire[j] = ram_wren_reg[2]; 59 assign ram_data[j] = ram_wren_wire[j] ? ram_data_reg[j] : 1'bz; 60 end 61 endgenerate 62 63 always @(posedge clock) 69 64 begin 70 65 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; 66 begin 67 osc_data_reg <= 48'd0; 68 ram_data_reg <= 18'd0; 69 ram_addr_reg <= 20'd0; 70 bus_miso_reg <= 16'd0; 71 bus_busy_reg <= 1'b0; 72 int_case_reg <= 5'd0; 73 int_cntr_reg <= 20'd0; 74 int_trig_reg <= 1'b0; 75 int_trig_addr_reg <= 20'd0; 76 cfg_cntr_max_reg <= 20'd0; 77 cfg_cntr_mid_reg <= 20'd0; 78 79 for(i = 0; i <= 2; i = i + 1) 80 begin 81 ram_wren_reg[i] <= 1'b0; 82 bus_mosi_reg[i] <= 16'd0; 83 end 79 84 end 80 85 else 81 86 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; 87 osc_data_reg <= osc_data_next; 88 ram_data_reg <= ram_data_next; 89 ram_addr_reg <= ram_addr_next; 90 bus_miso_reg <= bus_miso_next; 91 bus_busy_reg <= bus_busy_next; 92 int_case_reg <= int_case_next; 93 int_cntr_reg <= int_cntr_next; 94 int_trig_reg <= int_trig_next; 95 int_trig_addr_reg <= int_trig_addr_next; 96 cfg_cntr_max_reg <= cfg_cntr_max_next; 97 cfg_cntr_mid_reg <= cfg_cntr_mid_next; 98 99 for(i = 0; i <= 2; i = i + 1) 100 begin 101 ram_wren_reg[i] <= ram_wren_next[i]; 102 bus_mosi_reg[i] <= bus_mosi_next[i]; 103 end 89 104 end 90 105 end 106 91 107 92 108 always @* 93 109 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) 110 111 osc_data_next = osc_data_reg; 112 ram_data_next = ram_data_reg; 113 ram_addr_next = ram_addr_reg; 114 bus_miso_next = bus_miso_reg; 115 bus_busy_next = bus_busy_reg; 116 int_case_next = int_case_reg; 117 int_cntr_next = int_cntr_reg; 118 int_trig_next = int_trig_reg; 119 int_trig_addr_next = int_trig_addr_reg; 120 cfg_cntr_max_next = cfg_cntr_max_reg; 121 cfg_cntr_mid_next = cfg_cntr_mid_reg; 122 123 for(i = 0; i < 2; i = i + 1) 124 begin 125 ram_wren_next[i+1] = ram_wren_reg[i]; 126 bus_mosi_next[i+1] = bus_mosi_reg[i]; 127 end 128 ram_wren_next[0] = 1'b0; 129 bus_mosi_next[0] = 16'd0; 130 131 case (int_case_reg) 103 132 0: 104 133 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 134 ram_data_next = 18'd0; 135 ram_addr_next = 20'd0; 136 bus_busy_next = 1'b0; 137 int_cntr_next = 20'd0; 138 int_trig_next = 1'b0; 139 140 ram_data_next = {bus_mosi_reg[1][15:8], 1'b0, bus_mosi_reg[1][7:0], 1'b0}; 141 142 if (bus_ssel) 143 begin 144 bus_miso_next = {ram_data[17:10], ram_data[8:1]}; 145 ram_wren_next[0] = bus_wren; 146 if (bus_wren) 147 begin 148 ram_addr_next = bus_addr; 149 bus_mosi_next[0] = bus_mosi; 150 end 151 else 152 begin 153 // ram_addr_next = int_trig_addr_reg + bus_addr; 154 ram_addr_next = bus_addr; 155 end 156 end 157 else if (cfg_data[16]) 158 begin 159 // start recording 160 ram_wren_next[0] = 1'b1; 161 bus_busy_next = 1'b1; 162 int_case_next = 3'd1; 163 int_trig_addr_next = 20'd0; 164 cfg_cntr_max_next = {cfg_data[7:0], 10'd0}; 165 cfg_cntr_mid_next = {cfg_data[15:8], 10'd0}; 166 end 167 168 end 169 170 // sample recording 113 171 1: 114 172 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 173 ram_wren_next[0] = 1'b1; 174 if (frame) 175 begin 176 osc_data_next = osc_data; 177 ram_addr_next = ram_addr_reg + 20'd1; 178 int_case_next = 3'd2; 179 180 if ((~int_trig_reg) & (trg_flag) & 181 (int_cntr_reg == cfg_cntr_mid_reg)) 182 begin 183 int_trig_next = 1'b1; 184 int_trig_addr_next = ram_addr_reg; 185 end 186 187 if (int_trig_reg | (int_cntr_reg < cfg_cntr_mid_reg)) 188 begin 189 int_cntr_next = int_cntr_reg + 20'd1; 190 end 191 end 192 end 193 127 194 2: 128 195 begin 129 if (data_ready) 130 begin 131 wren_next = 1'b1; 132 data_next = data; 133 state_next = 4'd3; 134 end 196 ram_wren_next[0] = 1'b1; 197 ram_data_next = {osc_data_reg[15:8], 1'b0, osc_data_reg[7:0], 1'b0}; 198 ram_addr_next = ram_addr_reg + 20'd1; 199 int_case_next = 3'd3; 135 200 end 136 201 137 202 3: 138 203 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 204 ram_wren_next[0] = 1'b1; 205 ram_data_next = {osc_data_reg[31:24], 1'b0, osc_data_reg[23:16], 1'b0}; 206 ram_addr_next = ram_addr_reg + 20'd1; 207 int_case_next = 3'd4; 208 end 209 210 4: 211 begin 212 ram_wren_next[0] = 1'b1; 213 ram_data_next = {osc_data_reg[47:40], 1'b0, osc_data_reg[39:32], 1'b0}; 214 int_case_next = 3'd1; 215 if (int_cntr_reg >= cfg_cntr_max_reg) 216 begin 217 ram_wren_next[0] = 1'b0; 218 ram_addr_next = 20'd0; 219 int_case_next = 3'd0; 220 end 221 end 222 174 223 endcase 175 224 end 176 225 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; 226 assign bus_miso = bus_miso_reg; 227 assign bus_busy = bus_busy_reg; 180 228 181 229 endmodule
Note:
See TracChangeset
for help on using the changeset viewer.