|
发表于 2008-5-10 15:36:35
|
显示全部楼层
/***************************************************************
说明:假设a,b,c信号均在clk domain,即同步信号
code中状态机除非reset,没有返回IDLE的路径,通
常应该设置一个返回的控制信号.不知道满足不满足
楼主的需求,没有经过仿真,仅供参考
***************************************************************/
module test(
c,
a,
b,
clk,
rst_n
);
//===========================
//parameter declaration
//===========================
parameter UDLY = 1;
parameter IDLE = 1'b0;
parameter START = 1'b1;
//===========================
//ports declaration
//===========================
output c;
input a;
input b;
input clk;
input rst_n;
//===========================
//signals declaration
//===========================
reg cur_st;
reg nxt_st;
reg a_delay;
wire a_pose_edge;
wire c;
//===========================
//main code
//===========================
//a from 0 to 1
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
a_delay <= 1'b0;
else
a_delay <= #UDLY a;
end
assign a_pose_edge = !a_delay & a;
//state machine
always@(cur_st or a_pose_edge)
begin
case(cur_st)
IDLE:
if(a_pose_edge)
nxt_st = START;
else
nxt_st = IDLE;
START:
nxt_st = START;
default:
nxt_st = IDLE;
endcase
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
cur_st <= IDLE;
else
cur_st <= #UDLY nxt_st;
end
assign c = (cur_st == START)? b : 1'b0;
//=========================end code========================
endmodule
[ 本帖最后由 volcanozhd 于 2008-5-10 17:15 编辑 ] |
|