Вы находитесь на странице: 1из 2

I have modified and tested this program.

Using this program we can


rotate dc motor in both directions.
- Yadunandan.P

Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;

entity dcmotor is
generic(bits : integer := 8 ); -- number of bits used for duty cycle.
-- Also determines pwm period.
port ( CLK: in STD_LOGIC; -- 4 MHz clock
RESET,DIR: in STD_LOGIC; -- dircntr
pwm : out std_logic_VECTOR(2 DOWNTO 0);

ROW: in STD_LOGIC_VECTOR(0 to 3) ); -- this are the row lines


end dcmotor;

architecture dcmotor1 of dcmotor is


signal counter : std_logic_vector(bits - 1 downto 0):="11111110";
signal DIV_REG: STD_LOGIC_VECTOR (16 downto 0); -- clock divide register
signal DCLK,DDCLK,datain,tick: STD_LOGIC; -- this has the divided clock.
signal duty_cycle: integer range 0 to 255;
signal ROW1 : STD_LOGIC_VECTOR(0 to 3); -- this are the row lines

begin
-- select the appropriate lines for setting frequency
CLK_DIV: process (CLK, DIV_REG) -- clock divider
begin
if (CLK'event and CLK='1') then
DIV_REG <= DIV_REG + 1;
end if;
end process;
DDCLK<=DIV_REG(12);
---------------------------- END OF CLOCK DIVIDER
-------------------------------------------------
tick <= row(0) and row(1) and row(2) and row(3);
process(tick)
begin
if falling_edge(tick) then
case row is

when "1110" => duty_cycle <= 255 ; --motor speed 1


when "1101" => duty_cycle <= 200 ; --motor speed 2
when "1011" => duty_cycle <= 150 ; --motor speed 3
when "0111" => duty_cycle <= 100 ; --motor speed 4
when others => duty_cycle <= 100;
end case;
end if;
end process;
process(DDCLK, reset)
begin
if reset = '0' then
counter <= (others => '0');
PWM<="001";
elsif (DDCLK'event and DDCLK = '1') then

counter <= counter + 1;


if counter >= duty_cycle then

pwm(1) <= '0';

pwm(2) <= '0';

else

pwm(1) <= '1' and DIR ;


pwm(2) <= '1' and not(DIR);

end if;
end if;
end process;

end dcmotor1;

#PACE: Start of Constraints generated by PACE

#PACE: Start of PACE I/O Pin Assignments


NET "CLK" LOC = "p52" ;
NET "DIR" LOC = "p76" ;
NET "pwm<0>" LOC = "p4" ;
NET "pwm<1>" LOC = "p141" ;
NET "pwm<2>" LOC = "p5" ;
NET "RESET" LOC = "p74" ;

NET "ROW<0>" LOC = "p69" ;


NET "ROW<1>" LOC = "p63" ;
NET "ROW<2>" LOC = "p59" ;
NET "ROW<3>" LOC = "p57" ;

Вам также может понравиться