Skip to content

Commit a090608

Browse files
authored
Lutram example (#112)
* WIP: lutram example first commmit * lutram example
1 parent ca10c24 commit a090608

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

examples/lutram/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# LUTRAM test project
2+

examples/lutram/build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
yosys -p "read_verilog lutram.v; read_verilog prbs.v; read_verilog top.v; synth_gowin -json lutram.json"
4+
nextpnr-gowin --json lutram.json --write lutram-tec0117-synth.json --device GW1NR-LV9QN88C6/I5 --cst ../tec0117.cst
5+
gowin_pack -d GW1N-9 -o lutram-tec0117.fs lutram-tec0117-synth.json

examples/lutram/lutram.v

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Author: Niels A. Moseley, [email protected]
2+
3+
`default_nettype none
4+
5+
/* 1-bit by 16 element SRAM */
6+
module LUTRAM16S1(
7+
input wire clk,
8+
input wire [3:0] ad,
9+
input wire wre,
10+
input wire di,
11+
output wire do);
12+
13+
reg memory[0:15];
14+
15+
always@(posedge clk)
16+
begin
17+
if (wre == 1)
18+
begin
19+
memory[ad] <= di;
20+
end
21+
end
22+
23+
assign do = memory[ad];
24+
25+
endmodule

examples/lutram/prbs.v

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Author: Niels A. Moseley, [email protected]
2+
3+
`default_nettype none
4+
5+
/* 1-bit random bit generator */
6+
module PRBS7(
7+
input wire clk,
8+
input wire next,
9+
output wire out);
10+
11+
reg [6:0] d;
12+
13+
always @(posedge clk)
14+
begin
15+
if (next == 1)
16+
d <= { d[5:0], d[6] ^ d[5] };
17+
18+
if (d == 0)
19+
d <= 1;
20+
end
21+
22+
assign out = d[0];
23+
24+
endmodule

examples/lutram/top.v

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Top level of lutram test
2+
//
3+
// A PRBS generator is used to write random bits into the RAM
4+
// and checks if the resulting data out is the same.
5+
//
6+
// For each error, a counter is incremented. The counter is displayed
7+
// on the LEDs of the TEC0117 board.
8+
//
9+
// Author: Niels A. Moseley, [email protected]
10+
//
11+
12+
`default_nettype none
13+
14+
module top(clk, led, rst);
15+
16+
// inputs
17+
input wire clk; // clock 12 MHz
18+
input wire rst;
19+
20+
wire dout;
21+
reg wre = 0;
22+
wire din;
23+
wire random_bit;
24+
25+
reg next_bit = 0;
26+
reg [3:0] address = 0;
27+
reg [1:0] state = 0;
28+
reg [23:0] blinkCounter = 0;
29+
30+
// outputs
31+
output reg [7:0] led = 0; // leds for debugging
32+
33+
// test state machine
34+
always @(posedge clk)
35+
begin
36+
next_bit <= 0;
37+
wre <= 0;
38+
if (rst == 0)
39+
begin
40+
blinkCounter <= 0;
41+
led[6:0] <= 0;
42+
end
43+
else
44+
begin
45+
blinkCounter <= blinkCounter + 1;
46+
case(state)
47+
2'b00: begin next_bit <= 1; address <= address + 1; end /* setup for next test */
48+
2'b01: begin wre <= 1; end /* write bit */
49+
2'b10: begin ; end
50+
2'b11:
51+
begin
52+
if (random_bit != dout)
53+
led[6:0] <= led[6:0] + 1;
54+
end
55+
endcase
56+
state <= state + 1;
57+
58+
end
59+
60+
led[7] <= blinkCounter[23];
61+
end
62+
63+
PRBS7 prbs
64+
(
65+
.clk(clk),
66+
.next(next_bit),
67+
.out(random_bit)
68+
);
69+
70+
LUTRAM16S1 ram
71+
(
72+
.clk(clk),
73+
.wre(wre),
74+
.ad(address),
75+
.di(random_bit),
76+
.do(dout)
77+
);
78+
79+
endmodule

0 commit comments

Comments
 (0)