summaryrefslogtreecommitdiff
path: root/2004/n/fpga/src/portserie/clockgene/clockgene.vhd
blob: b98a6b324abcbaacb1fb37441d75ee641e4d39ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- clockgene.vhd
-- Eurobot 2004 : APB Team
-- Auteur : Pierre Prot
-- clock

-- fr�quence d'entr�e : 30MHz
-- fr�quence de sortie : 115kHz
-- diviseur = (freq d'entr�e)/(frequ sortie)

library ieee;
use	ieee.std_logic_1164.all;
use     ieee.std_logic_arith.all;
use     ieee.std_logic_unsigned.all;

use	work.nono_const.all;
-- pour la valeur de DIVIS_CK_SERIAL

-- param : 
--   00 -> 9600 bauds
--   01 -> 19200 bauds
--   10 -> 57600 bauds
--   11 -> 115200 bauds

-- horloge de ref
entity clockgene is
port(
	rst:	in std_logic;
	ckin:	in std_logic;
	ckout:	out std_logic;
	param:	in std_logic_vector(1 downto 0)
	);
end clockgene;


architecture rtl of clockgene is
signal compteur:std_logic_vector(10 downto 0):=(others=>'0');
signal div_param:integer; -- le diviseur param�trable
signal clr:std_logic;

begin

	clr<=rst;

	process(param,rst)
	begin
		case param is
		when "00"	=> div_param <= (DIVIS_CK_SERIAL*12);	-- 9600 * 12 =115200
		when "01"	=> div_param <= (DIVIS_CK_SERIAL*6);	-- 19200 * 6 =115200
		when "10"	=> div_param <= (DIVIS_CK_SERIAL*2);	-- 57600 * 2 =115200
		when "11"	=> div_param <= DIVIS_CK_SERIAL; 		-- 115200 * 1=115200
		when others => null;
		end case;
	end process;

-- baudmax : g�n�re la fr�quence n�c�ssaire � du 115200
 	baudmax:process(ckin,clr)
	begin
		if(clr='1') then
			ckout<='0';
			compteur<=(others=>'0');
		elsif(ckin'event and ckin='1') then
			if(compteur = div_param) then
				ckout<='1';
				compteur<=(others=>'0');
			else
				compteur <= compteur + 1;
				ckout<='0';
			end if;
		end if;
	end process;
end rtl;