summaryrefslogtreecommitdiff
path: root/2004/n/fpga/src/pwm/pwm_generator.vhd
blob: 960a7345df6852185083079631a839b384f0f131 (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
-- pwm_generator.vhd 
-- Eurobot 2004 : APB Team
-- Auteur : Fid�le GAFAN et Pierre-Andr� Galmes
-- G�n�rateur de signal PWM � partir du nombre de cycles 
-- � l'�tat haut et du nombre de cycles de l'enveloppe .
--

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

-- 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.


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;