Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me find the error in this VHDL code

Status
Not open for further replies.

Git

Full Member level 4
Joined
Dec 12, 2001
Messages
194
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Torino
Activity points
1,208
Spot the VHDL error...

Can anybody tell me what is wrong with the attached piece of VHDL please?. Xilinx ISE 7.1 is telling me it expects to see see IF rather than PROCESS near the end. I have looked at it too long if you know what I mean.

TIA

Git

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity counter is
Port ( enb : in std_logic;
dir : in std_logic;
clk : in std_logic;
rst : in std_logic;
op : out std_logic_vector(1 downto 0));
end counter;

architecture Behavioral of counter is
signal t_op : std_logic_vector(1 downto 0);
signal t_5 : std_logic_vector(2 downto 0);
begin
op <= t_op;
process(clk, rst, enb, dir)
begin
if rst='1' then
t_op <= "00";
t_5 <= "000";
else if clk = '1' and clk'event then
if enb = '1' then
if dir = '1' then -- Count UP
if t_5 = "100" then
t_5 <= "000";
t_op <= t_op + '1'; -- Carry
else
t_5 <= t_5 + '1';
end if;
else
if t_5 = "000" then
t_5 <= "100";
t_op <= t_op - '1'; -- Borrow
else
t_5 <= t_5 - '1';
end if;
end if;
end if;
end if;
end process;
end Behavioral;
 

Re: Spot the VHDL error...

Have you wrote the code with indent's original.

I guess the problem sits in the else if clk = '1' and clk'event then

change to elsif clk'event and clk = '1' then
 

    Git

    Points: 2
    Helpful Answer Positive Rating
Re: Spot the VHDL error...

Doh!. I *always* do that!. Thanks very much.

Yes, source was originally indented OK but the tabs got removed when posting. I think there's a posting tag I should have used.

Git
 

Re: Spot the VHDL error...

Here is the corrected code one "end if " was missing ...
Hope the code works now!
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity counter is
  port ( enb : in  std_logic;
         dir : in  std_logic;
         clk : in  std_logic;
         rst : in  std_logic;
         op  : out std_logic_vector(1 downto 0));
end counter;

architecture Behavioral of counter is
  signal t_op : std_logic_vector(1 downto 0);
  signal t_5  : std_logic_vector(2 downto 0);
begin
  op                  <= t_op;
  process(clk, rst, enb, dir)
  begin
    if rst = '1' then
      t_op            <= "00";
      t_5             <= "000";
    else
      if clk = '1' and clk'event then
        if enb = '1' then
          if dir = '1' then          -- Count UP
            if t_5 = "100" then
              t_5  <= "000";
              t_op <= t_op + '1';    -- Carry
            else
              t_5  <= t_5 + '1';
            end if;
          else
            if t_5 = "000" then
              t_5  <= "100";
              t_op <= t_op - '1';    -- Borrow
            else
              t_5  <= t_5 - '1';
            end if;
          end if;
        end if;
      end if;
    end if;
  end process;
end Behavioral;
 

Spot the VHDL error...

why don't you like rising_edge(clk)?
 

Re: Spot the VHDL error...

yes, as pointed out by nand_gates...one "end if" statement is missing.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top