3.7 STEP 9: A State Machine for the Display

3.7.1 Synopsis

In order to control the 7-segment display a simple state machine is necessary. In addition to the buttons for the desired exposure time another special button is present on the camera panel that allows the user to switch between the current exposure time and the number of pictures that have already been taken.

If one of the exposure time buttons is pressed the display will have to show the corresponding exposure time immediately. Otherwise, the display should toggle between exposure time and number of pictures whenever the SWITCH button is pressed.

The figure below shows the module interface:

 

The display controller module

 

3.7.2 Implementation

The VHDL code for the display controller

library ieee;
use ieee.std_logic_1164.all;
use work.P_DISPLAY.all;

entity DISP_CTRL is
  port(CLK       : in  std_ulogic;
       RESET    : in  std_ulogic;
       SWITCH    : in  std_ulogic;
       KEY       : in  T_DIGITS;
       SHOW_TIME : out std_ulogic);
end DISP_CTRL;

architecture RTL of DISP_CTRL is
  signal SHOW_STATE: std_ulogic;
begin
  SHOW_TIME <= SHOW_STATE;

  process (CLK, RESET)
    variable LAST_SWITCH: std_ulogic;
  begin
    if (RESET = '1') then
      LAST_SWITCH := '0';
      SHOW_STATE  <= '0';
    elsif (CLK'event and CLK = '1') then
      if KEY /= (0,0,0) then
        SHOW_STATE <= '1';
      else
        if LAST_SWITCH = '0' and
           SWITCH = '1' then
          SHOW_STATE <= not(SHOW_STATE);
        end if;
      end if;
      LAST_SWITCH := SWITCH;
    end if;     -- end of clocked process
  end process;
end RTL;
                     
  • The internal SHOW_STATE sig-
    nal is connected directly to the
    SHOW_TIME port. This way the
    signal can be read by the processes
    of the entity.
  • Variables that might be read
    before they are updated infer Flip-
    Flops that have to be reset as well.
  • If an exposure time is selected the
    display will show that time value,
  • Else, we have to wait for a rising edge of the SWITCH signal.
 
  • The current level of the SWITCH signal is stored for comparison in the next clock cycle.