add seq_detector_1011
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"extensionVersion": "1.6.1",
|
||||
"fileName": "c:\\Users\\elied\\Nextcloud\\garage\\Learn_FPGA\\seq_detector_1011\\seq_detecotr_1011.vcd",
|
||||
"markerTime": null,
|
||||
"altMarkerTime": null,
|
||||
"displayTimeUnit": "ps",
|
||||
"selectedSignal": {
|
||||
"name": "tb_seq_detector_1011.clk",
|
||||
"msb": -1,
|
||||
"lsb": -1
|
||||
},
|
||||
"zoomRatio": 0.005058356714266344,
|
||||
"scrollLeft": 0,
|
||||
"defaultPixelTime": 100000,
|
||||
"displayedSignals": [
|
||||
{
|
||||
"dataType": "netlist-variable",
|
||||
"netlistId": 0,
|
||||
"name": "detected",
|
||||
"scopePath": [
|
||||
"tb_seq_detector_1011"
|
||||
],
|
||||
"numberFormat": "binary",
|
||||
"colorIndex": 0,
|
||||
"rowHeight": 1,
|
||||
"verticalScale": 1,
|
||||
"nameType": "fullPath",
|
||||
"customName": "detected",
|
||||
"renderType": "binary",
|
||||
"valueLinkEnable": false
|
||||
},
|
||||
{
|
||||
"dataType": "netlist-variable",
|
||||
"netlistId": 2,
|
||||
"name": "in",
|
||||
"scopePath": [
|
||||
"tb_seq_detector_1011"
|
||||
],
|
||||
"numberFormat": "binary",
|
||||
"colorIndex": 0,
|
||||
"rowHeight": 1,
|
||||
"verticalScale": 1,
|
||||
"nameType": "fullPath",
|
||||
"customName": "in",
|
||||
"renderType": "binary",
|
||||
"valueLinkEnable": false
|
||||
},
|
||||
{
|
||||
"dataType": "netlist-variable",
|
||||
"netlistId": 3,
|
||||
"name": "rst",
|
||||
"scopePath": [
|
||||
"tb_seq_detector_1011"
|
||||
],
|
||||
"numberFormat": "binary",
|
||||
"colorIndex": 0,
|
||||
"rowHeight": 1,
|
||||
"verticalScale": 1,
|
||||
"nameType": "fullPath",
|
||||
"customName": "rst",
|
||||
"renderType": "binary",
|
||||
"valueLinkEnable": false
|
||||
},
|
||||
{
|
||||
"dataType": "netlist-variable",
|
||||
"netlistId": 1,
|
||||
"name": "clk",
|
||||
"scopePath": [
|
||||
"tb_seq_detector_1011"
|
||||
],
|
||||
"numberFormat": "binary",
|
||||
"colorIndex": 0,
|
||||
"rowHeight": 1,
|
||||
"verticalScale": 1,
|
||||
"nameType": "fullPath",
|
||||
"customName": "clk",
|
||||
"renderType": "binary",
|
||||
"valueLinkEnable": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
$date
|
||||
Sun Nov 29 10:28:41 2026
|
||||
$end
|
||||
$version
|
||||
Icarus Verilog
|
||||
$end
|
||||
$timescale
|
||||
1ps
|
||||
$end
|
||||
$scope module tb_seq_detector_1011 $end
|
||||
$var wire 1 ! detected $end
|
||||
$var reg 1 " clk $end
|
||||
$var reg 1 # in $end
|
||||
$var reg 1 $ rst $end
|
||||
$scope module dut $end
|
||||
$var wire 1 " clk $end
|
||||
$var wire 1 # in $end
|
||||
$var wire 1 $ rst $end
|
||||
$var wire 1 ! detected $end
|
||||
$var reg 3 % current_state [2:0] $end
|
||||
$var reg 3 & next_state [2:0] $end
|
||||
$upscope $end
|
||||
$upscope $end
|
||||
$enddefinitions $end
|
||||
$comment Show the parameter values. $end
|
||||
$dumpall
|
||||
$end
|
||||
#0
|
||||
$dumpvars
|
||||
b0 &
|
||||
bx %
|
||||
1$
|
||||
0#
|
||||
0"
|
||||
x!
|
||||
$end
|
||||
#5000
|
||||
0!
|
||||
b0 %
|
||||
1"
|
||||
#10000
|
||||
0"
|
||||
#15000
|
||||
1"
|
||||
#20000
|
||||
0"
|
||||
#25000
|
||||
b1 &
|
||||
1#
|
||||
0$
|
||||
1"
|
||||
#30000
|
||||
0"
|
||||
#35000
|
||||
b10 &
|
||||
0#
|
||||
b1 %
|
||||
1"
|
||||
#40000
|
||||
0"
|
||||
#45000
|
||||
b11 &
|
||||
b10 %
|
||||
1#
|
||||
1"
|
||||
#50000
|
||||
0"
|
||||
#55000
|
||||
b100 &
|
||||
b11 %
|
||||
1"
|
||||
#60000
|
||||
0"
|
||||
#65000
|
||||
b10 &
|
||||
1!
|
||||
b100 %
|
||||
0#
|
||||
1"
|
||||
#70000
|
||||
0"
|
||||
#75000
|
||||
b11 &
|
||||
1#
|
||||
0!
|
||||
b10 %
|
||||
1"
|
||||
#80000
|
||||
0"
|
||||
#85000
|
||||
b100 &
|
||||
b11 %
|
||||
1"
|
||||
#90000
|
||||
0"
|
||||
#95000
|
||||
b10 &
|
||||
0#
|
||||
1!
|
||||
b100 %
|
||||
1"
|
||||
#100000
|
||||
0"
|
||||
#105000
|
||||
b11 &
|
||||
0!
|
||||
b10 %
|
||||
1#
|
||||
1"
|
||||
#110000
|
||||
0"
|
||||
#115000
|
||||
b10 &
|
||||
0#
|
||||
b11 %
|
||||
1"
|
||||
#120000
|
||||
0"
|
||||
#125000
|
||||
b11 &
|
||||
b10 %
|
||||
1#
|
||||
1"
|
||||
#130000
|
||||
0"
|
||||
#135000
|
||||
b100 &
|
||||
b11 %
|
||||
1"
|
||||
#140000
|
||||
0"
|
||||
#145000
|
||||
b10 &
|
||||
1!
|
||||
b100 %
|
||||
0#
|
||||
1"
|
||||
#150000
|
||||
0"
|
||||
#155000
|
||||
b0 &
|
||||
0!
|
||||
b10 %
|
||||
1"
|
||||
#160000
|
||||
0"
|
||||
#165000
|
||||
b0 %
|
||||
1"
|
||||
@@ -0,0 +1,45 @@
|
||||
module seq_detector_1011 (
|
||||
input logic clk,
|
||||
input logic rst,
|
||||
input logic in,
|
||||
output logic detected
|
||||
);
|
||||
|
||||
|
||||
typedef enum logic [2:0]
|
||||
{
|
||||
IDLE,
|
||||
S1,
|
||||
S10,
|
||||
S101,
|
||||
S1011
|
||||
} state_t;
|
||||
|
||||
state_t current_state, next_state;
|
||||
|
||||
always_ff @(posedge clk) begin
|
||||
if (rst) begin
|
||||
current_state <= IDLE;
|
||||
end else begin
|
||||
current_state <= next_state;
|
||||
end
|
||||
end
|
||||
|
||||
always_comb begin
|
||||
next_state = IDLE;
|
||||
case (current_state)
|
||||
IDLE : if (in) next_state = S1; else next_state = IDLE;
|
||||
S1 : if (in) next_state = S1; else next_state = S10;
|
||||
S10 : if (in) next_state = S101; else next_state = IDLE;
|
||||
S101 : if (in) next_state = S1011; else next_state = S10;
|
||||
S1011 : if (in) next_state = S1; else next_state = S10;
|
||||
default : next_state = IDLE;
|
||||
endcase
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
assign detected = (current_state == S1011);
|
||||
|
||||
endmodule
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
module tb_seq_detector_1011;
|
||||
|
||||
logic clk;
|
||||
logic rst;
|
||||
logic in;
|
||||
logic detected;
|
||||
|
||||
seq_detector_1011 dut(
|
||||
.clk(clk),
|
||||
.rst(rst),
|
||||
.in(in),
|
||||
.detected(detected)
|
||||
);
|
||||
|
||||
initial begin
|
||||
clk = 1'b0;
|
||||
forever #5 clk = ~clk;
|
||||
end
|
||||
|
||||
initial begin
|
||||
$dumpfile("seq_detector_1011.vcd");
|
||||
$dumpvars(0, tb_seq_detector_1011);
|
||||
|
||||
rst = 1'b1;
|
||||
in = 1'b0;
|
||||
// detected = 1'b0; inutile output
|
||||
|
||||
#20;
|
||||
|
||||
@(posedge clk);
|
||||
|
||||
rst <= 1'b0;
|
||||
|
||||
in <= 1'b1; @(posedge clk); // Bit 1
|
||||
in <= 1'b0; @(posedge clk); // Bit 0
|
||||
in <= 1'b1; @(posedge clk); // Bit 1
|
||||
in <= 1'b1; @(posedge clk); // Bit 1 -> détection #1 attendue au cycle suivant
|
||||
in <= 1'b0; @(posedge clk); // Bit 0
|
||||
in <= 1'b1; @(posedge clk); // Bit 1
|
||||
in <= 1'b1; @(posedge clk); // Bit 1 -> détection #2 (chevauchement)
|
||||
in <= 1'b0; @(posedge clk); // Bit 0
|
||||
in <= 1'b1; @(posedge clk); // Bit 1
|
||||
in <= 1'b0; @(posedge clk); // Bit 0
|
||||
in <= 1'b1; @(posedge clk); // Bit 1
|
||||
in <= 1'b1; @(posedge clk); // Bit 1 -> détection #3 (chevauchement 101011)
|
||||
|
||||
in <= 1'b0;
|
||||
repeat (2) @(posedge clk); // Laisse 2 cycles pour voir la dernière détection retomber
|
||||
|
||||
$display("Fin de la simulation.");
|
||||
$finish;
|
||||
end;
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user