All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spinal.lib.misc.PDM.scala Maven / Gradle / Ivy

There is a newer version: 1.10.2a
Show newest version
package spinal.lib.misc.pdm

import spinal.core._
import spinal.lib._

class PDMCore(width: Int) extends Component {
  val io = new Bundle {
    val enable = in Bool()
    val density = in UInt(width+1 bits)
    val output = out Bool()
  }

  val counter = Reg(UInt(width bits))
  val outReg = Reg(Bool()) init(False)
  when(io.enable) {
    val nextCounter = (U(0, 1 bit) @@ counter) + io.density
    counter := nextCounter(width-1 downto 0)
    outReg := nextCounter(width)
  } otherwise {
    counter := 0
    outReg := False
  }
  io.output := outReg
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy