From 75c00606df6a2ba48d5354f32d5dbe327552ad45 Mon Sep 17 00:00:00 2001 From: Chick Markley Date: Thu, 5 Aug 2021 09:36:24 -0700 Subject: Small changes to memory doc (#2062) * Small changes to memory doc - Fixed typo "except" => "accept" - Use `Counter` explicitly in ROM section example. * Fix counter doc compile error * remove invisible doc block in memory example * more small fixes to make mem example pass doc compile * Get rid of sine wave iterator in memory doc * get rid of tabs on VecInit example * get rid of tabs on VecInit example--- docs/src/explanations/memories.md | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'docs/src') diff --git a/docs/src/explanations/memories.md b/docs/src/explanations/memories.md index 1f2f83be..10759f25 100644 --- a/docs/src/explanations/memories.md +++ b/docs/src/explanations/memories.md @@ -11,35 +11,32 @@ Chisel provides facilities for creating both read only and read/write memories. ## ROM Users can define read-only memories by constructing a `Vec` with `VecInit`. -`VecInit` can except either a variable-argument number of `Data` literals or a `Seq[Data]` literals that initialize the ROM. - -```scala mdoc:invisible -import chisel3._ -// This is bad, don't do this, use a val -def counter = util.Counter(true.B, 4)._1 -val Pi = 3.14 -def sin(t: Double): Double = t // What should this be? -``` +`VecInit` can accept either a variable-argument number of `Data` literals or a `Seq[Data]` literals that initialize the ROM. For example, users can create a small ROM initialized to 1, 2, 4, 8 and loop through all values using a counter as an address generator as follows: ```scala mdoc:compile-only +import chisel3._ +import chisel3.util.Counter val m = VecInit(1.U, 2.U, 4.U, 8.U) -val r = m(counter(m.length.U)) +val c = Counter(m.length) +c.inc() +val r = m(c.value) ``` -We can create an *n* value sine lookup table using a ROM initialized as follows: +We can create an *n* value sine lookup table generator using a ROM initialized as follows: ```scala mdoc:compile-only +import chisel3._ + +val Pi = math.Pi def sinTable(amp: Double, n: Int) = { val times = (0 until n).map(i => (i*2*Pi)/(n.toDouble-1) - Pi) val inits = - times.map(t => Math.round(amp * sin(t)).asSInt(32.W)) + times.map(t => Math.round(amp * math.sin(t)).asSInt(32.W)) VecInit(inits) } -def sinWave(amp: Double, n: Int) = - sinTable(amp, n)(counter(n.U)) ``` where `amp` is used to scale the fixpoint values stored in the ROM. -- cgit v1.2.3