Skip to content

Commit f97f011

Browse files
committed
Adding SystemVerilog versions of the demos
1 parent 376542b commit f97f011

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+602
-18
lines changed

demos/accumulate/Accumulate.sv

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
// Protect against undefined nets
5+
`default_nettype none
6+
7+
// This module represents an accumulator controlled by a down-counter. The data being
8+
// accumulated is from the SW[4:0] switches. KEY[0] is the active-low synchronous load
9+
// input. When KEY[0] is low the counter is loaded from switches SW[9:5]. When KEY[0] is
10+
// high the circuit accumulates each clock cycle until the counter reaches 0
11+
module Accumulate (CLOCK, RESETn, SW, LEDR);
12+
input logic CLOCK;
13+
input logic RESETn;
14+
input logic [ 9: 0] SW;
15+
output logic [ 9: 0] LEDR;
16+
17+
18+
logic [ 4: 0] count;
19+
logic [ 9: 0] sum;
20+
logic [ 4: 0] x, y;
21+
logic z;
22+
23+
assign x = SW[4:0];
24+
assign y = SW[9:5];
25+
26+
27+
// the accumulator
28+
always_ff @(posedge CLOCK)
29+
if (RESETn == 1'b0) // synchronous clear
30+
sum <= 0;
31+
else if (z == 1'b1)
32+
sum <= sum + x;
33+
34+
// the counter
35+
always_ff @(posedge CLOCK)
36+
if (RESETn == 1'b0) // synchronous load
37+
count <= y;
38+
else if (z == 1'b1)
39+
count <= count - 1'b1;
40+
41+
42+
assign z = | count;
43+
assign LEDR = sum;
44+
45+
endmodule

demos/accumulate/Top.sv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
// Protect against undefined nets
5+
`default_nettype none
6+
7+
module Top (CLOCK_50, KEY, SW, LEDR);
8+
input logic CLOCK_50; // DE-series 50 MHz clock signal
9+
input logic [ 3: 0] KEY; // DE-series pushbuttons
10+
input logic [ 9: 0] SW; // DE-series switches
11+
output logic [ 9: 0] LEDR; // DE-series LEDs
12+
13+
Accumulate U1 (CLOCK_50, KEY[0], SW, LEDR);
14+
15+
endmodule
16+

demos/accumulate/sim/run_compile.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ vlog ../tb/*.v
55
if exist ../*.v (
66
vlog ../*.v
77
)
8+
if exist ../*.sv (
9+
vlog ../*.sv
10+
)
811
if exist ../*.vhd (
912
vcom ../*.vhd
1013
)

demos/accumulate/sim/run_compile.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ if [ -f ../Top.v ]
1010
then
1111
vlog ../*.v
1212
fi
13+
if [ -f ../Top.sv ]
14+
then
15+
vlog ../*.sv
16+
fi
1317
if [ -f ../Top.vhd ]
1418
then
1519
vcom ../*.vhd

demos/addern/Addern.sv

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
// Protect against undefined nets
5+
`default_nettype none
6+
7+
// A multi-bit adder
8+
module Addern (Cin, X, Y, Sum, Cout);
9+
parameter n = 4;
10+
11+
input logic Cin;
12+
input logic [n-1:0] X, Y;
13+
output logic [n-1:0] Sum;
14+
output logic Cout;
15+
16+
assign {Cout, Sum} = X + Y + Cin;
17+
18+
endmodule

demos/addern/Top.sv

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
// Protect against undefined nets
5+
`default_nettype none
6+
7+
module Top (KEY, SW, LEDR);
8+
input logic [ 3: 0] KEY; // DE-series pushbuttons
9+
input logic [ 9: 0] SW; // DE-series switches
10+
output logic [ 9: 0] LEDR; // DE-series LEDs
11+
12+
Addern U1 (SW[9], SW[3:0], SW[7:4], LEDR[3:0], LEDR[4]);
13+
14+
endmodule
15+

demos/addern/sim/run_compile.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ vlog ../tb/*.v
55
if exist ../*.v (
66
vlog ../*.v
77
)
8+
if exist ../*.sv (
9+
vlog ../*.sv
10+
)
811
if exist ../*.vhd (
912
vcom ../*.vhd
1013
)

demos/addern/sim/run_compile.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ if [ -f ../Top.v ]
1010
then
1111
vlog ../*.v
1212
fi
13+
if [ -f ../Top.sv ]
14+
then
15+
vlog ../*.sv
16+
fi
1317
if [ -f ../Top.vhd ]
1418
then
1519
vcom ../*.vhd

demos/counter/Counter.sv

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
// Protect against undefined nets
5+
`default_nettype none
6+
7+
// This module implements an n-bit counter. Upper bits of the counter, driven by the
8+
// 50 MHz clock signal, are displayed on the LEDR lights. The counter can be reset to 0
9+
// using KEY[0].
10+
module Counter (CLOCK, RESETn, LEDR);
11+
input logic CLOCK;
12+
input logic RESETn;
13+
output logic [ 9: 0] LEDR;
14+
15+
parameter n = 24;
16+
17+
logic [n-1:0] count;
18+
19+
// the counter
20+
always_ff @(posedge CLOCK)
21+
if (RESETn == 1'b0) // synchronous clear
22+
count <= 0;
23+
else
24+
count <= count + 1;
25+
26+
assign LEDR = count[n-1:n-10];
27+
endmodule

demos/counter/Top.sv

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
// Protect against undefined nets
5+
`default_nettype none
6+
7+
module Top (CLOCK_50, KEY, LEDR);
8+
input logic CLOCK_50; // DE-series 50 MHz clock signal
9+
input logic [ 3: 0] KEY; // DE-series pushbuttons
10+
output logic [ 9: 0] LEDR; // DE-series LEDs
11+
12+
Counter U1 (CLOCK_50, KEY[0], LEDR);
13+
14+
endmodule
15+

0 commit comments

Comments
 (0)