Hello, I understand that you cannot add two std_logic_vector types because a std_logic_vector does not have a numeric value. You have to convert std_logic_vector to signed/unsigned; do the math operation and convert result back to std_logic_vector. But how do you add two signals of type std_logic? A std_logic type cannot be converted to signed/unsigned type because that requires an array type. I tried the following signal D, E, F : std_logic; signal G : std_logic_vector (0 to 0); begin Monitor: process is begin D <= '1'; E <= '0'; --F <= D + E; --Compile Error - D and E are not numeric values. --F <= unsigned(D); --Compile Error - D must be an array type. --F <= unsigned(G); --NO --G <= '1'; --NO Any suggestions? Thanks very much.
Ashok M. wrote: > A std_logic type cannot be converted to signed/unsigned type because > that requires an array type. Why digging in the mud and defining own "rules"? The definition of a signed/unsigned ist very similar to that of a std_logic_vector, you can check that out the free available code of those packages: https://www.csee.umbc.edu/portal/help/VHDL/packages/numeric_std.vhd
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
And: https://www.csee.umbc.edu/portal/help/VHDL/packages/std_logic_1164.vhd
1 | |
2 | |
3 | |
4 | |
> Any suggestions? VHDL does not give room to laziness and implicity. Everything thats written must be written down explicitly. Simply use the numeric_std package to cayst between std_logic_vector and signed/unsinged. And use the vesy same package to convert from integer to signed/unsinged and vice versa: http://www.lothar-miller.de/s9y/categories/16-Numeric_Std The same picture also exists in english mutations. > std_logic_vector (0 to 0); You are taking all tricky steps at once: 1. a one element array 2. with very strange bit order...
Guest
#6842047
Ashok M. wrote: > F <= D + E; --Compile Error - D and E are not numeric values. Sure! But what do you expect? D and E are one Bit each and F is also only one Bit. So how should addition work? What is '1' + '1'? If you say 2 this is "10" and will not fit in the single Bit of F. Ashok M. wrote: > G <= '1'; --NO G <= "1";
Guest
#6842062
But ... it can be done, add two std_logic and get one std_logic_vector(1 downto 0).
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
Thanks very much for the solution. It worked. I come from Verilog
background, and it is straight forward (loosely typed language) to add
two single bits and assign result to a single bit (discarding the msb).
In line with your solution, I tried the following and that worked as
well.
variable G : std_logic_vector (1 downto 0);
variable D, E : std_logic;
variable uS1 : unsigned (1 downto 0);
uS1 := unsigned'('0' & D) + unsigned'('0' & E);
G := std_logic_vector(uS1);
Thanks.
FPGA NOTFALLSEELSORGE wrote:
> But ... it can be done, add two std_logic and get one std_logic_vector(1
> downto 0).
>
>1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
Guest
#6845804
You can write:
1 | |
Reply
Please log in before posting.