Error (10476): VHDL error at PEnc83.vhd(42): type of identifier "sy" does not agree with its usage as "std_ulogic" type - vhdl

I'm new to VHDL and I don't understand what is giving me the error:
Error (10476): VHDL error at PEnc83.vhd(42): type of identifier "sy" does not agree with its usage as "std_ulogic" type
This error also applies for "sz".
Here is my code:
library ieee;
use ieee.std_logic_1164.all;
entity PEnc83 is
port(I: in STD_LOGIC_VECTOR(7 downto 0);
O: out STD_LOGIC_VECTOR(2 downto 0);
V: out STD_LOGIC_VECTOR);
end PEnc83;
architecture arq_penc83 of PEnc83 is
component PEnc421
port(
a: in STD_LOGIC_VECTOR(3 downto 0);
b: out STD_LOGIC_VECTOR(1 downto 0);
v: out std_logic_vector);
end component;
component MUX2
port(A, B: in STD_LOGIC_VECTOR(1 downto 0);
sel: in std_logic;
O: out STD_LOGIC_VECTOR(1 downto 0));
end component;
SIGNAL sa, sx, sb : std_logic_vector(1 downto 0);
SIGNAL sy, sz : std_logic_vector;
Begin
UPEnc1: PEnc421 port map (
a => I,
b => sa,
v => sy);
UPEnc2: PEnc421 port map (
a => I,
b => sx,
v => sz);
UPEnc3: PEnc421 port map (
a(0) => sy,
a(1) => sz,
a(2) => '0',
a(3) => '0',
b => sb,
v => V);
UMUX2: MUX2 port map(
A => sa,
B => sx,
sel => sb(2),
O => O);
O(2) <= sb(2);
end arq_penc83;
Since sy and sz are signals it should work like the other ones. But for some reason it just isn't, maybe is it because they are only 1 vector, but they are supposed to be only one vector that connects to PEnc3.

Change line 42 to "a(0) => sy(0)", change line 43 in the same way. Then the compiler will probably accept your code.

You have multiple errors in your source:
If you mean a single bit, use std_logic instead of std_logic_vector. I interpreted all places without constraints (( .. downto .. )) as such.
If you want to connect only parts of a vector, you need to specify this. This is specifically necessary where you assign vectors of different widths.
Do not use indexes outside the constraints.
Presumably you became confused when you "wired" the multiplexer.
This is a corrected source, which does not produce syntax errors. However, it can have logical errors, because I don't know the logic you try to implement.
library ieee;
use ieee.std_logic_1164.all;
entity PEnc83 is
port(I: in STD_LOGIC_VECTOR(7 downto 0);
O: out STD_LOGIC_VECTOR(2 downto 0);
V: out STD_LOGIC);
end PEnc83;
architecture arq_penc83 of PEnc83 is
component PEnc421
port(
a: in STD_LOGIC_VECTOR(3 downto 0);
b: out STD_LOGIC_VECTOR(1 downto 0);
v: out std_logic);
end component;
component MUX2
port(A, B: in STD_LOGIC_VECTOR(1 downto 0);
sel: in std_logic;
O: out STD_LOGIC_VECTOR(1 downto 0));
end component;
SIGNAL sa, sx, sb : std_logic_vector(1 downto 0);
SIGNAL sc, sy, sz : std_logic;
Begin
UPEnc1: PEnc421 port map (
a => I(7 downto 4),
b => sa,
v => sy);
UPEnc2: PEnc421 port map (
a => I(3 downto 0),
b => sx,
v => sz);
UPEnc3: PEnc421 port map (
a(0) => sy,
a(1) => sz,
a(2) => '0',
a(3) => '0',
b => sb,
v => V);
UMUX2: MUX2 port map(
A => sa,
B => sx,
sel => sb(0),
O => O(1 downto 0));
O(2) <= sc;
end arq_penc83;

Related

undefined symbol error but the symbol appears to be defined in the code VHDL

