OpenCores
URL https://opencores.org/ocsvn/ratpack/ratpack/trunk

Subversion Repositories ratpack

[/] [ratpack/] [trunk/] [bench/] [vhdl/] [ratpack_tb2.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 kavi
--------------------------------------------------------------------------------
2
-- Filename: ratpack_tb2.vhd
3
-- Purpose : A testbench for "ratpack" generating the Farey series' up to order 
4
--           12.
5
-- Author  : Nikolaos Kavvadias <nikolaos.kavvadias@gmail.com>
6
-- Date    : 14-May-2010
7
-- Version : 0.1
8
-- Revision: 0.0.0 (2010/05/14)
9
--           Initial version.
10
-- License : Copyright (C) 2010 by Nikolaos Kavvadias 
11
--           This program is free software. You can redistribute it and/or 
12
--           modify it under the terms of the GNU Lesser General Public License, 
13
--           either version 3 of the License, or (at your option) any later 
14
--           version. See COPYING.
15
--
16
--------------------------------------------------------------------------------
17
 
18
library STD;
19
use STD.textio.all;
20
use WORK.ratpack.all;
21
 
22
 
23
entity ratpack_tb is
24
end ratpack_tb;
25
 
26
 
27
architecture tb_arch of ratpack_tb is
28
  -------------------------------------------------------
29
  -- Declare results file
30
  -------------------------------------------------------
31
  file ResultsFile: text open write_mode is
32
  "ratpack_results.txt";
33
  -------------------------------------------------------
34
  -- Constant declarations
35
  -------------------------------------------------------
36
  constant CLK_PERIOD : time := 10 ns;
37
begin
38
 
39
  -- Compute the Farey sequences F1 to F12.
40
  -- The Farey sequence Fn for any positive integer n is the set of irreducible 
41
  -- rational numbers a/b with 0<=a<=b<=n  and (a,b)=1 arranged in increasing 
42
  -- order. 
43
  FAREY_SERIES: process
44
    variable a, b, c, d, k, n : integer;
45
    variable ta, tb, tc, td : integer;
46
    variable r : rational := RAT_ZERO;
47
    variable BufLine: line;
48
  begin
49
    for n in 1 to 12 loop
50
      write(Bufline, string'(" F"));
51
      write(Bufline, n);
52
      write(Bufline, string'("= "));
53
      -- Initialize a, b, c, d for computing the ascending Farey sequence
54
      a := 0;
55
      b := 1;
56
      c := 1;
57
      d := n;
58
      -- Print r = a/b
59
      r := to_rational(a, b);
60
      write(Bufline, r(numer));
61
      write(Bufline, string'("/"));
62
      write(Bufline, r(denom));
63
      write(Bufline, string'(" "));
64
      wait for CLK_PERIOD;
65
      -- Compute the subsequent terms of the Farey sequence
66
      while (c < n) loop
67
        k := (n + b) / d;
68
        ta := a;
69
        tb := b;
70
        tc := c;
71
        td := d;
72
        a := tc;
73
        b := td;
74
        c := k * tc - ta;
75
        d := k * td - tb;
76
        c := k * tc - ta;
77
        -- Print r = a/b
78
        r := to_rational(a, b);
79
        write(Bufline, r(numer));
80
        write(Bufline, string'("/"));
81
        write(Bufline, r(denom));
82
        write(Bufline, string'(" "));
83
        wait for CLK_PERIOD;
84
      end loop;
85
      writeline(ResultsFile, Bufline);
86
    end loop;
87
    wait for CLK_PERIOD;
88
  end process FAREY_SERIES;
89
 
90
end tb_arch;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.