Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

One shot pulse

Hi all,

I am beginner in VHDL. I am doing tutorial for one shot pulse. But, I am little bit confuse. What does 'idle' meaning in this code? and how do I can modify this VHDL code to generate pulse signal? I try to change the VHDL code by modifying the pulse <= '1'; to 0,1,0 in order to make it pulse signal. When I programmed into FPGA board, the light always on. Why does it happens?

----------------------------------------------------------------------------------------

library ieee;

use ieee.std_logic_1164.all;

use ieee.numeric_std.all;

entity pulse_5clk is

port (clk,reset: in std_logic;--reset=SW17

go,stop: in std_logic;--go = SW0, stop =SW1

pulse: out std_logic);--pulse=LEDR0

end pulse_5clk;

architecture fsm_arch of pulse_5clk is

type fsm_state_type is

(idle,delay1,delay2,delay3,delay4,delay5);

signal state_reg, state_next: fsm_state_type;

begin

--state register

process (clk,reset)

begin

if (reset='1') then

state_reg <=idle;

elsif (clk'event and clk='1') then

state_reg <=state_next;

end if;

end process;

--next-state logic & output logic

process (state_reg,go,stop)

begin

pulse <='0';

case state_reg is

when idle =>

if go = '1' then

state_next <=delay1;

else

state_next <=idle;

end if;

when delay1 =>

if stop = '1' then

state_next <=idle;

else

state_next <=delay2;

end if;

pulse <= '1';

when delay2 =>

if stop = '1' then

state_next <=idle;

else

state_next <=delay3;

end if;

pulse <= '1';

when delay3 =>

if stop = '1' then

state_next <=idle;

else

state_next <=delay4;

end if;

pulse <= '1';

when delay4 =>

if stop = '1' then

state_next <=idle;

else

state_next <=delay5;

end if;

pulse <= '1';

when delay5 =>

state_next <=idle;

pulse <= '1';

end case;

end process;

end fsm_arch;

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    In this code, the pulse signal will stay '0' until the go signal is set to '1'. Pulse will then remain high for 5 clock cycles unless stop is set to '1' during this time.

    THe idle state just means exaclt that - nothing - its waiting for the go signal.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    What does 'idle' meaning in this code? and how do I can modify this VHDL code to generate pulse signal? I try to change the VHDL code by modifying the pulse <= '1'; to 0,1,0 in order to make it pulse signal. When I programmed into FPGA board, the light always on. Why does it happens?

    --- Quote End ---

    idle is the state name same as other state name mentioned in the design like delay1,delay2 etc.You can observe that pulse signal is not assigned any value when state machine is in idle state.In this case it will hold its previous value which is "1" .So if you assign pulse <= '0' in idle state,led shouldn't glow. You should verify this using Modelsim before trying to test on hardware. One more thing if the clock frequency is very high, then you won't be able to observe the led "on" and "off" state. You need to slow down the clock using counter if clock frequency is very high.

    Regards,

    Krupesh
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    .You can observe that pulse signal is not assigned any value when state machine is in idle state.In this case it will hold its previous value which is "1"

    --- Quote End ---

    Yes it is, in idle, pulse is assigned to '0'. Pulse as a default '0' assignment above the case statement in the code.