How do I extract a single bit from signed signals in Simulink? (with no run time warnings and no HDL coder hardware cost)

17 visualizaciones (últimos 30 días)
Basically, I want to do bit slicing on a signed integer sfixN (having bits N-1 (sign) down to 0). E.g., I want to grab bit N-1, put it in OR gate, etc.) If you try to blindly use the Extract Bits block with signed integers, the output integers are signed, so you can't get single bits.
My solution was to use a convert block with input fixdt(1, N, 0) and output fixdt(0, N, 0), (since these are integers, setting Input and output to have equal RWW or SI give the same result). This works as expected - non-negative numbers are passed through and a negative number x, comes out as x + 2^N. However, this is always flagged as an overflow.
Is this the best way to extract bits from signed numbers? If so, is there a way to turn off warnings for just this block? If not, I'd love to know the right way.
Thanks, Dara

Respuesta aceptada

Tim McBrayer
Tim McBrayer el 13 de Mayo de 2014
Take a look at the "Bit Slice" block in the HDL Operations category of the HDL library. This block should accomplish what you are trying to do. To extract a single bit, simply set the upper and lower bounds of the slice to have the same value.
To access the HDL Coder library, run:
>> hdllib
hdllib dynamically creates a new library that contains all available blocks in your install that are supported for HDL code generation.
In R2014a and later, you can also access this category, along with all HDL-supported core Simulink blocks, in the HDL Coder Simulink library in the main Simulink library browser.
  1 comentario
Dara Parsavand
Dara Parsavand el 13 de Mayo de 2014
Editada: Dara Parsavand el 13 de Mayo de 2014
Tim,
I can't believe I missed that. I had run hdllib, and when I found Extract Bits in Simulink/Logic and Bit Operations, I thought that was the only choice. Guess I'll need to read through all the blocks when I get a chance. The block you suggested works just fine for me. Any chance future documentation for Extract Bits could point users to Bit Slice as an alternative? Thanks!
Dara

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by