Search code examples
vhdl

if statement problem while converting a vector


im new at vhdl coding, and there is a problem with if statement

so my code is the following i want to convert a vector(bar), if the statement is true (so in this example if its smaller than 10)

process(bar)
      variable tmp : integer;
    begin
      tmp := to_integer(signed(bar));
      if tmp < 10 then
            good(3) <= bar(3);
            good(2) <= bar(3) xor bar(2);
            good(1) <= bar(2) xor bar(1);
            good(0) <= bar(1) xor bar(0);
      end if;
    end process;

but the problem is that the statement is not working, if i put a bigger number for example "1111" it is converting in the same way as it converted before


Solution

  • From the comments it seems you want good to be set to 0 whenever bar >= 10. In that case you can just do:

    process(bar)
      variable tmp : integer;
    begin
      tmp := to_integer(signed(bar));
      if tmp < 10 then
        good(3) <= bar(3);
        good(2) <= bar(3) xor bar(2);
        good(1) <= bar(2) xor bar(1);
        good(0) <= bar(1) xor bar(0);
      else
        good <= (others => '0');
      end if;
    end process;