Google

Tuesday, June 24, 2008

DIGITAL LOGIC

DIGITAL LOGIC

Digital Logic is a whole subcategory of electronics stemming from the observation that by limiting signal values to two discrete values (5V and 0V, say) you can represent binary values: i.e. values made up of only the digits "0" and "1". Each one of these binary digits is called a bit (a contraction of "binary digit"). By convention, in a 5V system, 0V is assigned to the value 0 and 5V is assigned the value 1.

Strings of 0's and 1's can represent anything we like. We can have them represent numbers by using the binary number system. The binary number system is exactly like our base 10 numbering system except there are only the two numerals (0 and 1), not ten (0,1,2,3,4,5,6,7,8,9). In case you haven't done it for a while, in the decimal system we count like this (although normally we don't put the leading zero's in).

000, 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, ... 095, 096, 097, 098, 099, 100, 101, ...

The idea is that as we count, we go through all of our numerals in the rightmost column, then when we run out we increase the next column and go back to the 0 in the first column and repeat until the next column's numerals are all used up and so on. In the binary system we count exactly the same way, except we only have two numerals, so the next column thing happens a lot more often.

000, 001, 010, 011, 100, 101, 110, 111, ...
(0) (1) (2) (3) (4) (5) (6) (7)

You might think that this is kind of wasteful, since we're already using three digits (bits) by the time we've counted to 4, but this is offset by the fact that each digit can be assigned to just one wire carrying a 0 or 1. With three bits we can represent up to 8 things. With 8 bits (which is called a byte) we can represent up to 256 things. This number grows quickly, by the time you get to 64 bits, you can represent 18446744073709551616 things.

As you might suspect, you can add, subtract, multiply, divide, binary numbers very easily using the same techniques you're familiar with in regular decimal arithmetic. You can even have binary decimal fractions (111.01, for example is 7.25) and do all kinds of heavy mathematics. The things you can represent by binary numbers can be bank balances, colors, calendar dates, distances, speeds, instructions - anything you like. This is where computers come in - computers work with and by manipulation of binary numbers, all trading on the idea that you can use wires carrying 0's and 1's to represent things in the real world and also to switch circuitry on and off.

Microprocessors use 0's and 1's to do everything, so it should not be surprising that getting 0's and 1's in and out of them is extremely easy. In a conventional 5V system, If an input pin is connected to 5V, it will read a "1". If it's connected to a 0V it will read a "0". Similarly, if an output is set internally to 1 it will have 5V on the pin or 0V if a 0 set. Note that outputs can sometimes be disabled. When this happens the output is said to be floating and could have any value.

A relatively new phenomenon is the presence of analog inputs on microprocessors. Analog inputs permit the reading of voltages between 0V and the value of the chip's power supply voltage. (Note that a microprocessor should never be directly connected to a voltage greater than it's power supply). Inside the microprocessor equipped to handle analog input, there is a device called an analog to digital converter (ADC) which samples the voltage on the pin and converts it into a binary number. The resolution of the ADC is just the number of binary digits that it resolves the voltage into. If it were a 1bit ADC, it's one digit would be able to resolve the voltage range into only two levels (i.e. <>2.5V). A 2bit ADC would resolve the voltage range into four levels (00, 01, 10, 11), and so on. The PIC18 microprocessors have 10bit ADC's, so they can resolve the 0 - 5V range into 1024 levels - each one being 5V / 1024 = about 0.0049V.

No comments: