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

Subversion Repositories russels_paradox

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

Go to most recent revision | 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
    Port ( a_barber_shaves_event : in  STD_LOGIC;
25
           a_barber_doesnt_shave_event : in  STD_LOGIC; --like for a day...
26
           number_of_barbers_who_may_shave_themselves : out  STD_LOGIC;
27
           number_of_barbers_who_may_not_shave_themselves : out  STD_LOGIC);
28
end barbers;
29
 
30
architecture simulateable of barbers is
31
 
32
begin
33
 
34
   process(a_barber_shaves_event, a_barber_doesnt_shave_event)
35
   begin
36
      if big_bang = '1' then
37
         number_of_barbers_who_may_shave_themselves <= x"0";
38
         number_of_barbers_who_may_not_shave_themselves <= x"f";
39
      else
40
         number_of_barbers_who_may_shave_themselves <= number_of_barbers_who_may_shave_themselves + a_barber_doesnt_shave_event - a_barber_shaves_event;
41
         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;
42
      end if;
43
   end process;
44
 
45
end simulateable;
46
 
47
architecture synthesisable of barbers is
48
 
49
   signal counter1, counter2 : std_logic_vector(3 downto 0);
50
 
51
begin
52
 
53
   process(a_barber_shaves_event)
54
   begin
55
      if big_bang = '1' then
56
         counter1 <= x"f";
57
      elsif rising_edge(a_barber_shaves_event) then
58
         counter1 <= counter1 + '1';
59
      end if;
60
   end process;
61
 
62
   process(a_barber_doesnt_shave_event)
63
   begin
64
      if big_bang = '1' then
65
         counter2 <= x"0";
66
      elsif rising_edge(a_barber_doesnt_shave_event) then
67
         counter2 <= counter2 + '1';
68
      end if;
69
   end process;
70
 
71
number_of_barbers_who_may_shave_themselves <= counter2 - counter1;
72
number_of_barbers_who_may_not_shave_themselves <= counter1 - counter2;
73
 
74
end some_barbers;

powered by: WebSVN 2.1.0

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