Friday, April 6, 2012

The purple pirate...

A while ago I found out that a group order/build was going to happen at DorkbotPDX.  While there is no way I could be out there for the party, I do like to support group orders and my old bus pirate (many versions behind) is starting to show it's limits.

Yesterday the mailman brought the happy package and while I wasn't planning on soldering yesterday I get that itch and just had to build it.

The purple pcb (classic Laen) always makes me smile.

A couple of neat things about the way it was kitted out.  First, there was a well thought out page containing layouts/partial layouts with the similar part locations in bold.  This is absolutely makes builds a lot easier. (Although I would have done some of the sequences differently to make a few of the pads easier to access - I suspect that the intent was probably for paste/reflow).

The parts came taped on a few pages with data about the package type, the quantity and the values.  Maybe a bit of excessive tape but all the parts were still in place after the journey.  The pic was attached to a cardboard square separately - well protected.

A ribbon cable, snap on connector, headers also came in the box in a bag with the pcb.

While I did have a couple of ugly soldering pads, and I messed up a cap and a resistor (I had plenty of stock to replace them), I couldn't find any problems visually so I attached the programmer and first time it was the target and programmed without any difficulty. (Yay - the smoke test is always one of those exciting moments of truth).

I was really happy to get the serial connection right away.  This version of the bus pirate uses the pic (PIC 24FJ256GB106) to handle the usb connection directly and I wasn't certain how it would work...  No problems at all (I suspect it will allow higher throughput/lower latency than the ft chips but it will be awhile before I can test that out).

Yeah you can see my ugly soldering here.  I really like the layout on this version.  The bigger pic, the i2c eprom and the inclusion of multiple power supplies is going to make the tool a lot more flexible.

I didn't pay attention to the orientation of the socket because I plan on using other probes and not the ribbon cable...

If you don't have one, you may want to consider picking one up (although I think Ian still recommends the previous version - not certain about that). 

Lots of information at Dangerous Prototypes.

Thursday, April 5, 2012

Silly pointless stuff... (Mr Jiggles 2)

So yesterday Mr Jiggles became a little oscillator - but rather than a balanced sine wave we had a light distortion where the upper half was a bit wider and the lower half was a bit narrower.

I usually like to check the ground potential relative to the output if there is a problem, but this one is fine - maybe it could use a cap across the the supply but nothing to explain the distortion.

This is the signal on the supply voltage (no problems here either - inductors are great).

Making coffee I realized what the problems was (and it's a simple one).  This is the same oscillator with a tiny addition - the yellow curve is still the same output as before but now we have a blue curve that looks like a very happy sine wave (although shifted in phase 90 degrees).
The problem leading to the distortion turned out to be a silly mistake on my part - I sampled of a cap that had one end floating (which of course made it incapable of transferring energy in a balanced way).  A simple resistor to ground is all it takes from the floating cap terminal.  The phase shift above is from an additional resistor cap chain (more about that later).

Just for kicks let's look at the power coming into the collector at the same time as the oscillator state.  Lots to learn from this one... The first thing that jumps out is that our output is a balanced cyclic form but the voltage looks like two different curves.   If you haven't guessed, the reason is the led (remember there is a minimum voltage before it conducts and until we hit that voltage on the emitter not a lot gets to flow) - caps cover the transition interval.  We could just leave out the led and only have a resistor to limit the current but since we can't always have things linear in real life I'm leaving it in - for character.

Just for kicks let's dump the oscillator directly through a diode... notice the similar curve (not exactly the same because the difference in cap sizes.

Other fun things to do are to tap from the collector or the emitter, to put resistor dividers in line to change the output voltage range, to bias the base to change the operating point of the transistor... lots of things.. endless things...
But for now since we are pushing our signal through other objects, let's try to put it through other crystals.  If we use the same frequency the signal goes through nicely, but if a different frequency (4.078 MHz in this case) we get nothing at all... crystals make great filters.

What happens if we drive two oscillators at each other...
Now let's make Mr Jiggles a friend (perhaps with the different crystal) and then put them together.

If we pass the mixed signals (yellow) through another crystal (that matches one of the parent signals - in this case the blue line) the third crystal does a great job at pulling out the right signal (again crystals make great filters).

And for the last thing today let's change our second oscillator to the same frequency.  We get some loose coupling (breadboards are not ideal for this stuff - probably you should always just stick with simulations and finished pcbs - nothing to gain from imperfect circuits - always follow schematics exactly) but there's still lots of jitter.

We can plot this a different way and see the differences more clearly.

And what it looks like when we tightly couple the oscillators (between the capacitor dividers across each crystal).

Anyway, every once in a while I like to just play around a bit and get a feel for how things actually work and see the changes in reality... touch a few wires to see which is sensitive to noise and how that propagates... troubleshoot the unexpected behaviors... see what happens when the loads match and when they don't... it's silly and pointless, but fun.

Wednesday, April 4, 2012

Silly pointless stuff... (Mr Jiggles)

Let's do something silly and pointless... say we come across a crystal (in our junkbox, our backyard, wherever) and decide to make an oscillator.  (There are many many ways to do this but for the heck of it let's just play around and see if we can make it work).

