Sorry I've asked a similar question but I didn't get a answer so I posted this question

I'm currently designing a maximum detector in VHDL which is part of my homework. The whole system consists of a data generator, data processor and a cmd processor. What I am currently doing is the data processor.

The data processor receive a 12bit BCD signal from cmd processor and request a certain amount of random 8 bit SIGNED binary byte from a data generator corresponding to the BCD signal's value, then it need to find out the maximum and output the a 56-wide set of lines that contain the 7 bytes comprising the peak in the middle (i.e. bit indices 31 down to 23), and the 3 bytes either side of it. picture below is showing the block diagram.enter image description here

I wrote a process like this to find out the maximum and its location in the array but I don't know how to deal with the signed data. Therefore I'm asking for some advice to refine the code or to rewrite another one that is able to recognize signed bytes

enter image description here


closed as unclear what you're asking by uint128_t, Daniel Grillo, PeterJ, Autistic, Dave Tweed Mar 22 '16 at 13:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Please post the code as text in the question using the MarkDown syntax. And please post also the declarations of all used signals. I recommend, to implement the maximum finder in a separate VHDL entitiy. Your question might be easier to answer, if you give us the interface and protocol of such an entity. The VHDL package numeric_std provides a data type signed for calculations on signed binary numbers. \$\endgroup\$ – Martin Zabel Mar 13 '16 at 8:24
  • \$\begingroup\$ Please post your code and not a screenshots. \$\endgroup\$ – Paebbels Mar 13 '16 at 8:25
  • \$\begingroup\$ @MartinZabel Hi I just updated it. \$\endgroup\$ – EEEidolt Mar 13 '16 at 13:55
  • \$\begingroup\$ @Paebbels Sorry I can't upload code directly because my school will consider it as plagiarism if they find the my code on internet. \$\endgroup\$ – EEEidolt Mar 13 '16 at 13:57
  • 1
    \$\begingroup\$ Plagiarism tools may find your code even in the image , if they have enough OCR capabilities. The only way to get out of the plagiarism problem is to ask a more general question, e.g.: How do I compare two signed binary values in VHDL? \$\endgroup\$ – Martin Zabel Mar 13 '16 at 15:26

To answer the questions in the comments:

... but did you mean that I should use the package STD_LOGIC_SIGNED?

I just wondering if the compiler is 'smart' enough to recognize the sign of each number?

The compiler is smart enough if you use the correct data-types. A std_logic_vector is just an array (vector) of std_logic values (bits). This vector has no sign. If you use signed instead of std_logic_vector, the compiler knows that it is treating signed numbers.

Do not use the std_logic_arith and std_logic_signed packages from Synopsys. They have been super-seeded by the now VHDL Standard package numeric_std. This package defines the data type signed alongside with relational operators like <, <=, =, /=, >, >=. Both operands in the comparison can be of different length, the shorter operand will be sign-extended first.

You can convert from std_logic_vector to signed with:

signal x : std_logic_vector(7 downto 0); -- 8 bit for example
signal y : signed(7 downto 0);

y <= signed(x);

and back

signal y : signed(7 downto 0);
signal z : std_logic_vector(7 downto 0); -- 8 bit for example

z <= std_logic_vector(y);

Of course, you can also use variables instead of signals (using the := assignment).

For example, to find the maximum value in an array of signed numbers, you can do:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity maximum_finder is
end maximum_finder;

architecture behavioral of maximum_finder is
  type array_of_signed is array(natural range <>) of signed(3 downto 0);
  signal signed_numbers : array_of_signed(0 to 2) :=
    ( 0 => "0000",  --  0
      1 => "0001",  --  1
      2 => "1111"); -- -1

  signal maximum : signed(3 downto 0);

begin  -- behavioral

    variable tmp : signed(3 downto 0);
    tmp := "1000";                      -- smallest number = -8
    for i in signed_numbers'range loop
      if signed_numbers(i) > tmp then
        tmp := signed_numbers(i);
      end if;
    end loop;  -- i
    maximum <= tmp;
  end process;

end behavioral;

Of course, this does not actually solve your homework. You have to adapt it, to avoid plagiarism.


Not the answer you're looking for? Browse other questions tagged or ask your own question.