SECTION 8: DIGITAL FUNDAMENTALS MAE 2055 – Mechetronics I 2 Analog vs. Digital In this section of notes, we’ll be discussing digital electronic circuits. First, we’ll introduce the concepts of analog and digital signals, and discuss how analog signals can be converted to digital signals. K. Webb MAE 2055 – Mechetronics I Analog vs. Digital 3 Analog signals are continuous in time and amplitude All physical phenomena – pressure, temperature, velocity, strain, position, etc. – are analog in nature They can take on any value at any time Digital signals are discrete in time and amplitude They can only assume a finite number of discrete values at discrete instants in time Digital signals are representations of analog signals that are easily stored and processed electronically K. Webb MAE 2055 – Mechetronics I Analog vs. Digital – an example 4 Temperature is an analog quantity – at any instant in time it can assume any value www.faqs.com A mercury thermometer is an analog measure of temperature – the mercury can be at any height at any time K. Webb www.mdhb.com A digital thermometer samples the actual temperature at discrete instants in time and represents it with a finite number of possible values MAE 2055 – Mechetronics I Digital Measurement System 5 Analog Analog Input Signal Signal Conditioning/ Amplification Digital Analog to Digital Converter (ADC) Digital Data/Display Processing Digital Data Output/ Display The analog input signal is converted to a digital signal in an analog-to-digital converter (ADC or A/D) K. Webb MAE 2055 – Mechetronics I Analog-to-Digital Conversion 6 Continuous-time and -amplitude analog signals are converted to digital signals in A/D converters Analog signal is sampled in time, generating a series of discrete-time samples Discrete-time samples are quantized – amplitudes are mapped to a finite number of discrete amplitude values A continuous range of input values maps to a single quantization level Resulting digital signal is discrete in both time and amplitude Digital signal is easily processed, stored, and displayed K. Webb MAE 2055 – Mechetronics I A/D Conversion – sampling 7 The first step in converting from an analog signal to a digital signal is sampling Sampled signal is a discrete-time signal, but is still continuous in amplitude K. Webb MAE 2055 – Mechetronics I A/D Conversion – quantization 8 Next step is quantization Sampled signal becomes a digital signal The digital signal is discrete in both time and amplitude Amplitude values of the digital signal are expressed as codes # of A/D codes = 2N K. Webb N = # of bits 10 bit A/D has 1024 distinct quantization levels Digital signal stored as binary values MAE 2055 – Mechetronics I Sample Rate 9 Sample Rate The rate at which the measurement instrument samples and digitizes the analog input signal Measured in Hz or in samples per second (Sa/sec) Inverse of the sampling period fs = 1/Ts Places an upper limit on the frequency (bandwidth) of the input signal Can only accurately measure input signals whose frequency is no more than half the sample rate Otherwise K. Webb aliasing will occur f in fs 2 MAE 2055 – Mechetronics I Sample Rate – aliasing 10 Aliasing is a phenomena that results in a higher frequency signal appearing as a lower frequency signal Aliasing occurs due to failure to adhere to the Nyquist Criterion Nyquist says that the sampling frequency must be at least twice the maximum signal frequency f s 2 f in The Nyquist rate or Nyquist frequency is the minimum sampling rate for which no aliasing will occur f nyquist 2 f in K. Webb MAE 2055 – Mechetronics I Aliasing – f = 10 Hz, fs = 8 Hz 11 10 Hz signal sampled at 8 Hz Nyquist criterion violated Aliased signal appears at 2 Hz K. Webb MAE 2055 – Mechetronics I Aliasing – f = 10 Hz, fs = 9 Hz 12 10 Hz signal sampled at 9 Hz Nyquist criterion violated Aliased signal appears at 1 Hz K. Webb MAE 2055 – Mechetronics I Aliasing – f = 10 Hz, fs = 10 Hz 13 10 Hz signal sampled at 10 Hz Nyquist criterion violated Aliased signal appears at DC (0 Hz) K. Webb MAE 2055 – Mechetronics I Aliasing – f = 10 Hz, fs = 20 Hz 14 10 Hz signal sampled at 20 Hz Nyquist criterion satisfied Measured signal could appear, in theory, at DC – in practice, this would rarely happen K. Webb MAE 2055 – Mechetronics I Aliasing – f = 10 Hz, fs = 50 Hz 15 10 Hz signal sampled at 50 Hz Nyquist criterion satisfied Frequency of sampled signal is the same as the analog signal K. Webb MAE 2055 – Mechetronics I Digital Advantages 16 Noise immunity Analog signals are susceptible to corruption by noise and interference – information is conveyed the precise instantaneous voltage level of the signal Digital representations of analog signals encode information as series of bits Bits are either 1 or 0, high or low, Add a little noise to a 1 or a 0, and it will still be interpreted as a 1 or a 0 Signal processing Filtering, modulation, etc. can all be done much more accurately, efficiently, and inexpensively with digital circuits Miniscule transistors on an IC replace large, inaccurate, expensive capacitors and inductors K. Webb MAE 2055 – Mechetronics I 17 Number Systems When analog signals are converted to digital signals, the values of the samples must be converted to a numeric form appropriate for storage and processing by digital electronic circuits. This form is that of binary numbers. K. Webb MAE 2055 – Mechetronics I Number Systems 18 After an analog signal has been sampled, the values of those samples must be stored in memory to be processed, displayed, played, etc. We may think of these samples as taking on integer values in the range of, for example, 0 – 1023 or 0 – 256 or 0 – 65535, etc. But, how are these values represented for storage and processing? The answer is: in binary form Representing the samples of an analog signal is only one example of the use of binary numbers K. Webb They are used any time numbers are processed by a digital electronic circuit MAE 2055 – Mechetronics I Binary 19 In digital electronics, all values are binary in nature Binary, as its name implies, means that values can assume one of only two possible values: 0 or 1 In electronic circuits, binary values are typically represented by voltages: either high or low (e.g., 0 = 0V, 1 = 5V) In digital circuits all signals are either 1 or 0, either high voltage or low voltage, either true or false So, how do we represent numbers such as the values of a sampled signal? – as binary numbers K. Webb MAE 2055 – Mechetronics I Binary Number System 20 The binary number system is a base-two number system Binary numbers are strings of 1’s and 0’s Each digit, called a bit, represents an integer power of 2, increasing to the left Binary Number 11001011 1x27 + 1x26 + 0x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20 = 128 + 64 + 0 + 0 + 8 + 0 + 2 + 1 = 203 K. Webb MAE 2055 – Mechetronics I Decimal Number System 21 Binary (base 2) number system is not so different from the decimal (base 10) number system we’re used to Each digit in a decimal number represents the coefficient of an integer power of 10, increasing to the left Can define number systems with any arbitrary base we want (e.g., 2, 10, 3, 6, 16, etc.) Decimal Number 249176 2x105 + 4x104 + 9x103 + 1x102 + 7x101 + 6x100 = 200000 + 40000 + 9000 + 100 + 70 + 6 = 249176 K. Webb MAE 2055 – Mechetronics I Bits, Bytes, & Nibbles 22 Each binary digit is called a bit Each bit has a value of 1 or 0, so it can be represented with a signal in a digital circuit – either a high (0) or a low (1) voltage A collection of 8 bits is called a byte A byte can represent a decimal value from 0 to 255 Eight separate voltage signals in a digital circuit are required to represent a byte 4 bits is half of a byte, so it is called a nibble A K. Webb nibble can assume 16 values between 0 and 15 MAE 2055 – Mechetronics I Hexadecimal Number System 23 Binary numbers require many bits to represent a number in many applications (e.g., computers are now moving toward 64-bit processors) Long, cumbersome, and difficult to read in binary form Number of bits is typically a multiple of 8 – an integer number of bytes The hexadecimal number system (hex) is base 16 Each digit can assume 16 values from 0 – F 0123456789ABCDEF A hex digit is used to represent the four bits of a nibble K. Webb MAE 2055 – Mechetronics I Hexadecimal Number System 24 Hex numbers often denoted with a “0x” prefix or a “h” suffix The decimal number 500 is represented as 1F4 in hex, and may be denoted as: 0x1F4, or 0x01F4, or 1F4h, or 01F4h, etc. Binary Number Nibble 3 Nibble 2 Nibble 1 Nibble 0 1100 1011 1111 0100 Nibble 3: 1x23 + 1x22 + 0x21 + 0x20 = 12 = C Nibble 2: 1x23 + 0x22 + 1x21 + 1x20 = 11 = B Nibble 1: 1x23 + 1x22 + 1x21 + 1x20 = 15 = F Nibble 0: 0x23 + 1x22 + 0x21 + 0x20 = 12 = 4 K. Webb Hexadecimal Number 0xCBF4 MAE 2055 – Mechetronics I Binary-Coded Decimal – BCD 25 Each digit of a decimal number is represented by four binary bits Decimal Digit BCD 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 K. Webb Examples: Decimal BCD 37 0011 0111 249 0010 0100 1001 618 0110 0001 1000 The codes 1010, 1011, 1100, 1101, 1110 and 1111 are unused in the BCD system A “BCD” suffix is often used to denote a BCD number, e.g., 0111 0100BCD MAE 2055 – Mechetronics I 26 Digital Logic Generating, storing, and processing numbers is only one function of digital circuits. They are also used to perform logic operations. K. Webb MAE 2055 – Mechetronics I Digital Logic 27 We’ve seen that digital circuits and systems can be used to acquire, store, and process data in the form of numbers These numbers may represent the sampled values of an analog signal, or they may just be numbers, e.g., numbers used in computations Digital circuits are also used to perform logical operations on logic variables Logic variable represented by a single bit Each bit is represented by the high or low voltage of a single electrical signal K. Webb MAE 2055 – Mechetronics I Digital logic 28 Say you want to design a circuit to control the heat in your home. You want the circuit to turn the heat on under the following conditions: During the day if the temperature falls below the daytime set point During the night if the temperature falls below the nighttime set point Three logic variable inputs to the circuit: A block diagram of your system: Day DayLow NightLow Digital Logic Circuit •Day Heat = 1 if it’s the daytime = 0 it it’s night •DayLow = 1 if T < the day set point = 0 if T > the day set point •NightLow = 1 if T < the night set point = 0 if T > the night set point And one logic variable Output: •Heat K. Webb = 1 to turn the heat on = 0 if the heat should be off MAE 2055 – Mechetronics I Digital logic – truth table 29 The inputs are single-bit logic variables (electrical signals with high or low voltage levels) which, in this case, come from temperature sensors and a clock The output is a single logic bit that tell the heating system when to turn on We can construct a table showing all possible combinations of input states, along with the state of the output corresponding to each input combination This is referred to as a truth table Variable names have been abbreviated for simplicity K. Webb Truth Table Heat is turned on D DL NL H 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 MAE 2055 – Mechetronics I Digital logic – truth table 30 The truth table describes the behavior of the digital circuit for all possible combinations of input variables It specifies when the circuit should turn the heat on based on the state of the inputs We need a way to implement the logic described by the truth table with an electronic circuit This is done by building a circuit consisting of components called logic gates K. Webb Truth Table Heat is turned on D DL NL H 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 MAE 2055 – Mechetronics I 31 Logic Gates We’ve just seen how a truth table can be used to define the behavior of a digital circuit. Now we’ll look at the building blocks used to realize the circuit: logic gates. K. Webb MAE 2055 – Mechetronics I Logic Gates 32 Say you want to design a circuit to control the heat in your home. Logic Gate Schematic Symbol Truth Table You want the circuit to turn the heat on under the following conditions: A A B B C =C A∙B AND During the day if the temperature falls below the daytime 0 0 0 0 set 00 point Output C is high if both During the night if the temperature falls below the 0nighttime 0 1 1 00set point input A and input B are high (written A∙B) OR Output C is high if either input A or input B are high (written A+B) INV Output B is high if input A is low, and low if input A is high (written Ā) K. Webb 11 00 11 11 AA 00 00 11 11 00 11 B B C =CA+B 0 0 00 1 1 01 0 0 01 1 1 11 A A B =B Ā 0 0 11 1 1 00 MAE 2055 – Mechetronics I Logic Gates 33 Say you want to design a circuit to control the heat in your home. Logic Gate Schematic Symbol Truth Table You want the circuit to turn the heat on under the following conditions: A B C =A∙B NAND During the day if the temperature falls below the daytime set point 0 1set point During if the temperature falls below the0nighttime Output C isthe lownight if both 0 1 1 input A and input B 1 0 1 are high (written A∙B) NOR Output C is low if either input A or input B are high (written A+B) K. Webb 1 1 0 A 0 0 1 1 B 0 1 0 1 C = A+B 1 0 0 0 MAE 2055 – Mechetronics I Logic Gates 34 Say you want to design a circuit to control the heat in your home. Logic Gate Schematic Symbol Truth Table You want the circuit to turn the heat on under the following conditions: A B C=AB XOR (Exclusive Gate) During theOR day if the temperature falls below the daytime set point 0 0 point During if the temperature falls below the0nighttime set Output C isthe highnight if only 0 1 1 one input is high, not 1 0 1 both (written A B ) XNOR Output C is high if both or neither input is high (written A B ) K. Webb 1 1 0 A 0 0 1 1 B 0 1 0 1 C = AB 1 0 0 1 MAE 2055 – Mechetronics I Boolean Algebra 35 We use Boolean algebra to represent and manipulate logic expressions Boolean addition is equivalent to a logical OR operation: C = A + B Boolean multiplication is equivalent to a logical AND operation: C = A∙B C is 1 only if all terms in the product are 1 An inversion is written with an overbar: B = Ā C is 1 (or high or true) if any term in the sum is 1 C is 1 if A is 0, and vice versa Boolean expressions can include multiple variables and multiple operations, for example: K. Webb F = (A∙B∙C)+(Ā∙D∙Ē)+(B∙C∙D) MAE 2055 – Mechetronics I Boolean Algebra - rules 36 Familiar rules from algebra apply Commutative Law: A+B = B+A A∙B = B∙A Associative Law: A+(B+C) = (A+B)+C A∙(B∙C) = (A∙B)∙C Distributive Law: A∙(B+C) = A∙B + A∙C K. Webb MAE 2055 – Mechetronics I Boolean Algebra –rules & identities 37 K. Webb A+0=A A+1=1 A∙0=0 A∙1=A A+A=A A+Ā=1 A∙A=A A∙Ā=0 A + A∙B = A A + Ā∙B = A + B (A + B)∙(A + C) = A + BC MAE 2055 – Mechetronics I DeMorgan’s Laws 38 A logic expression can be transformed to an equivalent logic expression if: 1. 2. 3. 4. All variables in the expression are replaced with their inverses All AND operations are replaced with OR operations All OR operations are replaced with AND operations The entire expression is inverted A B C A B C K. Webb A B C A B C MAE 2055 – Mechetronics I NAND & NOR Gates 39 The basic logic functions – AND, OR, and NOT (inverter) – can all be implemented with only NAND gates or only NOR gates NAND NOR NOT AND OR K. Webb MAE 2055 – Mechetronics I 40 Logic Circuit Synthesis We will now discuss how to use a truth table, describing the desired circuit behavior, to a physical circuit that realizes that behavior. K. Webb MAE 2055 – Mechetronics I Boolean Algebra – logic circuit synthesis 41 Based on how we want a circuit to behave we can generate a truth table e.g., we want the circuit to turn the heat on (output is high) under certain conditions From the truth table we can generate a Boolean logic expression Different forms of logic expressions describing the circuit behavior defined by the truth table are possible – two such forms are: Sum-of-products form (SOP) Product-of-sums form (POS) K. Webb MAE 2055 – Mechetronics I Sum-of-Products 42 Let’s generate a SOP Boolean logic expression to describe the behavior of the circuit, as defined by the truth table Look at each row of the table for which H = 1 Truth Table D DL NL H 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 K. Webb Using all input variables, write a logic product that equals 1 for each of these rows Row 2: D∙DL∙NL These products Row 4: D∙DL∙NL are called Row 7: D∙DL∙NL minterms Row 8: D∙DL∙NL Create the SOP expression for the output variable by summing the minterms H = (D∙DL∙NL)+(D∙DL∙NL)+(D∙DL∙NL)+(D∙DL∙NL) MAE 2055 – Mechetronics I Sum-of-Products 43 Now we can use the SOP expression we’ve generated from the truth table to synthesize a logic circuit using logic gates Inverters provide inverted values of each input Three-input AND gates generate each minterm Output, H, is generated by combining all minterms in a four-input OR gate K. Webb MAE 2055 – Mechetronics I Product-of-Sums 44 Let’s generate a POS Boolean logic expression to describe the behavior of the circuit, as defined by the truth table Look at each row of the table for which H = 0 Truth Table D DL NL H 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 K. Webb Using all input variables, write a logic sum that equals 0 for each of these rows Row 1: D+DL+NL These products Row 3: D+DL+NL are called Row 5: D+DL+NL maxterms Row 6: D+DL+NL Create the POS expression for the output variable by taking the product of the maxterms H = (D+DL+NL)∙(D+DL+NL)∙(D+DL+NL)∙(D+DL+NL) MAE 2055 – Mechetronics I Product-of-Sums 45 Now we can use the POS expression we’ve generated from the truth table to synthesize a logic circuit using logic gates Inverters provide inverted values of each input Three-input OR gates generate each maxterm Output, H, is generated by combining all maxterms in a fourinput AND gate K. Webb MAE 2055 – Mechetronics I Logic Circuit Minimization 46 We just generated two logic circuit, a SOP circuit and a POS circuit, that use different gates to perform the same function SOP and POS circuit generated following this methodology do not necessarily realize the desired logic function using the minimum number of gates The SOP (POS) circuit in this example uses three inverters, four 3-input AND (OR) gates, and one 4-input OR (AND) gate In fact it could be realized with one inverter, two 2input AND gates, and one 2-input OR gate K. Webb MAE 2055 – Mechetronics I Logic Circuit Minimization 47 To see how we can reduce the number of gates, we’ll apply some of the rules and identities of Boolean algebra to our original SOP expression: H = (D∙DL∙NL)+(D∙DL∙NL)+(D∙DL∙NL)+(D∙DL∙NL) Factor out a D∙NL from the first two minterms and a D∙DL from the second: H = D∙NL∙(DL + DL) + D∙DL∙(NL + NL) Next, apply the Boolean identity A + Ā = 1: H = (D∙NL∙1) + (D∙DL∙1) And the identity A∙1 = A, yielding a greatly simplified expression: H = (D∙NL) + (D∙DL) K. Webb MAE 2055 – Mechetronics I Minimum SOP Form 48 By applying a few rules and identities of boolean algebra, we’ve greatly simplified the SOP logic expression defining our circuit, and we can now implement the circuit with significantly fewer gates In practice, many techniques exist for performing logic minimization On such technique is using a tool known as Karnaugh maps, though this is beyond the scope of this class H = (D∙NL) + (D∙DL) Heat is on if: (It’s daytime AND the temp is below the day set point) OR (it’s nighttime AND the temp is below the night set point) K. Webb MAE 2055 – Mechetronics I