4.2 Digital Logic, DIO and DAC • why digital logic? • truth tables for digital logic P NOT P AND P OR P XOR P NAND P NOR • examples of logic circuits • digital input and output (DIO) • digital-to-analog conversion (DAC) 4.2 : 1/11 Why Digital Logic? • High-voltage instruments are often interlocked to protect the user. Each access point is connected to a switch that has a binary output (0 closed, 1 open). The high voltage is shut down if any access point is opened. This is accomplished with OR logic. shut_off? = sw1 OR sw2 OR sw3 OR sw4 • Before a spectrum is recorded it might be necessary for the user to click on a scan button, the monochromator be set to the starting wavelength, and the sample chamber door be shut. record? = scan AND startλ AND door_shut • These types of logic decisions can be made in hardware or software. The hardware option simplifies the computer program and reduces the number of bits of logic information that need to be input to the computer. 4.2 : 2/11 Logic Gates and Truth Tables (1) • For electronics a 1 is taken as true and a 0 as false. The most common logic family is transistor-transistor logic (TTL) where +5 V = 1 and 0 V = 0. • NOT gate: Q = NOT A also written as _____ A 0 1 Q 1 0 A • AND gate: Q = A AND B A 0 0 1 1 4.2 : 3/11 B 0 1 0 1 Q 0 0 0 1 Q also written as _____ A B Q Logic Gates and Truth Tables (2) • OR gate: Q = A OR B A 0 0 1 1 B 0 1 0 1 also written as _____ Q 0 1 1 1 • XOR gate: Q = A XOR B A 0 0 1 1 B 0 1 0 1 Q 0 1 1 0 A Q B also written as ______ A B Q • note that OR and XOR differ when both inputs are 1 4.2 : 4/11 Logic Gates and Truth Tables (3) • NAND gate: Q = A NAND B A 0 0 1 1 B 0 1 0 1 Q 1 1 1 0 • NOR gate: Q = A NOR B A B Q 0 0 1 0 1 0 1 0 0 1 1 0 4.2 : 5/11 also written as ________ A B Q also written as ________ A B Q Example Logic Circuit (1) use OR, NAND and AND logic to create XOR logic ( A ⊕ B= ( A+B )i AiB A 0 0 1 1 B 0 1 0 1 (OR) 0 1 1 1 (NAND) 1 1 1 0 ) ()AND() A B Q A B 4.2 : 6/11 Example Logic Circuit (2) • use XOR, AND and OR logic to create an adder with carry from the right and carry to the left: A + B + Cin = S + Cout • the required truth table is given below (rotated 90°) A Cin A B S Cout 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 0 1 ____________________ B Cin Cin A B • to see this circuit in action see: www.play-hookey.com 4.2 : 7/11 S Cout Digital Input & Output (DIO) • binary output generated by external digital logic often needs to be communicated to a computer program • similarly, a logic calculation performed by software often needs to be communicated to an external circuit • the number of bits available for DIO depends upon the specific product with multiples of 8 being common • for output the computer sets the bits and the register holds the values until they are read by the external circuit • for input the external circuit sets the bits and the register holds the values until they are read by the computer program 4.2 : 8/11 0V 0 +5 V 1 digital control logic +5 V 1 0 0V 0 0V 0 0V 0 0V 0 0V experiment/ instrument DIO Continued • besides the DIO registers, ___________ (flags) are necessary • For example, an "input ready" bit tells the computer that a new value is ready for reading. After the computer reads the DIO it might set an "input read" bit that tells the external circuit that it can provide updated information. This is called handshaking. • A external circuit can "watch" an "output ready" control bit. With this approach the logic output will not be read until the computer has updated the DIO. • if the experiment has voltages that might inadvertently damage the DIO circuitry (or worse get into the computer), the outputs can be __________________ using light emitting diode/photodiode combinations • when the external circuit uses high voltage or the instrument is in a corrosive environment, _______________ can transfer the digital logic information 4.2 : 9/11 Digital-to-Analog Conversion • Often a digital value generated by a program needs to be converted into an external voltage. An example might be the generation of a _________________ in electrochemistry. • In the DAC shown below individual bits control a transistor switch that provides current to the op-amp. The resistor ladder makes the current associated with each bit to be exactly 1/2 that of the bit to the left. The current from all bits is summed. The op-amp behaves as a ______________________________. 50 k 50 k 50 k 100 k +10 V 0 0 1 1 50 k ! 100.0 μA MSB 4.2 : 10/11 50.0 μA 25.0 μA 12.5 μA LSB + 0 to -9.375 V DAC Performance • when all the binary combinations are output in order, the DAC output resembles a __________ • commercial DACs have from 4 to 18 bits (16 to 262,144 steps) • common output ranges might be 0 to 10 V or -5 to +5 V • some DACs have software controlled voltage ranges • most DACs can output new voltages every ___________ permitting the generation of arbitrarily-shaped waveforms 4.2 : 11/11 -10.000 V -7.500 V -5.000 V -2.500 V LSB = -0.625 V -0.000 V Binary Input