EmbDev.net

Forum: FPGA, VHDL & Verilog adding counter to stepper moudle


Author: saud (Guest)
Posted on:

Rate this post
0 useful
not useful
hello
please help mw to add a counter that will stop at 10 and here is the 
exaxt words from the proffesor
" The dispense state turn the dispense signal on to activate a stepper 
motor that issimulated on the red LEDR lights.Again, state machines are 
used for this part. Make sure to add a counter to count a number of 
steps (i.e. 10) before it stops. Otherwise, your vending machine will 
have a flaw dispensing soda to the whole population of UNT for 35 cents. 
A real stepper motor is connected to the board through the global IO pin 
(GPIO "

and here is the code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity stepper is
    Port ( dispense,reset,clk : in std_logic;
    Q : out std_logic_vector(3 downto 0));
end stepper;

architecture Behavioral of stepper is
type states is (three,six,twelve,nine);
signal current_state,next_state: states;
signal count: integer:=0;
begin

P1:process(reset,clk)
begin
  if reset='0' then
  current_state<=three;
  elsif rising_edge(clk) then
  current_state<=next_state;
end if;
end process;

p2:process(current_state, dispense)
begin
  if  dispense='1' then  --check for dispense active
  case current_state is

  when three =>
      Q<="0011";
      next_state<=six;
  when six =>
      Q<="0110";
      next_state<=twelve;
    when twelve =>
      Q<="1100";
      next_state<=nine;
  when nine =>
      Q<="1001";
      next_state<=three;
  when others =>
      Q<="0011";
      next_state<=three;
  end case;
  end if;
end process;
--GPIO(3 downto 0)<=Q;   --send output to the stepper motor hardware
end Behavioral;

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.