Structural Ring Oscillator VHDL - vhdl

I'm facing problems with the following ring oscillator code:
entity OSCILLATOR is
port( OUTPUT: out std_logic
);
end entity OSCILLATOR;
architecture structural of OSCILLATOR is
component DEL_INV is
generic(D: time);
port( INPUT: in std_logic;
OUTPUT: out std_logic
);
end component DEL_INV;
signal conn: std_logic := '0';
signal conn1: std_logic := '1';
signal conn2: std_logic := '0';
signal de: time := 2 ns;
begin
INV1: DEL_INV generic map(de) port map (conn, conn1);
INV2: DEL_INV generic map(de) port map (conn1, conn2);
INV3: DEL_INV generic map(de) port map (conn2, conn);
OUTPUT <= conn;
end architecture;
In particular, while simulating it, the output is always U.
Can someone explain why?

The initial values assigned to the signals conn*, to ensure well-defined start condition in simulation, are overwritten at start by an 'U' driven by the OUTPUT on the DEL_INV module, and the simulation thus ends up stuck in all U.
One solution is to handle the initial value through the DEL_INV module with a generic that allows different initial OUTPUT values, and then use this initial value on the OUTPUT until the value is well defined as '0' or '1', which can be detected through the is_x function.
Updated code for this is shown below. Note that I added the suggestions by Renaud Pacalet for for all: DEL_INV use entity work.DEL_INV(s); and inverter (not) in DEL_INV.
library ieee;
use ieee.std_logic_1164.all;
entity DEL_INV is
generic(
D: time;
XOUT: std_logic);
port(
INPUT: in std_logic;
OUTPUT: out std_logic);
end entity DEL_INV;
architecture s of DEL_INV is
signal PRE : std_logic;
begin
PRE <= (not INPUT) after D;
OUTPUT <= XOUT when is_x(PRE) else PRE; -- Drive XOUT if is_x to clean up
end architecture s;
library ieee;
use ieee.std_logic_1164.all;
entity OSCILLATOR is
port(
OUTPUT: out std_logic);
end entity OSCILLATOR;
architecture structural of OSCILLATOR is
component DEL_INV is
generic(
D: time;
XOUT: std_logic);
port(
INPUT: in std_logic;
OUTPUT: out std_logic);
end component DEL_INV;
for all: DEL_INV use entity work.DEL_INV(s);
signal conn : std_logic;
signal conn1 : std_logic;
signal conn2 : std_logic;
constant DE : time := 2 ns;
begin
INV1: DEL_INV generic map(de, '0') port map (conn, conn1);
INV2: DEL_INV generic map(de, '1') port map (conn1, conn2);
INV3: DEL_INV generic map(de, '0') port map (conn2, conn);
OUTPUT <= conn;
end architecture;

Related

Formal port does not exist in entity

