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

Subversion Repositories russels_paradox

[/] [russels_paradox/] [trunk/] [barber.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feketebv
----------------------------------------------------------------------------------
2
-- http://en.wikipedia.org/wiki/Barber_paradox =>
3
-- "The barber is a man in town who shaves all those, and only those,
4
-- men in town who do not shave themselves."
5
 
6
--The point is that the barber is represented by the logical value '1' in the two
7
--stage shift register. The '1' shows which set he currently belongs to. In a more
8
--sophisticated case we may assume there are several barbers in different cities,
9
--and the sets may include more elements at once.
10
 
11
--The reset state is arbitrarily choosen, and in a complex system might effect
12
--the long term behaviour: like if the model of the sets definition would somwhow
13
--happen to be an LFSR that does not run through all the combinations...
14
 
15
--If the barbers are not identical, FIFO-s can be used to hold their identifiers.
16
----------------------------------------------------------------------------------
17
 
18
library IEEE;
19
use IEEE.std_logic_1164.all;
20
use IEEE.numeric_std.all;
21
use IEEE.std_logic_unsigned.all;
22
 
23
entity barbers is
24 3 feketebv
    Port ( big_bang : in  STD_LOGIC;
25 4 feketebv
           a_barber_shaves_event : in  STD_LOGIC;
26 2 feketebv
           a_barber_doesnt_shave_event : in  STD_LOGIC; --like for a day...
27
           number_of_barbers_who_may_shave_themselves : out  STD_LOGIC;
28
           number_of_barbers_who_may_not_shave_themselves : out  STD_LOGIC);
29
end barbers;
30
 
31
architecture simulateable of barbers is
32
 
33
begin
34
 
35 3 feketebv
   process(big_bang, a_barber_shaves_event, a_barber_doesnt_shave_event)
36 2 feketebv
   begin
37
      if big_bang = '1' then
38
         number_of_barbers_who_may_shave_themselves <= x"0";
39
         number_of_barbers_who_may_not_shave_themselves <= x"f";
40
      else
41
         number_of_barbers_who_may_shave_themselves <= number_of_barbers_who_may_shave_themselves + a_barber_doesnt_shave_event - a_barber_shaves_event;
42
         number_of_barbers_who_may_not_shave_themselves <= number_of_barbers_who_may_not_shave_themselves - a_barber_doesnt_shave_event + a_barber_shaves_event;
43
      end if;
44
   end process;
45
 
46
end simulateable;
47
 
48
architecture synthesisable of barbers is
49
 
50
   signal counter1, counter2 : std_logic_vector(3 downto 0);
51
 
52
begin
53
 
54 3 feketebv
   process(big_bang, a_barber_shaves_event)
55 2 feketebv
   begin
56
      if big_bang = '1' then
57
         counter1 <= x"f";
58
      elsif rising_edge(a_barber_shaves_event) then
59
         counter1 <= counter1 + '1';
60
      end if;
61
   end process;
62
 
63 3 feketebv
   process(big_bang, a_barber_doesnt_shave_event)
64 2 feketebv
   begin
65
      if big_bang = '1' then
66
         counter2 <= x"0";
67
      elsif rising_edge(a_barber_doesnt_shave_event) then
68
         counter2 <= counter2 + '1';
69
      end if;
70
   end process;
71
 
72
number_of_barbers_who_may_shave_themselves <= counter2 - counter1;
73
number_of_barbers_who_may_not_shave_themselves <= counter1 - counter2;
74
 
75 5 feketebv
end synthesisable;

powered by: WebSVN 2.1.0

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