add edge_check.v and frequency_divide.v and sequencer_check_dev.v
This commit is contained in:
parent
0cca85eb0d
commit
d7cde61a95
|
@ -0,0 +1,155 @@
|
|||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :11—29
|
||||
//--Module : edge_check
|
||||
//--Function: check a edge including: posedge,negedge,both clk
|
||||
//=======================================
|
||||
module edge_check (
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
input wire din_vld,
|
||||
input wire din,
|
||||
|
||||
output wire edge_pos,
|
||||
output wire edge_neg,
|
||||
output wire edge_both
|
||||
);
|
||||
//==========================< 信号 >=========================
|
||||
reg din_r;
|
||||
|
||||
//=========================================================
|
||||
//-- din_r: flip_flop
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
din_r <= 1'b0;
|
||||
end else begin
|
||||
din_r <= din;
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- edge_pos,edge_neg,edge_both
|
||||
//=========================================================
|
||||
assign edge_pos = din_vld & din & ~din_r;
|
||||
assign edge_neg = din_vld & ~din & din_r;
|
||||
assign edge_both= din_vld & edge_pos | edge_neg;
|
||||
|
||||
endmodule
|
||||
|
||||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :11—29
|
||||
//--Module : sequence_modulo3_detector
|
||||
//--Function: Detect if the input signal sequence din is a multiple of 3
|
||||
//=======================================
|
||||
module seq_mod3_detec(
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
input wire din_vld,
|
||||
input wire din,
|
||||
|
||||
output wire detect
|
||||
);
|
||||
//==========================< 参数 >=========================
|
||||
localparam IDLE = 3'b000;
|
||||
localparam S0 = 3'b001;
|
||||
localparam S1 = 3'b010;
|
||||
localparam S2 = 3'b100;
|
||||
|
||||
//==========================< 信号 >=========================
|
||||
reg[4-1:0] sta_cur;
|
||||
reg[4-1:0] sta_nxt;
|
||||
|
||||
//=========================================================
|
||||
//-- FSM-1: state transiate
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
sta_cur <= IDLE;
|
||||
end else begin
|
||||
sta_cur <= sta_nxt;
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- FSM-2: state jump condition
|
||||
//=========================================================
|
||||
always @(*) begin
|
||||
case (sta_cur)
|
||||
IDLE: begin
|
||||
if(!din_vld) begin
|
||||
sta_nxt = IDLE;
|
||||
end else begin
|
||||
if(din) begin
|
||||
sta_nxt = S0;
|
||||
end else begin
|
||||
sta_nxt = S1;
|
||||
end
|
||||
end
|
||||
end
|
||||
S0: begin
|
||||
if(!din_vld) begin
|
||||
sta_nxt = S0;
|
||||
end else begin
|
||||
if (din) begin
|
||||
sta_nxt = S1;
|
||||
end else begin
|
||||
sta_nxt = S0;
|
||||
end
|
||||
end
|
||||
end
|
||||
S1 : begin
|
||||
if(!din_vld) begin
|
||||
sta_nxt = S1;
|
||||
end else begin
|
||||
if(din) begin
|
||||
sta_nxt = S0;
|
||||
end else begin
|
||||
sta_nxt = S2;
|
||||
end
|
||||
end
|
||||
end
|
||||
S2: begin
|
||||
if(!din_vld) begin
|
||||
sta_nxt = IDLE;
|
||||
end else begin
|
||||
if(din) begin
|
||||
sta_nxt = S2;
|
||||
end else begin
|
||||
sta_nxt = S1;
|
||||
end
|
||||
end
|
||||
end
|
||||
default: sta_nxt = IDLE;
|
||||
endcase
|
||||
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- FSM-3: state action
|
||||
//=========================================================
|
||||
reg mod3_res;
|
||||
|
||||
always @(posedge clk) begin
|
||||
if(!rst_n)begin
|
||||
mod3_res <= 1'b0;
|
||||
end else begin
|
||||
case (sta_cur)
|
||||
IDLE: mod3_res <= 1'b0;
|
||||
S0: mod3_res <= 1'b1;
|
||||
S1: mod3_res <= 1'b0;
|
||||
S2: mod3_res <= 1'b0;
|
||||
default: mod3_res <= 1'b0;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- detect
|
||||
//=========================================================
|
||||
assign detect = mod3_res;
|
||||
|
||||
endmodule
|
|
@ -0,0 +1,223 @@
|
|||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :10—28
|
||||
//--Module : frequency_divide_even
|
||||
//--Function: to get the divided frenquency
|
||||
//=======================================
|
||||
module frequency_divide_even#(
|
||||
//==========================< 参数 >=========================
|
||||
parameter DIVISOR = 4
|
||||
)(
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
output wire clk_out
|
||||
);
|
||||
//==========================< 参数 >=========================
|
||||
|
||||
|
||||
//==========================< 信号 >=========================
|
||||
reg [4 -1:0] cnt;
|
||||
reg clk_div_r;
|
||||
|
||||
//=========================================================
|
||||
//-- 计数器
|
||||
//=========================================================
|
||||
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if(!rst_n) begin
|
||||
cnt <= 4'b0;
|
||||
end else begin
|
||||
if(cnt==(DIVISOR/2-1)) begin
|
||||
cnt <= 4'b0;
|
||||
end else begin
|
||||
cnt <= cnt + 1'b1;;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- clk_div_r
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
clk_div_r <= 1'b0;
|
||||
end else begin
|
||||
if(cnt==(DIVISOR/2-1)) begin
|
||||
clk_div_r <= ~clk_div_r;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assign clk_out = clk_div_r;
|
||||
|
||||
endmodule
|
||||
|
||||
|
||||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :10—28
|
||||
//--Module : frequency_divide_odd
|
||||
//--Function: to get the divided frenquency
|
||||
//=======================================
|
||||
|
||||
module frequency_divide_odd#(
|
||||
//==========================< 参数 >=========================
|
||||
parameter DIVISOR = 3
|
||||
)(
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
output wire clk_out_not_50,
|
||||
output wire clk_out_is_50
|
||||
);
|
||||
//==========================< 参数 >=========================
|
||||
|
||||
//==========================< 信号 >=========================
|
||||
reg [4 -1:0] cnt_pos, cnt_neg;
|
||||
reg clk_p, clk_n;
|
||||
|
||||
|
||||
//=========================================================
|
||||
//-- cnt_pos, cnt_neg
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
cnt_pos <= 'b0;
|
||||
end else begin
|
||||
if (cnt_pos==DIVISOR-1) begin
|
||||
cnt_pos <= 4'b0;
|
||||
end else begin
|
||||
cnt_pos <= cnt_pos + 1'b1;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
always @(negedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
cnt_neg <= 'b0;
|
||||
end else begin
|
||||
if (cnt_neg==DIVISOR-1) begin
|
||||
cnt_neg <= 4'b0;
|
||||
end else begin
|
||||
cnt_neg <= cnt_neg + 1'b1;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- clk_p, clk_n
|
||||
//=========================================================
|
||||
//----上升沿触发
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
clk_p <= 1'b0;
|
||||
end else begin
|
||||
if(cnt_pos==(DIVISOR-1)/2) begin
|
||||
clk_p <= ~clk_p;
|
||||
end else if(cnt_pos==0) begin
|
||||
clk_p <= ~clk_p;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
//----下降沿触发
|
||||
always @(negedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
clk_n <= 1'b0;
|
||||
end else begin
|
||||
if (cnt_neg==(DIVISOR-1)/2) begin
|
||||
clk_n <= ~clk_n;
|
||||
end else if (cnt_neg==0) begin
|
||||
clk_n <= ~clk_n;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
//----Output
|
||||
assign clk_out_not_50 = clk_p;
|
||||
assign clk_out_is_50 = clk_p | clk_n;
|
||||
|
||||
endmodule
|
||||
|
||||
|
||||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :10—28
|
||||
//--Module : frequency_divide_half
|
||||
//--Function: to get the divided frenquency
|
||||
//=======================================
|
||||
module frequency_divide_half #(
|
||||
//==========================< 参数 >=========================
|
||||
parameter HALF = 3.5
|
||||
)(
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
output wire clk_div
|
||||
);
|
||||
//==========================< 参数 >=========================
|
||||
//localparam DIVISOR = 2 * HALF;
|
||||
localparam DIVISOR = 7;
|
||||
|
||||
//==========================< 信号 >=========================
|
||||
reg [4 -1:0] cnt;
|
||||
reg clk_p,clk_n;
|
||||
|
||||
//=========================================================
|
||||
//-- cnt
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
cnt <= 1'b0;
|
||||
end else begin
|
||||
if (cnt==DIVISOR-1) begin
|
||||
cnt <= 'b0;
|
||||
end else begin
|
||||
cnt <= cnt + 1'b1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- clk_p : clk_p will be traversed when cnt is 0 and 4
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
clk_p <= 1'b0;
|
||||
end else begin
|
||||
if (cnt==0) begin
|
||||
clk_p <= 1;
|
||||
end else if (cnt==(DIVISOR/2)+1) begin //cnt will tranverse when 4
|
||||
clk_p <= 1;
|
||||
end else begin
|
||||
clk_p <= 0;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- clk_n : clk_n will be traversed when cnt is 1 and 4
|
||||
//=========================================================
|
||||
always @(negedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
clk_n <= 1'b0;
|
||||
end else begin
|
||||
if(cnt==1) begin
|
||||
clk_n <= 1;
|
||||
end else if(cnt==(DIVISOR)/2 +1) begin
|
||||
clk_n <= 1;
|
||||
end else begin
|
||||
clk_n <= 0;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
//=========================================================
|
||||
//-- clk_div_half
|
||||
//=========================================================
|
||||
assign clk_div = clk_p | clk_n;
|
||||
|
||||
endmodule
|
|
@ -0,0 +1,143 @@
|
|||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :10—25
|
||||
//--Module : sequence_check_det
|
||||
//--Function: check a sequence using shift_reg
|
||||
//=======================================
|
||||
module sequen_check_det(
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
input wire din,
|
||||
output reg det
|
||||
);
|
||||
//==========================< 参数 >=========================
|
||||
localparam SEQUENCE_DET = 8'b1100_1101;
|
||||
|
||||
//==========================< 信号 >=========================
|
||||
reg [8 -1:0] shift_data;
|
||||
|
||||
//=========================================================
|
||||
//-- shift_data
|
||||
//=========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if(!rst_n) begin
|
||||
shift_data <= 8'b0000_0000;
|
||||
end else begin
|
||||
shift_data <= {shift_data[6:0],din};
|
||||
end
|
||||
end
|
||||
|
||||
assign det = (shift_data==SEQUENCE_DET) ? 1'b1 : 1'b0;
|
||||
|
||||
endmodule
|
||||
|
||||
|
||||
//--way_2
|
||||
|
||||
//=======================================
|
||||
//--Author : colonel
|
||||
//--Date :10—25
|
||||
//--Module : sequence_check_det
|
||||
//--Function: check a sequence using FSM
|
||||
//=======================================
|
||||
module sequen_check_det_fsm(
|
||||
//==========================< 端口 >=========================
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
input wire din,
|
||||
output wire det
|
||||
);
|
||||
//==========================< 参数 >==========================
|
||||
localparam SEQUENCE_DET = 4'b1011;
|
||||
localparam IDLE = 4'b0000;
|
||||
localparam S1 = 4'b0001;
|
||||
localparam S2 = 4'b0010;
|
||||
localparam S3 = 4'b0100;
|
||||
localparam S4 = 4'b1000;
|
||||
|
||||
//==========================< 信号 >==========================
|
||||
reg [3:0] sta_cur;
|
||||
reg [3:0] sta_nxt;
|
||||
|
||||
//===========================================================
|
||||
//--FSM-1:fsm transition
|
||||
//===========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if(!rst_n) begin
|
||||
sta_cur <= IDLE;
|
||||
end else begin
|
||||
sta_cur <= sta_nxt;
|
||||
end
|
||||
end
|
||||
|
||||
//===========================================================
|
||||
//--FSM-2:fsm jumb condition
|
||||
//===========================================================
|
||||
always @(*) begin
|
||||
case (sta_cur)
|
||||
IDLE: begin
|
||||
if(din==1'b1) begin
|
||||
sta_nxt <= S1;
|
||||
end else begin
|
||||
sta_nxt <= IDLE;
|
||||
end
|
||||
end
|
||||
|
||||
S1: begin
|
||||
if(din==1'b0) begin
|
||||
sta_nxt <= S2;
|
||||
end else begin
|
||||
sta_nxt <= S1;
|
||||
end
|
||||
end
|
||||
|
||||
S2: begin
|
||||
if(din==1'b1) begin
|
||||
sta_nxt <= S3;
|
||||
end else begin
|
||||
sta_nxt <= IDLE;
|
||||
end
|
||||
end
|
||||
|
||||
S3: begin
|
||||
if(din==1'b1) begin
|
||||
sta_nxt <= S4;
|
||||
end else begin
|
||||
sta_nxt <= S2;
|
||||
end
|
||||
end
|
||||
|
||||
S4: begin
|
||||
if(din==1'b1) begin
|
||||
sta_nxt <= S1;
|
||||
end else begin
|
||||
sta_nxt <= S2;
|
||||
end
|
||||
end
|
||||
default: begin
|
||||
sta_nxt <= IDLE;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
|
||||
//===========================================================
|
||||
//--FSM-3:fsm action
|
||||
//--det logic
|
||||
//===========================================================
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if(!rst_n) begin
|
||||
det <= 1'b0;
|
||||
end else begin
|
||||
case (sta_cur)
|
||||
IDLE: det <= 1'b0;
|
||||
S1 : det <= 1'b0;
|
||||
S2 : det <= 1'b0;
|
||||
S3 : det <= 1'b0;
|
||||
S4 : det <= 1'b1;
|
||||
default: det <= 1'b0;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
Loading…
Reference in New Issue