-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30c95d3
commit 2991b50
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
module Led_blinker | ||
( | ||
i_clock, | ||
i_enable, | ||
i_switch_1, | ||
i_switch_2, | ||
o_led_drive | ||
); | ||
|
||
input i_clock; | ||
input i_enable; | ||
input i_switch_1; | ||
input i_switch_2; | ||
output o_led_drive; | ||
|
||
parameter c_CNT_100HZ = 125; | ||
parameter c_CNT_50HZ = 250; | ||
parameter c_CNT_10HZ = 1250; | ||
parameter c_CNT_1HZ = 12500; | ||
|
||
reg [31:0] r_CNT_100HZ = 0; | ||
reg [31:0] r_CNT_50HZ = 0; | ||
reg [31:0] r_CNT_10HZ = 0; | ||
reg [31:0] r_CNT_1HZ = 0; | ||
|
||
reg r_TOGGLE_100HZ = 1'b0; | ||
reg r_TOGGLE_50HZ = 1'b0; | ||
reg r_TOGGLE_10HZ = 1'b0; | ||
reg r_TOGGLE_1HZ = 1'b0; | ||
|
||
reg r_LED_SELECT; | ||
//wire w_LED_SELECT; | ||
|
||
|
||
|
||
always @(posedge i_clock) | ||
begin | ||
if (c_CNT_100HZ == c_CNT_100HZ - 1) | ||
begin | ||
r_TOGGLE_100HZ <= !r_TOGGLE_100HZ; | ||
r_TOGGLE_100HZ <= 0; | ||
end | ||
else | ||
r_CNT_100HZ <= r_CNT_100HZ + 1; | ||
end | ||
|
||
always @(posedge i_clock) | ||
begin | ||
if (c_CNT_50HZ == c_CNT_50HZ - 1) | ||
begin | ||
r_TOGGLE_50HZ <= !r_TOGGLE_50HZ; | ||
r_TOGGLE_50HZ <= 0; | ||
end | ||
else | ||
r_CNT_50HZ <= r_CNT_50HZ + 1; | ||
end | ||
|
||
always @(posedge i_clock) | ||
begin | ||
if (c_CNT_10HZ == c_CNT_10HZ - 1) | ||
begin | ||
r_TOGGLE_10HZ <= !r_TOGGLE_10HZ; | ||
r_TOGGLE_10HZ <= 0; | ||
end | ||
else | ||
r_CNT_10HZ <= r_CNT_10HZ + 1; | ||
end | ||
|
||
always @(posedge i_clock) | ||
begin | ||
if (c_CNT_1HZ == c_CNT_1HZ - 1) | ||
begin | ||
r_TOGGLE_1HZ <= !r_TOGGLE_1HZ; | ||
r_TOGGLE_1HZ <= 0; | ||
end | ||
else | ||
r_CNT_1HZ <= r_CNT_1HZ + 1; | ||
end | ||
|
||
always @(*) begin | ||
case ({i_switch_1, i_switch_2}) | ||
/* verilator lint_off COMBDLY */ | ||
2'b11 : r_LED_SELECT <= r_TOGGLE_1HZ; | ||
2'b10 : r_LED_SELECT <= r_TOGGLE_10HZ; | ||
2'b01 : r_LED_SELECT <= r_TOGGLE_50HZ; | ||
2'b00 : r_LED_SELECT <= r_TOGGLE_100HZ; | ||
/* verilator lint_on COMBDLY */ | ||
endcase | ||
end | ||
|
||
assign o_led_drive = r_LED_SELECT & i_enable; | ||
|
||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
VERILATOR_ROOT := ../.. | ||
PROJECT_NAME := Led_blinker | ||
SOURCES := *.sv | ||
SIMFILES := *.cpp | ||
|
||
include $(VERILATOR_ROOT)/verilator.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "VLed_blinker.h" | ||
#include "verilated.h" | ||
|
||
#include <cassert> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
int main(int argc, char** argv) { | ||
VLed_blinker* top = new VLed_blinker; | ||
Verilated::commandArgs(argc, argv); | ||
|
||
int stimuli_a[] = { 2, -1, 1, -6 }; | ||
int stimuli_b[] = { 4, 5, 2, 7 }; | ||
|
||
for (int i = 0; i < sizeof(stimuli_a) / sizeof(stimuli_a[0]); i++) { | ||
if (Verilated::gotFinish()) break; | ||
|
||
top->a = stimuli_a[i]; | ||
top->b = stimuli_b[i]; | ||
|
||
top->eval(); | ||
|
||
assert(top->c == (stimuli_a[i] + stimuli_b[i])); | ||
} | ||
|
||
delete top; | ||
return 0; | ||
} |