Fast DDS with ATmega88

I’m planning to make some RFID hacking in near future using 150 kHz tags. Since I don’t have a signal generator, I decided to go where quite many people have gone before and build myself one, more specifically a DDS. Instead of just taking a complete project from the net, I thought this would be a good way to learn a bit of AVR assembly programming, and manual D/A (digital to analog) conversion using R-2R ladders. Here’s what I built:

I’m skipping the schematic to save some time – basically it’s a ATmega88 with 6-pin programming header, power, a 16 MHz crystal (other frequencies also work, lfuse for this setup if 0xFF) and a red LED that is not used. The R-2R ladder is wired with white jumper wires to PB0-PB5 (it’s a 6-bit DAC) so that PB0 is the “least significant bit” and PB5 the most significant one. Read on for details.

R-2R ladder in brief

The analog to digital converter in this project is a R-2R ladder built from 10 kOhm (R) and 20 kOhm (2R) resistors. By providing GND/VCC to the points a_{0}..a_{n-1} (see the diagram below), a voltage between GND and VCC * (1-1/2^n) can be seen at V_out (in this example n=6 and V_out can reach 63/64 of VCC).


(from Wikipedia R-2R article, licensed under creative commons, author Lsibilla)

If you want to check that it actually works, you can start with 1-bit version and easily see that when a_0 is 0V/5V, V_out is 0V/2.5V (5*(1-1/2^1)). If you derive a Thevenin equivalent circuit for this, you get one with 0/2.5V voltage source and 2R resistor in series. By adding another bit to this equivalent circuit, you can verify that the 2-bit version works also and it’s Thevenin equivalent resistance is also 2R – and by induction, you see that after any number of bits, the resistance stays at 2R and voltage is:

1/2 * a_{n-1} + 1/4 * a_{n-2} + … + 1/2^n * a_0

Read post

Weller Magnastat Autopsy and Repair

Immediately after soldering together my USB password thingy, my solder iron, the family heirloom Weller Magnastat stopped working. Some investigation showed that the base station was providing 24V AC voltage just fine, so I decided to unassemble the handpiece to see if something could be done. Here’s what I found:

It turned out my iron was salvageable; read on to learn a bit about the Magnastat and how I was able to repair mine.

Magnastat basics

The construction of the device is surprisingly simple (see this image): The first (blue) wire from A/C power unit goes straight to the heating element (first red wire with black tube around it). The second (black) A/C wire goes through the magnastat switch (brown and green wires) and then to the second heating element wire (second red wire without the black tube). A capacitor is wired parallel to the switch. With limited A/C experience I’m not sure if it’s for blocking DC current, smoothing the switch action or letting a small amount of A/C current through.

A long tube goes “out” the handle part into the iron tip, and the tip is placed at the head. The hollow tube above the tip is then placed over the tip and screwed to the base of the main assembly to keep the tip snugly in place. Here’s a diagram of the inner workings, from Cooper Industries’ website:

If you read a bit about the Magnastat, it turns out the temperature-controlling part, the “magnastat”, behind the tip is magnetic below a given temperature, and loses its magnetic properties above that: Initially the magnastat pulls the switch closed via a mechanism inside the long tube, but once desired temperature is reached, the magnetic property is lost and the switch opens. Once the tip cools down a bit, switch is pulled closed again, and so the temperature stays regulated.

Note that in my model the tip and the magnastat are one solid piece (magnastat is in the base of the tip), newer models have a separate magnastat and tip, and you can change the target temperature just by changing the magnastat part.

Read post

DIY USB password generator

Having done half a dozen V-USB tutorials I decided it’s time to whip up something cool. As USB keyboards were an area untouched, I decided to make a small USB HID keyboard device that types a password stored in EEPROM every time it’s attached. A new password can be generated just by tabbing CAPS LOCK a few times (4 times to start password regeneration and one tab for each password character generated, 10 is the default password length). Below you can see the device in action:

The place I work at requires me to change my password every few months so this would be one way to skip remembering a new password altogether (as long as I remember to write it down before regenerating a new one so password can be changed :).

What is inside?

The device is powered with a simplified version of the hardware I used in my ATtiny85 USB tutorial – I stripped away the LCD, reset pullup and both capacitors. If you’re better in cramming components inside enclosures I suggest adding at least a 0.1 uF capacitor between VCC and GND, but it seems to work fine even without it:

Read post

DIY resistor folder for 9.90€

If you’ve done even a bit of electronics, the chances are that you’ve already amassed a hefty collection of resistors. Buying them is fun but finding the right values from a stack of resistors is not. I noticed that you can buy actual “resistor folders” with nice labels and the full E24 series of 1500 resistors for $100. I already had resistors so I decided to make my own folder with less expense.

I walked into the nearest book store and quickly found a promising offering: 10 transparent plastic sheets of “collectible card holders” for about 3€. Any store having binders and associated supplies will probably have something similar. I also bought a thin A4 binder and 200+ label stickers for about 9.90€ total (about 1:1 to dollar prices). Here’s what I came home with (already added the stickers):

Each sheet had 9 pockets so for 3€ I get storage for 90 values, and 10-20 resistors fit into a pocket without making the page too heavy. I labeled the first 72 based on my E12 series and that left me with 2 extra pages for “exotic” resistor values. Here’s the first page of E12:

Read post

V-USB: Outputting Data with usbFunctionRead()

I promised to commenter Marek to post an example of using usbFunctionRead() to return larger amounts of data. So building upon the ATtiny85 version we made in last part, let’s add one more command to usbtest.exe:


#define USB_DATA_LONGOUT 5

// [...] Change the buffer size in main():
    char buffer[2048];

// [...] Add the following in the if-else structure in main():

    } else if(strcmp(argv[1], "longout") == 0) {
        nBytes = usb_control_msg(handle, 
            USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 
            USB_DATA_LONGOUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
        printf("Received %d bytes: %s\n", nBytes, buffer);
    }

Now let’s tell V-USB that we’re implementing usbFunctionRead() and doing transfers of more than 254 bytes in usbconfig.h:

Read post

7 Segment Multiplexing With ULN2003 & PNP Transistors

The reason a started my electronics hobby was that I wanted to build a chess clock. Lacking a proper LCD display, I chose to multiplex several 7-segment displays. Most sources in the net did not specify hardware at all, and those that did were driving the segments with a 74HC595 shift register and using NPN transistors to enable one common cathode display at a time. However, if you look at 74HC595 specs you’ll notice that it’s not designed to source the amount of current that is required to drive several multiplexed 7-segment displays. It might work, but no one can say for how long!

It took me a while to find a good, inexpensive and readily available alternative. I finally found it in ULN2003, which is inexpensive darlington array that can drive 500 mA from each of its pins. So I decided to write a little tutorial on 7 segment multiplexing that walks through all the needed hardware and software in detail. Here’s what we’ll build (click for a larger image):

For this tutorial I assume you know how to connect ATtiny2313 to a programmer and flash it with custom software. You’ll learn as much in IMakeProjects.com’s AVR tutorial. You’ll also need the following components:

Read post