Re: [myhdl-list] strange problem
Brought to you by:
jandecaluwe
|
From: Christopher F. <chr...@gm...> - 2009-03-17 15:51:47
|
On Tue, Mar 17, 2009 at 9:59 AM, Neal Becker <ndb...@gm...> wrote:
> I'm still trying to wrap my head around myhdl. This one is weird.
>
> In my testbench/monitor, which was working, I just added a variable
> 'input_sample_cnt':
>
> input_sample_cnt = 0
>
> @instance
> def stimulus():
> while (1):
> yield clock.negedge
> if (en):
> in_i.next = in_i_iter.next()
> in_q.next = in_q_iter.next()
> input_sample_cnt += 1
>
> reset.next = 0
>
> I get:
> input_sample_cnt += 1
> UnboundLocalError: local variable 'input_sample_cnt' referenced before
> assignment
>
> But I've had this all along:
> result_fd = file ('result', 'w')
> count_fd = file ('count', 'w')
> reset_fd = file ('reset', 'w')
> x_fd = file ('x', 'w')
> en_fd = file ('en', 'w')
> oe_fd = file ('oe', 'w')
>
> @instance
> def monitor():
> while 1:
> yield clock.posedge
> ##print 'reset:', reset, 'en:', en, 'x:', x, 'count:',
> to_hex(count), 'result:', to_hex(result)
> if (oe):
> print >> result_fd, to_hex (result_i), to_hex (result_q)
> print >> count_fd, to_hex (count)
> print >> x_fd, to_hex (in_i), to_hex (in_q)
> print >> reset_fd, to_hex (reset)
> print >> en_fd, to_hex (en)
> print >> oe_fd, to_hex (oe)
>
> This seems functionally the same thing (other than using +=). Why does
> this
> latter work, but the former not? What should I be doing instead?
>
>
I am not the most knowledgeable with this issue. But I think it is an issue
of scope. In your example the "input_sample_cnt" is part of the testbench
and not part of the stimulus generator. I forgot the relationship that the
"Signal" introduces. There should be a way to use simple variables as you
outline (need to check the cookbooks and examples to refresh my memory).
If you make your variable a "Signal+, and use input_sample_cnt.next = ... it
will work. As mentioned above I believe there is a method to use variable
but I don't know off the top of my head.
|