/* Google Varification Link */
Send As SMS

Friday, March 31, 2006

Geek Notes: It's the Law!


From time to time I will be writing entries that begin with the words Geek Notes. These are intended to let be write about some technical aspect of electronics, or pretty much any other geeky topic, to let me explain what I think I know, thus helping me grok the subject matter.


After spending many hours in class studying analog and digital electronics I've found a small handful of mathematical relations that popup again and again. I wish that early on I'd known how absolutely critical these would be in circuit analysis. So for your edification (I love that word) and my personal review let's discuss these relationships.

Before continuing there are a few prerequisites:
  • Knowledge of basic algebra.
  • Understanding of Scientific Notation (ie. 6.241×1018) and the related Engineering Notation.
    • The use of symbols such as: pico(p), nano(n), micro(µ), milli(m), kilo(k), mega(M), and giga(G).
  • Access to a scientific calculator (or equivalent utility).
  • At least a vague concept of Voltage, Current and Resistance.

If you have these this will be easy. I can promise whatever math involved will be simple, with me it has to be simple.

The most important formula in electronics is Ohm's Law: V = I * R Voltage(V measured in Volts) is equal to Current(I measured in Amps) multiplied by Resistance(R measured in Ohms).

Using simple algebra you can derive the other two equations: I = V / R and R = V / I. These are rather simple, but with my poor memory I can't always remember. So I've found the following image to be helpful. It's easy to remember and let's you "see" all three equations.
V=I*R
What's great is if you know any two of the variables you can determine the third using one of the three equations.

Circuit #1
An example is shown above. If you have a 6V battery connected to a 120K Ohm resistor you can calculate the current being drawn. In this case 50µA or 0.00005A. If you increase the Voltage of the battery, and keep the Resistance the same, the amount of Current will increase. Assuming 12V then it would be 12V / 120K Ohm = 100µA.

Circuit #1
You may ask how is this useful? A simple case, show above, assumes you're going to use a 5V power supply, a commonly used voltage, to power an LED (Light Emitting Diode). If you don't include a Resistor the Current flowing through the LED will be as great as the power supply can provide. It will be a race between which will fry first; the power supply fuse or the LED. Of course it will be the LED, a power supply that cannot burn out an LED is rather pathetic. [This is not a problem in a standard handheld flashlight because the small incandecent bulb behaves as a resistor and glows as a result of current flow. But if you increase the Voltage enough the Current will increase and you will eventually burn out the bulb.]

A typical LED can handle a maximum about ~30mA, or 0.03A, before it will either be destroyed or the overheating will limit it's operating life. If you want to keep it safe you need to calculate what size Resistor you need to limit the Current to no more than ~30mA. Using R = V / I you have 5V / 30mA = 167 Ohms. The nearest commonly available resistor value is 180 Ohms.

If you change the Voltage, the Current will also change. So to protect the LED you need to recalculate the Resistance required to keep the Current under 30mA. If you drop the Voltage to 3V, from two AA batteries for example, you now need 3V / 30mA = 100 Ohms at a minimum to keep the current at 30mA or less. In this case it would be safe to leave the 180 Ohm Resistor in place, the LED will be fine, yet it will be slightly dimmer.

It was pointed out to me that because the LED is a diode it is a semiconductor device and has certain properties that are beyond the scope of this entry. However the use of a Resistor to protect components from excessive Current is all but universal. A Resistor that prevents too high a current flow is referred to as a Current Limiting Resistor.

That's all for now. Next time: Part II - Power Mad!

