end
endmodule
通用型的二进制计数器一般具备更多功能,例如可以增/减计数、预置初值、同步清零、暂停等。74LS161就是一种常用的可预置4位二进制同步加法计数器。其功能表如下图表:
![](https://img-blog.csdnimg.cn/929e76a71dec4e78a03d916ee7049817.png)
| | |
| --- | --- |
| 输入 | 输出 |
| | | P | T | CP | D0 | D1 | D2 | D3 | Q0 | Q1 | Q2 | Q3 |
| *0* | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | *0* | *0* | *0* | *0* |
| *1* | *0* | Ⅹ | Ⅹ | ↑ | *D0* | *D1* | *D2* | *D3* | *D0* | *D1* | *D2* | *D3* |
| *1* | *1* | *1* | *1* | ↑ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | 计数 |
| *1* | *1* | *0* | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | 保持 |
| *1* | *1* | Ⅹ | *0* | Ⅹ | Ⅹ | Ⅹ | Ⅹ | Ⅹ | 保持 |
#### 0x01 利用IP核构造计数器
(1)根据上述74LS161的原理和参考代码,在vivado中设计计数电路:
module CNT161( input CR, input CP, input [3:0] D , input LD, input EP, input ET, output wire [3:0] Q);
wire [3:0] Din;
reg [3:0] Dout;
assign Din=D;
assign Q=Dout;
always@(posedge CP or negedge CR) begin
if (CR0) Dout&