Verilog hdl 如何检测时钟的上升沿和下降沿?
always@(posedgeclk)SCKr<={SCKr[1:0],SCK};wireSCK_risingedge=(SCKr[2:1]==2'b01);//noww...
always @(posedge clk) SCKr <= {SCKr[1:0], SCK};
wire
SCK_risingedge = (SCKr[2:1]==2'b01); // now we can detect SCK rising
edges
wire SCK_fallingedge = (SCKr[2:1]==2'b10); // and falling
edges
这段代码正确吗?怎样理解? 展开
wire
SCK_risingedge = (SCKr[2:1]==2'b01); // now we can detect SCK rising
edges
wire SCK_fallingedge = (SCKr[2:1]==2'b10); // and falling
edges
这段代码正确吗?怎样理解? 展开
2个回答
展开全部
regF1,F2;
always @(posedge CLK or negedge RSTn)
if(!RSTn)
begin
F1<=1'b1;
F2<=1'b1;
end
else
begin
F1<=SCKr;//需要检测的引脚
F2<=F1;
end
/******************************/
assign SCK_fallingedge = F2 && !F1;//检测时钟的上升沿
assign SCK_risingedge = F1 && !F2;//检测时钟的下降沿
always @(posedge CLK or negedge RSTn)
if(!RSTn) begin .... end
else if(SCK_fallingedge == 1)
bigin
//SCK_fallingedge为一表示上升沿到来,上升沿到来之后SCK_fallingedge会自动清零
end
else if(SCK_risingedge == 1)
begin
//同样,SCK_fallingedge为一表示下降沿到来,下降沿到来之后SCK_fallingedge会自动 清零
end
这是我经常用的方法,纯手打,望采纳。
always @(posedge CLK or negedge RSTn)
if(!RSTn)
begin
F1<=1'b1;
F2<=1'b1;
end
else
begin
F1<=SCKr;//需要检测的引脚
F2<=F1;
end
/******************************/
assign SCK_fallingedge = F2 && !F1;//检测时钟的上升沿
assign SCK_risingedge = F1 && !F2;//检测时钟的下降沿
always @(posedge CLK or negedge RSTn)
if(!RSTn) begin .... end
else if(SCK_fallingedge == 1)
bigin
//SCK_fallingedge为一表示上升沿到来,上升沿到来之后SCK_fallingedge会自动清零
end
else if(SCK_risingedge == 1)
begin
//同样,SCK_fallingedge为一表示下降沿到来,下降沿到来之后SCK_fallingedge会自动 清零
end
这是我经常用的方法,纯手打,望采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询