본문 바로가기

Semiconductor/ASIC & FPGA

Debounce a Switch in a FPGA

  Fix button glitches on your development board

 If you are using a development board that has switches, you should be careful. Physical switches such as push buttons and toggle switches are all subject to bouncing. Bouncing occurs when the switch is toggled or flipped. It happens in all switches as a result of the metal contracts coming together and apart quickly before they have time to settle out.

 

Glitches on switch

 

 The image above shows the transition from logic low to logic high of a switch closing. One would expect a nice clean transition. However the spikes are where the switch contacts create glitches on the line. Imagine if this switch was used to start some task in your code. The task would be started and stopped many times very rapidly. This would be create unwanted behavior. This switch is in need of some debounce filtering.

 

 To do this in an FPGA, the simplest thing to do is to create a an always block that samples the switch input. Once the switch input has been stable for enough time, the input is stable and can be sent to the rest of your code.

 

 Your always block should be sampling the switch input all the time. Once it sees the switch input is different from its output, it should enable a counter. If the counter reaches the end, the output is reassigned to match the input. This happens because the switch was stable for long enough.

'Semiconductor > ASIC & FPGA' 카테고리의 다른 글

Delay / Skew / Slack / Slew  (0) 2020.12.04
Block RAM( BRAM)  (0) 2020.11.12
Crossing Clock Domain  (0) 2020.11.10
Timing  (0) 2020.11.09
Propagation Delay  (0) 2020.11.08