Search code examples
signal-processingchisel

Building a DspComplex ROM in Chisel


I'm attempting to build a ROM-based Window function using DSPComplex and FixedPoint types, but seem to keep running into the following error:

chisel3.core.Binding$ExpectedHardwareException: vec element 'dsptools.numbers.DspComplex@32' must be hardware, not a bare Chisel type

The source code for my attempt at this looks like the following:

class TaylorWindow(len: Int, window: Seq[FixedPoint]) extends Module {
    val io = IO(new Bundle {
        val d_valid_in = Input(Bool()) 
        val sample = Input(DspComplex(FixedPoint(16.W, 8.BP), FixedPoint(16.W, 8.BP)))
        val windowed_sample = Output(DspComplex(FixedPoint(24.W, 8.BP), FixedPoint(24.W, 8.BP)))
        val d_valid_out = Output(Bool()) 
    })
     val win_coeff = Vec(window.map(x=>DspComplex(x, FixedPoint(0, 16.W, 8.BP))).toSeq) // ROM storing our coefficients. 

    io.d_valid_out := io.d_valid_in
    val counter = Reg(UInt(10.W))

    // Implicit reset
    io.windowed_sample:= io.sample * win_coeff(counter)
    when(io.d_valid_in) {
        counter := counter + 1.U
    }
}
println(getVerilog(new TaylorWindow(1024, fp_seq)))

I'm actually reading the coefficients in from a file (this particular window has a complex generation function that I'm doing in Python elsewhere) with the following sequence of steps

val filename = "../generated/taylor_coeffs"
val coeff_file = Source.fromFile(filename).getLines
val double_coeffs = coeff_file.map(x => x.toDouble)
val fp_coeffs = double_coeffs.map(x => FixedPoint.fromDouble(x, 16.W, 8.BP))
val fp_seq = fp_coeffs.toSeq

Does this mean the DSPComplex type isn't able to be translated to Verilog? Commenting out the win_coeff line seems to make the whole thing generate (but clearly doesn't do what I want it to do)


Solution

  • I think you should try using

      val win_coeff = VecInit(window.map(x=>DspComplex.wire(x, FixedPoint.fromDouble(0.0, 16.W, 8.BP))).toSeq) // ROM storing our coefficients.
    

    which will create hardware values like you want. The Vec just creates a Vec of the type specfied