-- HBridge_PWM library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_unsigned.all; entity HBridge_MOTOR is port( h_clk20k : in STD_LOGIC; h_clr : in STD_LOGIC; h_duty : in STD_LOGIC_vector(15 downto 0); h_EN1 : out STD_LOGIC; h_DIR1 : out STD_LOGIC; h_EN2 : out STD_LOGIC; h_DIR2 : out STD_LOGIC; h_sw : in STD_LOGIC_vector(3 downto 0) ); end HBridge_MOTOR; architecture HBridge_MOTOR of HBridge_MOTOR is signal count: STD_LOGIC_VECTOR(15 downto 0); signal duty1: STD_LOGIC_VECTOR(15 downto 0); signal duty2: STD_LOGIC_VECTOR(15 downto 0); begin -- count 2K -- count 20K process(h_clk20k, h_clr) begin if h_clr = '1' then count <= (others => '0'); duty1 <= (others => '0'); duty2 <= (others => '0'); h_DIR1 <= '0'; h_DIR2 <= '0'; elsif h_clk20k'event and h_clk20k = '1' then duty1(14 downto 8) <= h_duty(14 downto 8); duty2(14 downto 8) <= h_duty(6 downto 0); h_DIR1 <= h_duty(15); h_DIR2 <= h_duty(7); if conv_integer(count) = 24999 then count <= (others => '0'); else count <= count +1; end if; end if; end process; pwm1out: process(count, duty1) begin if count < duty1 then h_EN1 <= '1'; else h_EN1 <= '0'; end if; end process pwm1out; pwm2out: process(count, duty2) begin if count < duty2 then h_EN2 <= '1'; else h_EN2 <= '0'; end if; end process pwm2out; end HBridge_MOTOR;