In the context of UK rail signaling, a typical 4-aspect signal shows four possible states (aspects) to a train driver:
- Red (Stop)
- Yellow (Preliminary Caution)
- Double Yellow (Caution)
- Green (Clear)
This logic assumes a cyclic operation where the 'advance' input moves the signal to the next less restrictive aspect and the 'reset' input returns the signal to Red. For simplicity, we'll assume the input 'advance' toggles through the states sequentially from red to green and then cycles back to red, whereas the 'reset' sets the signal back to red no matter the current state.
Below is an example of such a state machine implemented in VHDL:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity four_aspect_signal is
port (
clk : in std_logic; -- Clock input
reset : in std_logic; -- Reset input
advance : in std_logic; -- Advance to the next aspect
aspect : out std_logic_vector(3 downto 0) -- Output signal aspects (4 bit)
);
end entity;
architecture fsm of four_aspect_signal is
type state_type is (RED, YELLOW, DOUBLE_YELLOW, GREEN);
signal current_state, next_state : state_type;
begin
-- State register
process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
current_state <= RED;
else
current_state <= next_state;
end if;
end if;
end process;
-- Next state logic
process(current_state, advance)
begin
case current_state is
when RED =>
if advance = '1' then
next_state <= YELLOW;
else
next_state <= RED;
end if;
when YELLOW =>
if advance = '1' then
next_state <= DOUBLE_YELLOW;
else
next_state <= YELLOW;
end if;
when DOUBLE_YELLOW =>
if advance = '1' then
next_state <= GREEN;
else
next_state <= DOUBLE_YELLOW;
end if;
when GREEN =>
if advance = '1' then
next_state <= RED;
else
next_state <= GREEN;
end if;
end case;
end process;
-- Output logic
aspect <= "1000" when current_state = RED else
"0100" when current_state = YELLOW else
"0010" when current_state = DOUBLE_YELLOW else
"0001" when current_state = GREEN else
"1000"; -- Default is RED
end architecture;
In this VHDL example, the four_aspect_signal entity has two inputs: advance and reset, as well as an output aspect which is a 4-bit vector representing the state of the signal. A simple state machine is implemented using a state_type enumeration type to define the operational states of the signal.
The state is registered with a rising edge clock process. When the reset input is high, the state machine is forced to the RED state. Otherwise, the advance input determines the next state transitions.
The output logic then maps the state of the signal to a 4-bit vector, aspect, where each bit could hypothetically represent an LED or some other indicator with 1 indicating the light is on and 0 indicating it's off (in practice, the encoding might be different).
The output aspect is represented as follows for each state:
- RED: "1000"
- YELLOW: "0100"
- DOUBLE_YELLOW: "0010"
- GREEN: "0001"
This is a simplified representation and does not account for debouncing, synchronization, or potential safety checks common in real-world signal systems. Additionally, ensure that your clock signal (clk) is appropriately configured and that debouncing is handled for the advance and reset inputs if they are triggered by mechanical switches.