Keeping a count of user button pushes -- need help

  • Thread starter thisguy928
  • Start date
  • #1

Main Question or Discussion Point

Hi, I'm using an Altera DE2 Development Board. I'm creating a counter that counts the number of times a user pushes a button. I'm using 74163 counter since I need to count 0-9 and I think it's easier to control. I must have it running on an internal clock. However, my counter didn't seem to be working to perfectly. when the button is pressed, P and T are true and the counter starts counting but it counts from 0-9 changing on the edge of clock. How am I able to implement this? how can I keep the single ou out count after the button is pressed and held even if the clock is 'clockkng'?
 
Last edited by a moderator:

Answers and Replies

  • #2
755
78
You will need to implement an edge detector and debounce circuit before feeding the counter.

I'm assuming that you mean that you have implemented the logic of a 74163 inside of the FPGA but the same thing applies if you are using an external discrete 74163.

Edge detect & debounce are easy to implement in your FPGA.
 
  • #3
meBigGuy
Gold Member
2,323
405
You are having one of 2 problems, I think, but I'm not sure which.

Either you are feeding the button into the counter clock input, in which case you are counting the mechanical bounce of the button (like emi guy said). Or, you are feeding a clock to the counter (which what I think you are doing) and want the count-enable signal to only allow 1 count per button press. For that to happen, the count enable signal can only be 1 clock in duration.

Either way, you must first debounce the switch.

Then, you must make a 1-shot circuit that causes 1 pulse that is 1 clock in duration, for each button press, to feed to the counter's enable input. It can be tricky because you have to synchronize the asynchronous input of the button to the internal clock using a meta-stable proof double synchronizer (look it up). That can be a 3 flip-flop shift register clocked off the internal clock that is fed by a high true button press signal. You use AND gate off the Q of the 2nd flop and the QN of the third flop to feed your count-enable (if it is high true). (or you can use low true and change the output detector. Or, you can detect the trailing edge of the button press, or whatever you want.)

The signal into the shift register (or, synchronizer and pulse generator as you will) must first be debounced. You can look that part up. There are lots of ways, so research it and then ask questions.
 

Related Threads on Keeping a count of user button pushes -- need help

  • Last Post
Replies
4
Views
3K
Replies
1
Views
4K
Replies
4
Views
720
  • Last Post
Replies
2
Views
693
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
9
Views
2K
Replies
12
Views
5K
  • Last Post
Replies
4
Views
1K
Replies
4
Views
2K
  • Last Post
Replies
4
Views
2K
Top