Rotating Sprocket Wheel GeneratorBackgroundMy friend Arthur, in his lifelong quest for circuits that don't really do anything useful, but are really neat nonetheless, built a really neat Lissajous pattern generator. This Lissajous pattern is not your traditional circle, oval, or figure-8, it is a circle with varying amplitude, in a pattern that makes it look like a sprocket. Not satisfied with that, he also made it so that the sprocket rotates. An interesting side-effect is that this circuit very clearly shows some of the shortcomings of digital oscilloscopes. Whenever an oscilloscope salesman comes around, he whips out this box with a switch and 2 BNC jacks. It has been known to render speechless the best salesmen from HP and Tektronix. They usually dismiss it as a toy, but I think that is just because they have to follow the party line: Analog scopes are dead. I have seen a digital scope or two accurately mimic the analog, most notably the Digital Phosphor scopes from Tektronix, but in general, the RSWG breaks digital scopes. I moved to another job about 1500 miles away from where Art spends his time being surly, making cool circuits and serenading passersby with his Theremins. After a short time at my new lab I was called upon to specify some oscilloscopes. I decided that I needed my own RSWG. Arthur has been so kind as to publish the schematics and theory behind his RSWG. His circuit works great, but it is pretty complex, and the construction would tax my patience, since he has managed to construct his RSWG with nothing but discrete ICs and a handful of ancillary components.
The CircleFirst of all, I had to see if I could even draw a simple circle on the oscilloscope screen. To do this, you must put out 2 sine waves in quadrature (a fancy term for 90° out of phase). When you feed these two waves into the X and Y inputs of an oscilloscope, you draw a circle on the oscilloscope's screen.
The 16F84 has 13 outputs. All 13 can serve as inputs, but only 12 are normal outputs, one is an open-drain. An open-drain output has no active pull up- you have to provide an external (passive) pull up. Since the 'F84 is CMOS based, this leaves us 12 outputs that have good, low impedance 1's or 0's. We want two channels, 12/2 = 6 bits/channel. Using the rough approximation of 6 dB/bit, 6 bits/channel * 6 dB/bit gives us approximately 36 dB/channel of dynamic range. This is still very visible on a scope, so I needed some filtering. I put this all together, and spent some time banging out the PIC assembly code to generate the quadrature sine-waves. To make it simple, I decided to use look-up tables to generate the waves. PICs are 8 bit RISC microcontrollers. They have a lot of limitations, one major one is that you can only do a 254 element look up table without pain. To generate two sine waves truly in quadrature, I had to offset the two sine-wave look up tables by 25% of their full length. It would have been really easy if I could use a 255 element look up table, since 255/4=64. The next smaller number that is a multiple of 4 is 252, so I decided to use a (63*4=) 252 element table to generate the quadrature sine waves. I wrote a spreadsheet to generate the values I needed for these lookup tables, packing them together because of the organization of the output registers on the PIC. I'm using bits 5-0 of port B for one channel, and bits 3-0 of port A, and bits 7-6 of port B for the second channel. This is 12 bits of information, so I made 2 look up tables, one lookup table for port A, the other for port B. This is a bit inefficient in terms of memory use, but it is quick.
Raw, the output of the R/2R D/A converter is still obviously quantized. I added a single pole passive low-pass filter to the output (a simple RC filter, where f(3dB)=1/(2piRC). After this simple filter- the circle was perfect as far as I could tell from the oscilloscope. Success.
The TeethNow that I had the circle, I needed to add teeth to make it a sprocket wheel. Since I wanted to keep the parts count low, I wanted to keep any amplifiers out of it. At first I thought I could use the open-drain output to pull the output down- well there's a problem with that approach. The open drain only pulls the output down to ground in one direction, down to ground. The sine wave is centered around a value, the value that I would get if I was to integrate wave over a single period. I need to attenuate the wave with respect to that value. Secondly- the output of the R/2R D/A converter is pretty high impedance. Without any impedance buffers, I would have to make the impedance of the first filter much higher than the impedance of the D/A converter. Any networks that followed the first filter would have to be even higher impedance still. I didn't see any easy way around these problems without adding more active devices.Since I had to add some amplification, I decided to make things easy and use op-amps. First I needed to place the output of the R/2R D/A converter at a voltage in-between the rails of the op-amp. Using a capacitor and a resistive voltage divider is the most traditional way. But I already had to use a resistor and a capacitor in the low-pass filter, so why not "split" the capacitor and use it to serve as the divider? It works great, and performs two functions (low pass and voltage divider) for slightly more than the effort of one (adding a capacitor). To actually generate the teeth I used the only I/O pin left, the open-drain, with a pull-up resistor. This goes to the control input on a 4066 bilateral switch. The resistor between the op-amps does nothing while the switch is open, but once it is closed, it serves as one of the resistors of a voltage divider. I decided that I wanted the tooth height to be one sixth of the radius of the circle. To make that so, the resistors have to be chosen to fit this equation 5/6= R30||R29/(R30||R29 + R26). Since the voltages are centered around 2.5V, R30 must equal R29. If we set R29=R30=100K, R26=10K.
![]() I started out with a 252 element look up table, but I ran into a problem- you can't divide a power of 2 into 252 that will leave us with a reasonable number of teeth. I really needed to have a 256 element look-up table, but that wasn't going to happen because of the architecture of the PIC, and my need for speed. I decided to change the size of the lookup table to 128, but put each element out twice. That way I could just key the tooth output off a single bit of the counter that keeps track of the pointer into the look-up table. Now that the tooth generation was complete, I measured the actual output frequency of the RSWG. I needed this to calculate the component values for the low pass network. I measured the outputs of the RSWG to be approximately 260 Hz. For convenience sake, I chose to use 2 0.01uF capacitors as the voltage divider, since I have a far better selection of resistors than capacitors. Plugging these into the equation F=1/(2piRC), and solving for R, R=1/(2*3.14*260*[0.01uF+0.01uF]), R=30.6K. 30.1K is a convenient value, so I went with that.
I mentioned up above that the Tektronix Digital Phosphor Oscilloscopes were pretty good at emulating an analog scope. I recently had the opportunity to evaluate one of their scopes for a few hours and was able to get these screen captures. This is one of the nicest features- the ability to go to a computer viewable image. First, here's a picture of the sine wave as generated by the circuit (after low pass filtering). Here's a picture of the sine wave with the tooth modulation. A picture of two waves in quadrature with the tooth modulation. Finally, a picture of the sprocket as rendered by the DPO.
Below I have links to a GIF file and a postscript
file that give the full schematics of my RSWG. Schematic
GIF file of RSWG schematic
Source
Parts
Used Part Type Designator
==== ========== ====================
4 0.01uF C1 C2 C5 C6
3 0.1uF C7 C8 C9
4 100K R27 R28 R29 R30
4 10K R25 R26 R31 R32
1 10MHz X1
1 16F84 U1
3 1N4007 D1 D2 D3
10 2.55K R15 R16 R17 R18 R19
R20 R21 R22 R23 R24
2 22uF C10 C11
2 30.1K R33 R34
2 330pF C12 C13
2 33pF C3 C4
2 4066 U3 U5
14 5.11K R1 R10 R11 R12 R13
R14 R2 R3 R4 R5 R6
R7 R8 R9
1 9V B1
2 BNC J1 J2
1 LM2940-5.0 U7
1 LM324 U6
Here's the actual circuit, as I constructed it, but without the BNC jacks
and 9V battery. I did not try to conserve space here, though obviously,
I could have. In the upper left you can see the power supply circuitry.
Directly below the power supply is the PIC and its crystal. The R/2R resistor
ladders are dead center, and the op-amp and 4066 are on the right side.
Back to projects page Back to Matt's Page This page was last modified 223 weeks ago, on Wed Aug 18 2004.
All information contained on this page is © 1999, Matthew J. Bennett, and may not be reproduced, archived, mirrored, bought, sold, or bartered without express written permission of the Author. |