MiS603 Development Board the Fifth Chapter button to shake the experiment

Source: Internet
Author: User

MiS603 Development Team

Date: 20150911

Company: Nanjing mi Lian Electronic Technology Co., Ltd.

Forum: www.osrc.cn

Website: www.milinker.com

Shop: http://osrc.taobao.com

Eat blog: http://blog.chinaaet.com/whilebreak

Blog Park: http://www.cnblogs.com/milinker/

MiS603 Development Board the Fifth Chapter button to shake the experiment

The chattering of the keys means that the keys are accompanied by a series of jitter in the moment of closing or loosening, which will directly affect the stability of the design system and reduce the response sensitivity. Therefore, jitter must be handled, that is, to eliminate the effects of jitter. In the actual project, there are many anti-shake schemes, such as the RS flip-flop, capacitor charge and discharge shake, software shake. This chapter uses the FPGA interior to design the chattering, namely takes the software to shake.

The mechanical characteristics of the keys determine the jitter time of the keys, the general jitter time in 5ms~10ms. It also means that each time the key is closed or loosened, the jitter time is skipped and the state of the key is detected. As long as the simple delay can be achieved by the key to eliminate jitter.

5.1 Hardware Analysis

The Mis603 Backplane is equipped with 5 independent keys to connect to the FPGA, see Misfun schematic diagram. Because the individual keys independent, the chattering process is the same, so this section with a button on the board SW4 to simulate the actual environment. Press the key every time, the corresponding LED lights reversed once. That is, the detection of the key is closed and disconnected process, if there is, the first time the LED light is lit, the second time, the LED lights off.

5.2 Timing Design

Due to the intrinsic characteristics of the keys, the jitter-stabilize-jitter-stable process is passed through each closure and disconnection. Therefore, to detect whether the button has a pressed process, you have to do two shake-out process. By detecting the value of the key input, when the BTNC is detected as low, start the counter, do 10ms delay, and then detect again, if the BTNC is still low, then the BTNC is pressed, set the button to press the flag bit. Again detect BTNC, if the BTNC is high, do 10ms delay, the second detection, if it is still high, then the BTNC has been disconnected, set the BTNC off the flag bit, through two flag bits, you can judge, BTNC has completed a closure to the process of disconnection, then led light reversal once. Shake the basic flow as shown.

It is very convenient to use the state machine to implement the above process. Through the state machine switch, the key every time from closed to the process of disconnection, respectively, the Low_flag and High_flag, when the two at the same time as high, LED lights to achieve a flip. That is, the first button led highlighting, the second led off, the third led highlighting ...

5.3 Program Source code

' Timescale 1ns/1ps

//-----------------------------------------------------------------------------------------------------

/*

* File name: KEY_JITTER.V

* Program Description:

Author

* Date Modified:

* Version number:

* All rights reserved: Nanjing mi Lian Electronic Technology Co., Ltd.

*/

//-----------------------------------------------------------------------------------------------------

Module Key_jitter (

Input clk_i,

Input Rst_n_i,

Input key_i,

Output [3:0] Led_o,

Output [18:0] DIV_CNT_TB,

Output [2:0] Key_state_tb

);

Localparam delay_param=19 ' D499_999;//for project

Localparam delay_param=19 ' d1500; For simulation

Localparam delay_param=19 ' D10; No Filter Jitter

reg [3:0] led_o_r;

(*keep = "TRUE" *) reg [18:0] div_cnt;//10ms jitter Time counter

[Email protected] (Posedge clk_i or Negedge rst_n_i)

Begin

if (!rst_n_i)

Div_cnt<=19 ' D0;

else if (Div_cnt<delay_param)

Div_cnt<=div_cnt+1 ' B1;

Else

div_cnt<=0;

End

Wire delay_10ms= (Div_cnt==delay_param)? 1 ' b1:1 ' B0;

Key Detection State machine

Localparam detecter1=3 ' b000;

Localparam detecter2=3 ' b001;

Localparam detecter3=3 ' b010;

Localparam detecter4=3 ' b011;

Localparam Led_dis =3 ' b100;

Reg Low_flag;

Reg High_flag;

reg [2:0] key_state;

