Re: [myhdl-list] intbv with max != 2**n. Error or annoyance?
Brought to you by:
jandecaluwe
From: Per K. <bas...@gm...> - 2013-01-28 11:54:46
|
Hi! Over the weekend I have come to the conclusion that it is an error. Checking the value of a combinatorical net before it has settled has to be wrong. So depending on implementation feasibility and in order of preference we could: - Wait until the net has stabilized before checking the range, or - Disable range checks for combinatorical nets, or - Assert whenever a signal with range delimiters != 2**n is used as a combinatorical net. What do you say guys? /Per On Fri, Jan 25, 2013 at 1:08 PM, Per Karlsson <bas...@gm...>wrote: > Hi! > Here is something that I can't make up my mind if it is an error or just > plain annoying: > > I have a signal where the max value is not an even 2**n, and I > combinatorically assign it the value of a signal with a higher max value, > but only on the condition that the value is within range. This is fine. > > But if the condition is moved to a separate @always_comb driving a flag > and the flag gates the assignment, then there is a ValueError. The > generated verilog is fine of course. > /Per > > ps. Here is an example: > > from myhdl import * > > def range_check(capped, clk, rstn, cnt_max): > cnt = Signal(intbv(0, min=0, max=cnt_max)) > less_flag = Signal(intbv(0)[1:0]) > > cnt_max = cnt.max > capped_max = capped.max > capped_width = len(capped) > > @always(clk.posedge, rstn.negedge) > def count(): > if rstn==0: > cnt.next = 0 > else: > if cnt + 1 == cnt_max: > cnt.next = 0 > else: > cnt.next = cnt + 1 > > @always_comb > def setcapped(): > if less_flag==1: > capped.next = cnt[capped_width:] > else: > capped.next = 0 > > @always_comb > def setless(): > if cnt < capped_max: > less_flag.next = 1 > else: > less_flag.next = 0 > > return instances() > > def tb(capped_max): > clk = Signal(intbv(0)[1:0]) > rstn = Signal(intbv(0)[1:0]) > > @instance > def rstngen(): > rstn.next = 0 > yield delay(100) > rstn.next = 1 > yield delay(10000) > raise StopSimulation > > @always(delay(10)) > def clkgen(): > clk.next = not clk > > capped = Signal(intbv(0, min=0, max=capped_max)) > cnt_max = 15 > dut = range_check(capped, clk, rstn, cnt_max) > return instances() > > s = Simulation(tb(4)) > s.run() > print "4 is OK" > s = Simulation(tb(5)) > s.run() > print "5 is not" > > |