Commit a386443f authored by apaj's avatar apaj

Adapted Accumulator problem/solution

parent 5270d4a7
// See LICENSE.txt for license details.
// January 20th, 2018 -adapted for Learning Journey
package problems
import chisel3._
import Chisel._
// Problem:
//
// Count incoming trues
// (increase counter every clock if 'in' is asserted)
//
class Accumulator extends Module {
val io = IO(new Bundle {
val in = Input(UInt(1.W))
val out = Output(UInt(8.W))
})
// Implement below ----------
io.out := 0.U
// Implement above ----------
class Accumulator extends Module {
val io = new Bundle {
val in = UInt(INPUT, 1)
val out = UInt(OUTPUT, 8)
}
// flush this out ...
io.out := UInt(0)
}
// See LICENSE.txt for license details.
// January 20th, 2018 - adapted for Learning Journey
package solutions
import chisel3._
import Chisel._
// Problem:
//
// Count incoming trues
// (increase counter every clock if 'in' is asserted)
//
class Accumulator extends Module {
val io = IO(new Bundle {
val in = Input(UInt(1.W))
val out = Output(UInt(8.W))
})
val accumulator = RegInit(0.U(8.W))
val io = new Bundle {
val in = UInt(width = 1, dir = INPUT)
val out = UInt(width = 8, dir = OUTPUT)
}
val accumulator = Reg(init=UInt(0, 8))
accumulator := accumulator + io.in
io.out := accumulator
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment