Altera_Forum
Honored Contributor
10 years agoHow to read signed values from FPGA in VHDL to Nios II system
Hi,
I am reading a 14-bit signed value from a 14-bit vhdl port into a 16 bit signed variable in Nios II. There is no way for me to define it as 14 bits since the standard are alt_8, alt_16 and alt_32. So, I define it asalt_16 value=0;
And I read the value using: value =IORD_ALTERA_AVALON_PIO_DATA(base);
The problem is it always give me positive value every time it is read from this line even though I am sure it has both positive and negative value from VHDL code. printf("\n value= %.2f \n", (float) value);
In the vhdl code, the 14 bits data is defined as follows: the msb represents the signed bit, the following 6 bits represent the magnitude, and the following 6 bits. signal a : sfixed(7 downto -6);
I want to know, 1. How could I check if the value is positive or negative cause I have no idea how to read each of the binary bit in Nios C code? 2. Is it using 2's complement? How could I do that in C code? I am using C code to program Nios II. Thank you in advance.