Created
March 30, 2017 07:37
-
-
Save digi0ps/700c57196c7b03f0b66ec3402dcb082d to your computer and use it in GitHub Desktop.
Stepper motor FPGA code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Library ieee; | |
Use ieee.std_logic_1164.all; | |
Use ieee.std_logic_unsigned.all; | |
Use ieee.std_logic_arith.all; | |
entity stm_st1 is | |
port (clk:in std_logic; rst:in std_logic; | |
out_stm:out std_logic_vector(3 downto 0)); | |
end stm_st1; | |
architecture stm_st_b of stm_st1 is | |
type state_type is (s0,s1,s2,s3); | |
signal state:state_type; | |
signal div:st_logic_vector(20 downto 0); | |
signal lk,clkwise,start:std_logic; | |
begin | |
process(clk,rst) | |
begin | |
if (rst='0') then | |
div<=(others=>'0'); | |
elsif(clk'event and clk='1') then | |
div<=div+1; | |
end if; | |
end process; | |
lk<=dic(15); | |
process(lk,rst,clkwise) | |
begin | |
if(rst='1')then | |
state<=s0; | |
elsif lk'event and lk='1' then | |
if clkwise='0' then | |
case state is | |
when s0=>state<=s1; | |
when s1=>state<=s2; | |
when s2=>state<=s3; | |
when s3=>state<=s0; | |
when others=>null; | |
end case | |
end if; | |
end if; | |
end process; | |
with state select | |
out_stm<="0110" when s0, | |
"1010" when s1, "1001" when s2, | |
"0101" when s3; | |
End stm_st_b; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment