要实现oe发生跳变时,这个输出置0,当定时时间到来时这个输出置1;
一下这个程序,帮忙修改下:
module Timer (
input rst,
input oe,
input clk,
output TI_flag
);
parameter
Ttime=100 ;//定时时间
wire flag; //定时器溢出标志位
reg [31:0] count;
assign (supply1 ,weak0)flag= (oe | ~oe) ? 0:1;
assign TI_flag=flag;
always @(posedge clk or negedge rst )
begin
if(!rst)
begin
count<=0;
flag<=0;
#3 flag<=1; //这里线网不能进行赋值
end
else if(count<(Ttime-1)&!TI_flag)
begin
count<=count+1'b1;
end
else
begin
count<=32'b0;
#3 flag<=0;
flag<=1; //定时溢出,标志位置1,定时完成,灭掉LED
end
end
endmodule
我自己解决了 ,原来用状态机就好了
module Timer (
input rst,
input oe,
input clk,
output TI_flag
);
parameter
Ttime=100 ,//定时时间
status0=0, //状态参数
status1=1,
status2=2;
reg [2:0] st=status0;
reg flag=1; //定时器溢出标志位
reg [31:0] count=0;
assign TI_flag= flag;
always @(posedge clk or negedge rst )
begin
if(!rst)
begin
st<=status0;
count<=0;
flag<=1;
end
case (st)
status0: begin
if(oe)
begin
flag<=0; //清零 开始计数定时
count<=0;
st<=status1;
end
else
st<= status0;
end
status1:begin
if(count<Ttime-1)
begin
st<=status1;
count<=count + 1;
end
else
begin
flag<=1;
st<=status2;
end
end
status2: begin
while(oe); //等待不使能定时器信号,使得可以让下一次oe=1信号来临时定时器被触发
st<=status0;
end
default: st<=status0;
endcase
end
endmodule
我自己解决了 ,原来用状态机就好了
module Timer (
input rst,
input oe,
input clk,
output TI_flag
);
parameter
Ttime=100 ,//定时时间
status0=0, //状态参数
status1=1,
status2=2;
reg [2:0] st=status0;
reg flag=1; //定时器溢出标志位
reg [31:0] count=0;
assign TI_flag= flag;
always @(posedge clk or negedge rst )
begin
if(!rst)
begin
st<=status0;
count<=0;
flag<=1;
end
case (st)
status0: begin
if(oe)
begin
flag<=0; //清零 开始计数定时
count<=0;
st<=status1;
end
else
st<= status0;
end
status1:begin
if(count<Ttime-1)
begin
st<=status1;
count<=count + 1;
end
else
begin
flag<=1;
st<=status2;
end
end
status2: begin
while(oe); //等待不使能定时器信号,使得可以让下一次oe=1信号来临时定时器被触发
st<=status0;
end
default: st<=status0;
endcase
end
endmodule