adding counter to stepper moudle

Guest #4111860
Rate this post
• ▲ 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

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.