Re: [myhdl-list] [newb] traceSignals question
Brought to you by:
jandecaluwe
|
From: Jan D. <ja...@ja...> - 2009-02-21 11:28:37
|
Neal Becker wrote:
> In the following simple test:
>
> from myhdl import Signal, always, intbv, Simulation, delay, toVerilog,
> traceSignals
>
> def ClkDriver(clk):
>
> halfPeriod = delay(1)
>
> @always(halfPeriod)
> def driveClk():
> clk.next = not clk
>
> return driveClk
>
> def Counter (count, clock, n):
>
> @always (clock.posedge)
> def cntLogic():
> if count == n-1:
> count.next = 0
> else:
> count.next = count + 1
>
> print count
> return cntLogic
>
> n = 16
>
> count = Signal (intbv(0)[4:])
> clock = Signal (bool())
>
> #clkdriver_inst = ClkDriver(clock)
> clkdriver_inst = traceSignals (ClkDriver, clock)
> cnt_inst = Counter (count, clock, n)
>
> sim = Simulation (clkdriver_inst, cnt_inst)
> sim.run(50)
>
> I assumed (it really isn't explained in the manual) that
> traceSignals (ClkDriver, clock) would only trace signals used by 'ClkDriver',
> which would only be clock. It seems my .vcd output includes others, such as
> 'count'. How is this determined? Am I using traceSignals correctly?
Yes, you're just seeing some scope effects.
traceSignals() extract hierarchy below the function argument, as you
would expect. However, all signals in the scope of a module are
considered, not just the ones used inside generators. This behavior
is normally what you'd expect, but sometimes it seems too broad,
as in this case.
The issue is that count and clock are globals, and therefore they
are in anybody's scope. Global signals work fine, but for larger
designs you would probably encapsulate your design in its own
function and get rid of global signals, like so:
def bench():
count = Signal (intbv(0)[4:])
clock = Signal (bool())
#clkdriver_inst = ClkDriver(clock)
clkdriver_inst = traceSignals (ClkDriver, clock)
cnt_inst = Counter (count, clock, n)
return clkdriver_inst, cnt_inst
sim = Simulation(bench())
sim.run(50)
And in such a case you'd only see the signals you expect.
Jan
--
Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com
Python as a hardware description language:
http://www.myhdl.org
|