I am confused about sequential logic with components (I am new).
I have these components, but I get confused how to use them within a process. I need help understanding how sequential logic works with components, also I am unsure if my input/output vectors are correct. I'm having trouble with the inputs and outputs for the shift registers, like if x(0) <= sin is the right call.
I have to design this:
(https://i.stack.imgur.com/mwVdw.jpg)
This is my main file
use IEEE.STD_LOGIC_1164.ALL;
entity sa_top is
port(
x: in STD_LOGIC_VECTOR(7 downto 0);
y: in STD_LOGIC_VECTOR(7 downto 0);
clk: in STD_LOGIC;
rst: in STD_LOGIC;
s: out STD_LOGIC_VECTOR(7 downto 0)
);
end sa_top;
architecture Behavioral of sa_top is
-- shift register
component sr is
port(
sin: in STD_LOGIC;
sout: out STD_LOGIC;
clk: in STD_LOGIC;
rst: in STD_LOGIC
);
end component sr;
-- d flip/flop
component dff is
port(
d: in STD_LOGIC;
q: in STD_LOGIC;
clk: in STD_LOGIC;
rst: in STD_LOGIC
);
end component dff;
-- full adder
component fa is
port(
a: in STD_LOGIC;
b: in STD_LOGIC;
cin: in STD_LOGIC;
sum: out STD_LOGIC;
cout: out STD_LOGIC
);
end component fa;
signal xi, yi, si: std_logic;
signal xo, yo, so: std_logic;
signal s_temp: std_logic;
signal carry: std_logic;
begin
xi <= x(0);
yi <= y(0);
inp_x_instance: sr port map(sin => xi, sout => xo, clk => clk, rst => rst);
inp_y_instance: sr port map(sin => yi, sout => yo, clk => clk, rst => rst);
adder_instace: fa port map(a => xo, b=> yo, cin => carry, sum => si, cout => carry);
op_s_instance: sr port map(sin => si, sout => so, clk => clk, rst => rst);
--df_instance: dff port map(d => s_temp, q => s_temp, clk => clk, rst => rst);
process(clk, s_temp) is
begin
if rst = '1' then
s <= (others=>'0');
elsif rising_edge(clk) then
s(0) <= so;
end if;
end process;
end Behavioral;```
I think what you are doing is correct, the only thing that you maybe got confused about is the actual shifting itself, you need to shift it the bits by 1 to the left into the other bits. Which can look something like this:
s(7 downto 1) <= s(6 downto 0);
So the final piece of code should look like this: (note that I have removed s_temp from the sensitivity list of the process)
process(clk) is
begin
if rst = '1' then
s <= (others=>'0');
elsif rising_edge(clk) then
s(7 downto 1) <= s(6 downto 0);
s(0) <= so;
end if;
end process;
Related
I got the warning "[Synth 8-6014] Unused sequential element MVM_RST_reg was removed. "
I am a little bit confused, because the signal is connected and used
The definition:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use IEEE.math_real.all;
use work.parameters.all;
entity MVM is
port (
EN: IN std_logic;
DIN: IN signed(DATA_WIDTH_IN-1 downto 0);
WEIGHT: IN signed(DATA_WIDTH_IN -1 downto 0);
CLK: IN std_logic;
RST: IN std_logic;
MVM_RESULT: OUT signed(DATA_WIDTH_IN-1 downto 0):= (OTHERS => '0')
);
end entity MVM;
architecture base of MVM is
begin
process(CLK)
variable acc_value : signed(DATA_WIDTH_IN-1 downto 0):= (OTHERS => '0');
begin
IF rising_edge(CLK) then
IF RST='1' THEN
acc_value := (OTHERS => '0'); -- reset accumulated value to 0
ELSIF EN='1' THEN
acc_value := resize((acc_value + WEIGHT* DIN), DATA_WIDTH_IN);
MVM_RESULT <= acc_value;
END IF;
END IF;
END process;
end base;
My component
component MVM is
port (
EN: in std_logic;
DIN: IN signed(DATA_WIDTH_IN-1 downto 0);
WEIGHT: IN signed(DATA_WIDTH_IN-1 downto 0);
CLK: IN std_logic;
RST: IN std_logic;
MVM_RESULT: OUT signed(DATA_WIDTH_IN-1 downto 0)
);
The signal
signal MVM_RST: std_logic;
My instantiation
MVM_UNITS: MVM
port MAP(
EN => MVM_En,
DIN => DIN_Array(i) ,
Weight => WEIGHT_Array(i),
CLK => CLK,
RST => MVM_RST,
MVM_RESULT => MVM_RESULT_ARRAY(i)
);
the usage of the Reset
state_machine: process(Clk) is
begin
if rising_edge(Clk) then
IF RST='1' then
MVM_RST <= '1';
Else
MVM_RST <= '0';
In detail the warning is reffering to the line RST=> MVM_RST of the instantiation
MVM_RST_reg is removed, because you reset acc_value instead of MVM_RESULT. acc_value is a variable and not a signal. This means, you will only get flipflops for acc_value, if there is a situation were you read acc_value before you assign a value to it. If RST=1, then you assign a value to acc_value but you do not read its value. So no flipflop is needed. If RST=0 and EN=1, then you first assign a value and then read it. So again, no flipflop is needed. As there is no flipflop for acc_value build in, you cannot reset any flipflops by MVM_RST. So the MVM_RST_reg is removed.
While all the code is perfectly compiled by ModelSim, I can't simulate it because of "Error loading design"
This is for a CRC encode and decode using a Linear Feedback Shift Register that uses D-FlipFlop as components. So the project is actually composed by the CRC box that contains the LFSR made by DFF.
library IEEE;
use IEEE.std_logic_1164.all;
entity CRC is
generic (
NBit : positive := 64;
poly : positive := 8
);
port(
clk :in std_logic;
reset :in std_logic;
md :in std_logic; --1 per sender, 0 per receiver
input :in std_logic_vector(Nbit-1 downto 0);
dout_s :out std_logic_vector(Nbit-1 downto 0);
dout_r :out std_logic_vector(Nbit-poly-1 downto 0)
);
end CRC;
architecture rtl of CRC is
component LFSR
generic (N : positive := 8);
port(
clk :in std_logic;
reset :in std_logic;
din :in std_logic;
dout :out std_logic_vector(N-1 downto 0);
ready :out std_logic
);
end component LFSR;
signal input_temp :std_logic_vector(Nbit-1 downto 0);
signal input_LFSR :std_logic;
signal output_LFSR :std_logic_vector(poly-1 downto 0);
signal ready_LFSR :std_logic;
constant crc_check :std_logic_vector(poly-1 downto 0):= (others => '0');
begin
LFSR_o: LFSR generic map (N => poly)
port map(
clk => clk,
reset => reset,
din => input_LFSR,
dout => output_LFSR,
ready => ready_LFSR
);
process (clk)
variable i : natural := 0;
begin
if (md = '1') then
input_temp(Nbit-1 downto poly)<=input(Nbit-1 downto poly);
input_temp(7 downto 0) <=(others =>'0');
if(rising_edge(clk)) then
input_LFSR <= input_temp(i);
i:= i+1;
if(ready_LFSR = '1') then
dout_s <= input(Nbit-1 downto 0) & output_LFSR;
end if;
end if;
elsif(md = '0') then
input_temp(Nbit-1 downto 0)<=input(Nbit-1 downto 0);
if(rising_edge(clk)) then
input_LFSR <= input_temp(i);
i:= i+1;
if(ready_LFSR = '1') then
--codice per il controllo
for t in 0 to poly-1 loop
if (output_LFSR(t)='1') then
dout_r <=(others =>'0');
exit;
elsif(t=poly-1 and output_LFSR(t)='0') then
dout_r <= input(Nbit-1 downto poly);
end if;
end loop;
end if;
end if;
end if;
end process;
end rtl;
here the LFSR
library IEEE;
use IEEE.std_logic_1164.all;
entity LFSR is
generic (NBit : positive := 8);
port(
clk :in std_logic;
reset :in std_logic;
din :in std_logic;
dout :out std_logic_vector(Nbit-1 downto 0);
ready :out std_logic
);
end LFSR;
architecture rtl of LFSR is
component DFC
port(
clk :in std_logic;
reset :in std_logic;
d :in std_logic;
crc :out std_logic;
q :out std_logic
);
end component DFC;
signal q_s : std_logic_vector (NBit-1 downto 0):= (others => '0');
signal crc_t : std_logic_vector (NBit-1 downto 0):= (others => '0'); --registro temporaneo su cui fare le operazioni
signal int_0 :std_logic := '0';
signal int_2 :std_logic := '0';
signal int_4 :std_logic := '0';
signal int_8 :std_logic := '0';
begin
int_0<= din xor q_s(7);
int_2<= q_s(1) xor q_s(7);
int_4<= q_s(3) xor q_s(7);
GEN: for i in 0 to Nbit-1 generate
FIRST: if i=0 generate
FF1: DFC port map (
clk => clk,
reset => reset,
d => int_0,
crc => crc_t(i), --funziona benissimo se metto dout(i)
q => q_s(i)
);
end generate FIRST;
THIRD: if i=2 generate
FF2: DFC port map (
clk => clk,
reset => reset,
d => int_2,
crc => crc_t(i),
q => q_s(i)
);
end generate THIRD;
FIFTH: if i=4 generate
FF4: DFC port map (
clk => clk,
reset => reset,
d => int_4,
crc => crc_t(i),
q => q_s(i)
);
end generate FIFTH;
INTERNAL: if i>0 and i<Nbit-1 and i/= 2 and i/=4 generate
FFI: DFC port map (
clk => clk,
reset => reset,
d => q_s(i-1),
crc => crc_t(i),
q => q_s(i)
);
end generate INTERNAL;
LAST: if i=Nbit-1 generate
FFN: DFC port map (
clk => clk,
reset => reset,
d => q_s(i-1),
crc => crc_t(i),
q => q_s(i)
);
end generate LAST;
end generate GEN;
process(clk)
variable t : natural := 0;
begin
--ready <= '0';
if(rising_edge(clk)) then
t:= t+1;
if t=24 then --per qualche ragione ho bisogno di 3 cicli di clock in più per arrivare al risultato ricercato
dout <= crc_t;
ready <='1';
end if;
end if;
end process;
end rtl;
here the DFF
library IEEE;
use IEEE.std_logic_1164.all;
entity DFC is
port(
clk :in std_logic;
reset :in std_logic;
d :in std_logic;
crc :out std_logic;
q :out std_logic
);
end DFC;
architecture rtl of DFC is
begin
process(clk, reset, d)
begin
if(reset = '1')then
q <= '0';
crc<= '0';
elsif (clk'event and clk='1') then
q <= d;
crc <= d;
end if;
end process;
end rtl;
and finally here the testbench for the CRC
library IEEE;
use IEEE.std_logic_1164.all;
entity CRC_tb is
end CRC_tb;
architecture testbench of CRC_tb is
component CRC is
generic (
NBit : positive := 20; --da rimettere a 64
poly : positive := 8
);
port(
clk :in std_logic;
reset :in std_logic;
md :in std_logic; --1 per sender, 0 per receiver
input :in std_logic_vector(Nbit-1 downto 0);
dout_s :out std_logic_vector(Nbit-1 downto 0);
dout_r :out std_logic_vector(Nbit-poly-1 downto 0)
);
end component;
constant T_CLK :time := 25 ns;
constant T_sim :time := 2000 ns;
signal sim_time :std_logic :='1';
constant M :integer :=20; --da rimettere a 64, Nbit
constant N :integer :=8; -- poly
signal clk_tb :std_logic :='0';
signal reset_tb :std_logic :='1';
signal md_tb :std_logic;
signal input_tb :std_logic_vector(M-1 downto 0);
signal dout_s_tb :std_logic_vector(M-1 downto 0);
signal dout_r_tb :std_logic_vector(M-N-1 downto 0);
begin
clk_tb <= (not(clk_tb)and sim_time) after T_CLK/2;
sim_time <= '0' after T_sim;
DUT_i : CRC
generic map (
Nbit => M,
poly => N
)
port map (
clk => clk_tb,
reset => reset_tb,
md => md_tb,
input => input_tb,
dout_s => dout_s_tb,
dout_r => dout_r_tb
);
input_process : process(clk_tb)
begin
if(rising_edge(clk_tb)) then
md_tb <= '1';
input_tb <= "10100111010000000000";
end if;
end process input_process;
end testbench;
I was expecting that everything went fine given that the CRC code doesn't do much if not creating connections. I'm very new to VHDL so I can't understand very well what
** Error: (vsim-3733) C:/Modeltech_pe_edu_10.4a/CRC2.0/CRC.vhd(50):
No default binding for component instance 'LFSR_o'.
The following component generic is not on the entity: N Time: 0 ns
Iteration: 0 Instance: /crc_tb/DUT_i/LFSR_o File:
C:/Modeltech_pe_edu_10.4a/CRC2.0/LFSR.vhd
Loading work.dfc(rtl)
Error loading design
means.
Thanks all for the answers.
My VHDL-Code is functionaly correct, in simulation it does what it's thought for. I tested in many variations and the code works correct.
But when i program the fpga (Nexyx 4 ddr) everything works well except the preload of the counter.
I don't know if the load enable (load_e) output from the fsm doesn't reach the counter or if the output signal that sais the counter is loaded (counter_loaded) doesn't reach the fsm but when i program the fpga it never pases from state C or D (waiting for counter loaded) to state E or F (where it makes a countdown).
I tested the other parts of the code in the target and it works properly, so the only problema so far is that one and i can't find the error, i'm thinking about timming, but i have no idea of how to solve it.
I leave here the counter and fsm code, as well as the TOP code, i`m new in VHDL and it might be lots of bad practice mistakes.
I'm spanish, that's the reason of my bad English and also the spanish name of some signal, but i add a comment next to them.
--------COUNTER---------------------------------------
entity counter is
Generic (NBITS : positive := 15
);
Port (clk : in STD_LOGIC;
rst : in STD_LOGIC;
ce : in STD_LOGIC;
load : in STD_LOGIC_VECTOR (NBITS-1 downto 0);
load_e : in STD_LOGIC;
unit : out STD_LOGIC_VECTOR(3 downto 0);
dec : out STD_LOGIC_VECTOR(3 downto 0);
zero_n : out STD_LOGIC; --true si cuenta = 0
loaded : out STD_LOGIC);
end counter;
architecture Behavioral of counter is
signal q_i : unsigned (NBITS-1 downto 0) := (others => '1');
begin
process(clk,rst)
begin
if rst = '1' then
q_i <= (OTHERS => '1');
loaded <= '0';
elsif rising_edge(clk) then
if CE = '1' then
if load_e = '1' then --ONE OF MY GUESSES OF THE PROBLEM
q_i <= unsigned(load);
loaded <= '1';
else
q_i <= q_i - 1;
loaded <= '0';
end if;
end if;
end if;
end process;
dec <= std_logic_vector(to_unsigned((to_integer(q_i(14 downto 10)) / 10),dec'length)); --first 5 bits are the tens
unit <= std_logic_vector(to_unsigned((to_integer(q_i(14 downto 10)) rem 10),unit'length)); --fist 5 bits are the unit
zero_n <= '1' WHEN q_i < "000010000000000" ELSE '0'; --cout is zero if the first 5 bits are less tan 1 in binary
end Behavioral;
------FINITE STATE MACHINE--------------------------------
entity maquina_estados is
Port (
clk : in STD_LOGIC;
rst : in STD_LOGIC;
corto : in STD_LOGIC;
largo : in STD_LOGIC;
b_on : in STD_LOGIC;
zero_n : in STD_LOGIC;
counter_loaded : in STD_LOGIC;
load_e : out STD_LOGIC;
load : out STD_LOGIC_VECTOR(14 downto 0);
bomba_led : out STD_LOGIC;
indica_on : out STD_LOGIC);
end maquina_estados;
architecture Behavioral of maquina_estados is
type state_type is (A, B, C, D, E, F); --define state(A = powered off, B = powered on, C = short coffee preload, D = large coffee preload, E = short coffee, F = large coffee)
signal state, next_state : state_type; --type state signal
begin
process(clk,rst)
begin
if rst = '1' then
state <= A;
elsif rising_edge(clk) then
state <= next_state;
end if;
end process;
process(state, b_on, corto, largo, zero_n, counter_loaded)
begin
CASE state IS
WHEN A => if b_on = '1' then
next_state <= B;
else
next_state <= A;
end if;
WHEN B => if b_on = '0' then
next_state <= A;
elsif corto = '1' then
next_state <= C;
elsif largo = '1' then
next_state <= D;
else
next_state <= B;
end if;
WHEN C => if counter_loaded = '1' then
next_state <= E;
else
next_state <= C;
end if;
WHEN D => if counter_loaded = '1' then
next_state <= F;
else
next_state <= D;
end if;
WHEN E => if zero_n = '1' then
next_state <= B;
else
next_state <= E;
end if;
WHEN F => if zero_n = '1' then
next_state <= B;
else
next_state <= F;
end if;
WHEN OTHERS => next_state <= A;
end case;
end process;
process(state)
begin
CASE state IS
WHEN A => load <= "111111111111111"; --default value of the count
load_e <= '0';
bomba_led <= '0';
indica_on <= '0';
WHEN B => load <= "111111111111111";
load_e <= '0';
bomba_led <= '0';
indica_on <= '1';
WHEN C => load <= "010101111111111"; --10 second, this in addition to a 1024 hz clock made posible to use the first 5 bits as the number
load_e <= '1';
bomba_led <= '0';
indica_on <= '1';
WHEN D => load <= "101001111111111"; --20 seconds
load_e <= '1';
bomba_led <= '0';
indica_on <= '1';
WHEN E => load <= "111111111111111";
load_e <= '0';
bomba_led <= '1';
indica_on <= '1';
WHEN F => load <= "111111111111111";
load_e <= '0';
bomba_led <= '1';
indica_on <= '1';
end case;
end process;
end behavioral;
------TOP-----------------------
entity TOP is
Generic(
FIN : positive := 100000000;
FOUT : positive := 1024);
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
corto : in STD_LOGIC;
largo : in STD_LOGIC;
b_on : in STD_LOGIC;
display_number : out STD_LOGIC_VECTOR (6 downto 0);
display_selection : out STD_LOGIC_VECTOR (7 downto 0);
bomba_led : out STD_LOGIC;
indica_on : out STD_LOGIC);
end TOP;
architecture Behavioral of TOP is
--instancies
component clk_divider is
-- Port ( );
generic(
FIN : positive;
FOUT : positive
);
port (
Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Clk_out : out STD_LOGIC
);
end component;
component maquina_estados is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
corto : in STD_LOGIC;
largo : in STD_LOGIC;
b_on : in STD_LOGIC;
zero_n : in STD_LOGIC;
counter_loaded : in STD_LOGIC;
load_e : out STD_LOGIC;
load : out STD_LOGIC_VECTOR(14 downto 0);
bomba_led : out STD_LOGIC;
indica_on : out STD_LOGIC);
end component;
component counter is
Generic (NBITS : positive
);
Port (clk : in STD_LOGIC;
rst : in STD_LOGIC;
ce : in STD_LOGIC;
load : in STD_LOGIC_VECTOR (NBITS-1 downto 0);
load_e : in STD_LOGIC;
unit : out STD_LOGIC_VECTOR(3 downto 0);
dec : out STD_LOGIC_VECTOR(3 downto 0);
zero_n : out STD_LOGIC;
loaded : out STD_LOGIC);
end component;
component clk_manager is
generic(
CLK_FREQ : positive
);
Port (
clk : in STD_LOGIC;
rst : in STD_LOGIC;
strobe_1024Hz : out STD_LOGIC;
strobe_128Hz : out STD_LOGIC
);
end component;
component decoder is
Port ( code : in STD_LOGIC_VECTOR(3 downto 0);
led : out STD_LOGIC_vector(6 downto 0)
);
end component;
component display_refresh is
Port ( clk : in STD_LOGIC;
ce : in STD_LOGIC;
segment_unit : in STD_LOGIC_VECTOR (6 downto 0);
segment_dec : in STD_LOGIC_VECTOR (6 downto 0);
display_number : out STD_LOGIC_VECTOR (6 downto 0);
display_selection : out STD_LOGIC_VECTOR (1 downto 0)); --cada elemento del vector corresponde a un 7 seg, true se ve false no
end component;
-- prescaler signals
signal prescaler_clk_out : STD_LOGIC;
--maquina estados signals
signal zero_n_fsm : STD_LOGIC;
signal load_e_fsm : STD_LOGIC;
signal load_fsm : STD_LOGIC_VECTOR(14 downto 0);
signal bomba_led_fsm: STD_LOGIC;
--counter signals
signal unit : STD_LOGIC_VECTOR(3 downto 0);
signal dec : STD_LOGIC_VECTOR(3 downto 0);
signal zero_n_cntr : STD_LOGIC;
signal load_e_cntr : STD_LOGIC;
signal load_cntr : STD_LOGIC_VECTOR(14 downto 0);
signal counter_loaded : STD_LOGIC;
--clk_manager signals
signal strobe_1024Hz : STD_LOGIC;
signal strobe_128Hz : STD_LOGIC;
signal ce_clkm : STD_LOGIC;
signal rst_clkm : STD_LOGIC;
--decoders signals
signal unit_code : STD_LOGIC_VECTOR(6 downto 0);
signal dec_code : STD_LOGIC_VECTOR(6 downto 0);
--display refresh signals
signal display_refresh_number : STD_LOGIC_VECTOR(6 downto 0);
signal display_refresh_selection : STD_LOGIC_VECTOR(1 downto 0);
begin
prescaler: clk_divider
generic map(
FIN => FIN,
FOUT => FOUT
)
port map(
Clk => clk,
Reset => rst,
Clk_out => prescaler_clk_out
);
sm: maquina_estados
Port map( clk => prescaler_clk_out,
rst => rst,
corto => corto,
largo => largo,
b_on => b_on,
zero_n => zero_n_fsm,
counter_loaded => counter_loaded,
load_e => load_e_fsm,
load => load_fsm,
bomba_led => bomba_led_fsm,
indica_on => indica_on);
cntr: counter
Generic map(NBITS => 15
)
Port map(clk => clk,
rst => rst,
ce => strobe_1024Hz,
load => load_cntr,
load_e => load_e_fsm,
unit => unit,
dec => dec,
zero_n => zero_n_cntr,
loaded => counter_loaded);
clk_m: clk_manager
generic map(
CLK_FREQ => FIN
)
Port map(
clk => clk,
rst => rst,
strobe_1024Hz => strobe_1024Hz,
strobe_128Hz => strobe_128Hz
);
unit_dcd: decoder
Port map(
code => unit,
led => unit_code
);
dec_dcd: decoder
Port map(
code => dec,
led => dec_code
);
dr: display_refresh
Port map(
clk => clk,
ce => strobe_128Hz,
segment_unit => unit_code,
segment_dec => dec_code,
display_number => display_refresh_number,
display_selection => display_refresh_selection);
display_number <= display_refresh_number WHEN bomba_led_fsm = '1' ELSE "1111111";
display_selection <= ("111111" & display_refresh_selection) WHEN bomba_led_fsm = '1' ELSE "11111111";
zero_n_fsm <= zero_n_cntr;
bomba_led <= bomba_led_fsm;
load_cntr <= load_fsm;
end Behavioral;
Here are all the reports that the implementation ans sythesis gave me:
Synthesis reports
implementation reports 1/6
implementation reports 2/6
implementation reports 3/6
implementation reports 4/6
implementation reports 5/6
implementation reports 6/6
I hope someone could find the problema and give me a solution or a way of how to debug this problem.
Thanks.
Your FSM is clocked on prescaler_clk_out, and your counter is clocked on clk, which is a red flag. This could easily lead to an implementation failure.
Draw a timing diagram showing all your clocks and resets, and your lower-frequency enables (in particular, strobe_1024Hz)
Try to clock all the logic on the same clock, presumably clk, and make sure that everything is synchronous to this clock (in other words, inputs have sufficient setup and hold times relative to this clock)
Make sure you are actually resetting the chip
Once you've done the timing diagram, write a constraints file that tells the synthesiser what your clocks are. clk_manager and clk_divider may be an issue here, but hopefully everything will be clocked on just 'clk', and the contstraints file will contain only the clock name and frequency. If you still can't get it to work, ask a new question, showing your timing diagram, and your attempt at a constraints file.
I am attempting to create a 16-bit factorial calculator for an unsigned binary number. In doing so I have created a data path and a state machine that
a.) outputs a final value of 1 if the value input is 0
b.) displays and overflow flag if the input is over 8!
c.) Calculates the value for the factorial if the value input is less then 8 and not zero.
The system seems to fall apart if the value I input is anything over 3 yet still not an overflow. I think the issue is somewhere in Test3, Update 1, update 2 in my state machine. Could anyone help explain what is going wrong?
State Machine:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity fact_16_ctrlv2 is
port(
go : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
overflow : in STD_LOGIC;
numeqcnt : in STD_LOGIC;
factzero : in STD_LOGIC;
flag: out STD_logic;
xload : out STD_LOGIC;
cntmux : out STD_LOGIC;
cntload : out STD_LOGIC;
factload : out STD_LOGIC;
factmux : out STD_LOGIC;
finalload : out STD_LOGIC;
finalmuxselect: out STD_logic;
decimalpoint: out std_logic
);
end fact_16_ctrlv2;
--}} End of automatically maintained section
architecture fact_16_ctrlv2 of fact_16_ctrlv2 is
type state_type is (start, input, test1, test2, test3, update1, update2, update3, done);
signal present_state, next_state: state_type;
begin
sreg: process(clk, clr)
begin
if clr='1' then
present_state <= start;
elsif clk'event and clk='1' then
present_state <= next_state;
end if;
end process;
c1: process(present_state, go, overflow, factzero, numeqcnt)
begin
case present_state is
when start =>
if go = '1' then
next_state <= input;
else
next_state <= start;
end if;
when input =>
next_state <= test1;
when test1 =>
if factzero= '1' then
next_state <= done;
else
next_state <= test2;
end if;
when test2 =>
if overflow = '1' then
next_state <= done;
else
next_state <= update3;
end if;
when update3 =>
next_state <= test3;
when test3 =>
if numeqcnt = '1' then
next_state <= done;
else
next_state <= update1;
end if;
when update1 =>
next_state <= update2;
when update2 =>
next_state <= test3;
when done =>
next_state <= done;
when others =>
null;
end case;
end process;
C2: process(present_state, overflow, numeqcnt, factzero)
begin
xload<= '0';
flag <= '0';
cntmux <= '0';
cntload<= '0';
factload<='0';
factmux<='0';
finalload <='0';
finalmuxselect<='0';
decimalpoint<='0';
case present_state is
when input =>
xload<='1';
--cntmux<='1';
--cntload<='1';
when test2 =>
if overflow ='1' then
flag <= '1';
finalmuxselect<='0';
finalload<='1';
factload <='1';
decimalpoint <='1';
end if;
when test1 =>
if factzero ='1' then
flag <= '1';
finalmuxselect <='1';
finalload <='1';
end if;
when update3 =>
cntmux<='1';
cntload<='1';
factmux<= '1';
factload<= '1';
when test3 =>
if numeqcnt ='1' then
finalmuxselect<='0';
--finalload<='1';
factload <='1';
cntload<='1';
factmux<='0';
else
end if;
when update1 =>
factmux<='0';
factload<='1';
when update2 =>
cntmux<='0';
cntload<='1';
--factload<='1';
when done =>
finalload<='1';
when others =>
null;
end case;
end process;
end fact_16_ctrlv2;
Data Path
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity fact_16_dp is
port(
clr : in STD_LOGIC;
clk : in STD_LOGIC;
X : in STD_LOGIC_VECTOR(3 downto 0);
overflow : out STD_LOGIC;
finalfact : out STD_LOGIC_VECTOR(15 downto 0);
cntload, cntmult, factload, factmult, xload, finalload :in Std_logic;
equalone, numcnt : out Std_logic;
finalmuxselect, flagin: in STD_logic
);
end fact_16_dp;
--}} End of automatically maintained section
architecture fact_16_dp of fact_16_dp is
-- Component declaration of the "mult16b(mult16b)" unit defined in
-- file: "./../src/multiplier.vhd"
component mult16b
port(
a : in STD_LOGIC_VECTOR(15 downto 0);
b : in STD_LOGIC_VECTOR(15 downto 0);
p : out STD_LOGIC_VECTOR(15 downto 0));
end component;
for all: mult16b use entity work.mult16b(mult16b);
-- Component declaration of the "comp(comp)" unit defined in
-- file: "./../src/comparitor.vhd"
component comp
generic(
N : INTEGER := 8);
port(
x : in STD_LOGIC_VECTOR(N-1 downto 0);
y : in STD_LOGIC_VECTOR(N-1 downto 0);
gt : out STD_LOGIC;
eq : out STD_LOGIC;
lt : out STD_LOGIC);
end component;
for all: comp use entity work.comp(comp);
-- Component declaration of the "adder(adder)" unit defined in
-- file: "./../src/adder.vhd"
component adder
generic(
N : INTEGER := 8);
port(
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
y : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: adder use entity work.adder(adder);
-- Component declaration of the "reg(reg)" unit defined in
-- file: "./../src/reg.vhd"
component reg
generic(
N : INTEGER := 8);
port(
load : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
d : in STD_LOGIC_VECTOR(N-1 downto 0);
q : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: reg use entity work.reg(reg);
-- Component declaration of the "mux2g(mux2g)" unit defined in
-- file: "./../src/mux21.vhd"
component mux2g
generic(
N : INTEGER);
port(
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
s : in STD_LOGIC;
y : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: mux2g use entity work.mux2g(mux2g);
-- Component declaration of the "mux4g(mux4g)" unit defined in
-- file: "./../src/mux4to1.vhd"
component mux4g
generic(
N : INTEGER);
port(
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
c : in STD_LOGIC_VECTOR(N-1 downto 0);
s : in STD_LOGIC_VECTOR(1 downto 0);
y : out STD_LOGIC_VECTOR(N-1 downto 0));
end component;
for all: mux4g use entity work.mux4g(mux4g);
--signal cntload, cntmult, numcnt, factload, factmult, xload, numload, equalone, finalload :Std_logic;
signal adderout, cntregout, cntregin, x2 :Std_logic_vector(3 downto 0);
signal xin, factregin, factregout, overin, factmout, checkzero, numregout, flag, finalmuxout, cntregoutb :Std_logic_vector(15 downto 0);
begin
x2 <= x;
xin <= "000000000000" & x2; --Change 4 bit number input into a 16 bit number
cntregoutb <= "000000000000" & cntregout; --change count from 4 bit value to a 16 bit value
flag <= "000000000000000" & flagin;
cntreg : reg --4-bit counter register
generic map(
N => 4
)
port map(
load => cntload,
clk => clk,
clr => clr,
d => cntregin, --not in drawing
q => cntregout
);
factreg : reg --16-bit fact register
generic map(
N => 16
)
port map(
load => factload,
clk => clk,
clr => clr,
d => factregin,
q => factregout
);
--numreg : reg --16-bit num register
--generic map(
--N => 16
--)
--port map(
--load => numload,
--clk => clk,
--clr => clr,
--d => xin,
--q => numregout
--);
xreg : reg --4-bit initial x vlaue register
generic map(
N => 4
)
port map(
load => xload,
clk => clk,
clr => clr,
d => x, --x(3:0)
q => x2
);
finalreg : reg --16-bit final fact register
generic map(
N => 16
)
port map(
load => finalload,
clk => clk,
clr => clr,
d => finalmuxout,
q => finalfact
);
cntmux : mux2g --4-bit cnt mux
generic map(
N => 4
)
port map(
b => "0001", --initial value set
a => adderout, --value after initial run through
s => cntmult,
y => cntregin --cntregin not in drawing
);
factmux : mux2g --16-bit fact mux
generic map(
N => 16
)
port map(
b => "0000000000000001", --initial value set
a => factmout, --value after initial run through
s => factmult,
y => factregin
);
add1 : adder --Increment counter 4-bit
generic map(
N => 4
)
port map(
a => cntregout, --add 1
b => "0001", --1
y => adderout --out of the adder
);
multiplier : mult16b --multiply cnt and fact 16-bit
port map(
a => factregout,
b => cntregoutb, --cnt plus 12 zeros to 16-bit
p => factmout --Multiplier out
);
greater8 : comp --16-bit check x overflow if greater then 8
generic map(
N => 16
)
port map(
x => xin, --check value to 8
y => "0000000000001000",
gt => overflow --send overflow flag
--eq => eq,
--lt => lt
);
check0 : comp --16-bit check x not equal to zero
generic map(
N => 16
)
port map(
x => xin,
y => "0000000000000000",
--gt => gt,
eq => equalone
--lt => lt
);
numeqcnt : comp --16-bit check if num equals cnt
generic map(
N => 16
)
port map(
x => xin,
y => cntregoutb, --need 16 bit
--gt => gt,
eq => numcnt --not in drawing
--lt => lt
);
finalmux: mux2g
generic map(
N => 16
)
port map(
a => factregout,
b => flag,
s => finalmuxselect,
y => finalmuxout
);
end fact_16_dp;
Connected together
-------------------------------------------------------------------------------
--
-- Title : fact_16
-- Design : lab4
-- Author :
-- Company :
--
-------------------------------------------------------------------------------
--
-- File : c:\My_Designs\lab4\lab4\src\fact_16.vhd
-- Generated : Tue Oct 14 16:40:38 2014
-- From : interface description file
-- By : Itf2Vhdl ver. 1.22
--
-------------------------------------------------------------------------------
--
-- Description :
--
-------------------------------------------------------------------------------
--{{ Section below this comment is automatically maintained
-- and may be overwritten
--{entity {fact_16} architecture {fact_16}}
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity fact_16 is
port(
go : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
x : in STD_LOGIC_VECTOR(3 downto 0);
overflowB : out STD_LOGIC;
factout : out STD_LOGIC_VECTOR(15 downto 0)
);
end fact_16;
architecture fact_16 of fact_16 is
-- Component declaration of the "fact_16_dp(fact_16_dp)" unit defined in
-- file: "./../src/fact_16_dp.vhd"
component fact_16_dp
port(
clr : in STD_LOGIC;
clk : in STD_LOGIC;
X : in STD_LOGIC_VECTOR(3 downto 0);
overflow : out STD_LOGIC;
finalfact : out STD_LOGIC_VECTOR(15 downto 0);
cntload : in STD_LOGIC;
cntmult : in STD_LOGIC;
factload : in STD_LOGIC;
factmult : in STD_LOGIC;
xload : in STD_LOGIC;
finalload : in STD_LOGIC;
equalone : out STD_LOGIC;
numcnt : out STD_LOGIC;
finalmuxselect : in STD_LOGIC;
flagin : in STD_LOGIC);
end component;
for all: fact_16_dp use entity work.fact_16_dp(fact_16_dp);
-- Component declaration of the "fact_16_ctrlv2(fact_16_ctrlv2)" unit defined in
-- file: "./../src/fact_16_ctrlv2.vhd"
component fact_16_ctrlv2
port(
go : in STD_LOGIC;
clk : in STD_LOGIC;
clr : in STD_LOGIC;
overflow : in STD_LOGIC;
numeqcnt : in STD_LOGIC;
factzero : in STD_LOGIC;
flag : out STD_LOGIC;
xload : out STD_LOGIC;
cntmux : out STD_LOGIC;
cntload : out STD_LOGIC;
factload : out STD_LOGIC;
factmux : out STD_LOGIC;
finalload : out STD_LOGIC;
finalmuxselect : out STD_LOGIC;
decimalpoint : out STD_LOGIC);
end component;
for all: fact_16_ctrlv2 use entity work.fact_16_ctrlv2(fact_16_ctrlv2);
signal overflow, numeqcnt, factzero, xload, cntmux, cntload, factload, flag, factmux, numload, finalload: STD_logic;
signal finalmuxselect: std_logic;
begin
Dpath : fact_16_dp
port map(
clr => clr,
clk => clk,
X => X,
overflow => overflow,
finalfact => factout,
cntload => cntload,
cntmult => cntmux,
factload => factload,
factmult => factmux,
xload => xload,
finalload => finalload,
equalone => factzero,
numcnt => numeqcnt,
finalmuxselect => finalmuxselect,
flagin => flag
);
Cunit : fact_16_ctrlv2
port map(
go => go,
clk => clk,
clr => clr,
overflow => overflow,
numeqcnt => numeqcnt,
factzero => factzero,
flag => flag,
xload => xload,
cntmux => cntmux,
cntload => cntload,
factload => factload,
factmux => factmux,
finalload => finalload,
finalmuxselect => finalmuxselect,
decimalpoint => overflowB
);
end fact_16;
I am designing a simple combination lock design in VHDL on a Spartan 6 FPGA. This error has come up and i am a bit confused to how i could fix it. I have "googled" this and according to this answer in this thread Too many comps of type “BUFGMUX” found to fit this deviceI beleive i know the problem but i am unsure how to solve it.
Now correct me if i am wrong but i believe this error came about due to the following code in my design
--clock divider
process(cclk,clr)
begin
if (clr ='1') then
Count200Hz <= X"00000";
--clk200 <= '0';
temp <= '0';
elsif rising_edge(cclk) then
if (Count200Hz = clk200HzEndVal) then
clk200 <= not temp;
Count200Hz <= X"00000";
else
Count200Hz <= Count200Hz + '1';
end if;
end if;
end process;
-- 2-bit counter
process(cclk,clr)
begin
if clr = '1' then
s <= "00";
elsif rising_edge(cclk) then
s <= s+1;
end if;
end process;
--state machine
state_mach:PROCESS(lclk, clr)
BEGIN
IF clr = '1' THEN
present_state <= idle;
ELSIF rising_edge(lclk) THEN
present_state <= next_state;
end if;
END PROCESS;
pulse_process: process(cclk, rst)
begin
if rst = '0' then
pulse <= '0';
count <= 0;
current_state <= idle;
elsif (rising_edge(cclk))then
current_state <= next_state;
....
These code are from different vhdl modules in my design.
does the ise believes that there are three different clock used in my design hence why the error is thrown??
The thing is that they are different clock but they stem from the systems clock ones the clock at an lower frequency, one is the clock pulse.
I have added my top-level design for some clarity
Any help is appreciated
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity simpleLock_top is
Port (
mclk : in STD_LOGIC;
rst : in STD_LOGIC;
btnl : in STD_LOGIC;
btnr : in STD_LOGIC;
sw : in STD_LOGIC_VECTOR (3 downto 0);
seg7 : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0);
led : out STD_LOGIC_VECTOR (7 DOWNTO 0);
dp : out STD_LOGIC);
end simpleLock_top;
architecture Behavioral of simpleLock_top is
component x7seg_msg is
Port (
x : in STD_LOGIC_VECTOR (15 downto 0);
cclk : in STD_LOGIC;
clr : in STD_LOGIC;
seg7 : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0);
dp : out STD_LOGIC);
end component;
component clkdiv is
Port (
cclk : in STD_LOGIC;
clr : in STD_LOGIC;
clk200 : out STD_LOGIC);
end component;
component simpleLock is
PORT (
lclk : IN STD_LOGIC;
clr : IN STD_LOGIC;
btnl : IN STD_LOGIC;
btnr : IN STD_LOGIC;
code : IN STD_LOGIC_VECTOR(15 DOWNTO 0);
sw : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
led : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
digit : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
user_input : OUT STD_LOGIC_VECTOR(15 downto 0));
end component;
component clock_pulse is
PORT (
cclk : IN STD_LOGIC;
rst : IN STD_LOGIC;
trig : IN STD_LOGIC;
pulse : OUT STD_LOGIC);
end component;
constant code : STD_LOGIC_VECTOR(15 downto 0):= X"1234";
signal digit: STD_LOGIC_VECTOR(3 DOWNTO 0);
signal user_input : std_logic_vector(15 downto 0);
signal clk200, clkp, btn01: STD_LOGIC;
signal btn : STD_LOGIC_VECTOR(1 DOWNTO 0);
begin
btn(0) <= btnr;
btn(1) <= btnl;
btn01 <= btn(0) or btn(1);
--led <= X"00";
V1: clkdiv
port map(
cclk => mclk,
clr => rst,
clk200 => clk200);
V2: x7seg_msg
port map(
x => user_input,
cclk => clk200,
clr => rst,
seg7 => seg7,
an => an,
dp => dp );
V3: simpleLock
port map(
lclk => clkp,
clr => rst,
btnl => btnl,
btnr => btnr,
code => code,
sw => sw,
led => led,
digit => digit,
user_input => user_input);
V4: clock_pulse
port map(
cclk => clk200,
rst => rst,
trig => btn01,
pulse => clkp);
end Behavioral;
Clock Enable
In an FPGA design, it is often better to use the less possible different clocks.
If your "clock_pulse" module generate a one cycle clock pulse, don't use this pulse as a clock ('clkp' in your code), but as a clock enable ('enable' in the code below).
myproc : process(clk, rst)
begin
if rst = '1' THEN
-- your asynchronously reseted signals
elsif rising_edge(clk) THEN
if enable = '1' then
-- things that must be done when you get the one cycle pulse
end if;
end if;
end process;
But take care of any unmanaged clock domain crossing...
Hope this helps.