I like to think of crystals as highly ordered structures that deform a bit in the right kind of electric field - remove the field and they go back to their original state and in the process create a tiny electric field of their own.   Now depending on how the little crystal is cut, what it's composed of, how it's treated it will have at least one frequency at which it likes to oscillate.

The problem is that the amount of energy stored in our crystal (let's call him Mr Jiggles) is very very tiny.  If we just attach a voltage source (DC), the crystal will never get the chance to cycle between a deformed and a native state... When we want an alternating current and not direct current we put a capacitor in line.  A good guess is something like 1 to 20 pf (too much capacitance or too little capacitance will not work well - remember the crystal needs to draw and throw a small amount of energy and the matching the cap to the amount makes it happy).

The other thing we need to consider is how we will make the little amount of energy useful - we need to make it bigger.  It happens that our little friend (the npn bjt) does a great job of taking a tiny current and making it bigger. 
Originally I thought of using a 3904 but I had a bc347 out already so I'll just use that (generic-ish standard npn that easily covers the voltage ranges and current and frequency here).  Like everything else there are a lot of ways to use these components - for our purpose I want to start with a fixed current so I don't blow things up.  My favorite little current limiter is a little resistor and an led (I like 8 volts for these transistors so a 4.7k resistor gives between 1 and 2 mA witht he led voltage drop). 

I know I'm going to link the crystal to the base (to control a bigger current collector to emitter) and I know we need a voltage to load the crystal (but not a lot) so let's start with a 220k resistor to pull the base high from the collector.

The last thing to think about is what happens to the AC amplified signal we make...  It's not going to be nice to the power supply (or the ground) if we allow the AC component to just flow where we don't want it.  I like to put an inductor inline with the supply (the magnetic field induced by the current flow resists changing at certain frequencies - kind of like the opposite of a cap).  This way way little AC signal can propagate back to the supply. Speaking of capacitors we need to do something about emitter of the transistor where it attaches to ground.  While the resistor/led combo will provide a DC path (and limit the current flow) but I want to add a cap to filter the AC.  Right now I don't care what size, I'll change it later.

It's a good thing to build this out really quick and make certain it works... If you attach 8 volts across the collector and the led it ought to stay lit and if you short the base to ground it ought to go off (the 220k resistor limits the current so nothing bad will happen and you won't break anything).

The last thing on my mind is how to get the crystal jiggling int he first place... one way is to feedback a bit the output from the emitter (always a little noise at the start).  We can do this with a pair of little caps across the crystal (small values - 1 to 20pf-ish).  This may not be needed, but what the heck let's just put them in place.  It's also not a bad place to sample the signal from the crystal without causing too much distortion from the probe.

And when we try it out, it works (well at least it jiggles)... except it's not a very pretty signal.  Let's try to figure it out...

