1

I have a 16bits register declared like that :

val counterReg = RegInit(0.U(16.W))

And I want to do indexed dibit assignment on module output like that :

//..
  val io = IO(new Bundle {
     val dibit = Output(UInt(2.W))
  })
//..
var indexReg = RegInit(0.U(4.W))
//..
io.dibit = vectorizedCounter(indexReg)

But I have some difficulties to know how to declare vectorizedCounter().

I found some examples using Bundles, but for Vector I don't know. And I can't manage to do that with UInt():

val counterReg = RegInit(UInt(16.W))
//...
io.dibit := counterReg(indexReg*2.U + 1.U, indexReg*2.U)
4
  • io.dibit := ? Nov 22, 2019 at 14:51
  • exact, corrected (but it was not the problem ;)
    – FabienM
    Nov 22, 2019 at 15:44
  • Is vectorizedCounter a UInt? Nov 22, 2019 at 16:03
  • Yes it is. I updated the question to add the type.
    – FabienM
    Nov 22, 2019 at 20:09

1 Answer 1

2

You could dynamically shift and bit extract the result:

io.dibit := (counterReg >> indexReg)(1, 0)
1
  • I am doing similar but in my case, the widths may not be proper multiple, hence, the width I take may wraparound, so some bits are from one end and remaining after wraparound. I am having to use a UInt as index, which is not allowed, how may I handle that ? My question is @ stackoverflow.com/questions/67650528/…. Thanks
    – potato
    May 23, 2021 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.