-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservo_pwm.vhd
36 lines (34 loc) · 1.02 KB
/
servo_pwm.vhd
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity servo_pwm is
PORT (
clk : IN STD_LOGIC;
reset : IN STD_LOGIC;
pos : IN STD_LOGIC_VECTOR(6 downto 0);
servo : OUT STD_LOGIC
);
end servo_pwm;
architecture Behavioral of servo_pwm is
-- Counter, from 0 to 1279.
signal cnt : unsigned(10 downto 0);
-- Temporal signal used to generate the PWM pulse.
signal pwmi: unsigned(7 downto 0);
begin
-- Minimum value should be 0.5ms.
pwmi <= unsigned('0' & pos) + 32;
-- Counter process, from 0 to 1279.
counter: process (reset, clk) begin
if (reset = '1') then
cnt <= (others => '0');
elsif rising_edge(clk) then
if (cnt = 1279) then
cnt <= (others => '0');
else
cnt <= cnt + 1;
end if;
end if;
end process;
-- Output signal for the servomotor.
servo <= '1' when (cnt < pwmi) else '0';
end Behavioral;