Professional Documents
Culture Documents
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity stepper is
port(clk:instd_logic;
reset:instd_logic;
dir:instd_logic;
s0:inoutstd_logic_vector(3 downto 0));
end stepper;
architecturestepper_arch of stepper is
signal s1:std_logic_vector(25 downto 0);
signal s2:std_logic;
begin
process(reset,clk)
begin
if(reset='1')then
s1<=(others=>'0');
elsif(clk'event and clk='1')then
s1<=s1+1;
end if;
end process;
s2<=s1(16);
process(reset,s2)
begin
if(reset='1')then
s0<="0001";
elsif(s2'event and s2='1')then
if(dir='1')then
s0(2 downto 0)<=s0(3 downto 1);
s0(3)<=s0(0);
elsif(dir='0')then
s0(3 downto 1)<=s0(2 downto 0);
s0(0)<=s0(3);
end if;
end if;
end process;
endstepper_arch;
DC Motor
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
begin
process(psw,sclkdiv)
variablevdcm : bit;
begin
if(sclkdiv = "0000000000000") then
vdcm := '1';
end if;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entityposramp_wave is
port(reset:instd_logic;
clk:instd_logic;
d0:inoutstd_logic_vector(11 downto 0));
endposramp_wave;
architecture behavioral of posramp_wave is
signalclk_div:std_logic_vector(5 downto 0);
signalclkdiv:std_logic;
begin
process(reset,clk)
begin
if(reset='1') then
clk_div<=(others=>'0');
elsif(clk'event and clk='1')then
clk_div<=clk_div+1;
end if;
end process;
clkdiv<=clk_div(1);
process(reset,clkdiv)
begin
clkdiv<=clk_div(1);
if(reset='1')then
d0<=(others=>'0');
elsif(clkdiv'event and clkdiv='1')then
d0<=d0+1;
end if;
end process;
end behavioral;
Rampwave (Negetive)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entitynegramp_wave is
port(reset:instd_logic;
clk:instd_logic;
d0:inoutstd_logic_vector(11 downto 0));
endnegramp_wave;
architecture behavioral of negramp_wave is
signalclk_div:std_logic_vector(5 downto 0);
signalclkdiv:std_logic;
begin
process(reset,clk)
begin
if(reset='1') then
clk_div<=(others=>'0');
elsif(clk'event and clk='1')then
clk_div<=clk_div+1;
end if;
end process;
clkdiv<=clk_div(1);
process(reset,clkdiv)
begin
clkdiv<=clk_div(1);
if(reset='1')then
d0<=(others=>'0');
elsif(clkdiv'event and clkdiv='1')then
d0<=d0-1;
end if;
end process;
end behavioral;
LCD DISPLAY
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY LCD_CODE IS
PORT
(
Header6 : OUT std_logic_vector(2 DOWNTO 0);
Header5 : OUT std_logic_vector(7 DOWNTO 0);
clk100k : IN std_logic
);
END LCD_CODE;--End of Entity
--Signal declaration
BEGIN
clk_div: PROCESS (clk100k)
BEGIN
IF( RISING_EDGE(clk100k)) THEN
clkdiv<= clkdiv + 1;
END IF;
clkkey<= clkdiv(14);
BEGIN
CASE lcd_disp IS
WHEN "000000" =>lcd_ctr_data<= "10000110100";--434 Font 5*10
WHEN "000001" =>lcd_ctr_data<= "00000110100";--"00000111000";
WHEN "000010" =>lcd_ctr_data<= "10000001110";--40e Display on and cursor blink off
WHEN "000011" =>lcd_ctr_data<= "00000001110";
WHEN "000110" =>lcd_ctr_data<= "10000000001";--401 Clear display
WHEN "000111" =>lcd_ctr_data<= "00000000001";
WHEN "001010" =>lcd_ctr_data<= "10101011001";--559 y
WHEN "001011" =>lcd_ctr_data<= "00101000001";
WHEN "001100" =>lcd_ctr_data<= "10101000101";--545 E
WHEN "001101" =>lcd_ctr_data<= "00101000100";
WHEN "001110" =>lcd_ctr_data<= "10101001110";--54e N
WHEN "001111" =>lcd_ctr_data<= "00101010011";
WHEN "010000" =>lcd_ctr_data<= "10101000101";--545 E
WHEN "010001" =>lcd_ctr_data<= "00110000000";
WHEN "010010" =>lcd_ctr_data<= "10101010000";--550 p
WHEN "010011" =>lcd_ctr_data<= "00101000010";
WHEN "010100" =>lcd_ctr_data<= "10101001111";--54f O
WHEN "010101" =>lcd_ctr_data<= "00101000001";
WHEN "010110" =>lcd_ctr_data<= "10101011001";--559 y
WHEN "010111" =>lcd_ctr_data<= "00101001110";
WHEN "011000" =>lcd_ctr_data<= "10101000001";--541 A
WHEN "011001" =>lcd_ctr_data<= "00101000111";
WHEN OTHERS =>lcd_ctr_data<= "11111111111";--7ff
END CASE ;
lcd_data <= lcd_ctr_data(7 DOWNTO 0);
lcd_control<= lcd_ctr_data(10 DOWNTO 8);
END PROCESS lcddisp;
END Behavioral;--End of arch
Dcmotor (new)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entitydcmotor is
Port ( clk : in STD_LOGIC;
reset, dir : in STD_LOGIC;
pwm : out STD_LOGIC_VECTOR (1 downto 0);
rly : out STD_LOGIC);
enddcmotor;
architecture Behavioral of dcmotor is
signalcounter:STD_LOGIC_VECTOR (7 downto 0):="11111110";
signaldiv_reg:STD_LOGIC_VECTOR (16 downto 0);
signaldclk,ddclk,datain,tick:STD_LOGIC;
signaldcycle:integer range 0 to 255 ; begin
process(clk,div_reg) begin
if(clk'event and clk='1')then div_reg<= div_reg+1;
end if;
end process;
process(ddclk,reset) begin
if reset='0'then counter<="00000000"; pwm<="01";
elsif(ddclk'event and ddclk='1')then counter<=counter+1;
if(counter >=dcycle)then pwm(1)<='0';
elsepwm(1)<='1';
end if;
end if;
end process;
rly<=dir;
end Behavioral;