Counter constructor

Counter(
  1. Logic en,
  2. Logic reset,
  3. Logic clk, {
  4. int width = 8,
  5. String name = 'counter',
})

Creates a Counter of width bits driven by clk.

Increments on each rising edge when en is high. reset synchronously clears the count to zero.

Implementation

Counter(
  Logic en,
  Logic reset,
  Logic clk, {
  this.width = 8,
  super.name = 'counter',
}) : super(definitionName: 'Counter_W$width') {
  en = addInput('en', en);
  reset = addInput('reset', reset);
  clk = addInput('clk', clk);
  addOutput('val', width: width);

  val <= flop(clk, reset: reset, en: en, val + 1);
}