Saturday, 19 of May of 2012

BB313 Parts List Update — 2.1mm DC Barrel Jack

The BB313 parts list has been updated with a new DC barrel jack, after Mouser suddenly declared the old one obsolete. Mouser’s suggested replacement is (naturally) out of stock and isn’t expected until June, so you can use this one in the meantime, though it’s a bit more expensive.

Thanks to Steve Wall for alerting me about the change of status. This was unexpected, as I had ordered 25 of the old barrel jacks only a week earlier, and there was no indication of end-of-life. Goes to show you need to keep a close eye on your supply chain, even for generic parts.


Opampomancy: Feedback Networks and the Non-Inverting Amplifier

The purpose of this post is to lay out some of the stuff I wish someone had explained to me when I was first learning about electronics. This is a pretty entry-level introduction, intended by me to ‘fill in the gaps’ with regard to basic operating principles. Opamps are not all that complicated, but for many people they appear as a black box. With so many schematics available online, it can be very tempting to simply ‘cut-and-paste’ subcircuits into your own designs without understanding them. This is okay to a point, and useful for learning, but it may come back to bite you later if your design doesn’t work the way you expect it to.

 

First, let’s look at the schematic symbol for an op-amp and identify the pins and their functions.

V+ is the positive supply and V- is the negative supply. Often these will be omitted in diagrams, especially if the opamp is part of a dual or quad package. For most schematics, it is implied that the opamp is connected to such supply rails.

Vin+ is the non-inverting input. Because of the plus sign, you may be tempted to call this the positive input, but that would be something of a misnomer because the signal voltage applied to it can positive or negative with respect to ground.

Vin- is the inverting input. Again, the signal voltage applied here can be positive or negative with respect to ground.

Vout is the voltage output.

 

There are two concepts which are typically used to describe how opamps function. The first is: the voltage output of the opamp is the voltage difference between the two inputs multiplied by the gain of the device. The gain of the device is often denoted as A, and refers to the open-loop gain of the amp. Further, the voltage difference refers to the difference between the voltage at the non-inverting input (Vin+) and the voltage at the inverting input (Vin-). In other words:

(1)   \begin{equation*}V_o = A \cdot (V_{in+} - V_{in-})\end{equation*}

This voltage difference can be considered the input to the opamp. The order of terms in the above subtraction is where the inputs get their names. To explain, let’s assume that the voltage at Vin+ is X, and the voltage at Vin- is 0 (ground). Thus, Vin would be X – 0, which is just X. However, if Vin+ = 0 and Vin- = X, the input voltage would be -X (negative X), thus its sign would be inverted, hence the term inverting input. This sign inversion would hold true regardless of whether X itself was a positive or negative value (with respect to ground).

So now that we’ve dealt with the Vin terms, let’s talk about A. A, as mentioned above, is the open-loop gain of the opampit is typically very large, on the order or 10,000 or more. This huge gain factor makes an open-loop opamp pretty useless for most applications. There are very few occasions where you would need to multiply a signal 10,000+ times, and even then it would be unwise to do so using an open-loop opamp. The reason is that even though A can be regarded as quite large, it’s very difficult to control exactly how large it will be. This is due to a number of factors, but mostly it’s due to manufacturing variances. The gain of the opamp is directly related to the gains of the individual transistors which make it up. Transistor gain can be difficult to control, particularly in large numbers. While it is possible to create very precise transistors, and thus pretty precise opamps, it’s not at all cheap. Further, it’s completely unnecessary, as we will soon see.

It’s much better to approach opamp design from a different angle. Rather than create a device which has a large but precise gain factor, it’s better to create one with a theoretically infinite gain and provide some other constraint which can be used to control it. This brings us to the second big concept for opamp functionality:

 

“An opamp tries to keep the voltage across its two inputs at zero.”

 

In fact this is the fundamental operating principle of all opamps, but when I was first learning about active devices, I always found this statement to be very confusing. The problem is that very few sources go on to explain why this is so. It seems a little counter-intuitive. Amplifiers aren’t supposed to make things smaller (or zero), they’re supposed to make them bigger, so why is the opamp trying to mitigate it’s own inputs, and how the heck does it do that?