so, i keep getting those errors and I don`t know how to do to resolve them because I have the definition of the component in the code. Those are the errors:
ERROR:HDLParsers:3312 - "D:/licenta/multyv3/multy.vhd" Line 123.
Undefined symbol 'D'. ERROR:HDLParsers:1209 -
"D:/licenta/multyv3/multy.vhd" Line 123. D: Undefined symbol (last
report in this block) ERROR:HDLParsers:3312 -
"D:/licenta/multyv3/multy.vhd" Line 124. Undefined symbol 'Q'.
ERROR:HDLParsers:1209 - "D:/licenta/multyv3/multy.vhd" Line 124. Q:
Undefined symbol (last report in this block)
The errors are in the cell_4
entity multy is
port (
x: in std_logic_vector (3 downto 0);
y: in std_logic_vector (3 downto 0);
p: out std_logic_vector (7 downto 0);
clk: in std_logic
);
end entity multy;
architecture rtl of multy is
component Ripple_Adder
port (
A: in std_logic_vector (3 downto 0);
B: in std_logic_vector (3 downto 0);
Cin: in std_logic;
S: out std_logic_vector (3 downto 0);
Cout: out std_logic
);
end component;
component FlipFlopPack
generic(
N : integer := 4
);
port(
Q : out std_logic_vector (N-1 downto 0);
Clk : in std_logic;
D : in std_logic_vector (N-1 downto 0)
);
end component;
-- AND Product terms:
signal G0, G1, G2: std_logic_vector (3 downto 0);
-- B Inputs (B0 has three bits of AND product)
signal B0, B1, B2: std_logic_vector (3 downto 0);
-- D flip flop signals (Qyout)
signal I: std_logic_vector (3 downto 0);
-- D flip flop signal (Qxout)
signal O: std_logic_vector (3 downto 0);
-- d flip flop signal for S
signal S1, S2, S3: std_logic_vector (3 downto 0);
-- signal for p
signal P1: std_logic_vector (3 downto 0);
begin
-- y(1) thru y (3) AND products, assigned aggregates:
G0 <= (O(3) and I(1), O(2) and I(1), O(1) and I(1), O(0) and I(1));
G1 <= (O(3) and I(2), O(2) and I(2), O(1) and I(2), O(0) and I(2));
G2 <= (O(3) and I(3), O(2) and I(3), O(1) and I(3), O(0) and I(3));
-- y(0) AND products (and y0(3) '0'):
B0 <= ('0', O(3) and I(0), O(2) and I(0), O(1) and I(0));
-- named association:
cell_1:
Ripple_Adder
port map (
a => G0,
b => B0,
cin => '0',
cout => S1(3), -- named association can be in any order
S(3) => S1(2), -- individual elements of S, all are associated
S(2) => S1(1), -- all formal members must be provide contiguously
S(1) => S1(0),
S(0) => P1(1)
);
cell_2:
Ripple_Adder
port map (
a => G1,
b => B1,
cin => '0',
cout => S2(3),
S(3) => S2(2),
S(2) => S2(1),
S(1) => S2(0),
S(0) => P1(2)
);
cell_3:
Ripple_Adder
port map (
a => G2,
b => B2,
cin => '0',
cout => S3(3),
S(3) => S3(2),
S(2) => S3(1),
S(1) => S3(0),
S(0) => P1(3)
);
cell_4:
FlipFlopPack
port map (
x => D,
O => Q,
clk => clk
);
cell_5:
FlipFlopPack
port map (
y => D,
I => Q,
clk => clk
);
cell_6:
FlipFlopPack
port map (
S1 => D,
B1 => Q,
clk => clk
);
cell_7:
FlipFlopPack
port map (
S2 => D,
B2 => Q,
clk => clk
);
cell_8:
FlipFlopPack
port map (
S3 => D,
p(7 downto 4) => Q,
clk => clk
);
cell_9:
FlipFlopPack
port map (
P(3 downto 0) => D,
p(3 downto 0) => Q,
clk => clk
);
P1(0) <= O(0) and I(0);
end architecture rtl;
The port names of the component need to be on the left side of =>
For example:
cell_4:
FlipFlopPack
port map (
D => x,
Q => O,
Clk => clk
);
This applies to all instantiations of FlipFlopPack.

VHDL typecast signed to std_logic_vector

I am looking at this example and below answer which is a nice solution to produce two's complement:
library ieee;
use ieee.numeric_std.all;
entity twoscomplement is
generic
(
Nbits : positive := 8
);
port
(
A : in unsigned (Nbits-1 downto 0);
Y : out signed (Nbits downto 0)
);
end entity twoscomplement;
architecture a1 of twoscomplement is
begin
Y <= -signed(resize(A, Y'length));
end architecture;
I want to use the said example to have two's complement and then make a "16-bit subtractor". The code will look like the following:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity subtractor_16bit is
Port ( a : in STD_LOGIC_VECTOR(15 downto 0);
b : in STD_LOGIC_VECTOR(15 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR(15 downto 0);
cout : out STD_LOGIC;
over : out STD_LOGIC
);
end subtractor_16bit;
architecture Behavioral of subtractor_16bit is
component fulladder_16bit is
Port (
a : in STD_LOGIC_VECTOR(15 downto 0);
b : in STD_LOGIC_VECTOR(15 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR(15 downto 0);
cout : out STD_LOGIC;
over : out STD_LOGIC
);
end component;
component twoscomplement is
Port (
A : in unsigned (15 downto 0);
C : out signed (15 downto 0)
);
end component;
signal n1 : STD_LOGIC_VECTOR(15 downto 0);
begin
twoscomplement_1: twoscomplement port map (a => a ,c => n1); --ERROR
fulladder_16bit_1: fulladder_16bit port map (a => a, b => n1, sum => sum , cin => cin, cout => cout, over => over);
end Behavioral;
However, I am receiving an error saying:
Error: type error near a; current type std_logic_vector; expected type unsigned.
Kindly help me to solve this problem.
As nobody is answering this and nobody is down voting it, I will answer.
Look at the error
Error: type error near a; current type std_logic_vector; expected type unsigned.
Now look at entity subtractor_16bit.
[...]
entity subtractor_16bit is
Port ( a : in STD_LOGIC_VECTOR(15 downto 0);
[...]
component twoscomplement is
Port (
A : in unsigned (15 downto 0);
[...]
twoscomplement_1: twoscomplement port map (a => a ,c => n1);
[...]
What do you see? twoscomplement expects an unsigned, while a is std_logic_vector! Just like the error says.
std_logic_vector and unsigned are two separate types. As VHDL is a strongly typed language, you cannot just put the data from one type to another. You need to use type conversion.
For unrelated types, you should implement a type conversion function. Or functions, if you want bidirectional conversion. E.g.
function (input : type_a) return type_b;
But in this case, std_logic_vector and unsigned have the same underlying type, std_logic. (std_ulogic actually since VHDL-2008 I believe.)
In that case you can convert from one type to another explicitly. E.g.
signal a_u : unsigned(y downto 0);
signal a_slv : std_logic_vector(y downto 0);
begin
a_u <= unsigned(a_slv);
Next, your not instantiating the twoscomplement component properly. The entity has a generic Nbits. By default you set it to 8. But in your architecture Behavioral of subtractor_16bit, you feed it with 16 bits, without changing the generic value. That doesn't work.
Also: twoscomplement has two ports: A and Y. But in subtractor_16bit you start using A and C. That's bad coding practice.
Finally, you can drop the component declarations. Just instantiate the entities from the library. E.g.
twoscomplement_1: entity work.twoscomplement [...]
So, subtractor_16bit should look something like this:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity subtractor_16bit is
Port (
a : in STD_LOGIC_VECTOR(15 downto 0);
b : in STD_LOGIC_VECTOR(15 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR(15 downto 0);
cout : out STD_LOGIC;
over : out STD_LOGIC
);
end entity;
architecture structural of subtractor_16bit is
use IEEE.NUMERIC_STD.ALL;
signal n1 : signed(a'range);
begin
twoscomplement_1: entity work.twoscomplement
generic map(
NBits => a'length
)
port map (
a => unsigned(a),
y => n1
);
fulladder_16bit_1: entity work.fulladder_16bit
port map (
a => a,
b => std_logic_vector(n1),
sum => sum,
cin => cin,
cout => cout,
over => over
);
end architecture;
...
HOWEVER this will still not work.
As you see on your entity twoscomplement, port A has a size of NBits, and port Y has a size of NBits+1. That is because you seem to want to keep 16-bit value precision. So when converting unsigned to signed, you need to add a 17th bit for the sign. As a result, the rest of you code will need to be modified!
.... But this can be fixed a different way. I will learn you something about two's complement: -a = not(a) + 1.
Proof (Take 4 bits signed precision):
0 = b'0000 => -0 is not(b'0000)+1 = b'1111'+1 = b'0000'
7 = b'0111 => -7 is not(b'0111)+1 = b'1000'+1 = b'1001'
-6 = b'1010' => 6 is not(b'1010)+1 = b'0101'+1 = b'0110'
See?
So now I will solve your puzzle for you:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity subtractor_16bit is
Port (
a : in STD_LOGIC_VECTOR(15 downto 0);
b : in STD_LOGIC_VECTOR(15 downto 0);
sum : out STD_LOGIC_VECTOR(15 downto 0);
cout : out STD_LOGIC;
over : out STD_LOGIC
);
end entity;
architecture structural of subtractor_16bit is
begin
fulladder_16bit_1: entity work.fulladder_16bit
port map (
a => a,
b => not(b),
sum => sum,
cin => '1',
cout => cout,
over => over
);
end architecture;
You will still need to change/fix the cout and over behavior...

Why am I not seeing an output when I synthesize?

I have been working on a lab assignment that is practically complete, but am running into an issue where I am not seeing an output when synthesizing. I have 7 blocks, that when tested individually display the correct output. How is it that I wouldn't get any output at all when using the top module and test bench files? Below is my top module, followed by my test bench as I suspect the problem may be there. I've looked it over and can't pinpoint anything I may have done wrong. Any help would be appreciated.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity top_module is port(
x,y : in std_logic_vector(7 downto 0);
opcode : in std_logic_vector(2 downto 0);
z : out std_logic_vector(7 downto 0)
);
end top_module;
architecture behavior of top_module is
signal bwAnd, bwOr, bwXor, add, subtract, bwComplement, mux_in1, mux_in2, mux_in3, mux_in4, mux_in5, mux_in6 : std_logic_vector(7 downto 0);
component BW_And is port(
x,y : in std_logic_vector(7 downto 0);
z1 : out std_logic_vector(7 downto 0)
);
end component;
component BW_Rr is port(
x,y : in std_logic_vector(7 downto 0);
z2 : out std_logic_vector(7 downto 0)
);
end component;
component BW_Xor is port(
x,y : in std_logic_vector(7 downto 0);
z3 : out std_logic_vector(7 downto 0)
);
end component;
component full_adder_8 is port(
x,y : in std_logic_vector(7 downto 0);
cin : in std_logic_vector(7 downto 0) := "00000000";
sum, cout: out std_logic_vector(7 downto 0)
);
end component;
component full_subtractor_8 is port(
x,y : in std_logic_vector(7 downto 0);
cin : in std_logic_vector(7 downto 0) := "11111111";
difference, cout: out std_logic_vector(7 downto 0)
);
end component;
component Complement is port(
x : in std_logic_vector(7 downto 0);
z4 : out std_logic_vector(7 downto 0)
);
end component;
component mux is port(
z1,z2,z3,sum,difference,z4 : in std_logic_vector(7 downto 0);
opcode : in std_logic_vector(2 downto 0);
mux_out : out std_logic_vector(7 downto 0)
);
end component;
begin
--instantiating components and mapping ports
c0: BW_And port map(x => x, y => y, z1 => bwAnd);
c1: BW_Or port map(x => x, y => y, z2 => bwOr);
c2: BW_Xor port map(x => x, y => y, z3 => bwXor);
c3: full_adder_8 port map(x => x, y => y, sum => add);
c4: full_subtractor_8 port map(x => x, y => y, difference => subtract);
c5: Complement port map(x => x, z4 => bwComplement);
c6: mux port map(z1 => mux_in1, z2 => mux_in2, z3 => mux_in3, sum => mux_in4, difference => mux_in5, z4 =>mux_in6, opcode => opcode, mux_out => z);
end behavior;
Test Bench:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Lab4 is
end Lab4;
architecture behavior of Lab4 is
component top_module is port(
x,y : in std_logic_vector(7 downto 0);
opcode : in std_logic_vector(2 downto 0);
z : out std_logic_vector(7 downto 0)
);
end component;
signal test_x : std_logic_vector(7 downto 0);
signal test_y : std_logic_vector(7 downto 0);
signal test_opcode : std_logic_vector(2 downto 0) := "000";
signal test_z : std_logic_vector(7 downto 0);
begin
uut: top_module port map (x => test_x, y => test_y, opcode => test_opcode, z => test_z);
sim_proc : process
begin
test_x <= "00010100"; test_y <= "11001111"; test_opcode <= "000";
wait for 100 ns;
test_x <= "00010100"; test_y <= "11001111"; test_opcode <= "001";
wait for 100 ns;
test_x <= "00010100"; test_y <= "11001111"; test_opcode <= "010";
wait for 100 ns;
test_x <= "00010100"; test_y <= "11001111"; test_opcode <= "011";
wait for 100 ns;
test_x <= "00010100"; test_y <= "11001111"; test_opcode <= "100";
wait for 100 ns;
test_x <= "00010100"; test_y <= "11001111"; test_opcode <= "101";
end process;
end behavior;
Entities for each component:
entity BW_And is port(
x,y : in std_logic_vector(7 downto 0);
z1 : out std_logic_vector(7 downto 0)
);
end BW_And;
entity BW_Or is port(
x,y : in std_logic_vector(7 downto 0);
z2 : out std_logic_vector(7 downto 0)
);
end BW_Or;
entity BW_Xor is port(
x,y : in std_logic_vector(7 downto 0);
z3 : out std_logic_vector(7 downto 0)
);
end BW_Xor;
entity full_adder_8 is port(
x,y : in std_logic_vector(7 downto 0);
cin : in std_logic_vector(7 downto 0) := "00000000";
sum, cout: out std_logic_vector(7 downto 0)
);
end full_adder_8;
entity full_subtractor_8 is port(
x,y : in std_logic_vector(7 downto 0);
cin : in std_logic_vector(7 downto 0) := "11111111";
difference, cout: out std_logic_vector(7 downto 0)
);
end full_subtractor_8;
entity Complement is port(
x : in std_logic_vector(7 downto 0);
z4 : out std_logic_vector(7 downto 0)
);
end Complement;
entity mux is port(
z1,z2,z3,sum,difference,z4 : in std_logic_vector(7 downto 0);
opcode : in std_logic_vector(2 downto 0);
mux_out : out std_logic_vector(7 downto 0)
);
end mux;
I realized where my problem was after all. The issue was with my mux file. In my process, I only passed "opcode" neglecting to pass in all of the inputs.
Before:
process (opcode)
.
.
.
end process;
After:
process (z1,z2,z3,sum,difference,z4,opcode)
.
.
.
end process;

vhdl feedback the output of a block to its input

I have an adder block and I need to feed the output (std_logic_vector) back to one of the adder's input ports to be added with another number (This is to be done in another entity where the adder is used.). I tried to do that thru a process with sensitivity list but it did not work. Is there a way to do so?
Note: no clocks are used.
Here is my code:
library IEEE;
use IEEE.std_logic_1164.all;
entity example is
port (
X: IN std_logic_vector(15 downto 0);
Y: IN std_logic_vector(15 downto 0);
Z: OUT std_logic_vector(15 downto 0)
);
end example;
architecture arch_example of example is
component adder is
port(a: in std_logic_vector(15 downto 0);
b: in std_logic_vector(15 downto 0);
cin: in std_logic;
s: out std_logic_vector(15 downto 0);
overflow: out std_logic);
end component;
signal s, ain, bin: std_logic_vector(15 downto 0);
signal cin, overflow, useless: std_logic;
begin
process(x, y) is
begin
ain <= x;
bin <= y;
cin <= '0';
end process;
process(s, overflow) is
begin
ain <= s;
bin <= "1111111110000001";
cin <= overflow;
end process;
U1: adder port map (ain, bin, cin, s, overflow);
z <= s;
end arch_example;
In your code, you have multiple drivers for the signals ain, bin, and cin because two processes are driving these signals at the same time. You can think of it as two gates driving the same wire.
To add another number to an intermediate result in a fully combinational design, you will need a second adder. The first adder cannot be re-used because you cannot easily tell, when to switch to the new inputs with multiplexers for example. (It will be possible with the concepts of asynchronous logic, but that is much more complex.)
A simple solution is to instantiate your adder component twice:
architecture arch_example of example is
component adder is
port(a: in std_logic_vector(15 downto 0);
b: in std_logic_vector(15 downto 0);
cin: in std_logic;
s: out std_logic_vector(15 downto 0);
overflow: out std_logic);
end component;
signal s : std_logic_vector(15 downto 0);
signal overflow : std_logic;
begin
U1: adder port map (x, y, '0', s, overflow);
U2: adder port map (s, "1111111110000001", overflow, z, open);
end arch_example;
The code snippet above uses positional assignment of component ports. This should be avoided because one can easily mixup the order of the ports. I recommend to use named assignments instead. Here one can explictly see which port (on the left of =>) is assigned to which signal (on the right):
architecture arch_example of example is
component adder is
port(a: in std_logic_vector(15 downto 0);
b: in std_logic_vector(15 downto 0);
cin: in std_logic;
s: out std_logic_vector(15 downto 0);
overflow: out std_logic);
end component;
signal s : std_logic_vector(15 downto 0);
signal overflow : std_logic;
begin
U1: adder port map (
a => x,
b => y,
cin => '0',
s => s,
overflow => overflow);
U2: adder port map (
a => s,
b => "1111111110000001",
cin => overflow,
s => z,
overflow => open);
end arch_example;

How to map with a 163 bit number with a 1-bit number?

I have two 163 bit numbers and and I want to map with the multiplier. But for the multiplier, a (162 downto 0) and b is only one bit. So how can I do that? Please help.
entity demo_pointadd is
Port ( x : in STD_LOGIC_VECTOR (162 downto 0);
y : in STD_LOGIC_VECTOR(162 downto 0);
p : out STD_LOGIC_VECTOR (162 downto 0);
q : out STD_LOGIC_VECTOR (162 downto 0);
clk : in STD_LOGIC;
reset : in STD_LOGIC);
end demo_pointadd;
-- component declaration
component full_163bitmul
Port ( a : in STD_LOGIC_VECTOR (162 downto 0);
b : in STD_LOGIC;
clk : in STD_LOGIC;
reset : in STD_LOGIC;
c : out STD_LOGIC_VECTOR (162 downto 0));
end component;
begin
mul_1 :full_163bitmul
port map (a => x,
b => y, --- PROBLEM??
clk => clk,
reset => reset,
c => p);
this seems to be no multiplier by itself. when I take a guess on the code of full_163bitmul, the output 'c' will be 'a' (if b='1') or all Zeros (if b='0') or undefined (if b is 'Z' | 'X' | ...).
if you want to build a full multiplier out of it, you have to loop through 'y' vector and bring single bits to 'b' input and add-and-shift the results.
sig_b<=y(i);
mul_1 :full_163bitmul
port map
(a => s_x,
b => sig_b,
clk => clk,
reset => reset,
c => temp);
...

Resources