05-11-2012 07:58 AM - edited 05-12-2012 04:25 AM
I want to take values from MATLAB thorgh Gateway-in to the blackbox in IEEE 754 Single prcision format(Single).
I have tried out this:
- I am entering one vlaue in MATALB command line as shown below:
>> A=3.556 A = 3.5560 >> whos Name Size Bytes Class Attributes A 1x1 8 double >> A=single(3.556) A = 3.5560 >> whos Name Size Bytes Class Attributes A 1x1 4 single
By default MATLAB takes double. I trie out single also.
2. In constant the cominations i have tried out for double as well as single vales of A are as follows:
In constant Properties : Signal Atributes > Output Data type > Inherit: Inherit from 'Constant value' or Single or fixft(1,32,23)
But i want to know how can we get ~exact fp values into FPGA.
Thanks & Regards,
Solved! Go to Solution.
05-12-2012 01:29 AM - edited 05-12-2012 01:30 AM
There is a native support for floating-point operations in System Generator 13.3 (or higher).But if you are using older version, you can do a following trick: pass single precision floating-point value as 32-bit integer with same bits.
1. Gateway In block expects integer value, so set its properties to Fixed-point, Unsigned, Number of bits = 32, Binary point = 0.
2. Reinterpret the bits of your floating-point number as unsigned integer using MATLAB typecast function:
% single precision floating-point number a_single = single(1.23); % reinterpret it as 32-bit unsigned integer a_uint32 = typecast(a_single, 'uint32');
Now you can pass a_uint32 value to Gateway In block.
To check the bits of your number you can use MATLAB function dec2bin. It returns following result for single(1.23):
>> dec2bin(a_uint32, 32) ans = 00111111100111010111000010100100