Author Topic: Using code to remove bounce  (Read 1004 times)

0 Members and 1 Guest are viewing this topic.

Offline mriPaulTopic starter

  • Contributor
  • Posts: 16
  • Country: us
Using code to remove bounce
« on: June 22, 2020, 12:34:50 am »
I am using VHDL to read encoder pulses on an FPGA. Currently, I detect the change in the two pins and wait a set time for the any bouncing to stop and repeat. It just occurred to me that instead of waiting for my PC817 to settle, I read the change and change the inputs to outputs driven to the what the change was for a short time to shunt away the bounce. Is that common practice..bad practice?
 

Offline cruff

  • Regular Contributor
  • *
  • Posts: 75
  • Country: us
Re: Using code to remove bounce
« Reply #1 on: June 22, 2020, 01:28:16 am »
Do I understand you to say you are thinking of switching the FPGA I/O pin reading the encoder pins to an output in an attempt to force the pin bounce to stop? That won't work, and may damage the pin driver in the FPGA.
 

Online wraper

  • Supporter
  • ****
  • Posts: 17517
  • Country: lv
Re: Using code to remove bounce
« Reply #2 on: June 22, 2020, 01:42:43 am »
You should not wait for bouncing to stop. It's a very flawed way how to do it, and regretfully implemented in many devices. Bouncing may never stop completely and you will get missed pulses. Much more robust way is add/substract counter with state transition when you get more of one state than another state with some hysteresis. Say you count from 0 to 20 with readings done with certain intervals of time. When counter gets to min or max, you detect a state change. Also you can consider that contact is closed basically instantly without waiting bouncing to stop at all (as there is no bounce at all when contact is open), and only debounce a transition to open state.
Quote
I read the change and change the inputs to outputs driven to the what the change was for a short time to shunt away the bounce.
That's some stupid nonsense. It won't fix the bounce and only abuses both FPGA and encoder.
« Last Edit: June 22, 2020, 01:54:16 am by wraper »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf