3.8 STEP 7: A Timer

3.8.1 Synopsis

After a picture has been taken, the film is transported forward automatically. In order to detect malfunction, e.g. end of film or a torn film, a transport supervision module needs to be implemented. If the servo motor has not finished the film transport after 2 seconds, an error signal is generated.

The timeout function is generated with the help of a counter. As the clock frequency is 8192 Hz, 2 seconds correspond to a maximum value of 16383 (=14 bit). The CLK and RESET signals are needed for the Flip-Flops again.

The start of the film transport is signaled via the MOTOR_GO signal. It is set to '1' when the transportation begins. When the servo motor has finished, the MOTOR_READY signal is set to '1'. An error is reported via the MOTOR_ERROR signal in the same way, i.e. it is set to '1' if the MOTOR_READY pulse has not occurred in time. The signals are active for the duration of one clock period, only, in order to make an edge detection dispensable.

The interface of the module is depicted in the next drawing:

 

The transport timeout supervision module

 

3.8.2 Implementation

The VHDL code for the motor timeout supervision

library ieee;
use ieee.std_logic_1164.all;

entity MOTOR_TIMER is
  port(CLK      : in  std_ulogic;
       RESET      : in  std_ulogic;
       MOTOR_GO    : in  std_ulogic;
       MOTOR_READY : in  std_ulogic;
       MOTOR_ERROR : out std_ulogic);
end MOTOR_TIMER;

architecture RTL of MOTOR_TIMER is
begin
  process (CLK, RESET)
    variable COUNTER : integer
                        range 0 to 16383;
    variable COUNT : std_ulogic;
  begin
    if (RESET = '1') then
      COUNTER     := 0;
      COUNT     := '0';
      MOTOR_ERROR <= '0';

    elsif (CLK'event and CLK = '1') then
      MOTOR_ERROR <= '0';


      if MOTOR_GO = '1' then
        COUNT := '1';
        COUNTER := 0;
      end if;

      if MOTOR_READY = '1' then
        COUNT := '0';
      end if;

      if COUNT = '1' then
        if COUNTER /= 16383 then
          COUNTER := COUNTER + 1;
        else
          MOTOR_ERROR <= '1';
          COUNT := '0';
        end if;
      end if;   -- if COUNTING
    end if;     -- end of clocked process
  end process;
end RTL;
  • Only std_ulogic and the prede-
    fined integer data type are used in
    this module
               
  • Variables are declared within a
    process. The COUNT-flag is used
    to signal whether the module is
    actually counting
  • An error should be an exception,
    i.e. the MOTOR_ERROR signal is
    set to '0' as default
  • The counter is reset to 0 and the
    COUNT flag is set when the film
    transport begins
  • The counter has to be stopped
    when the motor has finished
  • If we are actually counting...
 
  • The counter is incremented as long
    as the timeout condition is not full-
    filled
  • Else, the counter is stopped and
    the error is reported
  • For the sake of clarity, the corre-
    sponding condition is added as
    comment after the end of if-state-
    ments that span many lines