I am getting this error while trying to implement a D flip-flop and simulate it:
VRFC 10-718] formal port does not exist in entity .
Please compare the definition of block to its component
declaration and its instantiation to detect the mismatch.
I am new to the language and can't figure out why this happening.
Bellow is my VHDL code.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Interfata is
port(
clk : in std_logic;
data :in std_logic;
Q : out std_logic;
Qnot : out std_logic
);
end Interfata;
architecture Behavioral of Interfata is
component LATCH
port(
set : in std_logic;
reset : in std_logic;
data : out std_logic;
data_not : out std_logic
);
end component;
signal latch_set: std_logic;
signal latch_reset:std_logic;
begin
uut1: latch port map(
set => latch_set,
reset => latch_reset,
data => Q,
data_not => Qnot
);
process(clk,data)
begin
if(clk' event and clk='1') then
latch_set <= data;
latch_reset <= not data;
end if;
end process;
end Behavioral;
here's the latch.vhd code
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity latch is
port(
set : in std_logic;
reset :in std_logic;
data : out std_logic;
data_not : out std_logic
);
end latch;
architecture Behavioral of latch is
signal data_temp : std_logic:='0';
signal data_not_temp : std_logic:='1';
begin
process(set, reset) begin
data_temp <= not(reset or data_not_temp);
data_not_temp <= not(set or data_temp);
data <= data_temp;
data_not <= data_not_temp;
end process;
end Behavioral;

VHDL 3-bit sequence counter with T-Flip Flops

I am new to VHDL and I can't see a solution to my problem. I want to find a VHDL code for my 3-bit sequence counter with T Flip Flop's which goes: ..,0,4,5,7,6,2,3,1,0,... I made a truth table and minimized equations for T_FF like so:
T0=Q2 xor Q1 xor Q0;
T1=(Q2 xor Q1) and Q0;
T2= not(Q2 xor Q1) and Q0;
Then I draw the circuit:
Last VHDL:
T-FLIP FLOP
library ieee;
use ieee.std_logic_1164.all;
entity tff is
port(
clk: in std_logic;
reset: in std_logic;
t: in std_logic;
q: out std_logic
);
end tff;
architecture behave of tff is
-- signal q_reg: std_logic; --v registru
-- signal q_next: std_logic; --naslednje stanje
begin
process
variable x: std_logic:='0';
begin
wait on clk;
if (clk' event and clk = '1') then
if reset='1' then
x:='0';
else x:=t;
end if;
end if;
if (t = '1') then
q<=not x;
else
q<=x;
end if;
end process;
end behave;
-----------------------------------------------------------
Gray counter
library ieee;
use ieee.std_logic_1164.all;
entity tff_gray is
port(
clk: in std_logic;
reset: in std_logic;
q: inout std_logic_vector (2 downto 0)
--q: out std_logic
);
end tff_gray;
architecture behave of tff_gray is
component tff is
port(
clk: in std_logic;
reset: in std_logic;
t: in std_logic;
q: out std_logic
);
end component;
signal i0,i1,i2: std_logic; --v registru
--signal q_next: std_logic; --naslednje stanje
begin
i0<=q(0) xor q(1) xor q(2);
i1<=q(0) and (q(1) xor q(2));
i2<=q(0) and not(q(1) xor q(2));
Tff0: tff port map(clk, reset, i0, Q(0));
Tff1: tff port map(clk, reset, i1, Q(1));
Tff2: tff port map(clk, reset, i2, Q(2));
end behave;
I wrote this bunch of code of what I found over the internet. When I compiled my code it all went through without a problem but the simulation is wrong. I went through this code a lot of times and I don't know what is wrong. If anyone has any idea please share.
I have mostly watched this altera site and LBEbooks on YouTube.
A number of things. Firstly:
T-FF aka toggle flip flop
You've got your toggle flip-flop description incorrect.
A toggle flip flop flips the output if T='1'. so:
signal q_int : std_logic := '0';
begin
tff_proc: process(clk) begin
if rising_edge(clk) then
if t='1' then
q_int <= not q_int;
end if;
-- reset statement
if reset='1' then
q_int <= '0';
end if;
end if;
end process;
q <= q_int;
redundant code
Don't combine wait on clk and if (clk'event and clk='1') as they do the same thing. Combining will cause issues. Refer to my example above for correct instantiations.
component instantiation
You don't need to include the component tff code in your tff_gray entity. Just simply instantiate the entity directly from the library. e.g.
Tff0: entity work.tff port map(clk, reset, i0, q(0));
bidirectional ports (inout type)
Using the inout type, which you use for the q of tff_gray can give problems in simulation and implementation. It should be out.
However, you must have encountered the cannot read outputs error. This is no longer an issue in VHDL-2008, so you should compile using VHDL-2008 mode.
Alternatively, you need to use intermediate signals, like I did in the example above. E.g.
signal q_int : std_logic_vector(2 downto 0) := (others => '0');
[...]
q <= q_int;

VHDL Testbench : Output not changing

I'm currently learning about writing testbenchs for my VHDL components. I am trying to test a clock synchronizer, just made up of two cascaded D-type flip flops. I have written a testbench, supplying a clock and appropriate input signal stimuli but I see no output changing when I simulate, it just remains at "00".
I would be very grateful for any assistance!
EDIT: the dff component is a standard Quartus component, not quite sure how to get at the internal code.
Here is the component VHDL:
library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
--This device is to synchronize external signals that are asynchronous to the
--system by use of two cascaded D-Type flip flops, in order to avoid metastability issues.
--Set the generic term Nbits as required for the number of asynchronous inputs to
--be synchronized to the system clock OUTPUT(0) corresponds to INPUT(0), ect.
entity CLOCK_SYNCHRONIZER is
generic(Nbits : positive := 2);
port
(
--Define inputs
SYS_CLOCK : in std_logic;
RESET : in std_logic;
INPUT : in std_logic_vector(Nbits-1 downto 0);
--Define output
OUTPUT : out std_logic_vector(Nbits-1 downto 0) := (others=>'0')
);
end entity;
architecture v1 of CLOCK_SYNCHRONIZER is
--Declare signal for structural VHDL component wiring
signal A : std_logic_vector(Nbits-1 downto 0);
--Declare D-Type Flip-Flop
component dff
port(D : in std_logic; CLK : in std_logic; CLRN : in std_logic; Q : out std_logic);
end component;
begin
--Generate and wire number of synchronizers required
g1 : for n in Nbits-1 downto 0 generate
c1 : dff port map(D=>input(n), CLK=>sys_clock, Q=>A(n), CLRN=>reset);
c2 : dff port map(D=>A(n), CLK=>sys_clock, Q=>output(n), CLRN=>reset);
end generate;
end architecture v1;
And here is the testbench:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity testbench is
end entity;
architecture v1 of testbench is
component CLOCK_SYNCHRONIZER
generic(Nbits : positive := 2);
port
(
--Define inputs
SYS_CLOCK : in std_logic;
RESET : in std_logic;
INPUT : in std_logic_vector(Nbits-1 downto 0);
--Define output
OUTPUT : out std_logic_vector(Nbits-1 downto 0)
);
end component;
constant Bus_width : integer := 2;
signal SYS_CLOCK : std_logic := '0';
signal RESET : std_logic := '1';
signal INPUT : std_logic_vector(Bus_width-1 downto 0) := (others=>'0');
signal OUTPUT : std_logic_vector(Bus_width-1 downto 0) := (others=>'0');
begin
C1 : CLOCK_SYNCHRONIZER
generic map(Nbits=>Bus_width)
port map(SYS_CLOCK=>SYS_CLOCK, RESET=>RESET, INPUT=>INPUT, OUTPUT=>OUTPUT);
always : process
begin
for i in 0 to 50 loop
INPUT <= "11";
wait for 24ns;
INPUT <= "00";
wait for 24ns;
end loop;
WAIT;
end process;
clk : process
begin
for i in 0 to 50 loop
SYS_CLOCK <= '1';
wait for 5ns;
SYS_CLOCK <= '0';
wait for 5ns;
end loop;
WAIT;
end process;
end architecture v1;
The problem is that you have not compiled an entity to bind to the dff component. See this example on EDA Playground, where you see the following warnings:
ELAB1 WARNING ELAB1_0026: "There is no default binding for component
"dff". (No entity named "dff" was found)." "design.vhd" 45 0 ...
ELBREAD: Warning: ELBREAD_0037 Component /testbench/C1/g1__1/c1 : dff not bound.
ELBREAD: Warning: ELBREAD_0037 Component /testbench/C1/g1__1/c2 : dff not bound.
ELBREAD: Warning: ELBREAD_0037 Component /testbench/C1/g1__0/c1 : dff not bound.
ELBREAD: Warning: ELBREAD_0037 Component /testbench/C1/g1__0/c2 : dff not bound.
Given you have no configuration, this needs to have be called dff and must have exactly the same ports as the dff component, ie:
entity dff is
port(D : in std_logic; CLK : in std_logic; CLRN : in std_logic; Q : out std_logic);
end entity;
(Google "VHDL default binding rules")
This needs to model the functionality of the dff flip-flop. I have assumed the following functionality:
architecture v1 of dff is
begin
process (CLK, CLRN)
begin
if CLRN = '0' then
Q <= '0';
elsif rising_edge(CLK) then
Q <= D;
end if;
end process;
end architecture v1;
You can see this now does something more sensible on EDA Playground. (I haven't checked to see whether it is doing the right thing.)
BTW: why are you initialising this output? That seems a strange thing to do:
OUTPUT : out std_logic_vector(Nbits-1 downto 0) := (others=>'0')

how to get a T flip flop simulation waveform using Xilinx ISE design suite

I tried to simulate a TFF using Xilinx ISE web pack and ModelSim using following block diagram and structural Code was written using VHDL. But I am unable to get the correct waveform. Due to the T-flip flop is sequential circuit, first I gave the output value as 1 or 0 for one output (Q) to start to the process.
T flip flop truth table and block diagram
simulation waveform
code for AND gate:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity AND_GATE is
Port ( X : in STD_LOGIC;
Y : in STD_LOGIC;
W : in STD_LOGIC;
Z : out STD_LOGIC);
end AND_GATE;
architecture Behavioral of AND_GATE is
begin
Z <= X AND Y AND W;
end Behavioral;
code for NOR gate:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity NOR_GATE is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
C : out STD_LOGIC);
end NOR_GATE;
architecture Behavioral of NOR_GATE is
begin
c <= A NOR B;
end Behavioral;
code for T-FF:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TFF_2 is
Port ( T : in STD_LOGIC;
CLK : in STD_LOGIC;
Q : inout STD_LOGIC;
s : inout STD_LOGIC);
end TFF_2;
architecture STRUCTURAL of TFF_2 is
--declare components being used in T -FF
component TFF is
Port ( T : in STD_LOGIC;
CLK : in STD_LOGIC;
RST : in STD_LOGIC;
Q : out STD_LOGIC);
end component;
component NOR_GATE is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
C : out STD_LOGIC);
end component;
component AND_GATE is
Port ( X : in STD_LOGIC;
Y : in STD_LOGIC;
W : in STD_LOGIC;
Z : out STD_LOGIC);
end component;
--declare signals
signal S1, S2 : STD_LOGIC;
begin
C1 : AND_GATE port map (Q, T, CLK, S1);
C2 : AND_GATE port map (S, T, CLK, S2);
C3 : NOR_GATE port map (S1, S, Q);
C4 : NOR_GATE port map (S2, Q, S);
end STRUCTURAL;
These files synthesized without any errors but in the simulation expected output was not given.
There are a few suggestions I have.
There are non initialised variables. Add := '0'; at the end of the declarations. Simulation might show "X" or unknown. The Synthesised design will work OK, being the hardware will go to one or zero, but simulators need to be directed.
Some of your output variables have feedback into inputs. The design is asynchronous, being that you are not using a clock of some description to time the iterations. Consider using a process and something like if rising_edge(clk)

