VHDL code position: p179_ex7_3_ADCINT
Note: 1: the code is state machine code with multi-process
2: The FSM is for ADC 0809 control
3: see also example 7-2
-------------------------------------------------------------------------------
LIBARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY ADCINT IS
PORT ( D : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
CLK, EOC : IN STD_LOGIC;
ALE, START, OE,
ADDA, LOCK0 : OUT STD_LOGIC;
Q : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END ENTITY ADCINT;
ARCHITECTURE BEHAV OF ADCINT IS
TYPE states IS ( st0, st1, st2, st3, st4 );
SIGNAL current_state, next_state : states := st0;
SIGNAL REGL : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL LOCK : STD_LOGIC;
BEGIN
ADDA <= '1'; -- ADC0809 channel select:
-- 0-channel 0; 1-channel 1
Q <= REGL;
LOCK0 <= LOCK;
COM1:
PROCESS ( current_state, EOC )
BEGIN
CASE current_state IS
WHEN st0 => -- ADC 0809 initial
next_state <= st1;
WHEN st1 => -- ADC 0809 start sampling
next_state <= st2;
WHEN st2 => -- ADC 0809 state test and wait
IF EOC = '1' THEN
next_state <= st3;
ELSE
next_state <= st2;
END IF;
WHEN st3 => -- ADC 0809 data output
next_state <= st4;
WHEN st4 =>
next_state <= st0;
WHEN OTHERS =>
next_state <=st0;
END CASE;
END PROCESS COM1;
COM2:
PROCESS ( current_state )
BEGIN
CASE current_state IS
WHEN st0 => -- ADC 0809 initial
ALE <= '0';
START <= '0';
LOCK <= '0';
OE <= '0';
WHEN st1 => -- ADC 0809 start sampling
ALE <= '1';
START <= '1';
LOCK <= '0';
OE <= '0';
WHEN st2 => -- ADC 0809 state test and wait
ALE <= '0';
START <= '0';
LOCK <= '0';
OE <= '0';
WHEN st3 => -- ADC 0809 data output
ALE <= '0';
START <= '0';
LOCK <= '0';
OE <= '1';
WHEN st4 =>
ALE <= '0';
START <= '0';
LOCK <= '1';
OE <= '1';
WHEN OTHERS =>
ALE <= '0';
START <= '0';
LOCK <= '1';
EBD CASE;
END PROCESS COM2;
REG:
PROCESS ( CLK )
BEGIN
IF CLK'EVENT AND CLK = '1' THEN
current_state <= next_state;
END IF;
END PROCESS REG;
LATCH1:
PROCESS ( LOCK ) -- latch data in the rising edge of LOCK
BEGIN
IF LOCK'EVENT AND LOCK = '1' THEN
REGL <= D;
END IF;
END PROCESS LATCH1;
END ARCHITECTURE BEHAV;