I’ll answer the second question first. The how is with a feedback network. The original statement would be more complete if it read:

 

“An opamp tries to keep the voltage across its two inputs zero by using a feedback network to control one of the inputs with the output.

 

The construction of the feedback network will determine the extent to which the opamp has to swing the output one direction or another, so that one of the inputs is equal to the other input. The easiest way to explain this is by looking at a simple circuit — the non-inverting amplifier:

In the non-inverting amplifier, the input voltage is applied to the non-inverting (+) input of the amp. The output of the amp is connected, via a feedback resistor, to the inverting (-) input. There are two resistors here which make up the feedback network. The first is the aforementioned feedback resistor (R_feedback or R_f), and the second is a resistor from the inverting input to ground, called R_ground or simply R_g. Let’s ignore the non-inverting input for now and just look at the feedback network — it forms what is known as a voltage divider. Below is an example of a simple voltage divider circuit.

A voltage divider is so named because it provides a fraction of the input voltage as its output. The simplest voltage divider is made with two resistors, R1 and R2. In the figure above, the output voltage (Vout) is equal to the input voltage (Vin) times the ratio of the lower resistance, R2, to the total resistance, R1+R2. The lower point of R2 is tied to ground.

(2)    \begin{equation*} V_o = V_{in} \cdot \frac{R_2}{R_1+R_2} \end{equation*}

The nice thing about the voltage divider is that it has lots of applications, one of which is in our non-inverting amplifier feedback network. In that case, the input to the voltage divider would be the output of the opamp, and the inverting input of the opamp is the output of the voltage divider. Seems very confusing, I know. Perhaps a diagram will help.

The formula for the voltage divider still applies, and we can substitute the terms from the non-inverting amplifier from above:

(3)    \begin{equation*} V_{in-} = V_o \cdot \frac{R_g}{R_f+R_g} \end{equation*}

To make things a little clearer, let’s replace the resistor fraction with something less cluttered — the greek letter Beta:

(4)    \begin{equation*} \beta = \frac{R_g}{R_f+R_g} \end{equation*}

–thus–

(5)    \begin{equation*} V_{in-} = V_o \cdot \beta \end{equation*}

Ok, now we need to relate this equation to the whole circuit, so that we can come up with the transfer function for the non-inverting amplifier. A transfer function is an equation that describes the output in terms of the input. It’s usually written as follows:

(6)    \begin{equation*} \frac{output}{input} = transfer function \end{equation*}

In other words, it’s a function that describes the ratio of the output to the input. This is an easy form to understand and use, because to find the value of the output, all we need to do is multiply the transfer function by the input value. Remember that the input to the whole circuit is at the non-inverting input, so we are going to need to include that in our function as well.

NOTE: From this point on, it’s mostly just a lot of algebra — moving terms around between both sides of the equation until we get a nice Vout/Vin transfer function. If you’re thinking of studying electrical engineering, you should know that this stuff is critical. Being able to do algebra like this quickly is something you should make an effort to get really good at, because you will use it all the time. There aren’t really any shortcuts here — you just have to do it.

One of the problems when you’re studying this stuff is that textbook authors tend to ‘skip steps’ when reducing or reconfiguring equations, because they assume some intermediate steps are self-evident. Sometimes they are, particularly if you have a lot of experience working equations, but for n00bs (or sleepy college students), they are not. As such, I’m going to try to show each and every step, and explain what I’m doing, so you can understand it.

Getting back to the problem at hand, we need to create a transfer function for our opamp+feedback network. In order to do that, we will take equation (3) and substitute it into equation (1), replacing Vin- with the voltage divider equation. Doing that, we get:

(7)    \begin{equation*} V_o = A \cdot \left(V_{in+} - V_o \cdot \beta\right) \end{equation*}

–or–

(8)    \begin{equation*} V_o = A \cdot V_{in+} - A \cdot V_o \cdot \beta \end{equation*}

