简体   繁体   English

凿子代码显示错误的输出

[英]Chisel code showing wrong output

This is the code for byte selector 这是字节选择器的代码

class Comp extends Module {
val io = IO(new Bundle {
val in = Input(UInt(25.W))
val out = Output(UInt(25.W))
val i = Input(UInt(4.W))
val out0   = Output(UInt(5.W))
val out1   = Output(UInt(5.W))

})


val r8 = Wire(UInt(5.W))
io.out := Reverse(io.in)
for (i <- 0 to 20 by 5)

{

io.out0 := io.out (i+4, i)


when(io.out0 === 31.U) {
r8 := 0.U            
}.elsewhen(io.out0 === 0.U) {
    r8 := 31.U
}.elsewhen(io.out0 === 17.U) {
    r8 := 14.U  
}.elsewhen(io.out0 === 14.U) {
    r8 := 17.U            
}.otherwise {
    r8 := 27.U            
}


io.out1 := r8
}

This only selects the byte 20 to 24 ie when i = 20 and not the rest of the bytes. 这仅选择字节20 to 24即当i = 20而不是其余字节。 Everytime I get the output as 27 which is when the for loop selects the most significant 5 bits. 每次我得到的输出为27时,这是当for循环选择最高5位的时候。 Can somebody help? 有人可以帮忙吗?

The scala for loop is like GENERATE in VHDL, you have to see it as a multiple declaration of : scala for循环类似于VHDL中的GENERATE,您必须将其视为以下内容的多重声明:

io.out0 := io.out (i+4, i)

You can see it as following code : 您可以看到以下代码:

io.out0 := io.out (4, 0)
io.out0 := io.out (8, 5)
io.out0 := io.out (14, 10)
io.out0 := io.out (18, 15)
io.out0 := io.out (24, 20)

The symbol ':=' is a connection between signal. 符号“:=”是信号之间的连接。 Each line of above code is seen as new connection erasing the old connection. 以上代码的每一行都被视为擦除旧连接的新连接。

Then only the last connection will be really used. 然后,仅最后一个连接将被真正使用。

To do the connections as you want, you have to change (I think) the declaration of io.out and use an index like following: 要进行所需的连接,您必须更改(我认为) io.out的声明并使用如下所示的索引:

for ( i <- 0 to 20 by 5)
{
io.out(i) := io.out (i+4, i)
}

With io.out declared as a Vector (Vec()) 将io.out声明为Vector(Vec())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM