Build a software Golden Model of a tap configurable FIR.
Redesign our test to use this model, and confirm that it works.
Refactor our My4ElementFir to allow an configurable number of taps.
Test the new circuit using our new test harness.
Golden Model
1 2 3 4 5 6 7 8 9 10 11 12
classScalaFirFilter(taps: Seq[Int]) { var pseudoRegisters = List.fill(taps.length)(0)
defpoke(value: Int): Int = { pseudoRegisters = value :: pseudoRegisters.take(taps.length - 1) var accumulator = 0 for(i <- taps.indices) { accumulator += taps(i) * pseudoRegisters(i) } accumulator } }
mutable.ArrayBuffer[]
We are using a Scala collection type called ArrayBuffer. ArrayBuffer allows you to append elements using the **+= **operator (also insert and delete, but we don’t need this).
classMyManyElementFir(consts: Seq[Int], bitWidth: Int) extendsModule{ val io = IO(newBundle { val in = Input(UInt(bitWidth.W)) val out = Output(UInt(bitWidth.W)) })
val regs = mutable.ArrayBuffer[UInt]() for(i <- 0 until consts.length) { if(i == 0) regs += io.in // not register else regs += RegNext(regs.last, 0.U) // register } val muls = mutable.ArrayBuffer[UInt]() for(i <- 0 until consts.length) { muls += regs(i) * consts(i).U }
classMyManyDynamicElementVecFir(length: Int) extendsModule{ val io = IO(newBundle { val in = Input(UInt(8.W)) val out = Output(UInt(8.W)) val consts = Input(Vec(length, UInt(8.W))) })
Writes will only be performed when wen (write enable) is asserted.
The register at index 0 (the first register) is always zero when you read from it, regardless of what you write to it (it’s often useful to have 0 handy).