It can be seen from the following figure that there is a difference between the ideal waveform and the actual waveform. The actual waveform has jitter at the moment of pressing and releasing. The length of the jitter time is related to the mechanical characteristics of the button, which is generally 5~10ms. Usually we manually press and release, the time to stabilize the closure in this action is more than 20ms. Therefore, the MCU should add debounce operation when detecting whether the keyboard is pressed. There is a dedicated debounce circuit and a special debounce chip. However, we usually use the software delay method to solve the jitter problem.
/* Software debounces */
If (0 == K1 ) //If there is a key press
{
Delay_ms(8); //delay for a while
If (0 == K1) //If there is a key press, it is detected as a stable closed state
{
. . . //What you need to do after pressing the button
}
While(!K1); // Release the detection, if you hold it down, it will always be in the loop.
}
Indeed, the debounce on the software does ensure effective detection of the keys. But is this debounce really necessary? Someone raised such a question. Jitter is generated during the press of the button. If the button is not pressed, will the jitter occur? If there is no button press, the jitter will also appear on the I/O. I will hammer the microcontroller immediately and never use such a microcontroller. So the appearance of jitter means that the button has been pressed, although this level has not stabilized. So as long as we detect the button press, we can return the key value. The key of the problem is that when you execute our other task tasks, the jitter process is not finished, so it may cause duplication. Detection. Therefore, how to avoid repeated detection after returning the key value, or execute the function function when the button is pressed, when the execution time of the function function is less than the jitter time, how to avoid re-executing the function function becomes a problem we have to consider. . This is a matter of benevolence and benevolence, and the wise man will see wisdom. Leave it to everyone to think about it. Therefore, the purpose of eliminating jitter is to prevent the button from being pressed once and responding multiple times.
90W Medical Power Supply,90W Medical Device Power Supply,90W Medical Power Adapter,90W Rade Power Supplies
Shenzhen Longxc Power Supply Co., Ltd , https://www.longxcpower.com