Loop problem

32 views
Skip to first unread message

soham bhattacharya

unread,
Aug 12, 2022, 10:22:27 PMAug 12
to chisel-users
Hi there,
    Good day. I am new in chisel. I am doing a simple addition and want to see the add value till the input last value. Can you please help me out in  this code. Actually, it is throwing throwing the same value again and again. I am not able to figure it out where's the error:

class Soham extends Module{
 val io = IO(new Bundle {
  //val n = Input(UInt(4.W))
  val a = Input(UInt(8.W))
  val b = Input(UInt(8.W))
  val p = Output(UInt(8.W))
  //val p2 = Output(FixedPoint(32.W, 8.BP))
})

io.p := io.a + io.b
 
}

class SohamTest extends AnyFlatSpec with Matchers {
"Soham" should "pass" in {
test(new Soham) { c =>



val limit = 10
for(i <- 0 until limit) {

val in_A = 5
val in_B = 6
 
 c.io.a.poke(in_A.U)
 c.io.b.poke(in_B.U)
 
 c.clock.step(1)
 
 
 
 println( "Resultx:" + c.io.p.peek() +i)
   
   }
  }
 }
 }

Output:

Resultx:UInt<8>(11)0
Resultx:UInt<8>(11)1
Resultx:UInt<8>(11)2
Resultx:UInt<8>(11)3
Resultx:UInt<8>(11)4
Resultx:UInt<8>(11)5
Resultx:UInt<8>(11)6
Resultx:UInt<8>(11)7
Resultx:UInt<8>(11)8
Resultx:UInt<8>(11)9


Your time and consideration is appreciated.

Thanks & Regards,
Soham Bhattacharya.




Martin Schoeberl

unread,
Aug 15, 2022, 11:18:14 AMAug 15
to chisel...@googlegroups.com
Why should the output value change when you always provide the same input:

val in_A = 5
val in_B = 6
 
 c.io.a.poke(in_A.U)
 c.io.b.poke(in_B.U)

Cheers,
MArtin

--
You received this message because you are subscribed to the Google Groups "chisel-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chisel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/ac4023d1-c486-453b-b19e-0f732617c5f8n%40googlegroups.com.

soham bhattacharya

unread,
Aug 15, 2022, 11:34:56 AMAug 15
to chisel-users
No actually, I want to do this.Any idea how can I do this:

Actually, I have used the register. But the value is coming as it is. Basically, when I am using a loop like

val io = IO(new Bundle {

val x_in = Input(FixedPoint(32.W, 16.BP))
val y_in = Input(FixedPoint(16.W, 8.BP))
val h = Input(FixedPoint(32.W, 16.BP))
val y_out = Output(FixedPoint(32.W, 16.BP))
})
val mx = Reg(FixedPoint(32.W, 16.BP))
for(i<-0 until 5) {
mx := io.y_in + io.x_in

 io.x_in := mx

}
io.y_out := mx

}

My question is that it is throwing the same result. and the loop is not rolling. But point is just like in C, we have to denote the 'i' in statement within the loop, but in chisel, it is throwing we cannot use it as because it is fixed point. Any idea?


Reply all
Reply to author
Forward
0 new messages