The next step is to get both Vo terms over on the same side of the equation, so let’s do it:

(9)    \begin{equation*} V_o + A \cdot V_o \cdot \beta = A \cdot V_{in+} \end{equation*}

Now we extract the Vo term as a common coefficient of both terms on the left.

(10)    \begin{equation*} V_o \cdot \left(1 + A \cdot \beta\right) = A \cdot V_{in+} \end{equation*}

Our original mission, of course, was to find the transfer function of Vo/Vin. Vin, in this case, is Vin+, so we want to find Vo/Vin+, so we divide both sides by Vo.

(11)    \begin{equation*} 1 + A \cdot \beta = \frac {(A \cdot V_{in+})}{V_o} \end{equation*}

Now we’ll divide both sides by A:

(12)    \begin{equation*} \frac{\left(1 + A \cdot \beta\right)}{A} = \frac {V_{in+}}{V_o} \end{equation*}

which becomes:

(13)    \begin{equation*} \frac{1}{A} + \frac{A \cdot \beta}{A} = \frac {V_{in+}}{V_o} \end{equation*}

Now we can use a little trick to simplify things. Recall that A is very large — theoretically infinite. As such, 1/A is very small, theoretically zero. We can use this to our advantage, because it means we can get rid of the 1/A term by equating it to zero. Further, looking at the second term on the left, the A in the numerator and the denominator cancel out, so we can get rid of them too.

(14)    \begin{equation*} 0 + \frac{A \cdot \beta}{A} = \beta = \frac {V_{in+}}{V_o} \end{equation*}

Oh snap! Look how much simpler that is! Now we can substitute back the resistor fraction for Beta:

(15)    \begin{equation*} \frac{R_g}{R_f+R_g} = \frac {V_{in+}}{V_o} \end{equation*}

and we invert both sides to get the Vout/Vin form we’re aiming for:

(16)    \begin{equation*} \frac {V_o}{V_{in+}} = \frac{R_f+R_g}{R_g} \end{equation*}

Rg/Rg = 1, so:

(17)    \begin{equation*} \frac {V_o}{V_{in+}} = \frac{R_f}{R_g} + 1 \end{equation*}

To figure out Vo in terms of Vin, we simply multiply:

(18)    \begin{equation*} {V_o} = V_{in+} \cdot (\frac{R_f}{R_g} + 1) \end{equation*}

And that’s the equation of a non-inverting amplifier. Now that we know where that formula comes from and how it’s derived, it’s a little easier to understand the concept of a feedback network. In order to create a voltage at Vin- which is equal to the voltage at Vin+, the opamp has to produce an output voltage  which, when attenuated by the Rf/Rg divider, is equal to Vin+. So, if the voltage divider is set up to output 50% of its input, the opamp has to produce a voltage twice as large as the voltage at Vin+ in order to mitigate it. As such, it is indeed acting as an amplifier with a gain of 2. Likewise, other voltage divider values would produce different gains, as expressed in equation 18.

So now that you know how it works, you should build a couple circuits to try it out. Happy amplifying!

About the equations: the equations here are rendered as alpha-channel PNGs with the WP QuickLaTeX plugin. This is a great plugin which renders LaTeX beautifully and even provides equation numbers. If you want something that will allow you to write nice-looking equations on a blog, you should check it out.


BB313 Pinout Reference Sheet

I created this reference sheet for my BB313 board outlining all the alternate pin functions and descriptions. While I’ve pretty much got the pins memorized at this point (from constantly cross-checking with the ’313 datasheet), I wish I’d thought of this earlier. The sheet is a single-page 8.5×11 PDF, so you can just print it out and keep it for reference at the workbench (or desktop). You can get the PDF, as well as all the project source files, at the GitHub project page.


‘Constant Brightness’ HSB to RGB Algorithm

For an embedded project I’m working on, I had to implement an algorithm to convert from HSB (hue/saturation/brightness) to RGB color values. This is what I came up with. It creates a ‘constant brightness’ RGB value: at full saturation (no ‘whitewash’), only two of the 3 RGB colors are on at a time, and their ‘on’ times are mathematically complimentary (though not phase-complimentary) with respect to the max 255 value.

