Re: [myhdl-list] Generating 160 bit signal
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2015-03-12 18:45:34
|
On 3/7/2015 4:12 PM, Edward Vidal wrote: > Hello All, > Trying to take 16 values from an image to generate 160 bit signal > Here is an example that might help. Differs from yours in that it uses ShadowSignals and elaboration to build the "flat" representation. The example uses an 8x5 matrix of 8bit signals and creates a 160 bit flat version of the 4 lsb from each matrix element. def m_flatten(matrix, flat): _flat = ConcatSignal(*[col(4,0) for row in matrix for col in row]) @always_comb def rtl(): flat.next = _flat return rtl def test_flatten(): matrix = [[Signal(intbv(0)[8:]) for col in range(5)] for row in range(8)] flat = Signal(intbv(0)[160:]) tbdut = m_flatten(matrix, flat) @instance def tbstim(): yield delay(1) print(bin(flat, 160)) assert flat == 0 matrix[0][0].next = 0x8 yield delay(1) print(bin(flat, 160)) assert flat[160-1] == 1 return tbdut, tbstim Simulation(test_flatten()).run() https://gist.github.com/cfelton/d52fc4abe8d50b73c13c <snip> > Most of the time it works > working okay generates a signal of 160 <snip> > ValueError: intbv value -4 < minimum 0 I believe the error you are seeing can be explained with this little example: x = intbv(0)[16:] y = intbv(0, min=-128, max=128) z = intbv(0, min=0, max=256) # this will work x[:] = (y << 8) | z print(x) # this will fail y[:] = -8 x[:] = (y << 8) | z print(x) # this will work y[:] = 118 x[:] = (y << 8) | z print(x) Regards, Chris |