Forum: FPGA, VHDL & Verilog Generating a square wave from input push button

Author: Calibroflower (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
I am programming an FPGA that uses push buttons as input signals. I am 
programming a finite state machine with 11 states that transition from 
state to state using specific button presses. For example, in my design, 
state 0 goes to state 1 using button1. This is the same transition case 
from state 1 to 2 and from state 2 to 3. This state transition system is 
implemented in my vhdl code using case statements much like the "switch" 
statement in c++. I am lighting up certain LEDs in each state to keep 
track of which state the board is currently in. My issue is that when I 
press button1 while in sate 0, the board shows that it has moved to 
state 3. What i think is happening is that it is indeed going to state 1 
and 2 but the same button press in state 0 is also being read in state 1 
and 2. This happens so fast that the boards doesnt have enough time to 
show the LED indications for state 1 and 2. It stops at state 3 because 
state 3 moves to state 4 using a different button. So my question is, 
how do I make the button press signal have a rising edge and a falling 
edge such that a single button press is read only in one state and not 
the ones that follow it? The press button signals are debounced but this 
only makes the signal a uniform wave. Any help is appreciated, thanks.

I attached my vhdl code.
The "btnC, btnL, btnR,..." are the push buttons.

Author: easylife (Guest)
Posted on:

Rate this post
0 useful
not useful
You could insert additional states which are waiting for button release.
For instance, instead of transitioning directly from state 0 to 1, 
insert another state which is waiting for button release and then 
switches to state 1.

Author: Cle (Guest)
Posted on:

Rate this post
0 useful
not useful
Just switch on the rising edge?
Something like : 

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
    FSM: process(clk, my_btnC)
    if(my_btnC ='1') then
        my_state <= s0;
NEVER EVER use a async input directly as a reset source. You may 
encounter spurious problems when leaving the reset. This is because 
your FSM are some flipflops in reality. And the reset goes to their 
reset input. When the reset is deactivated at the same moment (+-a few 
ps) when a rising_edge on the lock occurs (and that is about 10..100 
million times per second) then some of the FSM flipflops see a 
deactivated reset and some not. And therefore the FSM starts with a 
undetermined wrong state...

Calibroflower wrote:
> Any help is appreciated, thanks.
Run a simulation. And see how your code reacts to "short" and "long" key 

Then you will find out that you edge detection (and before that 
debouncing) on each button input.

: Edited by Moderator


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.