Project

General

Profile

Download (2.26 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
-- Copyright (C) 2002 Morgan Kaufmann Publishers, Inc
3

    
4
-- This file is part of VESTs (Vhdl tESTs).
5

    
6
-- VESTs is free software; you can redistribute it and/or modify it
7
-- under the terms of the GNU General Public License as published by the
8
-- Free Software Foundation; either version 2 of the License, or (at
9
-- your option) any later version. 
10

    
11
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
12
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
-- for more details. 
15

    
16
-- You should have received a copy of the GNU General Public License
17
-- along with VESTs; if not, write to the Free Software Foundation,
18
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
19

    
20
entity limited is
21
end entity limited;
22

    
23

    
24

    
25
architecture test of limited is
26

    
27
  -- code from book
28

    
29
  function limited ( value, min, max : real ) return real is
30
  begin
31
    if value > max then
32
      return max;
33
    elsif value < min then
34
      return min;
35
    else
36
      return value;
37
    end if;
38
  end function limited;
39

    
40
  -- end code from book
41

    
42
begin
43

    
44
  tester : process is
45

    
46
    variable new_temperature, current_temperature, increment : real;
47
    variable new_motor_speed, old_motor_speed,
48
             scale_factor, error : real;
49

    
50
  begin
51

    
52
    current_temperature := 75.0;
53
    increment := 10.0;
54

    
55
    -- code from book (in text)
56

    
57
    new_temperature := limited ( current_temperature + increment, 10.0, 100.0 );
58

    
59
    -- end code from book
60

    
61
    increment := 60.0;
62
    new_temperature := limited ( current_temperature + increment, 10.0, 100.0 );
63
    increment := -100.0;
64
    new_temperature := limited ( current_temperature + increment, 10.0, 100.0 );
65

    
66
    old_motor_speed := 1000.0;
67
    scale_factor := 5.0;
68
    error := 5.0;
69

    
70
    -- code from book (in text)
71

    
72
    new_motor_speed := old_motor_speed
73
                       + scale_factor * limited ( error, -10.0, +10.0 );
74

    
75
    -- end code from book
76

    
77
    error := 15.0;
78
    new_motor_speed := old_motor_speed
79
                       + scale_factor * limited ( error, -10.0, +10.0 );
80

    
81
    error := -20.0;
82
    new_motor_speed := old_motor_speed
83
                       + scale_factor * limited ( error, -10.0, +10.0 );
84

    
85
    wait;
86
  end process tester;
87

    
88
end architecture test;
(10-10/12)