0
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

In your code, the compilation errors you are encountering are due to an incorrect cast. You are trying to use Clock variables as if they were booleans.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks pal! Sorry if I don’t speak English very well. And Yes I have read something about it elsewhere, risingedge function can only be used with Booleans, right? So if I’d detect the edges of the clock signal, what should I do then? Do I use a register which gives the current value of the clock signal so that the clock becomes Boolean? Or do we have a built in function that can be used with clock signal? \$\endgroup\$ Commented Sep 6, 2023 at 18:28
  • \$\begingroup\$ The main issue is that the data types of your variables do not match. You just need to use a cast to tell your variables to behave as booleans. This way, there are no data type compatibility issues. No external libraries are needed. However, if you want to use the ones you found, you need to import them correctly. Based on the compilation errors you encountered, the system couldn't locate the components you wanted to use. Please ensure they have been imported. \$\endgroup\$
    – porrokynoa
    Commented Sep 7, 2023 at 7:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.