summaryrefslogtreecommitdiff
path: root/2004/n/fpga/src/pwm/pwm_generator.vhd
blob: af73f005a819fd6aee433638451a5a5599a46be8 (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
74
-------------------------------------------------------------------------------
--pwm_generator.vhd 
--Eurobot 2004 : APB Team
--Auteur : Fid�le GAFAN
--Registre � d�calage affichantles signaux PWM
--

-- Les commentaires ci-dessous ne sont plus trop valables.
-- Maintenant, clock = 40MHz


--REMARQUE(S):changer tccompt,q et valuecompt
--            si CLK#32MHz et/ou qu'on modifie les valeurs de r�f�rence de T1
--            et T2 
-- Tcmax = 20ms / 1us 
--	 = 20161 cycles.

-- Si DATACOMPT = 0, on veut que T2 vale 0,5ms donc on initialise Q � la 
-- valeur Q=0,5ms/1us=505.

-- Si DATACOMPT=255,on veut que T2 vale 1,5ms donc on initialise Q � la 
-- valeur Q=1,5ms/1us=1515.

-- Pour toute autre valeur de DATACOMPT comprise entre les deux 
-- pr�c�dentes et diff�rentes de ces derni�res,on initialise Q avec
-- Q=(0,5ms/1us)+(DATACOMPT*min[((1,5ms-0,5ms)/1us)/(255-1)]

------------------------------------------------rtl de la sortie pwm en fonction de tc

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

use	work.nono_const.all;
use	work.pwm_const.all;

--ENTITE
entity pwm_generator is
	port ( 
	    rst : in std_logic;
	    clk : in std_logic;
	    pwm_in	: in T_DOUBLE_OCTET;
            pwm_out	: out std_logic
	     );
end entity;

--ARCHITECTURE
architecture RTL of pwm_generator is 
    signal compt : T_DOUBLE_OCTET;
    signal reg : T_DOUBLE_OCTET;
begin

    process(rst, clk)
    begin
	if (rst = '1') then
            compt <=  x"0000";
	    reg <= x"0000";
	    pwm_out <= '0';
        elsif (clk'event and clk = '1') then
	    compt <= compt + x"0001";
	    if (compt < reg) then
		pwm_out <= '1';
	    else
		pwm_out <= '0';
	    	if (compt = PWM_NB_CYCLE_20MS) then
		    compt <= x"0000";
		    reg <= pwm_in;
	        end if;
	    end if;
	end if;
    end process;
	       
end RTL;