Increasing saturation will increase the overall brightness of the LEDs, but that is to be expected — for a given maximum magnitude, there is more overall energy in white light than there is in light of a particular color. The saturation calculation works by adding a constant ‘floor’ value to all channels. Individual color values are then placed between this floor and the 255 maximum. A saturation value of 0 results in all channels at 100% duty cycle.

The ‘brightness’ is the last calculation performed. It takes a saturation modified hue value, and simply proportions it to the maximum value. So, a brightness of 197 will output light which is ~197/255 of the maximum output value. Naturally, there are losses inherent to integer arithmetic, but it’s close enough for most uses. Further, the linear nature of the brightness control means it is not ‘gamma corrected’ — that would require logarithmic brightness control which, for what I’m doing, is completely unnecessary.

This algorithm uses no sine tables or floating point math, so it’s pretty fast, though it could probably be optimized to use shifts and adds instead of mults and divides. It’s also relatively small. The code itself is in C, so it can be used on most platforms.

/******************************************************************************
 * accepts hue, saturation and brightness values and outputs three 8-bit color
 * values in an array (color[])
 *
 * saturation (sat) and brightness (bright) are 8-bit values.
 *
 * hue (index) is a value between 0 and 767. hue values out of range are
 * rendered as 0.
 *
 *****************************************************************************/
void hsb2rgb(uint16_t index, uint8_t sat, uint8_t bright, uint8_t color[3])
{
	uint16_t r_temp, g_temp, b_temp;
	uint8_t index_mod;
	uint8_t inverse_sat = (sat ^ 255);

	index = index % 768;
	index_mod = index % 256;

	if (index < 256)
	{
		r_temp = index_mod ^ 255;
		g_temp = index_mod;
		b_temp = 0;
	}

	else if (index < 512)
	{
		r_temp = 0;
		g_temp = index_mod ^ 255;
		b_temp = index_mod;
	}

	else if ( index < 768)
	{
		r_temp = index_mod;
		g_temp = 0;
		b_temp = index_mod ^ 255;
	}

	else
	{
		r_temp = 0;
		g_temp = 0;
		b_temp = 0;
	}

	r_temp = ((r_temp * sat) / 255) + inverse_sat;
	g_temp = ((g_temp * sat) / 255) + inverse_sat;
	b_temp = ((b_temp * sat) / 255) + inverse_sat;

	r_temp = (r_temp * bright) / 255;
	g_temp = (g_temp * bright) / 255;
	b_temp = (b_temp * bright) / 255;

	color[RED] 	= (uint8_t)r_temp;
	color[GREEN]	= (uint8_t)g_temp;
	color[BLUE]	= (uint8_t)b_temp;
}

Amazing Steamed Greenbeans with Mirepoix

Photo enlarged to show deliciousness.

So tonight I made some awesome panko chicken. To go along with it, I made this delicious steamed green bean recipe. I was surprised at just how good it was, so I’m posting it here. You can thank me later.

  • 1 package frozen green beans, defrosted.
  • 1 cup baby carrots, chopped into 1/2-inch discs.
  • 1/2 cup chopped celery
  • 1/2 cup chopped yellow onion.
  • 1 tsp each garlic powder, coriander seed, black pepper.
  • 1/2 tsp. thyme.
  • 1 tsp. unsalted butter.
  • 1-1/2 tbsp olive oil (not extra virgin)

Fill a medium saucepan with about 3-4 cups of cold water.

Place all the vegetables into a steamer and cover with the spices. Drizzle the olive oil over the veggies and then toss the mixture a few times until the vegetables are evenly coated. Place the pat of butter on top of the vegetables, and put the steamer on top of the saucepan.

Set the burner to medium-high and let the water come to a boil. Open up the steamer and toss the vegetables around a bit. Depending on the steamer and what kind of heat ‘medium-high’ corresponds to on your stove, it should take about 8 minutes. Basically, you want to stop the process when the onions are translucent and the carrots are just tender (but not mushy).

