0

I want to change binary to decimal so I used to_integer. I intend that I put X <= 10110101 then M <= 181 and separate integer with hundreds, tens, units and I intend M_100 <= 1, M_10 <= 8, M_1 <= 1

I also need to change decimal to binary, I intend temp1 <= 0001, temp2 <= 1000, temp3 <= 0001

Please let me know the reason why the code error, shown below the code, occurs.

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

entity TEST is
    port(X: in std_logic_vector(7 downto 0);
          M_100: buffer integer;
          M_10: buffer integer;
          M_1: buffer integer;
          M: buffer integer;
         Y: out std_logic_vector(2 downto 0));
end TEST;

architecture EX of TEST is

signal temp1: std_logic;
signal temp2: std_logic;
signal temp3: std_logic;

begin

X <= "00110101";
M <= to_integer(unsigned(X)); 
M_100 <= M/100;
    with M_100 select temp1 <= "0000" when 0,
                                    <= "0001" when 1,
                                    <= "0010" when 2,
                                    <= "0011" when 3,
                                    <= "0100" when 4,
                                    <= "0101" when 5,
                                    <= "0110" when 6,
                                    <= "0111" when 7,
                                    <= "1000" when 8,
                                    <= "1001" when 9;
M_10 <= (M - (M_100*100))/10;
    with M_10 select temp2 <= "0000" when 0,
                                    <= "0001" when 1,
                                    <= "0010" when 2,
                                    <= "0011" when 3,
                                    <= "0100" when 4,
                                    <= "0101" when 5,
                                    <= "0110" when 6,
                                    <= "0111" when 7,
                                    <= "1000" when 8,
                                    <= "1001" when 9;
M_1 <= (M - (M_100*100) - (M_10*10));   
    with M_1 select temp3 <= "0000" when 0,
                                    <= "0001" when 1,
                                    <= "0010" when 2,
                                    <= "0011" when 3,
                                    <= "0100" when 4,
                                    <= "0101" when 5,
                                    <= "0110" when 6,
                                    <= "0111" when 7,
                                    <= "1000" when 8,
                                    <= "1001" when 9;       
Y(2) <= temp1, Y(1) <= temp2, Y(0) <= temp3;

end EX;

error code : VHDL syntax error "near text "<="; expecting "(", or an identifier, or unary operator" occur in sentence with ~ select - <= ["0001", ..., "1001"] when [1,2,..., 9]

David Buck
  • 3,752
  • 35
  • 31
  • 35
hitoomi
  • 11
  • 2
  • [VHDL syntax error at near text (ID: 10500)](https://www.intel.com/content/www/us/en/programmable/quartushelp/13.0/mergedProjects/msgs/msgs/evrfx_vhdl_syntax_error.htm). IEEE Std 1076-1993 9.5.2 Selected signal assignments "selected_signal_assignment ::= with expression select target <= options selected_waveforms; selected_waveforms ::= { waveform **when** choices , } waveform **when** choices" Note the single occurrence of `<=`. There are additional semantic errors. –  May 18 '21 at 07:26
  • See [Convert 8bit binary number to BCD in VHDL](https://stackoverflow.com/questions/23871792/convert-8bit-binary-number-to-bcd-in-vhdl). –  May 18 '21 at 16:36

1 Answers1

0

I see 3 issues.

1: temp1, 2 and 3 are std_logic. They do not take vector assigments. You are probably after std_logic_vector.

2: The syntax for your with/select is wrong. It should look like this:

with M_100 select temp1 <= "0000" when 0,
                           "0001" when 1,
                           "0010" when 2,
                           "0011" when 3,
                           "0100" when 4,
                           "0101" when 5,
                           "0110" when 6,
                           "0111" when 7,
                           "1000" when 8,
                           "1001" when 9;

3: Usually it's a good idea to specify a default condition, to avoid latches or undefined logic.

with M_100 select temp1 <= "0000" when 0,
                           "0001" when 1,
                           "0010" when 2,
                           "0011" when 3,
                           "0100" when 4,
                           "0101" when 5,
                           "0110" when 6,
                           "0111" when 7,
                           "1000" when 8,
                           "1001" when 9,
                           "0000" when others;
Dharman
  • 30,962
  • 25
  • 85
  • 135
anderswb
  • 492
  • 5
  • 14