------------------------------------------------------------------------
-- File: speed.vhd
--
-- Group: Korrey Scott 237118
-- Milton Mah 341428
-- Mike Holden 346386
--
-- Course: EE 552
-- Project: ASM
-- Instructor: Dr. Duncan Elliott
-- Completed: Mar. 9, 1998
------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
------------------------------------------------------------------------
-- Entity: speed
--
-- Inputs: reset: connected to the master reset. Resets the speed
-- module to initial state.
-- seconds_pulse: a 1 Hertz pulse generated by clock.vhd
--
-- revolution: pulse generated by the rotation of the wheel
--
-- Outputs: velocity: the velocity of the automobile, in meters per second
-- determined by the rotation frequency and circumference
-- of the wheel
------------------------------------------------------------------------
entity speed is
generic ( circumference:positive:=2;
max_distance:positive:=127;
max_dist_minus_circ:positive:=125
);
port (
revolution, reset : in std_logic;
seconds_pulse : in std_logic;
velocity : out integer range 0 to max_distance
);
end speed;
------------------------------------------------------------------------
-- Architecture: behaviour of speed
--
-- Description: The purpose of this module is calculate the velocity
-- of the automobile, in meters per second.
------------------------------------------------------------------------
architecture behaviour of speed is
signal distance_gone : integer range 0 to max_distance;
signal reset_distance : std_logic;
signal start_distance : std_logic;
begin
get_velocity : process
variable velocity_bak : integer range 0 to max_distance;
begin
wait until rising_edge(seconds_pulse);
if reset = '1' then
reset_distance <= '1';
velocity <= 0;
elsif start_distance = '1' then
reset_distance <= '0';
else
velocity <= distance_gone;
reset_distance <= '1';
end if;
end process get_velocity;
get_distance : process
begin
wait until rising_edge(revolution);
if reset = '1' then
start_distance <= '0';
distance_gone <= 0;
elsif reset_distance = '1' then
distance_gone <= 0;
start_distance <= '1';
else
start_distance <= '0';
if distance_gone < max_dist_minus_circ then
distance_gone <= distance_gone + circumference;
end if;
end if;
end process get_distance;
end behaviour;