Turn the heat off, strain the excess water from the vegetables and serve.


BB313: A Breadboarding Platform for the ATTiny2313/4313

A little over a year ago, I started playing around with the newly available AVR ATTiny4313. It’s a neat little chip, and you can have a lot of fun with it. However, I soon got tired of wiring up programming headers, power supplies and all the other stuff you need to get up and running. I also grew wary of all this support circuitry taking up significant breadboard real estate.

To eliminate all that hassle, I created the BB313. It’s got all the stuff you need (programming header, regulated 5V power, etc.) wrapped up in a nice little package, and it plugs in on the edge of the breadboard so you have lots of space for other stuff. I also added an 6-pin connector for an FTDI cable or adapter.

I originally designed it for myself, but I figured other people might like it too, so I’m releasing it open-source CC-BY-SA 3.0) so you can make your own.

All the details and source files are at the project page. If you find it useful, please let me know!

You might also find the following items useful:

USBtinyISP programmer, FTDI friend, and 9V switching power supply, all available from Adafruit Industries in NYC.

 


New Tumblr: Installation-A-Day

A couple weeks ago, I started a new tumblr, Installation-A-Day, to showcase neat art installations I come across in my travels. You can also follow it on Twitter. It’s still in the formative stages, so any feedback is appreciated. I’m trying to be democratic about what I post there — basically, I just want to showcase people putting themselves and their ideas out into the world. Lots of people have cool ideas, but not everyone has the resources to make slick, DSLR films about them.

I hope you check it out and enjoy it, and maybe even submit your own work.


The Future of Drones…

My friend Phil loves to talk about drones. There will be drones in the future, he says: drones will deliver the mail, drones will be used to gather news, etc. He sure does love them drones. So here’s a list of a few things I think drones will do in the future.

Drones will…

… direct traffic: There is an accident or fuel spill or something on a highway. The police car rolls up: now the officer has to investigate the situation _and_ control/avoid the traffic at the same time, or wait for a second officer to show up. In the future, a drone — launched from the roof of a police car or emergency vehicle and equipped with a suspended blinky sign — will hover in place keeping traffic a safe distance away. The message on the sign will be remotely controlled by the officer (who can update it in real time) and it will tell you what’s going on: “keep to the left” or “slow down, accident ahead” or “oil on roadway: proceed with caution”, etc. They could also provide temporary traffic signals in the case of a power outage, where the regular stoplights might cease to function.

… help firefighters working structure fires: Drones will go airborne and scope out a burning building from above, allowing a bird’s eye view of the fire and helping track how it spreads. A camera (possibly IR) feed relayed to the ground will be useful in detecting an impending roof collapse or locating trapped survivors that the firefighters on the ground cannot see. These drones might also carry grappling hook ropes into position, to aid in either pulling a building down or providing an escape route. In addition, they will…

… be equipped with powerful lights. This can be used in emergency situations for lighting large, outdoor areas quickly. It can also be used by filmmakers and photographers to provide high-angle focused or diffused light sources. I can’t tell you how many shoots I’ve done where I wished for an easily positioned (and controllable) overhead light.

… build sandbag levees: Heavy-duty drones will be given the repetitive and arduous task of building sandbag levees before an impending flood. Structure building drones already exist, and this is a natural extension of such capability. This frees up human volunteers to concentrate on other areas, such as evacuation.

… clean windows on the upper floors of buildings: because it’s really cold up there.

… transport clean water: one of the biggest problems in developing countries is the lack of fresh, clean water. Contaminated or dirty water causes all sorts of diseases, including dysentery, but often sources of clean water are a day’s walk away or more. Sometimes pipelines are not an option either, due to geography or other barriers. Water-bearing drones (“aquarians”) can be used to carry water from the clean sources to the people who need it.

… decorate very large Christmas trees: in my lifetime, I expect to see the tree at Rockefeller Center get this treatment, after which I will eat some astronaut ice cream on my hover-yacht, while watching my totally open-source TV (because it’s the future, yo).