Ahhhh... silly mistake.  If you look back at the sketch I connected the crystal directly to the base (and this isn't going to leave any room for the jiggling to happen unimpaired - like trying to dance in a car - not going to be beautiful).

Putting a cap (20pf) in line between the crystal and the base of the transistor makes things a lot better, but there is still some unhappiness.  It looks like the rate of increase gets ugly (bad slope) when the voltage get's high - but it doesn't seem to occur when the voltage drops (except perhaps a bit on the very lowest voltage)...

If we try changing the cap on the emitter (remember I just grabbed one at random at first) if makes things much worse if we increase it.

If we make the cap on the emitter smaller (here 20pf) it's much nicer... but still not a happy sine wave.  Interestingly the shape on the upper voltage is wider than the lower voltage area... why would that be? 

Enough for today... think about it and we'll see next time.,.

Monday, April 2, 2012

Silly pointless stuff... (panel meter)

Say you came across a sexy panel meter and wanted to make it work (maybe you found it in your junk box or perhaps your garden - doesn't matter - but let's pretend you don't know anything about this mystery device).

This one has a little offset (doesn't quite rest at zero) but the for now that doesn't matter.  The range seems to go to 20 milliamps.

If we look at the back there are two threaded posts, on of which is labeled with a plus sign (so we know the polarity at least).  Since the needle is near zero we will assume that supplying a positive voltage to the post with the plus will make it go up.

We need some little source of current to test our mystery sexy panel meter and a good source of smallish predictable currents at small voltages (3 to 8 volts DC - battery, bench supply, whatever) is an led and a resistor.

It doesn't matter very much what resistor you use (within reason for whatever led you have), but setup something that makes a reasonable amount of light and it should be fine.

Quick little measurements (about 5 volts, about 1k and about 2 volts across the resistor - remember the voltage drop on the led - our little circuit pulls 3.27 milliamps).  If you check the math rather than measuring it will come out perfectly -> remember V=IR -> so I=V/R -> so I=(5.04 - 1.98)/983.3 = 0.003275 amps.

But... if we put the panel meter in the circuit the needle slams full scale instantly (oh no 3.27mA should be less than 20mA - what's wrong?)

The reason is of course that the meter doesn't really read milliamps at the scale reading... In this case the full scale is 1mA (so we need to put 1/20th the real current through the meter to make it match the scale).

Our little meter doesn't say what the actual resistance is (we could measure it but that's means we have to do a bit of math (very simple math) and today I don't want to do math for this.

Instead let's just try putting a 10 ohm resistor in parallel with the meter terminals.  If we do this and try again the meter gives us a reading... yay.

But the reading isn't right... we get around 8mA on the scale and we know we only have 3.27mA.  It would have been nice to know the meter resistance - but rather than measuring let's use a potentiometer in the way that we aren't supposed to (normally the dial should be used to set the wiper to a value (a potential) between the high and low terminals but I'm just going to use the low terminal and the wiper as a simple variable resistor... yup, shouldn't do this in a design but it's actually too easy a solution on the bench as a variable resistor).

By putting the potentiometer in series with the meter (and that combination in parallel with the 10 ohm resistor) we can adjust the pot until we get the right reading on the scale. 

When we do this it comes to about 117 ohms (and that's easy to make with a 100 ohm and a 15 ohm resistor in series).

So now we have the right reading on the scale for the actual current (yay).  A 15 ohm and a 100 ohms resistor in series with the meter and then a 10 ohm in parallel with the set. (All I have to do is fix the little offset at zero).

Just for the heck of it the math for figuring out the extra resistors is easy:  The meter is 73.9 ohms, the resistor we want in parallel is 9.93 ohms and we want a 20 fold change in the scale... so (73.9 + x + 9.93)/9.93 = 20 -> 83.84 + x = 20(9.93) -> x = 198.6 - 83.84 -> x = 114.86

So all this is kind of silly - it's a very simple thing to do but it's fun sometimes to do things in a different way than usual.  Now everyone seems to like digital displays - they are great, but there's something about the old style panel meters that I have a fondness for...