Hi guys,
I was wondering if someone could help me with a simple state machine i'm trying to get to work.
I'll try to explain what it needs to do and then my "source code" so far.
Suppose you step out of the car and the lights are still on and door is open, then a beeper should alert you about it.
The first 5 seconds the beeper should beep with a pause of 1 second between the beep sounds. After that with a pause of 500 milliseconds. And then with no pause untill door is closed.
This is my code:
library IEEE;
use IEEE.std_logic_1164.all;
entity carbeeper is
port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
door : in STD_LOGIC;
light : in STD_LOGIC;
beeper : out STD_LOGIC );
end carbeeper;
-- SYMBOLIC ENCODED state machine: Sreg0
type Sreg0_type is (S1, S2, S3, S4, S5, S6);
signal Sreg0: Sreg0_type;
Signal state: bit_vector( 2 downto 0 );
begin
Sreg0_machine:
process (clk,reset)
begin
if (reset = '1') then state <= "000";
elsif (clk ='1' and clk'event) then
case state is
when "000"=> --idle
if (door = '1' & lamp = '1') then beeper <= '1';
state <= "001";
else beeper <= '0';
state <="000"
when "001" -- door open?
when S3 =>
if yes then
Sreg0 <= S4;
Reset low;
elsif no then
Sreg0 <= S1;
Reset low;
end if;
when S4 =>
if yes then
Sreg0 <= S5;
beeper on;
clk high;
elsif no then
Sreg0 <= S1;
clk high;
end if;
when S5 =>
if yes then
Sreg0 <= S6;
switch off;
end if;
when S6 =>
if no then
Sreg0 <= S5;
beeper on;
elsif yes then
Sreg0 <= S1;
end if;
when others =>
null;
end case;
end if;
end if;
end process;
end carbeeper;
I was wondering if someone could help me with a simple state machine i'm trying to get to work.
I'll try to explain what it needs to do and then my "source code" so far.
Suppose you step out of the car and the lights are still on and door is open, then a beeper should alert you about it.
The first 5 seconds the beeper should beep with a pause of 1 second between the beep sounds. After that with a pause of 500 milliseconds. And then with no pause untill door is closed.
This is my code:
library IEEE;
use IEEE.std_logic_1164.all;
entity carbeeper is
port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
door : in STD_LOGIC;
light : in STD_LOGIC;
beeper : out STD_LOGIC );
end carbeeper;
-- SYMBOLIC ENCODED state machine: Sreg0
type Sreg0_type is (S1, S2, S3, S4, S5, S6);
signal Sreg0: Sreg0_type;
Signal state: bit_vector( 2 downto 0 );
begin
Sreg0_machine:
process (clk,reset)
begin
if (reset = '1') then state <= "000";
elsif (clk ='1' and clk'event) then
case state is
when "000"=> --idle
if (door = '1' & lamp = '1') then beeper <= '1';
state <= "001";
else beeper <= '0';
state <="000"
when "001" -- door open?
when S3 =>
if yes then
Sreg0 <= S4;
Reset low;
elsif no then
Sreg0 <= S1;
Reset low;
end if;
when S4 =>
if yes then
Sreg0 <= S5;
beeper on;
clk high;
elsif no then
Sreg0 <= S1;
clk high;
end if;
when S5 =>
if yes then
Sreg0 <= S6;
switch off;
end if;
when S6 =>
if no then
Sreg0 <= S5;
beeper on;
elsif yes then
Sreg0 <= S1;
end if;
when others =>
null;
end case;
end if;
end if;
end process;
end carbeeper;