… inspect high-tension power and telephone lines: this is currently done by people in helicopters, and it is quite dangerous. Drones don’t care, because drones are fearless.

… deliver takeout food: until we get widespread replication technology, we’ll have drones. Drones are naturally suited to delivering small, uniform packages (like Bento boxes, for example). I imagine something along the lines of the Indian Dabbawala industry, which is a vast delivery network for lunchtime food that uses uniform payload containers and an efficient routing system to make the rounds. Eventually, your lunchtime lo mein will eventually be delivered to you by an autonomous flying robot.

… chase away birds at airports: birds getting sucked into jet engines poses a serious safety risk, particularly on takeoff and landing. This problem is currently dealt with by using decoys or actively hunting the birds. A squadron of drones could be useful flying around in pseudo-random low-level patterns and generally creating an unfriendly environment for the birds.

… become integral tools of augmented reality: I’ve had this idea kicking around in my head for a bit about using drones for augmented reality. The Parrot AR (in all its photo studio glory, above) is one type of ARdrone — the HD camera and smartphone control allow you to augment your reality by giving yourself a new point of perspective. My idea is nothing like that, really. Rather, I’m imagining fog machines mounted on drones (downdraft turbulence problems anticipated). There’s one set of drones which drop a sheet of fog and emit sound, and another set which projects images or movies onto said fog sheet. This means you could deploy actors anywhere on earth, and have them play out some narrative. For whatever reason, the spark for this idea was the Marty Robbins song El Paso*. I imagine an army of drones playing out this whole tragedy across the breadth of the West Texas desert. First in the cantina, where we see the dancing Falina in her grand dress and the gunfight, then the subsequent flight across the desert, and finally (dramatic pause) the inevitable return and puff of smoke from the fatal shot. This idea in particular has the potential to go from avant-garde to mass production very quickly.

Now, obviously, we need to refine drone technology a bit to accomplish a lot of these things. For example, current (affordable, non-military) drones are not stable in high crosswinds. For the firefighting example above, they will also need to be stable in the presence of strong thermal updrafts and higher temps. In the case of the levee construction drones, they will need to be able to operate in the rain as well, and lift loads upwards of 50 pounds. I’m confident all of these problems will be solved, though, because the initial research cost pales in comparison to the savings and efficiency increase, as well as added safety. So there you have it. If you have your own ideas about things drones can be used for, post them up in the comments!

*this is a great song musically, and the lyrics are well-written, but I could do without the ‘woman as evil temptress’ trope.


Oscilloscope Christmas Tree

When I was a little kid, my dad worked at Bell Labs. Every year around Christmas, we’d go visit him at work. One memory which has always stuck with me from my holiday visits was seeing a Christmas tree on an oscilloscope. I was pretty amazed by it. Engineers are a funny bunch — they tend to celebrate holidays in the most uniquely nerdy and wonderful ways, just like kids. When I recently acquired a new ‘scope and wanted to familiarize myself with it, I knew exactly what my test circuit was going to be.

In honor of the nameless BTL engineer whose scope scribbling captivated me as a child, here we are. Maybe the same thing will happen for some other kid. There are a lot of holiday parties coming up. You could put this on one of your scopes at work or at your hackerspace, and some other kid will see it, and it’ll fire their imagination too. It looks pretty neat at any rate, and it’s downright fascinating after a few fortified egg nogs.

While I suspect the original was built with 74xx logic circuits, or maybe a couple 555′s (you could easily make a Christmas tree shape by combining triangle (x) and sawtooth (y) waveforms), this one uses an AVR ATTiny2313. (I used my handy BB313 board). You could do this with an Arduino too (that is covered below) — pretty much anything that has an 8-bit timer with dual PWM outputs will do the job. The discussion will apply regardless of the implementation (though the numbers might change).

Before you continue, bear in mind that I assume you already know how to use an oscilloscope: how to attach the probes, adjust the voltage ranges, put it in XY mode, etc.

