Re: [myhdl-list] Generating 160 bit signal
Brought to you by:
jandecaluwe
From: Edward V. <dev...@sb...> - 2015-03-13 19:57:06
|
Chris, I made some changes to flaten.py at https://github.com/develone/jpeg-2000-test/blob/master/jpeg2k/parallel_jpeg/flaten.py. I added a random number for testing. This needs .signed() to work. Is this only for Python? In your example you started adding values at the MSB is this the preferred method? Regards Edward Vidal Jr. e-mail dev...@sb... 915-595-1613 On Thursday, March 12, 2015 12:45 PM, Christopher Felton <chr...@gm...> wrote: 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 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ myhdl-list mailing list myh...@li... https://lists.sourceforge.net/lists/listinfo/myhdl-list |