I have encountered in a problem of rising edge detection in writing chisel code. Here is the code I wrote.
package multiplicationPart
import chisel3._
import chisel3.util._
import chisel3.experimental._
//multiplication Module
class multiplier(size: Int = 4, width: Int = 8) extends Module {
val io = IO(new Bundle {
val clock = Input(Clock())
val message = Input(Vec(size - 1, SInt(width.W)))
val kernal = Input(Vec(size - 1, Vec(size - 1, SInt(width.W))))
val result = Output(Vec(size - 1, Vec(size - 1, SInt(width.W))))
})
val combineMessage = Reg(Vec(size - 1, Vec(1, SInt(width.W))))
val stored = Reg(Vec(size - 2, Vec(size - 1, SInt(width.W))))
val prevClock = RegInit(false.B)
val rising = !prevClock && io.clock
val falling = prevClock && !io.clock
prevClock := io.clock
when (rising) {
for (p <- 0 until size - 1) {
combineMessage(p)(0) := io.message(p)
}
}//whatever message is now, it is saved to combineMessage registers at positive edge of the clk signal
when (falling){
for (j <- 0 until size - 2) {
for (i <- 0 until size - 1) {
stored(i)(j + 1) := stored(i)(j)//whatever is stored in stored registers will shift to the right by 1
//so as to leave the room for the next column
}
}
}
for (q <- 0 until size - 1) {
for (t <- 0 until size - 1) {
var tempResult = 0.U(width.W)
for (r <- 0 until size - 1) {
for (s <- 0 until size - 1) {
tempResult := combineMessage(s)(r) * io.kernal(s)(r)
}
}
io.result(q)(t) := tempResult
}
}
}
and the compiler says:
[error] /home/chenhe/Desktop/multiplicationPart/src/main/scala/multiplier.scala:19:33: type mismatch;
[error] found : chisel3.core.Clock
[error] required: chisel3.core.Bool
[error] val rising = !prevClock && io.clock
[error] ^
[error] /home/chenhe/Desktop/multiplicationPart/src/main/scala/multiplier.scala:20:30: value unary_! is not a member of chisel3.core.Clock
[error] val falling = prevClock && !io.clock
[error] ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
I searched online and I found risingEdge
and fallingEdge
functions. Here's an updated version.
package multiplicationPart
import chisel3._
import chisel3.util._
import chisel3.experimental._
//multiplication Module
class multiplier(size: Int = 4, width: Int = 8) extends Module {
val io = IO(new Bundle {
val clock = Input(Clock())
val message = Input(Vec(size - 1, SInt(width.W)))
val kernal = Input(Vec(size - 1, Vec(size - 1, SInt(width.W))))
val result = Output(Vec(size - 1, Vec(size - 1, SInt(width.W))))
})
val combineMessage = Reg(Vec(size - 1, Vec(1, SInt(width.W))))
val stored = Reg(Vec(size - 2, Vec(size - 1, SInt(width.W))))
val rising = risingEdge(io.clock)
val falling = fallingEdge(io.clock)
when (rising) {
for (p <- 0 until size - 1) {
combineMessage(p)(0) := io.message(p)
}
}//whatever message is now, it is saved to combineMessage registers at positive edge of the clk signal
when (falling){
for (j <- 0 until size - 2) {
for (i <- 0 until size - 1) {
stored(i)(j + 1) := stored(i)(j)//whatever is stored in stored registers will shift to the right by 1
//so as to leave the room for the next column
}
}
}
for (q <- 0 until size - 1) {
for (t <- 0 until size - 1) {
var tempResult = 0.U(width.W)
for (r <- 0 until size - 1) {
for (s <- 0 until size - 1) {
tempResult := combineMessage(s)(r) * io.kernal(s)(r)
}
}
io.result(q)(t) := tempResult
}
}
}
But this time the compiler says this:
[error] /home/chenhe/Desktop/multiplicationPart/src/main/scala/multiplier.scala:19:16: not found: value risingEdge
[error] val rising = risingEdge(io.clock)
[error] ^
[error] /home/chenhe/Desktop/multiplicationPart/src/main/scala/multiplier.scala:20:17: not found: value fallingEdge
[error] val falling = fallingEdge(io.clock)
[error] ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed
Are they because of the libraries I imported (I guess)?
Can someone help me to deal with rising and falling edge detection of the clock signal?