@@ -18,6 +18,8 @@ Dual-port RAM is a type of computer memory that allows
18
18
two separate devices to read and write data simultaneously.
19
19
This is achieved by having two separate access ports, one for each device.
20
20
21
+ The B port will have precedence if data is written to both ports at the same time.
22
+
21
23
_ I used
22
24
[ iverilog] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/hardware/tools/simulation/iverilog-cheat-sheet )
23
25
to simulate and
50
52
behavioral model,
51
53
52
54
``` verilog
53
- // DATA TYPES
54
- reg [7:0] mem [0:15];
55
- reg [3:0] address_register_A, address_register_B;
55
+ // PARAMETERS
56
+ parameter DATA_WIDTH = 8;
57
+ parameter ADDR_WIDTH = 4;
58
+ parameter MEM_DEPTH = 16;
56
59
57
- // OUTPUT (THIS MAKES IT SYNCHRONOUS)
58
- assign data_out_A = mem[address_register_A];
59
- assign data_out_B = mem[address_register_B];
60
+ // DATA TYPES
61
+ reg [DATA_WIDTH-1:0] mem [0:MEM_DEPTH-1]; // RAM (16x8)
60
62
61
- // RAM
63
+ // PORT A
62
64
// ALWAYS BLOCK with NON-BLOCKING PROCEDURAL ASSIGNMENT STATEMENT
63
65
always @(posedge clk_A) begin
66
+ // WRITE (DATA PASS)
64
67
if (we_A) begin
65
68
mem[addr_A] <= data_in_A;
69
+ data_out_A <= data_in_A;
70
+ // READ
66
71
end else begin
67
- address_register_A <= addr_A;
72
+ data_out_A <= mem[ addr_A] ;
68
73
end
69
74
end
70
75
71
- // RAM
76
+ // PORT B - HAS PRECEDENCE FOR WRITE
72
77
// ALWAYS BLOCK with NON-BLOCKING PROCEDURAL ASSIGNMENT STATEMENT
73
78
always @(posedge clk_B) begin
79
+ //WRITE (DATA PASS)
74
80
if (we_B) begin
75
81
mem[addr_B] <= data_in_B;
82
+ data_out_B <= data_in_B;
83
+ //READ
76
84
end else begin
77
- address_register_B <= addr_B;
85
+ data_out_B <= mem[ addr_B] ;
78
86
end
79
87
end
88
+
89
+ endmodule
80
90
```
81
91
82
92
## RUN (SIMULATE)
@@ -118,34 +128,34 @@ TEST START --------------------------------
118
128
119
129
| TIME(ns) | WE_A | ADDR_A | DATA_IN_A | DATA_OUT_A | WE_B | ADDR_B | DATA_IN_B | DATA_OUT_B |
120
130
----------------------------------------------------------------------------------------------
121
- 1 INIT | 12 | | 1 | 0000 | 00000000 | xxxxxxxx |
122
- 1 INIT | 15 | 1 | 0000 | 00000000 | xxxxxxxx |
123
- 2 WR_B | 26 | | 1 | 0001 | 11110011 | xxxxxxxx |
124
- 2 WR_A | 35 | 1 | 0000 | 11110000 | xxxxxxxx |
125
- 3 WR_B | 40 | | 1 | 0011 | 11001111 | xxxxxxxx |
126
- 4 WR_B | 54 | | 1 | 1111 | 11101010 | xxxxxxxx |
127
- 3 WR_A | 55 | 1 | 0001 | 00001111 | xxxxxxxx |
128
- 5 RD_B | 68 | | 0 | 0001 | xxxxxxxx | 00001111 |
129
- 4 WR_A | 75 | 1 | 1110 | 10101010 | xxxxxxxx |
131
+ 1 INIT | 12 | | 1 | 0000 | 00000000 | 00000000 |
132
+ 1 INIT_ | 15 | 1 | 0000 | 00000000 | 00000000 |
133
+ 2 WR_B | 26 | | 1 | 0001 | 11110011 | 11110011 |
134
+ 2 WR_A_ | 35 | 1 | 0000 | 11110000 | 11110000 |
135
+ 3 WR_B | 40 | | 1 | 0011 | 11001111 | 11001111 |
136
+ 4 WR_B | 54 | | 1 | 1110 | 11101010 | 11101010 |
137
+ 3 WR_A_ | 55 | 1 | 0001 | 00001111 | 00001111 |
138
+ 5 RD_B | 68 | | 0 | 1110 | xxxxxxxx | 11101010 |
139
+ 4 WR_A_ | 75 | 1 | 1110 | 10101010 | 10101010 |
130
140
6 RD_B | 82 | | 0 | 0011 | xxxxxxxx | 11001111 |
131
- 5 RD_A | 95 | 0 | 0000 | xxxxxxxx | 11110000 |
132
- 7 RD_B | 96 | | 0 | 1111 | xxxxxxxx | 11101010 |
133
- 8 RD_B | 110 | | 0 | 1110 | xxxxxxxx | 10101010 |
134
- 6 RD_A | 115 | 0 | 0001 | xxxxxxxx | 00001111 |
141
+ 5 RD_A_ | 95 | 0 | 1110 | xxxxxxxx | 10101010 |
142
+ 7 RD_B | 96 | | 0 | 1111 | xxxxxxxx | xxxxxxxx |
143
+ 8 RD_B | 110 | | 0 | 0011 | xxxxxxxx | 11001111 |
144
+ 6 RD_A_ | 115 | 0 | 0001 | xxxxxxxx | 00001111 |
135
145
9 RD_B | 124 | | 0 | 1001 | xxxxxxxx | xxxxxxxx |
136
- 7 RD_A | 135 | 0 | 1110 | xxxxxxxx | 10101010 |
137
- 10 RD_B | 138 | | 0 | 1111 | xxxxxxxx | 11101010 |
138
- 11 WR_B | 152 | | 1 | 1111 | 00000000 | 00000000 |
139
- 8 WR_A | 155 | 1 | 1001 | 00000111 | 10101010 |
140
- 12 WR_B | 166 | | 1 | 0001 | 00011000 | 00000000 |
141
- 9 WR_A | 175 | 1 | 1111 | 11111010 | 10101010 |
142
- 13 RD_B | 180 | | 0 | 1111 | xxxxxxxx | 11111010 |
146
+ 7 RD_A_ | 135 | 0 | 0011 | xxxxxxxx | 11001111 |
147
+ 10 RD_B | 138 | | 0 | 1111 | xxxxxxxx | xxxxxxxx |
148
+ 11 WR_B | 152 | | 1 | 1111 | 01000000 | 01000000 |
149
+ 8 WR_A_ | 155 | 1 | 1001 | 00000111 | 00000111 |
150
+ 12 WR_B | 166 | | 1 | 0001 | 00011000 | 00011000 |
151
+ 9 WR_A_ | 175 | 1 | 1111 | 11111010 | 11111010 |
152
+ 13 RD_B | 180 | | 0 | 0001 | xxxxxxxx | 00011000 |
143
153
14 RD_B | 194 | | 0 | 0001 | xxxxxxxx | 00011000 |
144
- 10 WR_A | 195 | 1 | 1100 | 00000011 | 10101010 |
145
- 11 WR_A | 215 | 1 | 0010 | 00001111 | 10101010 |
146
- 12 RD_A | 235 | 0 | 0001 | xxxxxxxx | 00011000 |
147
- 13 RD_A | 255 | 0 | 1111 | xxxxxxxx | 11111010 |
148
- 14 RD_A | 275 | 0 | 0001 | xxxxxxxx | 00011000 |
154
+ 10 WR_A_ | 195 | 1 | 1100 | 00000011 | 00000011 |
155
+ 11 WR_A_ | 215 | 1 | 0010 | 00001111 | 00001111 |
156
+ 12 RD_A_ | 235 | 0 | 0001 | xxxxxxxx | 00011000 |
157
+ 13 RD_A_ | 255 | 0 | 0001 | xxxxxxxx | 00011000 |
158
+ 14 RD_A_ | 275 | 0 | 0001 | xxxxxxxx | 00011000 |
149
159
150
160
VECTORS_A: 14
151
161
ERRORS_A: 0
0 commit comments