The ATTiny code is here, and this is the schematic for the circuit:

How it works:

The PWM outputs feed two RC low-pass filter circuits, with a time constant chosen to effectively suppress the jitter from the rectangular waveforms. The PWM outputs (and hence the DC components of the signals) jump from one point in the drawing to the next; in order to actually draw lines to make the tree shape, you have to interpolate between those points. The delay between one ‘drawing’ point and the next has to be chosen to allow the charge/discharge curve of the RC circuit to do the interpolation. You’ll notice in the photo above that the ‘straight’ lines are slightly curved. This is the because the jumps in x don’t quite equal the jumps in y. You’ll also notice that the tree appears a bit crooked. This is the result of the RC curve not settling out completely before the next transition — the voltages never quite get to where they’re supposed to go before they switch to a new value. Personally, I rather like these imperfections — the tree has a hand-drawn quality to it, like a homemade ornament. You could make the lines straighter and the drawing more uniform by using a longer delay, but it will lower the overall refresh rate, resulting in noticeable flicker. How you draw your oscilloscope Christmas tree says a lot about your personality.

The ATTiny’s clock is running off of a ceramic resonator at 16MHz. The PWM frequency is 16MHz/256 or 62.5kHz. The corner frequency of the filter is 160Hz, which is about 8.5 octaves (2.5 decades) below that. I used 10k resistors and 0.1uF caps here — you could also use any other “equivalent” RC combo (100k/0.01uF or 1k/1uF, etc.) If you choose to use a chip with a different clock frequency, then you’ll have to adjust the RC circuit accordingly.

Reducing the capacitor values (or increasing the resistor values) will shift the corner frequency of the filter up, and you’ll start to see the lines get crooked, like resistors in a schematic. These are triangle waves resulting from filtering the rectangular PWM signal. This can look pretty cool too, actually, as below where I switched to 0.022uF capacitors.

Now the tree has needles, and all it took was changing the coefficients of a partial differential equation — easy! (this might be a great way to introduce a kid to the concept of filtering — just sayin’).

Arduino Implementation:

Doing this on an Arduino isn’t much different than using the ATTiny, except that it’s more expensive and instead of a real schematic, you have to read this ridiculous handy cartoon (above).*

The Arduino code is here. It uses no libraries, so all you have to do is extract the folder into your Arduino directory, set up your oscilloscope and load the sketch.

Possible alternative methods:

  • If you really, really want a perfect, orthogonal tree, you can use an R2R ladder or dedicated DAC/soundcard to generate the control voltages.
  • You can get straighter lines if you use a current mirror to feed the RC circuit, thus making it a “true” integrator with a straight-line slope.
  • If you want to increase the refresh rate, you could set an upper limit on the 8-bit timer to a lower value, say 64, and set all your points therein. Note on the ATTiny you’ll probably have to do this using an interrupt from the other timer, but it would give you faster PWM output, which means you can use a smaller filter time constant and thus a higher refresh rate.
  • …or, you could overclock the AVR (you know you’ve always wanted to).
  • As I mentioned in the beginning, you might be able to do something like this with a couple of 555′s generating triangle and sawtooth waveforms. If you get their phases matched correctly and with the right frequency ratio, you could have a pretty nice looking tree!

Be as creative as you like with it — I hope you enjoy making it work for you.

Merry Christmas!

*just kidding — I love Arduino! Buon Natale!

 

UPDATE – Several folks have done this themselves and written in:

EmbeddedEric did an awesome Frosty the Snowman with his daughters.

aussie_nick did one using a DSO.

Goran did one for the Calgary On-Air Engineers.

Gordon Pearce took it to the next level with animation using sine functions:

Nice!


Showing Off My Halloween Project On Tonight’s @adafruit Show+Tell

Behold, the Auto-Loupe!

This is my latest project: part Halloween costume, part optics hack, and part embedded mechatronics, I call it the Auto-Loupe. I’m showing it off tonight on Adafruit’s Show+Tell show, and will be documenting it over the coming weeks.

Tune in and check it out!