[Email protected] (Posedge clk_i or Negedge rst_n_i)

Begin

if (!rst_n_i)

Begin

key_state<=detecter1;

low_flag<=0;

high_flag<=0;

Led_o_r<=4 ' b1111;

End

else if (delay_10ms)//Every 10ms detection, each time the key closure and disconnection process, LED lights flip once

Begin

Case (Key_state)

DETECTER1:

Begin

if (Key_i!=1 ' B1)

key_state<=detecter2;

Else

key_state<=detecter1;

End

DETECTER2:

Begin

if (Key_i!=1 ' B1)

Begin

Low_flag<=1 ' B1;

key_state<=detecter3;

End

Else

Begin

key_state<=detecter1;

low_flag<=low_flag;

End

End

DETECTER3:

Begin

if (Key_i==1 ' B1)

key_state<=detecter4;

Else

key_state<=detecter3;

End

DETECTER4:

Begin

if (Key_i==1 ' B1)

Begin

High_flag<=1 ' B1;

key_state<=led_dis;

End

Else

Begin

high_flag<=high_flag;

key_state<=detecter3;

End

End

Led_dis:

Begin

if (High_flag & Low_flag)

Begin

key_state<=detecter1;

led_o_r<=~led_o_r;

High_flag<=1 ' B0;

Low_flag<=1 ' B0;

End

Else

Begin

led_o_r<=led_o_r;

key_state<=key_state;

high_flag<=high_flag;

low_flag<=low_flag;

End

End

Default

Begin

key_state<=detecter1;

led_o_r<=0;

high_flag<=0;

low_flag<=0;

End

Endcase

End

Else

Begin

key_state<=key_state;

led_o_r<=led_o_r;

high_flag<=high_flag;

low_flag<=low_flag;

End

End

Assign Led_o=led_o_r;

Assign div_cnt_tb=div_cnt;

Assign Key_state_tb=key_state;

Endmodule

5.4 Program Analysis

? The DIV_CNT counter is defined in the program to realize 10ms jitter delay operation.

? The program defines a key_state section state machine, which consists of 5 states. The first 4 is the button closure and disconnection detection and chattering state, after the completion of the first 4 states, through the LED light to show the closure and disconnection of the button;

? Two flag bits are defined in the program, Low_flag and High_flag, respectively. Low_flag indicates that the key press is detected, that is, the key is closed, High_flag indicates that the key is detected and the key is broken. In the presence of two flags for the same time as 1 o'clock, the key to complete a closed and disconnected;

? program, the state machine to do a loop, back and forth to detect the key state, and each time the state of the switch time is 10ms, the state of the switching time, is also the key anti-jitter detection process.

5.5 Pre-integrated wiring simulation timing

In order to express the program workflow clearly, DIV_CNT_TB,DIV_START_TB,KEY_STATE_TB these signals are added in the source code. The counter is intentionally set to a smaller value in order to reduce the time that the simulation waits. The simulation diagram is shown below.

5.6 Chipscope on-line Logic Analyzer simulation

For the chattering test, the logic Analyzer can not be very intuitive expression of the entire design process, so the section will be discarded, directly observe the button press, LED lights can be correctly extinguished and lit as test results.

5.7 Output results

Press the key SW4 every time the LED lights are off and lit. LED Light response error-free. For a clear expression of the effect of shaking, you can set the delay parameter is very small, you can find that when the key button has been pressed down, LED is not responding.

5.8 Summary

A button shake is an action that a touch switch must take. Otherwise, the keys will not work. In a working system, the keys are not shaken and may even crash the system directly. From the above examples can also be seen, whether it is the key to shake, or the marquee, the premise of the design is to master the Verilog grammar. In subsequent chapters, you will not be limited to a single file. Based on the gradual increase of the code volume, the module is divided into files to achieve the function of the whole system.

Serial communication interface, as one of the most common means of communication, is widely used in industry. The advantage is that the communication line is simple, only 2 wires are needed to receive and transmit the data, and the communication protocol is simple and reliable. This section will focus on the use of FPGA to achieve serial communication, through the serial debugging assistant and Mis603 backplane to achieve communication.

MiS603 Development Board the Fifth Chapter button to shake the experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.