Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP541 More on Verilog; Debouncing switches

Similar presentations


Presentation on theme: "COMP541 More on Verilog; Debouncing switches"— Presentation transcript:

1 COMP541 More on Verilog; Debouncing switches
Montek Singh Feb 15, 2012

2 First Topic More Verilog…

3 Hierarchy Always make your design modular easier to read and debug
easier to reuse before you write even one line of Verilog… …draw a picture black boxes boxes within boxes module and3(input a, b, c, output y); assign y = a & b & c; endmodule module inv(input a, output y); assign y = ~a; endmodule module nand3(input a, b, c output y); wire n1; // internal signal and3 andgate(a, b, c, n1); // instance of and3 inv inverter(n1, y); // instance of inverter endmodule

4 Internal Variables Internals = those that are not inputs/outputs
declare them as wire or reg depending on whether they are combinational or state holding module fulladder(input a, b, cin, output s, cout); wire p, g; // internal assign p = a ^ b; assign g = a & b; assign s = p ^ cin; assign cout = g | (p & cin); endmodule

5 Bitwise Operators (we have used)
module gates(input [3:0] a, b, output [3:0] y1, y2, y3, y4, y5); assign y1 = a & b; // AND assign y2 = a | b; // OR assign y3 = a ^ b; // XOR assign y4 = ~(a & b); // NAND assign y5 = ~(a | b); // NOR endmodule

6 Comments // single line comment /*…*/ multiline comment

7 Reduction Operators (&)
module and8(input [7:0] a, output y); assign y = &a; // &a is much easier to write than // assign y = a[7] & a[6] & a[5] & a[4] & // a[3] & a[2] & a[1] & a[0]; endmodule

8 Reduction Operators (|, ~|, ~&, ^, ~^, ^~)
Several others (see online reference) | = OR all the bits together ~| = NOR all the bits together ~& = NAND all the bits together ^ = XOR all the bits together ~^, ^~ = XNOR all the bits together

9 Operator Precedence ~ NOT *, /, % mult, div, mod +, - add,sub
Highest ~ NOT *, /, % mult, div, mod +, - add,sub <<, >> shift <<<, >>> arithmetic shift <, <=, >, >= comparison ==, != equal, not equal &, ~& AND, NAND ^, ~^ XOR, XNOR |, ~| OR, XOR ?: ternary operator Lowest

10 Numbers Format: N’Bvalue N = number of bits, B = base
N’B is optional but recommended (default is decimal) whenever in doubt, specify the # of bits Number # Bits Base Decimal Equivalent Value Stored 3’b101 3 binary 5 101 ’b11 unsized 00…0011 8’b11 8 8’b1010_1011 171 3’d6 decimal 6 110 6’o42 octal 34 100010 8’hAB hexadecimal 42 Unsized 00…

11 Bit Manipulations: splitting bits off
module mux2_8(input [7:0] d0, d1, input s, output [7:0] y); mux2 lsbmux(d0[3:0], d1[3:0], s, y[3:0]); mux2 msbmux(d0[7:4], d1[7:4], s, y[7:4]); endmodule Verilog: Synthesis:

12 Bit Manipulations: packing bits
assign y = {a[2:1], {3{b[0]}}, a[0], 6’b100_010}; // if y is a 12-bit signal, the above statement produces: y = a[2] a[1] b[0] b[0] b[0] a[0] // underscores (_) are used for formatting only to make it easier to read. Verilog ignores them.

13 What is switch bounce? Let’s solve it in class!
Debouncing switches What is switch bounce? Let’s solve it in class!

14 Switch bounce Switches bounce or “chatter”
each press/release can bounce hundreds of times! Let’s design a chatter-free switch for Friday’s lab!

15 Lab Preview: Buttons and Debouncing
Mechanical switches “bounce” vibrations cause them to go to 1 and 0 a number of times called “chatter” hundreds of times! We want to do 2 things: “Debounce”: Any ideas? Synchronize with clock i.e., only need to look at it at the next +ve edge of clock Ideas?


Download ppt "COMP541 More on Verilog; Debouncing switches"

Similar presentations


Ads by Google