No Sim Results when implicit reg not initialized #2437
-
Below I create a slow counter(I know I can simply use regEn) where the initial register value of slowCount is never specified. The compiler doesn't complain about this, but I also don't see any simulation results. Should the compiler complain about no knowing the initial value of a Signal? module BlinkyCount(topEntity, main) where
import qualified Data.List as List
import Clash.Prelude
incrWhenTrue :: Num a => Bool -> a -> a
incrWhenTrue cond val
| cond = val + 1
| otherwise = val
slowCount :: HiddenClockResetEnable dom => Signal dom (Signed 8)
slowCount = incrWhenTrue <$> (riseEvery d1024) <*> slowCount
sim_results = sampleN @System 64 slowCount
main :: IO ()
main = do
putStrLn "Simulating Blinky"
print $ List.zip [0..] sim_results |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
You currently have no state that stores the counter value.
Do note that, since the output of an uninitialized circuit is If you do want initial state, you should probably be using register
You can also refactor the code into a single line: |
Beta Was this translation helpful? Give feedback.
slowCount
forms a combinatorial loop. That is, its value depends on itself, without a memory element inserted in between. Simulation will therefore be stuck in an ifinite loop, trying to calculate1 + val
whereval ~ 1 + val
. E.g.,