(I'd like to give special thanks to William E. Den Beste of Bill's Electronics Reference Library for his assistance in creating the schematic illustrations above and helping me better understand what I'm talking about. All errors are mine and mine alone.)

Friday, March 24, 2006

The Shipping News

I received this email today from MikroElektronika regarding my order.
...
Your order has been assembled and delivered to
customs yesterday.I am so sorry because delivery
delay, we have many orders and our delivery was
not fast as it was several months ago.

It can take 1 - 3 days to get though customs
and 3 - 9 days for airmail delivery Europe or
7-18 days to all parts of the world.

Please let me know as soon as you get your
items.

Thank you for your order,
...

Best case that means only an 11 day wait, worst case it's 30 days! So it's feeling more like a month before Christmas.

Thursday, March 23, 2006

If It's Thursday, This Must Be Belgrade



Well this is a first. I placed a direct order to MikroElektronika in Belgrade. I ordered one of the products I wrote about a week ago. The EasyPic 3, a PIC USB programmer with lots of bells and whistles. I was swayed a bit by the many resonably priced options and 30% discount on their compilers. I haven't bought a compiler yet, but I suspect they will extend the discount for awhile.

Normally when I order direct from a manufacture it's a US company. Not because I think they are better, but it's just more convenient. I often see the high shipping fees that overseas customers have to pay. Now I'm the overseas customer and while the shipping was reasonable, I wonder how long I'm gonna have to wait? (Sorta feels like the week before Xmas)

Tuesday, March 21, 2006

A Day Late and a Volt Short

I'm not happy with myself. I overlooked something fundamental regarding the temperature sensor project. It was to work in the Fahrenheit scale and in accordance with the demands of small size and low power everything was to work off of one 3V type CR2032 lithium battery.

I've worked with the LM35 Precision Centigrade Temperature Sensor before. It's a good sensor but won't work in this project because it's approximate 1oC accuracy is too course. Also without a negative power supply it bottoms out at 2oC. That is low enough for here in Northern California, where it rarely freezes. Elsewhere lower temperature are far more common and the point of the sensor is to detect and record highs and lows.

I've ordered a couple of LM34s, these are Fahrenheit sensors, so I get the resolution I want. Without a negative power supply these bottom out at 4oF, that's much better. This is plenty cold to be useful everywhere but the coldest laboratory freezers, polar weather stations or Minnesota.

Just one small, 2 volt problem. The LM34 and LM35 both require a 5V power supply, not 3V. I guess I get to start again...

I've begun a search for a precision temperature sensor that works at 3V. So far they have all been Centigrade only. Often with a ±3oC accuracy. I don't see how these can be labeled "Precision". I can work with a Centigrade sensor if it has a ±1/2oC accuracy.

So far the other sensors that work at 3V have been more complex affairs with built in ADC and I2C interfaces, etc. These might work. If so then I could drop the requirement that the PIC have a built in ADC.

I'm still searching...

Friday, March 17, 2006

PIC's Everywhere!

I'm at the stage of deciding exactly which PIC MPU I should use for the temperature sensor project. There are a few absolute considerations; at least one 8-bit ADC, enough I/O ports to comunicate with the I2C EEPROM and analog switch (to power down components) and of course enough RAM and EEPROM memory to hold the software to measure, record and format the temperature data.

I want to use the least expensive and lowest pin count I can, just to make this a bit more challenging. The more popular (ie. supported) the chip the better. The final circuit is to fit inside a old 35mm film roll case. I'd like to avoid SMT packaging if possible, I don't want soldering to become a major problem. Therefore the 40-pin, and maybe the 28-pin, DIPs are too big.

You'd think this would narrow it down to only one, but it not quite that easy. The Microchip site was too much with too many options. I decided to take a look at the Jameco catalog, assuming they would limit their selection to the more popular MPUs. I was surprised, there were 128 different PIC MPUs available just in the DIP package (ignoring SOIC, SSOP, TSSOP and PLCC packages).

After examining at least eight datasheets so far my eyes feel like they about to bleed... I'll let you know when I'm down to two or three, but this might take awhile...

Wednesday, March 15, 2006

Another PIC Parameter

I spoke with Prof. Brixen today about the best way to interface the LM34 temperature sensor with a PIC microcontroller. I've wanted to keep the PIC used to be as simple as possible. (I must admit I do wish the smaller 8-pin versions had the I2C hardware interface, but that's asking alot).

