Saturday, March 24, 2012

Digital Logic Circuits

One of the classes I'm taking this semester is called Mechatronics. The area of study is becoming extremely common in modern technology; an easy example of this is robotics. In fact, I just recently signed up for a robotics class in my last semester here at UT. It's really fascinating stuff but the inner workings are incredibly complex.

Anyway, this class, the coolest-sounding one I've ever taken, is not living up to its name. It's essentially a crash course in Electrical Engineering; no mechanics to speak of. It's interesting but it's tough, it's not taught very well, the textbook sucks, and I'm not good at it.

The lab is a bit more interesting. Thankfully there are no lab reports, but prelabs are insanely time-consuming and sometimes depressingly frustrating (seriously). I have spent over 6 hours on one or two before, even working with another friend. It wouldn't be so bad if the lecture actually lined up with the lab, but we get a crappy 50 minute lab lesson every week with an entirely new concept each time, and the prelabs require inside-and-out knowledge of that material.

Regardless, this week's lab was actually really neat, and almost fun if it weren't so challenging. It was a mock digital logic circuit design for a vending machine. I shouldn't have to tell you that it's way simpler than a real vending machine, but it was still an interesting mental exercise.

Pictured below is the final page of the prelab. Believe it or not, this is a simple logic circuit. It's NOWHERE near as complex as the electronics in, say, a remote control.

I'll explain what this is supposed to be later in the post.


 This is the closest thing to rocket surgery I've ever done.
Now do you understand why I have little patience for people that don't know how to USE electronics?

If you want to make the most of your day and learn something interesting, keep on reading.

This is the first thing I've ever done that actually used binary (1s and 0s; 1=true and 0=false). Binary and regular numbers can be interconverted, and it's actually easy to learn. The one weird thing is that it reads from right to left. The rightmost digit has a value of 1 and doubles every time as you move one to the left (<- 32 16 8 4 2 1). Every real number is a combination of 1s and 0s. A 1 means you count the number, and a 0 means you ignore it. So 001 is 1, 010 is 2, and 100 is 4. Logically, 011 is 3, 110 is 6, and 111 is 7.

 Hopefully this shirt makes sense to you now.

Okay, so why the binary lesson? Because binary is really freakin' important. It's used in almost every electronic device you own. It's worthwhile to understand.

Let me relate it to something you use all the time:

A 1 or a 0 is called a bit (b). 8 bits are called a byte (B). 1000 bytes make a kilobyte (KB), 1000 kilobytes make a megabyte (MB), and 1000 megabytes make a terabyte (TB). You've also heard the terms of kilobit and megabit, and those are usually used in telling you transfer or connection speeds (a DSL connection is typically 1.5 megabits per second, or Mbps, for download speed. That means your computer can receive 1.5 million 1s and 0s per second. The best part is that this is SLOW to some people. 30 megabit cable is not uncommon.)

Everything on a memory card or hard drive is just a lot of 1s and 0s that are bunched together in groups of 8s. Pictures are all 1s and 0s. Songs are all 1s and 0s. Games are all 1s and 0s. You get the idea. If you ever wonder why your computer says your hard drive or memory card have less storage space than what the box said, that's because computers take bytes in groups of 1024 instead of 1000. So don't worry; you're not getting ripped off-- you're getting all the bits as advertised.

 These things can go up to at least a terabyte-- that's a trillion 1s and 0s!

So, back to the vending machine problem.
There are 4 buttons (A, B, C, and D) on the machine: 2 for coin input, and 2 for snack selection.

The buttons are like binary: 1 for a pressed button, and 0 for unpressed. 4 buttons means 4 bits. They could be anything from 0000 to 1111; the bits are labeled ABCD in the circuit diagram.

If you separate the buttons by function, you get two sets of 2 bits: with 2 binary digits, you can have a total of 4 combinations: 00 (combo #1), 01 (#2), 10 (#3), or 11 (#4) and you can assign a meaning to each combination.

For the coins, 00 (#1) is no coin, 01 (#2) is a nickel, 10 (#3) is a dime, and 11 (#4) is a quarter.
For the snacks, 00 is no snack, 01 is a snack that costs $0.05, 10 costs $0.10, and 11 costs $0.25.

The vending machine has to decide whether or not to give you the snack you selected based on the coin you put in, what change (if any) to give you, and to return your money if you don't get a snack. This stuff makes intuitive sense but we had to convert it all into binary because that's how circuits work.

The two circuits we built in the lab collectively output the value of the first coin in the coin return (a second coin only appears if you buy the 5-cent snack or the 10-cent snack with a quarter).

So, either you will get no coin (00), a nickel (01), a dime (10), or a quarter (11) back.

Since each individual circuit only outputs either a 1 or 0, we had to make two during the lab: one for the bit on the right, and one for the bit on the left (e.g., a 0 and a 1, respectively, for a dime as the first coin in the return). The first circuit is the one drawn on the paper, and the second one is the picture of the actual circuit.

Again, this is not even close to the complexity of computers and cell phones or even a real vending machine. Don't take electronics for granted. Appreciate how mind-blowingly complex they are.


No comments:

Post a Comment