EmbDev.net

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


von Calibroflower (Guest)


Attached files:

Rate this post
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.

von easylife (Guest)


Rate this post
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.

von Cle (Guest)


Rate this post
useful
not useful
Just switch on the rising edge?
Something like : 
http://insights.sigasi.com/tech/clock-edge-detection.html

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
1
    FSM: process(clk, my_btnC)
2
    begin
3
    if(my_btnC ='1') then
4
        my_state <= s0;
5
    elsif...
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 
presses.

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

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.