Tuesday, August 17, 2010

Op-amps, are they really that cool?

Yes, yes they are! The Operational Amplifiers (op-amps) are among the most widely used electronic devices in consumer, industrial, and scientific electronics. They were originally produced for mathematical operations (hence its name) but in fact they can be used for many many other purposes.

Yes, they are in Terminators too.

You know, back in the day, op-amps were constructed from vacuum tubes, meaning that they were poorly functional power hungry-devices that wouldn’t make it till these days if it wasn’t for one person, so if you ever have to thank anyone for pretty much everything you enjoy of modern day electronics (and probably for robots wiping out mankind) is this man: Robert Widlar

Bob Widlar was an electronic engineer in the 60s, he’s better known for being the designer of the first mass-produced op-amp IC in 1966 (among other cool stuff like the first voltage regulator IC) but also for  his akward pranks and  rabit ass way of life that are remembered in legends, myths and anecdotes, just like this one:

“On one occasion, when National Semiconductor tried to save money by cutting its landscaping expenses, Mr. Widlar brought a goat to work in his car to eat the grass in front of the company headquarters.”

True story boys.

At the age of 33, when he was wealthy enough on company stocks and already a "legendary chip designer", Widlar quit his job, left Sillicon Valley and hide somewhere in Mexico where he lived until his death in 1991.


So... how do they work?

In a very basic way, an op-amp is an electronic device with two inputs and one output

The value of the output is the difference in voltage between the two inputs multiplied for a gain factor, the usual gain (in open loop) is very large, and I mean quite fucking huge (over 9000!)… that means that even a very small difference between the inputs (and I’m talking micro volts here) will result in amplifier saturation.

Amplifier Saturation: If higher voltage is applied to the pin V+, the output will corresponds to the source VS+, however, if the higher voltage is applied to the pin V- , the output will be VS-

“I see what you did there…”

That should do the trick if what you want is a comparator circuit to, let’s say,  “control the direction of a DC motor”. On the other hand, if you plan to build a death laser machine to destroy France you’ll need to control that gain somehow… a feedback into the circuit is the way to go.

Feedback enables the amplifier to keep the inputs at almost the same voltage, avoiding that evil saturation stuff. However, you got to be careful; shit comes in two flavors, positive feedback and negative feedback. Usually, negative feedback is the one you want to hang up with.

“Yeeeeiii”

The previous image shows a non inverting amplifier.There are a lot of resistor/capacitor or  even coil configurations for the op-amps depending on the application you need. If you're interested, you really should give a look to this article. I also recommend you this links if you want to dig deeper on the history and insides of an op-amp.



Wednesday, August 11, 2010

Simpsons Moment




Homer : The sum of the square roots of any two sides of an isosceles triangle is equal to the square root of the remaining side.

Man : That's a right triangle, you idiot!

Homer : D'oh!


Thursday, August 5, 2010

A cup of tea with your processor


A couple of weeks ago I went through one of those cruel technical examinations that every newly graduated engineer has before getting his/her first job. 

It wasn’t that bad, Object Orientation: easy! C Language: bring it on! Circuit Analysis: checked! They even asked Elemental Physics: piece of cake… All was fun and games until Assembly came on the ring.

Ohhh shi…


Note for the new guys: Assembly is a low level language used to program microcontrollers and processors.

It turned out that they really needed an assembly badass for that position, so after leaving in despair, I decided to do a little research on the subject and learn about this so called dark arts of programming, hoping  to never experience that shit again.


The story behind the story.

63 years ago the world's first electronic digital computer was turned on, they called it ENIAC, shit was huge, had more than 800 km of cable inside, weighted about 330 tons and check this out: contained more 17,000 bulbs in its cherry belly (how many vintage guitar amplifiers is that?). This copper monster was capable of doing about 100,000 operations per second (kind of lame right now but fucking awesome in the 40’s). 

Anyway, what was really great about ENIAC was that you could actually program that shit. Yeah, even though they needed to reconfigure every single bulb and rewire more than a few kinky circuits in a process that took several days to several people, a programmable computer was a huge step in the olden days. 

"Yeah baby!"

After a while, scientist and engineers got tired of switching bulbs, and one day a crazy Hungarian dude designed a system that could take a crapload of binary code as a set of instructions to create a program, soon,  the first computer language was born... Machine Language

Still, Machine Language was boring as hell and hard as fuck, it didn’t take long for Assembly to first saw the light of day in the early 50’s. 

Note:  A common mistake is to call it assembler language; actually an assembler is what is used to translate assembly language into machine code. 


Why should you give a fuck about Assembly?

Well… you don’t really have to; you can do pretty much everything in C. It’s true that an assembly program will use the memory in a more efficient way but  the time and effort you may put in it probably won’t be worth it, today’s processors are so fucking awesome that you cannot really tell the difference.

Protip:  However, If you are on the road of electronics many employers will ask you for assembly skills (I learned that the hard way).



Hello World

Before this post gets too long I’m going to try and explain an assembly program in a really basic way so we all get the neck.


First of all, when a line start with a "." it means that we are about to tell something important to our processor. For example, ".model small" is like telling it: “easy boy, we won’t use a lot of memory”

The stack is used to store temporary data, it isn’t used in this program but you still need it, you could say that those are processor manners. (since the purpose of this program is to make an .EXE file, the stack is a must)

.data 
message db "Fucking Magnets, How Do They Work?" ,"$"

It's like: “Hey dude, I’m done with the stack stuff, we’re starting the data segment now, be cool and define some bytes, these bytes should contain the information between the brackets and don’t forget that "message" is how we will identify this byte-string thing”.

As you may have guessed, ".code" means that the code segment is about to start and that the data segment has just ended.

"main proc"is, as in any other programming language, the declaration of a procedure that ends in "main endp", let’s say that here is where you put the shit that you want your processor to do.

And then the tricky part begins, remember how we told it to remember that "message" would be the identifier? Well, "seg message" is the number of the memory segment where "message" is in, we need to know this number in order to know where the fuck is that byte-string thing.

"ax" is a register, and registers are like empty bottles where you put stuff. The instruction mov commands our processor to move "seg message" into our "ax" bottle, then we move what we just put in "ax" into the Data Segment register ("ds").  It has to be this way, "mov dsseg message" is not allowed (processor manners again).

I think you get the idea

"mov ah, 09" means to load the "ah" register with a nine.. shit start making sense right?

Ok, we have the number of the segment where message was in order to locate it, well, we also need the offset within the data segment of the bit-string thing to be able to reach it (kind of a x,y coordinates), we do that with "lea dxmessage", (lea: load effective address).

Don’t stop reading you lazy bastard, we’re almost done.

"int 21h" is an interrupt (I may talk a little bit about interrupts in another post) that tells our processor.. “Do stuff man!”. The first thing the processor does is to check "ah". There is a nine remember? , the nine means that the procedure shall write our bit-string “Fucking Magnets, How Do They Work?” to the screen.

mov ax4c00h
int 21h

Finally, these two instructions are pretty much the same, we load 4c00h in our "ax" register ("ah" contains the higher byte of the "ax" register, that would be 4c) and then the same int goes and checks "ah".  This time it contains 4c, that means “exit program”.

And that's pretty much it... I intend to write several post going deeper on assembly and its nasty secrets,  in the meantime if you want to learn more, I highly recommend this site: