1 Digital Logic Design Engr. Kashif Shahzad
2 What’s Course About? Digital logic, focusing on the design of computers Stay above transistor level Only one class on transistors and VLSI Only one class on transistors and VLSI Each person designs a MIPS CPU and peripheral logic (VGA, joystick) and peripheral logic (VGA, joystick) Project like an Atari 2600 game Project like an Atari 2600 game High-level language Modern design practices Modern design practices
3 How Can We Do This? Field Programmable Gate Arrays Chips with a lot of circuits Chips with a lot of circuits Tens of thousands to millions of transistors Programmable Programmable We write “programs” describing design Tools translate to gates/wires Download pattern to chip
4 Use This Board
5 Schematic Diagram
6Verilog/* * A 32-bit counter with only 4 bits of output. The idea is * A 32-bit counter with only 4 bits of output. The idea is * to select which of the counter stages you want to pass on. * to select which of the counter stages you want to pass on. * * Anselmo Lastra, November 2002 * Anselmo Lastra, November 2002 */ */ module cntr_32c(clk,res,out); module cntr_32c(clk,res,out); input clk; input clk; input res; input res; output [3:0] out; output [3:0] out; reg [31:0] count; reg [31:0] count; (posedge res or posedge clk) if(res) if(res) count <= 0; else count <= count + 1; count <= count + 1; assign out[3] = count[28]; assign out[3] = count[28]; assign out[2] = count[27]; assign out[2] = count[27]; assign out[1] = count[26]; assign out[1] = count[26]; assign out[0] = count[25]; assign out[0] = count[25];endmodule
7 Binary Signaling Zero volts FALSE or 0 FALSE or 0 3.3 or 5 volts TRUE or 1 TRUE or 1 Modern chips down to 1V Why not multilevel signaling?
8 Discrete Data Some data inherently discrete Names (sets of letters) Names (sets of letters) Some quantized Music recorded from microphone Music recorded from microphone Note that other examples like music from CD or electronic keyboard already quantized Note that other examples like music from CD or electronic keyboard already quantized Mouse movement is quantized Mouse movement is quantized Well, some mice
9BCD Binary Coded Decimal Decimal digits stored in binary Four bits/digit Four bits/digit Like hex, except stops at 9 Like hex, except stops at 9 Example Example 931 is coded as is coded as Remember: these are just encodings. Meanings are assigned by us.
10 Other Codes Exist Non positional Example: Gray Code Only one bit changes at a time Only one bit changes at a time 000,001,011,010,110,111,101, ,001,011,010,110,111,101,100 Why is this useful? Why is this useful? Actually there’s a family of Gray codes Actually there’s a family of Gray codes Ref:
11 Shaft Encoder
12 Character Codes From numbers to letters ASCII Stands for American Standard Code for Information Interchange Stands for American Standard Code for Information Interchange Only 7 bits defined Only 7 bits defined Unicode You may make up your own code for the MIPS VGA
13 ASCII table
14 Even Parity Sometimes high-order bit of ASCII coded to enable detection of errors Even parity – set bit to make number of 1’s even Examples A ( ) with even parity is C ( ) with even parity is
15 Odd Parity Similar except make the number of 1’s odd Examples A ( ) with odd parity is C ( ) with odd parity is
16 Error Detection Note that parity detects only simple errors One, three, etc. bits One, three, etc. bits More complex methods exist Some that enable recovery of original info Cost is more redundant bits Cost is more redundant bits
17 Today’s Topics Introduction Digital logic Number systems Arithmetic Codes Parity The encoding is key Standards are used to agree on encodings Standards are used to agree on encodings Special purpose codes for particular uses Special purpose codes for particular uses
18Homework None, but… I expect you to know number systems well and be able to do conversions and arithmetic Decimal – Binary Decimal – Binary Binary – Decimal Binary – Decimal Decimal – Hex Decimal – Hex Hex – Decimal Hex – Decimal Can do some of the problems – 1-2, 1-4, 1-7 if you think you need a refresher. Answers on book website.
19 Binary – Powers of 2 Positional representation Each digit represents a power of 2 So 101 binary is or = = 5
20 Converting Binary to Decimal Easy, just multiply digit by power of 2 Just like a decimal number is represented Example follows
21 Binary Decimal Example = 156 What is in decimal?
22 Decimal to Binary A little more work than binary to decimal Some examples 3 = = 11 (that’s ) 3 = = 11 (that’s ) 5 = = 101 (that’s ) 5 = = 101 (that’s )
23 Algorithm – Decimal to Binary Find largest power-of-two smaller than decimal number Make the appropriate binary digit a ‘1’ Subtract the power of 2 from decimal Do the same thing again
24 Decimal Binary Example Convert 28 decimal to binary is too large, so use 16 Binary 10000Decimal 28 – 16 = 12 Binary 11000Decimal 12 – 8 = 4 Next is 8 Binary 11100Decimal 4 – 4 = 0 Next is 4
25Hexadecimal Strings of 0s and 1s too hard to write Use base-16 or hexadecimal – 4 bits DecBinHex DecBinHex ? ? ? ? ? ?
26Hexadecimal Letters to represent DecBinHex DecBinHex a b c d e f Power of 2Power of 2 Size of byteSize of byte Why use base 16?
27 Hex to Binary Convention – write 0x before number Hex to Binary – just convert digits BinHex a 1011b 1100c 1101d 1110e 1111f 0x2ac x2ac = No magic – remember hex digit = 4 bits
28 Binary to Hex Just convert groups of 4 bits BinHex a 1011b 1100c 1101d 1110e 1111f b = 0x537b 0101 0111 0011
29 Hex to Decimal Just multiply each hex digit by decimal value, and add the results. x2ac = 684 DecHex a 11b 12c 13d 14e 15f
30 Decimal to Hex Analogous to decimal binary. 1. Find largest power-of-16 smaller than decimal number 2. Divide by power-of-16. The integer result is hex digit. 3. The remainder is new decimal number. 4. Do the same thing again
31 Decimal to Hex DecHex a 11b 12c 13d 14e 15f /256 = 2 0x2__ 684%256 = /16 = 10 = a 0x2a_ 172%16 = 12 = c 0x2ac
32Octal Octal is base 8 Similar to hexadecimal Conversions Conversions Less convenient for use with 8-bit bytes
33 Arithmetic -- addition Binary similar to decimal arithmetic No carries Carries 1+1 is 2 (or 10 2 ), which results in a carry
34 Arithmetic -- subtraction No borrows Borrows results in a borrow
35 Arithmetic -- multiplication Successive additions of multiplicand or zero, multiplied by 2 (10 2 ). Note that multiplication by 10 2 just shifts bits left. 1011X 101
36 Hexadecimal Arithmetic Similar If you’re doing by hand, easiest to convert each set of digits to decimal and back Skill is not very useful…