---------------------------------------------------------------------------- -- -- Oscilloscope Digital Trigger -- -- This is an implementation of a trigger for a digital oscilloscope in -- VHDL. There are three inputs to the system, one selects the trigger -- slope and the other two determine the relationship between the trigger -- level and the signal level. The only output is a trigger signal which -- indicates a trigger even has occurred. -- -- Revision History: -- 13 Apr 04 Glen George Initial revision. -- ---------------------------------------------------------------------------- -- bring in the necessary packages library ieee; use ieee.std_logic_1164.all; -- -- Oscilloscope Digital Trigger entity declaration -- entity ScopeTrigger is port ( TS : in std_logic; -- trigger slope (1 -> negative, 0 -> positive) TEQ : in std_logic; -- signal and trigger levels equal TLT : in std_logic; -- signal level < trigger level clk : in std_logic; -- clock Reset : in std_logic; -- reset the system TrigEvent : out std_logic -- a trigger event has occurred ); end ScopeTrigger; -- -- Oscilloscope Digital Trigger Moore State Machine architecture -- architecture Moore_machine of ScopeTrigger is type states is ( -- states the receiver can be in: IDLE, -- waiting for start of trigger event WAIT_POS, -- waiting for a positive slope trigger WAIT_NEG, -- waiting for a negative slope trigger TRIGGER -- got a trigger event ); signal CurrentState : states; -- current state signal NextState : states; -- next state begin -- compute the next state (function of current state and inputs) and -- output (function of current state only) using concurrent statements -- first do the next state calculation (based on current state and inputs) NextState <= -- IDLE state transitions WAIT_POS when (CurrentState = IDLE and Reset = '0' and TS = '0' and TLT = '1' and TEQ = '0') else WAIT_NEG when (CurrentState = IDLE and Reset = '0' and TS = '1' and TLT = '0' and TEQ = '0') -- WAIT_POS state transitions else WAIT_POS when (CurrentState = WAIT_POS and Reset = '0' and TS = '0' and TLT = '1') else TRIGGER when (CurrentState = WAIT_POS and Reset = '0' and TS = '0' and TLT = '0') -- WAIT_NEG state transitions else WAIT_NEG when (CurrentState = WAIT_NEG and Reset = '0' and TS = '1' and TLT = '0' and TEQ = '0') else TRIGGER when (CurrentState = WAIT_NEG and Reset = '0' and TS = '1' and (TLT = '1' or TEQ = '1')) -- TRIGGER state transitions (always back to IDLE) else IDLE when (CurrentState = TRIGGER) -- all other transitions (like when resetting) are to IDLE else IDLE; -- now do the output calculation (function of current state only) -- only generate trigger output when in the TRIGGER state TrigEvent <= '1' when (CurrentState = TRIGGER) else '0'; -- storage of current state (loads the next state on the clock) process (clk) begin if clk = '1' then -- only change on rising edge of clock CurrentState <= NextState; -- save the new state information end if; end process; end Moore_machine; -- -- Oscilloscope Digital Trigger Mealy State Machine architecture -- architecture Mealy_machine of ScopeTrigger is type states is ( -- states the receiver can be in: IDLE, -- waiting for start of trigger event WAIT_POS, -- waiting for a positive slope trigger WAIT_NEG -- waiting for a negative slope trigger ); signal CurrentState : states; -- current state signal NextState : states; -- next state begin -- compute the next state (function of current state and inputs) and -- output (function of current state only) using concurrent statements -- first do the next state calculation (based on current state and inputs) NextState <= -- IDLE state transitions WAIT_POS when (CurrentState = IDLE and Reset = '0' and TS = '0' and TLT = '1' and TEQ = '0') else WAIT_NEG when (CurrentState = IDLE and Reset = '0' and TS = '1' and TLT = '0' and TEQ = '0') -- WAIT_POS state transitions else WAIT_POS when (CurrentState = WAIT_POS and Reset = '0' and TS = '0' and TLT = '1') -- WAIT_NEG state transitions else WAIT_NEG when (CurrentState = WAIT_NEG and Reset = '0' and TS = '1' and TLT = '0' and TEQ = '0') -- all other transitions (like when resetting) are to IDLE else IDLE; -- now do the output calculation (function of current state only and inputs) -- only generate trigger output when in WAIT_POS or WAIT_NEG and get trigger condition TrigEvent <= -- trigger from WAIT_POS state '1' when (CurrentState = WAIT_POS and Reset = '0' and TS = '0' and TLT = '0') -- trigger from WAIT_NEG state else '1' when (CurrentState = WAIT_NEG and Reset = '0' and TS = '1' and (TLT = '1' or TEQ = '1')) -- no other triggers else '0'; -- storage of current state (loads the next state on the clock) process (clk) begin if clk = '1' then -- only change on rising edge of clock CurrentState <= NextState; -- save the new state information end if; end process; end Mealy_machine;