I have a set of test vectors saved in a csv file and formatted as
follows:
1 | 0010,1000,1010
|
2 | 1110,0101,0001
|
3 | 1001,0001,0000
|
These are randomly generated and can be of any arbitrary length or
number. Here the number is 3 (3 vectors per row) and length is 4 (4 bits
for each vector).
I wanted to read these vectors in verilog and apply them to an array of
instastiated modules. In other words, 0010 will be applied to the first
instance, 1010 to the third instance. Next apply 1110 to first instance,
0001 to the third and so on.
We have three latches (Lat Module) and we are generating 3 instances of
it in Lat_array module. I want the operation be like: first indexed
instance gets the first 4 bits, second instance gets the second set of
four bits and the final instance gets the last four bits in the row. All
of them get the 4bits at the same time and output at the same. After
that, the data in the next row is applied in the same order as another
input test vectors. The desired vs actual waveforms are attached.
I tried the following code, I could test a single module, but I dont
know how to test several instances using the test vectors above. Could
you please guide me where I doing wrong and how to implement this?
Top level module:
1 | module Lat_array #(parameter number =3, parameter length = 4)(ins, clks, resets,outs);
|
2 |
|
3 | input [length- 1:0] ins;
|
4 |
|
5 | input clks, resets;
|
6 |
|
7 | output [length-1:0] outs;
|
8 |
|
9 | generate
|
10 | genvar i;
|
11 | for (i=0; i<number; i=i+1) begin
|
12 | Lat lat(
|
13 | .clk(clks)
|
14 | ,.reset(resets)
|
15 | ,.in(ins)
|
16 | ,.out(outs)
|
17 | );
|
18 | end
|
19 | endgenerate
|
20 |
|
21 | endmodule
|
The Lat module:
1 | module Lat #(parameter length = 4)(in, clk, reset,out);
|
2 |
|
3 | input [length- 1:0] in;
|
4 | input clk, reset;
|
5 |
|
6 | output [length-1:0] out;
|
7 |
|
8 | reg [length-1:0] res;
|
9 |
|
10 | always @ (posedge clk) begin
|
11 | if (!reset)
|
12 | res <= 0;
|
13 | else
|
14 | res <= in;
|
15 | end
|
16 | assign out = res;
|
17 |
|
18 | endmodule
|
Testbench:
1 | `timescale 1ns/1ps
|
2 |
|
3 | module tb;
|
4 |
|
5 | parameter number = 3;
|
6 | parameter length = 4;
|
7 |
|
8 | reg [length-1:0] in;
|
9 |
|
10 | reg clk, reset;
|
11 |
|
12 | wire [length-1:0] out;
|
13 |
|
14 | Lat_array #(.number(number), .length(length)) lat_insts (.ins(in), .clks(clk), .resets(reset), .outs(out));
|
15 |
|
16 | initial begin
|
17 | reset <=0;
|
18 | clk <=0;
|
19 | end
|
20 |
|
21 | always @(clk) #100 clk <= ~clk;
|
22 |
|
23 |
|
24 | reg [length-1:0] temp;
|
25 | reg [length- 1:0] test_in [(3*number)-1:0];
|
26 |
|
27 | integer f, k;
|
28 |
|
29 | initial begin
|
30 |
|
31 | #500 reset <= 1;
|
32 | in <= 0;
|
33 |
|
34 | f = $fopen("test.csv", "r");
|
35 | for (integer i = 0; i < 3; i = i + 1)
|
36 | //while(! $feof(f))
|
37 | begin
|
38 | for(integer j = 0; j < number; j = j + 1)
|
39 | begin
|
40 |
|
41 | k = $fscanf(f,"%b,",temp);
|
42 | $display("%b", temp);
|
43 |
|
44 | test_in[j] = temp;
|
45 | end
|
46 | #10; in = test_in[i-1];
|
47 | end
|
48 | #200 reset <=0;
|
49 | $monitor("in=%b, out=%b", in, out);
|
50 | #1000 $finish;
|
51 | end
|
52 | endmodule
|