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.

Problem with writing a code for a state machine on Xilinx

Status
Not open for further replies.

NoHa111

Junior Member level 3
Joined
Sep 2, 2005
Messages
25
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,515
STATE MACHINE

Hi all,

please i have a problem in writing a code for simple state machine on xilinix
this is the code and the errors always appear in process2 at every (when) it just says that (unexpected when,expected end)!!!!

here is the 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 bass2 is
Port ( wp : out STD_LOGIC_VECTOR (11 downto 0);
wz : out STD_LOGIC_VECTOR (11 downto 0);
bup : in STD_LOGIC;
bdn : in STD_LOGIC);
end bass2;

architecture Behavioral of bass2 is
type state_type is (flat, six, twelve, nsix, ntwelve);
signal state, next_state: state_type;

begin

process1: process (bup, bdn)
begin
if (bup ='0' and bdn='0') then
state <= flat;
elsif (bup = '1' or bdn='1') then
state <= next_state;
end if;
end process process1;


process2 : process (bup, bdn)
begin
case state is
when flat =>
if (bup = '1' and bdn='0') then
next_state <= six;
else if (bup = '0' and bdn='1') then
next_state <= nsix;
end if;

when six =>
if (bup = '1' and bdn='0') then
next_state <= twelve;
else if (bup = '0' and bdn='1') then
next_state <= flat;
end if;
when twelve =>
if (bup = '1' and bdn='0') then
next_state <= twelve;
else if (bup = '0' and bdn='1') then
next_state <= six;
end if;
when nsix =>
if (bup = '1' and bdn='0') then
next_state <= flat;
else if (bup = '0' and bdn='1') then
next_state <= ntwelve;
end if;
when ntwelve =>
if (bup = '1' and bdn='0') then
next_state <= nsix;
else if (bup = '0' and bdn='1') then
next_state <= ntwelve;
end if;

end case;
end process process2;


process3 : process (state)
begin
case state is
when flat => wp <= "011000100001";
when six => wp <= "011000100001";
when twelve => wp <= "011000100001";
when nsix => wp <= "011000011111";
when ntwelve => wp <= "110000110111";

end case;
end process process3;



end Behavioral;




sorry if it seems silly but i am a bigginer (really it is my first code:D)
please i need your help urgently and ASAP

THANKS ALOT IN ADVANCE
NOHA
 

Re: STATE MACHINE

Check out this!

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 bass2 is
  port ( wp  : out std_logic_vector (11 downto 0);
         wz  : out std_logic_vector (11 downto 0);
         bup : in  std_logic;
         bdn : in  std_logic);
end bass2;

architecture Behavioral of bass2 is
  type state_type is (flat, six, twelve, nsix, ntwelve);
  signal state, next_state : state_type;

begin

  process1 : process (bup, bdn)
  begin
    if (bup = '0' and bdn = '0') then
      state <= flat;
    elsif (bup = '1' or bdn = '1') then
      state <= next_state;
    end if;
  end process process1;


  process2 : process (bup, bdn)
  begin
    case state is
      when flat =>
        if (bup = '1' and bdn = '0') then
          next_state      <= six;
        elsif (bup = '0' and bdn = '1') then
          next_state <= nsix;
        end if;

      when six                    =>
        if (bup = '1' and bdn = '0') then
          next_state                     <= twelve;
        elsif (bup = '0' and bdn = '1') then
          next_state                <= flat;
        end if;
      when twelve            =>
        if (bup = '1' and bdn = '0') then
          next_state                <= twelve;
        elsif (bup = '0' and bdn = '1') then
          next_state           <= six;
        end if;
      when nsix         =>
        if (bup = '1' and bdn = '0') then
          next_state           <= flat;
        elsif (bup = '0' and bdn = '1') then
          next_state      <= ntwelve;
        end if;
      when ntwelve =>
        if (bup = '1' and bdn = '0') then
          next_state      <= nsix;
        elsif (bup = '0' and bdn = '1') then
          next_state <= ntwelve;
        end if;

    end case;
  end process process2;
  
  process3 : process (state)
  begin
    case state is
      when flat    => wp <= "011000100001";
      when six     => wp <= "011000100001";
      when twelve  => wp <= "011000100001";
      when nsix    => wp <= "011000011111";
      when ntwelve => wp <= "110000110111";
                      
    end case;
  end process process3;
end Behavioral;
 

    NoHa111

    Points: 2
    Helpful Answer Positive Rating
Re: STATE MACHINE

THANKS alot for your help
now it works prperly:D
 

Re: STATE MACHINE

salamo alikom noha,

u just need to replace the ELSE IF by ELSIF
it's just one word
cause if it's ELSE IF, then u wrote two IF but only one end
do u get it ?

good luck,
Salma:)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top