Home > Software engineering >  Is Chisel Counter more than 32 bits possible?
Is Chisel Counter more than 32 bits possible?

Time:11-29

I declared a counter like this :

  val MAXCOUNT = ((BigInt(1) << COUNT_WIDTH)-1)
  val counterSize = log2Ceil(MAXCOUNT)
  println("Maxcount -> "   MAXCOUNT   ", "   counterSize   " bits")
  val (counterValue, counterWrap) = Counter(0 until MAXCOUNT by 1)
  io.leds := counterValue(counterSize-1, counterSize-8)

I'm using BigInt because I want to count with value more than 32 bits width. But Chisel3 tell me that only Int is accepted for counter value. Then it's not possible to count more than 2**32 ?

[error] pimpcounter/hdl/src/main/scala/Blink.scala:17:53: type mismatch;
[error]  found   : scala.math.BigInt
[error]  required: Int
[error]   val (counterValue, counterWrap) = Counter(0 until MAXCOUNT by 1)
[error]                                                     ^

CodePudding user response:

It does look like the chisel3.util.Counter API only allows 31-bit max (31-bit because of the use of Scala Int which is signed). This limitation should probably be lifted (by making the API take NumericRange[BigInt] instead of just Range (which is NumericRange[Int]).

The workaround is to just use a Reg as your counter:

val counterValue = RegInit(0.U(countersize.W))
counterValue := counterValue   1.U
  • Related