以下博客分析格式和部分代码参考学习:
HDLBits 系列(41)根据仿真波形来设计电路之组合逻辑
Sim/circuit4
原题复现
思路以及代码
直接画出相应的卡诺图
ab/cd | 00 | 01 | 11 | 10 |
---|---|---|---|---|
00 | 0 | 0 | 1 | 1 |
01 | 1 | 1 | 1 | 1 |
11 | 1 | 1 | 1 | 1 |
10 | 0 | 0 | 1 | 1 |
module top_module (
input a,
input b,
input c,
input d,
output q );//
assign q = c|b;// Fix me
endmodule
Sim/circuit5
原题复现
思路以及代码
根据波形图,就可以看出,这个可以利用case 语句来判断选择那个作为输出。
module top_module (
input [3:0] a,
input [3:0] b,
input [3:0] c,
input [3:0] d,
input [3:0] e,
output [3:0] q );
always@(*)begin
case(c)
0: q= b;
1: q= e;
2: q= a;
3: q= d;
default: q=4'hf;
endcase
end
endmodule
Sim/circuit6
1.原题复现:
2.思路以及代码:
根据时序图就可以得到:
module top_module (
input [2:0] a,
output [15:0] q );
always@(*)begin
case(a)
0: q= 16'h1232;
1: q= 16'haee0;
2: q= 16'h27d4;
3: q= 16'h5a0e;
4: q= 16'h2066;
5: q= 16'h64ce;
6: q= 16'hc526;
7: q= 16'h2f19;
default:q=16'h1232;
endcase
end
endmodule
Sim/circuit7
1.原题复现
2.思路以及代码
一个简单的时序电路
module top_module (
input clk,
input a,
output q );
always@(posedge clk)begin
q<=~a;
end
endmodule
Sim/circuit10
1.原题复现
2.思路以及代码:
通过网上学习他人思路以及根据题目的意思,可以得到:
如果不做卡诺图化简,能够得到:
module top_module (
input clk,
input a,
input b,
output q,
output state );
wire state_next;
always @(posedge clk)
state <= state_next;
assign q = ~state & ~a & b |
~state & a & ~b |
state & a & b |
state & ~a & ~b;
assign state_next = a & b | state & a | state & b;
endmodule