VHDL: Internal signal in component not triggered

I am new to VHDL. I have this entity (shortened):
entity foo is
port (CLK : in std_logic;
out_A : out std_logic;
);
end foo;
architecture Structure of foo is
component D_Flipflop
port (
D : in std_logic;
CLK : in std_logic;
Q : out std_logic;
not_Q : out std_logic);
end component;
signal D_A, qA, not_qA : std_logic;
begin
my_Flipflop : D_Flipflop
port map(
not_qA,
CLK,
qA,
not_qA
);
end Structure;
As you can see, I want to use the D_Flipflop like a Toggle-Flipflop, so I redirected the output to the input by the signal not_qA (is that possible?). The problem is that from outside, only the port CLK of foo is visible as input and - at least in the Vivado Simulator - the signals qA and not_qA are never evaluated.
This is the architecture of D_Flipflop:
architecture Behavioral of D_Flipflop is
begin
set_state : process(CLK, D)
variable state : std_logic := '0';
begin
if falling_edge(CLK) then
state := D;
Q <= state;
not_Q <= not state;
end if;
end process set_state;
end Behavioral;
I googled a lot for this. No chance. Any solutions?
It's not as you indicate in the title to the question that the internal signal to component my_Flipflop didn't trigger, it's that there is no method to provide a known non-meta value state - the not of 'U' is 'U'.
This is caused by the not operator. Refer to the not_table in the
body of package std_logic_1164:
-- truth table for "not" function
CONSTANT not_table: stdlogic_1d :=
-- -------------------------------------------------
-- | U X 0 1 Z W L H - |
-- -------------------------------------------------
( 'U', 'X', '1', '0', 'X', 'X', '1', '0', 'X' );
See the changes and the added testbench:
library ieee; -- Added Context clause (MCVe)
use ieee.std_logic_1164.all;
entity D_Flipflop is
port (
D: in std_logic;
CLK: in std_logic;
Q: out std_logic;
not_Q: out std_logic := '0'
);
end entity;
architecture behavioral of D_Flipflop is
begin
set_state:
process (CLK) -- removed D from sensitivity list
variable state: std_logic := '0';
begin
if falling_edge(CLK) then
state := D;
Q <= state;
not_Q <= not state;
end if;
end process;
end architecture;
library ieee; -- added context clause
use ieee.std_logic_1164.all;
entity foo is
port (
CLK: in std_logic;
out_A: out std_logic -- removed extra ';'
);
end entity;
architecture Structure of foo is
component D_Flipflop is
port (
D: in std_logic;
CLK: in std_logic;
Q: out std_logic;
not_Q: out std_logic
);
end component;
-- signal D_A: std_logic; -- not used
signal qA: std_logic;
signal not_qA: std_logic := '1'; -- notice this didn't matter
begin
my_Flipflop:
D_Flipflop
port map (
not_qA,
CLK,
qA,
not_qA
);
out_A <= qA; -- Added
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity foo_tb is
end entity;
architecture fum of foo_tb is
signal CLK: std_logic := '0';
signal out_A: std_logic;
begin
DUT:
entity work.foo
port map (
CLK => CLK,
out_A => out_A
);
CLOCK:
process
begin
wait for 10 ns;
CLK <= not CLK;
if Now > 200 ns then
wait;
end if;
end process;
end architecture;
The not_Q output of the D_Flipflop has been initialized to '0' (it could have as easily been initialized to '1'). This represents the equivalent of a collector set for the Flip Flop on power up.
Now the Flip Flop can toggle - it has a known non-meta value on the D input.
This gives:
(clickable)

Resources