I going to need to use a PIC that has at least one 8-bit ADC. I'm trying to avoid using a op-amp to increase the 10mV/oC to a wider voltage range to use the full 8-bit range. I need to study the PIC families and see if any allow you to change the reference voltage of the ADC. (Update: Several of the PIC MPUs allow you to use either VDD or another reference voltage for the ADC. This may require an additional chip to provide precision voltage reference.)

Off to look at a lot of datasheets...

Tuesday, March 14, 2006

Compilers, Assemblers, Debuggers Oh My

I've been spending time reviewing what development tools exist for the PIC microcontroller line. It's overwhelming.

There is the free Microchip PIC Assembler. I want to re-introduce myself to assembly language programming. I know some who believe wanting to program in assembly is masochistic in the extreme. It can be painful, yet you gain a deep understanding of what's exactly going on inside the CPU.

I may sound like a grumpy old man, but the majority of today's programmers have never used an assembler or even reviewed the op-codes for the CPU's they use. Of those I know, most have no interest either. To them the computer is just a "virtual" object that executes their code. This attitude certainly contributes to the abundance of bloatware in the software industry. Why optimize code for size or speed when there are always bigger harddrives, larger RAM chips and faster CPUs? Besides the code as to be out the door yesterday so there's no time...

Sorry, just pining nostalgicially for past jobs as a grunt programmer. :)

Back to tools. There are a number of C compilers, BASIC compilers and even a Pascal compiler. I want to avoid BASIC if possible. I worked for six years using a version of BASIC that was years ahead of it's time back in the mid-1980's. I know when done right BASIC can do good things. Yet it does separate you from the hardware, as would Pascal.

Assembly is intense, and remains an option. The C compilers look the most interesting. I never liked C when I wrote business applications. I can't understand why it was once such a popular tool for high-level applications. I've always seen C as a glorified Assembler with great data structures. Which is great when working in an environment with limited resources or you need to twiddle bits, but lousy for a business app.

There are several C compilers from various vendors. Microchip offers a free version of their C compiler, targeted for the PIC18 series, with the limitation of a 12K code size. I don't know if I'll be using a PIC18, but the compiler availability makes it attractive.

Also I need a development board for the PIC line. Microchip offers a basic development board for around $50US. I've read it's the most popular tool used. However I discovered another development board that supports a very wide range of PIC controllers and had some wonderful bells and whistles. It's offered by MikroElektronika based in Belgrade. Their EasyPIC 3 Development System is a little more than twice the price of the basic Microchip board, with a lot more features.

Before I buy I'll checkout some newsgroups and websites. Unless I hear very bad things about the company I suspect this will be my choice. If you buy the development board from them they offer a discount on any of their related compilers. I'll keep you informed.

Saturday, March 11, 2006

Simpson's Did It!


While browsing the Maxim website I came across a surprise. They have a series of single chip (iButton packaging to be exact) that contain a temperature sensor, EEPROM memory, Real-time clock, serial protocol, etc. The DS1922L,DS1922T Temperature Logger iButton with 8kB Datalog Memory. It's everything I've been wanting to create with my Temperature Sensor/Datalogger project, but better, stronger, faster and smaller.

I should not have been surprised by it's existance. Because logging a temperature, over a long period of time, is such an obvious need. Being so obvious was a major reason I considered the project in the first place. But finding the entire circuit done much better in a rugged package depressed me for part of the day. I definately need to develop a thicker skin if I'm going to be working with such circuits for a living.

The DS1922 series is impressive. However I checked all the usual sources; Jameco, Digi-Key and Mouser. None of them carried the chip. Maxim gives the prices as $49US @ 1 unit, or $28US @ 1000+ units. That is a bit pricy.

I will take a closer look at it. I'm not familiar with iButton or the 1-Wire protocol. I still have not thought of a good way to get the data out of the EEPROM in my version, so I need to keep my options open.

I need to remember the entire point of this exercise was not to just develop a datalogger, but to learn by doing. Using an all-in-one, pre-developed system isn't going to help me learn.