开发者

Simulink: Bit extraction from 1-Byte Hex

开发者 https://www.devze.com 2023-02-06 20:04 出处:网络
I\'m relatively new to Simulink and I am looking for a possibility to extract 1-3 specific bits from one byte.

I'm relatively new to Simulink and I am looking for a possibility to extract 1-3 specific bits from one byte. As far as I know the input format (bin, dec, hex) of the constant is irrelevant for the following!? But how can I say that the constant "1234" is he开发者_C百科x and not dec?

In my model I use the "Constant Block" as my source (will be parametrised by a MATLAB variable which comes from a m-file). A further processing with the "Extract Bits Block" causes an error on incompatible data types.

Can someone help me to deal with this issue?

Greets, poeschlorn


You should probably do the conversion hex->dec in your .m initialization file and use this value in Simulink.


Maybe this is not the most elegant solution, but I converted my input to decimal and then created a BCD representation of it via OR and AND logic blocks for further use.


If you have the Communications Toolbox/Blockset then you can use the Integer to Bit Converter block to do a conversion to a vector of binary digits then just extract the "bits" that you want. The Bit to Integer Converter block will do the reverse transformation.

If you don't have the Communicatins Blockset then it wouldn't be hard to do a similar thing to this using a plain MATLAB Function block.

Simulink: Bit extraction from 1-Byte Hex

0

精彩评论

暂无评论...
验证码 换一张
取 消