I have a question about a conversion of an unsigned 10-bit vector to signed 8 bit vector. What is the best :
signed_data(7 downto 0)
I have a question about a conversion of an unsigned 10-bit vector to signed 8 bit vector. What is the best :
signed_data(7 downto 0)
u(7)
unsigned =3D> signed
What I want to do is :
unsigned min: 0000000000 => signed min: 1 000001 => integer min :
-127 unsigned max: 1111111111 => signed max: 0 1111111 => integer max : 127
You didn't tell us that :-)
Do you also want linear scaling between these two endpoints? I guess so. Let's start again.
You have unsigned input U in the range [0,1023].
You have signed output S in the range [-127, +127]. I don't know why you choose to exclude -128, but hey, that's OK.
So what do you want to do?
S = U/4 - 127
is pretty close, I think, if U/4 is taken to mean the whole-number part of the result (throw away the fraction). But unfortunately, 1020/4 = 255 and 255-127 = 128, so you'll get +128 rather than +127 as the upper limit. If you can accept -128 as the lower limit (this is the true minimum value of a signed 8-bit) then you can do
S = U/4 - 128
and all is well. Now, U/4 is simply the eight most significant bits of U; and -128 is easily done by just flipping the MSB; so
S7
so, I return to my first message, that is correct :
if ( unsigned_data =3D "00000000" ) then signed_data
No, it's not; you're being unacceptably careless.
This test will never be true, because unsigned_data is
10 bits wide and can never be equal to an 8-bit vector.And now you're trying to copy a 10-bit expression into an 8-bit result.
But yes, you're on the right track.
Always true, usually ignored!
Have something to add? Share your thoughts — no account required.
Ask the community — no account required