Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity counter4bit is port( mod_value: in std_logic_vector(0 to 3); clock: in std_logic; enable_count: in std_logic; reset: in std_logic; direction: in std_logic; output_counter: out std_logic_vector(0 to 3) ); end counter4bit; architecture structural of counter4bit is component register4bit is port( Din : in std_logic_vector(3 downto 0); en : in std_logic; clock : in std_logic; reset : in std_logic; Dout : out std_logic_vector(3 downto 0)); end component; signal dig, tmp: std_logic_vector(3 downto 0); begin mod1: register4bit port map (tmp(0) <= Dout(0), tmp(1) <= Dout(1),tmp(2) <= Dout(2),tmp(3) <= Dout(3), Din(0) <= mod_value(0), Din(1) <= mod_value(1), Din(2) <= mod_value(2), Din(3) <= mod_value(3), reset <= reset, clock <= clock, en < reset); process(Clock,Reset) begin if Reset='1' then dig <= "0000"; elsif ( rising_edge(clock)) then if (enable_count<='1' and direction<='0') then if dig <= "tmp(3)tmp(2)tmp(1)tmp(0)" then dig <= "0000"; else dig <= dig + 1; if (enable_count<='1' and direction<='1') then dig <= dig - 1; end if; end if; end if; end if; end process; output_counter <= dig; end structural;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; use IEEE.numeric_std.all; -- TOP VHDL design which implements a 8-bit Universal Shift Register entity register4bit is port ( Din : in std_logic_vector(3 downto 0); EN : in std_logic; Clock : in std_logic; Reset : in std_logic; Dout : out std_logic_vector(3 downto 0)); end entity register4bit; --// End of entity --// This is an architecture of 4-bits universal shift register architecture structural of register4bit is component D_flip_flop is port ( D : in std_logic; EN : in std_logic; Clock : in std_logic; Reset : in std_logic; Q : out std_logic); end component; begin U1: D_flip_flop port map(D => Din(0), EN => EN, Clock => Clock, Reset => Reset, Q=> Dout(0)); U2: D_flip_flop port map(D => Din(1), EN => EN, Clock => Clock, Reset => Reset, Q=> Dout(1) ); U3: D_flip_flop port map(D => Din(2), EN => EN, Clock => Clock, Reset => Reset, Q=> Dout(2) ); U4: D_flip_flop port map(D => Din(3), EN => EN, Clock => Clock, Reset => Reset, Q=> Dout(3) ); end structural; Here is the code for the d-type flip flop used to do the register: library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; use IEEE.numeric_std.all; -- TOP VHDL design which implements a 8-bit Universal Shift Register entity D_flip_flop is port ( D : in std_logic; EN : in std_logic; Clock : in std_logic; Reset : in std_logic; Q : out std_logic); end entity D_flip_flop; --// End of entity --// This is an architecture of 4-bits universal shift register architecture RTL of D_flip_flop is begin PROCESS ( Clock, Reset ) BEGIN IF Reset = '1' THEN Q <= '0'; ELSIF rising_edge(Clock) THEN Q <= D; END IF; END PROCESS; end RTL; -- End of architectural block
Error (10482): VHDL error at counter4bit.vhd(29): object "Dout" is used but not declared
Error (10482): VHDL error at counter4bit.vhd(29): object "Din" is used but not declared
Error (10558): VHDL error at counter4bit.vhd(29): cannot associate formal port "Dout" of mode "out" with an expression
Error (10589): VHDL Port Map Aspect error at counter4bit.vhd(29): too many actuals for block "register4bit" with only 5 formals
Error (10784): HDL error at counter4bit.vhd(17): see declaration for object "register4bit"
Error: Quartus II 32-bit Analysis & Synthesis was unsuccessful. 5 errors, 1 warning
Error: Peak virtual memory: 361 megabytes
Error: Processing ended: Wed Mar 09 14:41:42 2016
Error: Elapsed time: 00:00:01
Error: Total CPU time (on all processors): 00:00:01
Error (293001): Quartus II Full Compilation was unsuccessful. 7 errors, 1 warning
mod1: register4bit port map (tmp(0) <= Dout(0), tmp(1) <= Dout(1),tmp(2) <= Dout(2),tmp(3) <= Dout(3), Din(0) <= mod_value(0), Din(1) <= mod_value(1), Din(2) <= mod_value(2), Din(3) <= mod_value(3), reset <= reset, clock <= clock, en < reset);
port map (
Dout => tmp,
Din => mod_value,
etc
port amp (entity_port_name => top_level_signal_connection, ....
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity counter4bit is port( mod_value: in std_logic_vector(0 to 3); clock: in std_logic; enable_count: in std_logic; reset: in std_logic; direction: in std_logic; output_counter: out std_logic_vector(0 to 3) ); end counter4bit; architecture structural of counter4bit is component register4bit is port( Din : in std_logic_vector(3 downto 0); en : in std_logic; clock : in std_logic; reset : in std_logic; Dout : out std_logic_vector(3 downto 0)); end component; signal dig, tmp: std_logic_vector(3 downto 0); begin mod1: register4bit port map ( Dout => tmp, Din => mod_value, reset <= reset, clock <= clock, en <= reset); process(Clock,Reset) begin if Reset='1' then dig <= "0000"; elsif ( rising_edge(clock)) then if (enable_count<='1' and direction<='0') then if dig <= "tmp(3)tmp(2)tmp(1)tmp(0)" then dig <= "0000"; else dig <= dig + 1; if (enable_count<='1' and direction<='1') then dig <= dig - 1; end if; end if; end if; end if; end process; output_counter <= dig; end structural;
Error (10437): VHDL Association List error at counter4bit.vhd(31): positional associations must be listed before named associations
Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 1 error, 0 warnings
Error: Peak virtual memory: 511 megabytes
Error: Processing ended: Wed Mar 09 17:51:56 2016
Error: Elapsed time: 00:00:01
Error: Total CPU time (on all processors): 00:00:01
Error (293001): Quartus II Full Compilation was unsuccessful. 3 errors, 0 warnings
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity counter4bit is port( mod_value: in std_logic_vector(0 to 3); clock: in std_logic; enable_count: in std_logic; reset: in std_logic; direction: in std_logic; output_counter: out std_logic_vector(0 to 3) ); end counter4bit; architecture structural of counter4bit is component register4bit is port( Din : in std_logic_vector(3 downto 0); en : in std_logic; clock : in std_logic; reset : in std_logic; Dout : out std_logic_vector(3 downto 0)); end component; signal dig, tmp: std_logic_vector(3 downto 0); begin mod1: register4bit port map ( Dout => tmp, Din => mod_value, reset => reset, clock => clock, en => reset); process(Clock,Reset) begin if Reset='1' then dig <= "0000"; elsif ( rising_edge(clock)) then if (enable_count<='1' and direction<='0') then if dig <= "tmp(3)tmp(2)tmp(1)tmp(0)" then dig <= "0000"; else dig <= dig + 1; if (enable_count<='1' and direction<='1') then dig <= dig - 1; end if; end if; end if; end if; end process; output_counter <= dig; end structural;
Error (10327): VHDL error at counter4bit.vhd(41): can't determine definition of operator ""<="" -- found 0 possible definitions
Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 1 error, 0 warnings
Error: Peak virtual memory: 511 megabytes
Error: Processing ended: Wed Mar 09 19:33:46 2016
Error: Elapsed time: 00:00:08
Error: Total CPU time (on all processors): 00:00:02
Error (293001): Quartus II Full Compilation was unsuccessful. 3 errors, 0 warnings
if dig <= "tmp(3)tmp(2)tmp(1)tmp(0)" then
if dig <= tmp then
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 process(Clock,Reset) begin if Reset='1' then dig <= "0000"; elsif ( rising_edge(clock)) then if (enable_count<='1' and direction<='0') then if dig <= "tmp(3)tmp(2)tmp(1)tmp(0)" then dig <= "0000"; else dig <= dig + 1; -- add 1 to dig if (enable_count<='1' and direction<='1') then -- but if this is met then subtract 1 from dig (this means you did nothing) dig <= dig - 1; -- dig +1 -1? end if; end if; end if; end if; end process;
if (enable_count<='1' and direction<='0') then
if (enable_count = '1' and direction = '0') then
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 if (count_enable = '1') then -- counter is enabled if (direction = '0') then -- counting up if (dig = tmp) then dig <= (others =>'0'); else dig <= dig + 1; end if; else -- count down direction is '1' dig <= dig - 1; end if; end if;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter4bit is
port(
mod_value: in std_logic_vector(0 to 3);
clock: in std_logic;
enable_count: in std_logic;
reset: in std_logic;
direction: in std_logic;
output_counter: out std_logic_vector(0 to 3) );
end counter4bit;
architecture structural of counter4bit is
component register4bit is
port(
Din : in std_logic_vector(3 downto 0);
en : in std_logic;
clock : in std_logic;
reset : in std_logic;
Dout : out std_logic_vector(3 downto 0));
end component;
signal dig, tmp: std_logic_vector(3 downto 0);
begin
mod1: register4bit port map ( Dout => tmp,
Din => mod_value,
reset => reset,
clock => clock,
en => reset);
process(Clock,Reset)
begin
if Reset='1' then
dig <= "0000";
elsif ( rising_edge(clock)) then
if (enable_count = '1') then
if (direction = '0') then
if (dig = tmp) then
dig <= (others =>'0');
else
dig <= dig + 1;
end if;
elsif (dig = "0000") then
dig <= tmp;
else
dig <= dig - 1;
end if;
end if;
end if;
end process;
output_counter <= dig;
end structural;
You can't call out each individual bit of the bus in an instantiation you connect the entire bus with one named association. This is why the tools complain about too many actuals.
my_inst : entity work.Register4Bit
port map (
dout(0) <= tmp(1),
dout(2 downto 1) <= tmp(0) & tmp(2),
dout(3) <= tmp(3) --must be connected or you get an error
);
port map (
-- interface 0
Din(0) => Ain,
Vin(0) => v(0),
-- interface 1
Din(1) => Bin,
Vin(1) => v(1),
-- pretend there is more here
-- ...
)
-------------------------------------------------------------------------------------------
-- Project : Programmable Up/Down Counter Design
-- File : Clock_Divider.vhd
-- Authors : Alistair A. McEwan and Irfan Mir
-- Company : University of Leicester
-- Date : 10 March 2013
-------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Clock_Divider is
GENERIC(LIMIT : integer := 2);
PORT (
Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
Clk_Div : OUT STD_LOGIC
);
end Clock_Divider;
architecture Behavioral of Clock_Divider is
signal cnt : STD_LOGIC_VECTOR(31 downto 0);
begin
PC: process (Clock, Reset)
begin
if rising_edge(Clock) then
if Reset = '1' then
cnt <= (others => '0');
Clk_Div <= '0';
elsif cnt = LIMIT-1 then
cnt <= (others => '0');
Clk_Div <= '1';
else
cnt <= cnt+1;
Clk_Div <= '0';
end if;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter4bit_half is
port(
mod_value: in std_logic_vector(0 to 3);
clk_div: in std_logic;
enable_count: in std_logic;
reset: in std_logic;
direction: in std_logic;
output_counter: out std_logic_vector(0 to 3) );
end counter4bit_half;
architecture behavioral of counter4bit_half is
component register4bit is
port(
Din : in std_logic_vector(3 downto 0);
en : in std_logic;
clock : in std_logic;
reset : in std_logic;
Dout : out std_logic_vector(3 downto 0));
end component;
signal dig, tmp: std_logic_vector(3 downto 0);
begin
mod1: register4bit port map ( Dout => tmp,
Din => mod_value,
reset => reset,
clock => clk_div,
en => reset);
process(clk_div, Reset)
begin
if Reset='1' then
dig <= "0000";
elsif ( rising_edge(clk_div)) then
if (enable_count = '1') then
if (direction = '0') then
if (dig = tmp) then
dig <= (others =>'0');
else
dig <= dig + 1;
end if;
elsif (dig = "0000") then
dig <= tmp;
else
dig <= dig - 1;
end if;
end if;
end if;
end process;
output_counter <= dig;
end behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter4bit is
port(
mod_value: in std_logic_vector(0 to 3);
clock: in std_logic;
enable_count: in std_logic;
reset: in std_logic;
direction: in std_logic;
output_counter: out std_logic_vector(0 to 3) );
end counter4bit;
architecture structural of counter4bit is
component Clock_Divider is
GENERIC ( LIMIT : integer := 2 );
PORT ( Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
Clk_Div : OUT STD_LOGIC );
end component;
signal clk : STD_LOGIC;
Begin
clkdiv: Clock_Divider GENERIC MAP (LIMIT => 50000000)
PORT MAP (
Clock => Clock,
Reset => Reset,
Clk_Div => clk);
component counter4bit_half is
port(
mod_value: in std_logic_vector(0 to 3);
clk_div: in std_logic;
enable_count: in std_logic;
reset: in std_logic;
direction: in std_logic;
output_counter: out std_logic_vector(0 to 3));
end component;
signal clk: std_logic;
begin
cntr: counter4bit_half port map (
mod_value => mod_value,
direction => direction,
enable_count => enable_count,
clock => clk,
reset => reset
output_counter => output_counter);
end structural;
Error (10500): VHDL syntax error at counter4bit.vhd(32) near text "component"; expecting "end", or "(", or an identifier ("component" is a reserved keyword), or a concurrent statement
Error (10500): VHDL syntax error at counter4bit.vhd(37) near text "in"; expecting "(", or an identifier ("in" is a reserved keyword), or a sequential statement
Error (10500): VHDL syntax error at counter4bit.vhd(38) near text "in"; expecting "(", or an identifier ("in" is a reserved keyword), or a sequential statement
Error (10500): VHDL syntax error at counter4bit.vhd(39) near text "in"; expecting "(", or an identifier ("in" is a reserved keyword), or a sequential statement
Error (10500): VHDL syntax error at counter4bit.vhd(40) near text "out"; expecting "(", or an identifier ("out" is a reserved keyword), or a sequential statement
Error (10500): VHDL syntax error at counter4bit.vhd(40) near text ")"; expecting "(", or "'", or "."
Error (10500): VHDL syntax error at counter4bit.vhd(45) near text "begin"; expecting "end", or "(", or an identifier ("begin" is a reserved keyword), or a concurrent statement
Error (10500): VHDL syntax error at counter4bit.vhd(52) near text "output_counter"; expecting ")", or ","
Error: Quartus II 32-bit Analysis & Synthesis was unsuccessful. 8 errors, 1 warning
Error: Peak virtual memory: 361 megabytes
Error: Processing ended: Thu Mar 10 12:22:06 2016
Error: Elapsed time: 00:00:01
Error: Total CPU time (on all processors): 00:00:01
Error (293001): Quartus II Full Compilation was unsuccessful. 10 errors, 1 warning
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter4bit_modproc is
GENERIC(LIMIT : integer := 2);
port(
mod_value: in std_logic_vector(0 to 3);
clock: in std_logic;
enable_count: in std_logic;
reset: in std_logic;
direction: in std_logic;
output_counter: out std_logic_vector(0 to 3) );
end counter4bit_modproc;
architecture behavioral of counter4bit_modproc is
component Clock_Divider is
GENERIC ( LIMIT : integer := 2 );
PORT ( Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
Clk_Div : OUT STD_LOGIC );
end component;
signal dig: std_logic_vector(3 downto 0);
begin
process(clock, Reset)
begin
if Reset='1' then
dig <= "0000";
elsif ( rising_edge(clock)) then
if (enable_count = '1') then
if (direction = '0') then
if (dig = mod_value) then
dig <= (others =>'0');
else
dig <= dig + 1;
end if;
elsif (dig = "0000") then
dig <= mod_value;
else
dig <= dig - 1;
end if;
end if;
end if;
end process;
output_counter <= dig;
end behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Clock_Divider is
GENERIC(LIMIT : integer := 2);
PORT (
Clock : IN STD_LOGIC;
Reset : IN STD_LOGIC;
Clk_Div : OUT STD_LOGIC
);
end Clock_Divider;
architecture Behavioral of Clock_Divider is
signal cnt : STD_LOGIC_VECTOR(31 downto 0);
begin
PC: process (Clock, Reset)
begin
if rising_edge(Clock) then
if Reset = '1' then
cnt <= (others => '0');
Clk_Div <= '0';
elsif cnt = LIMIT-1 then
cnt <= (others => '0');
Clk_Div <= '1';
else
cnt <= cnt+1;
Clk_Div <= '0';
end if;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter4bit_modproc is
GENERIC(LIMIT : integer := 2);
port(
mod_value: in std_logic_vector(3 downto 0);
clock: in std_logic;
enable_count: in std_logic;
reset: in std_logic;
direction: in std_logic;
output_counter: out std_logic_vector(3 downto 0) );
end counter4bit_modproc;
architecture behavioral of counter4bit_modproc is
component Clock_Divider is
generic ( LIMIT : integer := 2 );
port (
Clock : in std_logic;
Reset : in std_logic;
Clk_Div : out std_logic);
end component;
signal dig: std_logic_vector(3 downto 0);
signal clk: std_LOGIC;
begin
clkdiv: Clock_Divider generic map (LIMIT => 50000000)
port map (
clock => Clock,
Reset => Reset,
clk_Div => clk);
process(clk, Reset)
begin
if Reset='1' then
dig <= "0000";
elsif ( rising_edge(clk)) then
if (enable_count = '1') then
if (direction = '0') then
if (dig <= mod_value) then
dig <= "0000";
--dig <= (others =>'0');
else
dig <= dig + 1;
end if;
elsif (dig = "0000") then
dig <= mod_value;
else
dig <= dig - 1;
end if;
end if;
end if;
end process;
output_counter <= dig;
end behavioral;
if (dig <= mod_value) then -- dig less than or equal to mod_value, i.e. 0 <= 4? YES!
dig <= "0000"; -- Make dig 0 again
else
dig <= dig + 1;
end if;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 clkdiv: Clock_Divider generic map (LIMIT => 50000000) port map ( clock => Clock, Reset => Reset, clk_Div => clk); -- generated clock from a flip-flop, NO, very bad practice! process(clk, Reset) begin if Reset='1' then dig <= "0000"; elsif ( rising_edge(clk)) then -- NO don't use the SIGNAL from a flip-flop as a clock.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 process (Reset, Clock) begin if (Reset = '1') then div_cnt <= 0; div_clk <= 0; elsif (rising_edge(Clock)) then if (div_cnt < NEW_CLK_PERIOD/2-1) then div_cnt <= div_cnt + 1; else -- toggle the div_clk at half of the LIMIT count value div_cnt <= 0; div_clk <= not div_clk; -- 50% duty cycle generated clock instead of a single pulse end if; end if; end process;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?