简介
在学习FPGA时,整理的一些问题,慢慢积累,期待自己的进步。
个人邮箱: 1149025224@qq.com
欢迎交流!
2 选 1 选择器
先说什么是选择器?
好几个女同学向你求婚,你选其中一个当老婆。即多输入单输出。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13好,做个题 这个模块有输入: a, b, sel,输出: out sel 信号作为选择信号,当 sel = 1 时选择 b,sel=0 时选择 a。 ```py module top_module( input a, b, sel, output out ); assign out = (sel) ? b : a; endmodule
256选1, 位宽 1
什么是位宽?
暂可以理解为一根线有一个电压,可代表1或0,
那么四根线可以有四个电压,可代表0000、0001…直到1110、1111,
那么输入信号是一根线,代表的是一位,位宽就是1,四根线就可以代表四位,位宽为4。
以上如果想深究可以百度一下啦
实现一个 256 选 1 选择器,sel 信号作为选择信号,当 sel = 0 时选择 in[0],sel = 1 时选择 in[1],以此类推。
复制代码
1
2
3
4
5
6
7
8
9module top_module ( input [255:0] in, input [7:0] sel, output out ); assign out = in[sel]; endmodule
9 选 1 选择器,位宽 4
sel 信号作为选择信号,当 sel = 0 时选择 a,sel = 1 时选择 b,以此类推。sel 信号位宽为 4bit,当 sel 大于 8 时,输出 16’hffff。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20module top_module( input [15:0] a, b, c, d, e, f, g, h, i, input [3:0] sel, output reg [15:0] out ); always @(*)begin case(sel) 4'd0:out = a; 4'd1:out = b; 4'd2:out = c; 4'd3:out = d; 4'd4:out = e; 4'd5:out = f; 4'd6:out = g; 4'd7:out = h; 4'd8:out = i; default:out=16'hffff; endcase end endmodule
256 选 1 选择器,位宽 4
el 信号作为选择信号,当 sel = 0 时选择 in[3:0],sel = 1 时选择 in[7:4],以此类推。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17module top_module ( input [1023:0] in, input [7:0] sel, output [3:0] out ); // We can't part-select multiple bits without an error, but we can select one bit at a time, // four times, then concatenate them together. assign out = {in[sel*4+3], in[sel*4+2], in[sel*4+1], in[sel*4+0]}; // Alternatively, "indexed vector part select" works better, but has an unfamiliar syntax: // assign out = in[sel*4 +: 4]; // Select starting at index "sel*4", then select a total width of 4 bits with increasing (+:) index number. // assign out = in[sel*4+3 -: 4]; // Select starting at index "sel*4+3", then select a total width of 4 bits with decreasing (-:) index number. // Note: The width (4 in this case) must be constant. endmodule
学习总结
位宽较小时使用 assign 语句,三元表达式,case 语句;
位宽较宽时的多路选择器,需要根据需求灵活地使用位选择符 [ ] 或者位连接符{ }。
最后
以上就是缥缈发夹最近收集整理的关于FPGA初学者__个人学习笔记(三)_选择器、多路复用器的全部内容,更多相关FPGA初学者__个人学习笔记(三)_选择器、多路复用器内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复