------------------------------------------------------------------------

-- File: mileage.vhd

--

-- Group: Milton Mah 341428

-- Korrey Scott 237118

-- Mike Holden 346386

--

-- Course: EE 552

-- Project: ASM

-- Instructor: Dr. Duncan Elliott

-- Completed: Feb. 21, 1998

------------------------------------------------------------------------

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

 

------------------------------------------------------------------------

-- Entity: mileage

--

-- Inputs: litres_ml: a signal that sends a pulse for every ml of fuel

-- spent in the tank

-- revolution: The mileage is recalculated for every turn of the wheel

--

-- reset: Initializes the module to a state ready to be used.

--

-- Outputs: km_per_litre: The mileage the vehicle is currently getting.

------------------------------------------------------------------------

entity mileage is

generic ( max_mileage: positive := 127;

circumference : positive:=2;

max_dist_minus_circ: positive := 125);

port( litres_ml:in std_logic;

revolution, reset:in std_logic;

km_per_litre:out integer range 0 to max_mileage

);

end mileage;

 

------------------------------------------------------------------------

-- Architecture: behaviour of mileage

--

-- Description: This module recalculates the mileage every pulse of the

-- litres_ml signal. The circumference of the wheel is determines

-- the distance travelled on each revolution

------------------------------------------------------------------------

architecture reading of mileage is

signal distance_gone : integer range 0 to max_mileage;

signal reset_distance : std_logic;

signal start_distance : std_logic;

begin

get_mileage : process

variable velocity_bak : integer range 0 to max_mileage;

begin

wait until rising_edge(litres_ml);

if reset = '1' then

reset_distance <= '1';

km_per_litre <= 0;

elsif start_distance = '1' then

reset_distance <= '0';

else

km_per_litre <= distance_gone;

reset_distance <= '1';

end if;

end process get_mileage;

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 reading;