2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
6 --------------------------------------------------------------------------------
7 -- This entity is a generator of PWM signal.
9 -- PWM bit width is configurable by PWM_WIDTH generic parameter.
11 -- In practice, to generate PWM signal component must be fed by a counter vector
12 -- (pwm_cnt input) of appropriate width and also period! (One counter can be
13 -- used by several PWM generators and generated signals are then synchronized.)
15 -- The period of the input counter vector should be by 1 smaller than the count
16 -- of all possible PWM values, i.e. counter vector should never reaches the
17 -- maximum possible PWM value, and counting should start from 0. E.g. when full
18 -- range of PWM values is used, binary counter should be reset just one step
19 -- before it overflows. In such a case, when PWM value is maximal, output keeps
22 -- PWM value is buffered and any change is propageted to the output by the next
23 -- pwm period - 'pwm_cyc' must by feed.
24 --------------------------------------------------------------------------------
32 din : in std_logic_vector (PWM_WIDTH-1 downto 0);
35 pwm_cnt : in std_logic_vector (PWM_WIDTH-1 downto 0);
36 pwm_cyc : in std_logic; -- Indicate new pwm period
40 --------------------------------------------------------------------------------
42 architecture behavioral of pwm is
44 -- Register accessible from bus
45 signal reg : std_logic_vector (PWM_WIDTH-1 downto 0) := (others => '0');
46 -- Compare value during pwm cycle, loaded from 'reg' when new period begins.
47 signal cmp : std_logic_vector (PWM_WIDTH-1 downto 0) := (others => '0');
49 --------------------------------------------------------------------------------
53 -- Peripheral register
54 PWM_REGISTER : process (clk, reset)
57 reg <= (others => '0');
59 elsif rising_edge(clk) then
67 -- Generation of PWM signal
68 -- When 'pwm_cyc' is high then new 'cmp' is loaded and 'counter' is reset
69 -- with next clk edge. Pwm output is delayed by one clock.
70 PWM_GEN : process (clk, reset)
75 elsif rising_edge(clk) then