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