Saturday, May 19, 2012

DIY Audio Function Generator Part 2

This is going to be a pretty short post, but I just wanted to give an update on the DIY Function Generator project I am working.

You can check out Part 1 here: diy-audio-function-generator-part-1

I started to pull together the Schematic and PCB Layout for the board in DesignSpark. I've kind of cheated a bit and just thrown parts in the schematic and passed them through to the PCB Layout side of DesignSpark without connecting anything up yet. I did this just to get a jump start on the "look" of the layout and match it up to my concept drawing.



Next I'll go back to the schematic and start connecting things up.

I have appreciated all the supportive comments and feedback I have received about this project so far.  James Grenert was kind enough to email me an old Elektor article from Nov. 1994 that has a very similar Lamp Based Wien-Bridge Oscillator Circuit as the Jim Williams one I am using as a basis for this Function Generator.

Below is the article (Note this was Google-translated to English from the original German article, so there are some miss-translated words... but it is still very readable)


SPOT-SINUS GENERATOR – ELEKTOR 11/1994

SIMPLE AND LOW DISTORTION

Oscillators come in many shapes and varieties, each with its own specific characteristics. A type known for its beautiful sinusoidal output signal, the Wien-bridge oscillator. Here we describe a repackaged in a modern implementation, as a special old-fashioned method of keeping the amplitude constant. Perhaps nowhere as electronic engineers have been as creative in the design of oscillators. For each specific application there is a suitable type oscillator. There are RC, LC and crystal oscillators, high-and low-frequency oscillators, low-power vermogensoscillatoren. Do you want a rectangle, saw-tooth or sinusoidal signal? You name it. Or variable frequency oscillator, the modular-be? It's all or is in any case to make. For the testing of audio equipment is often a source who need a nice clean sine supplies. The best is of course an adjustable version, but also a fixed l-kHz generator is a very useful tool, but as long as the signal produced is low distortion. An oscillator type here eminently suited for, is the classic Wien-bridge oscillator.

The Wien bridge consists of a combination of an RC network and a series-parallel RC network. The two resistors and two capacitors have the same value. At the central frequency, the phase rotation is zero, because the two networks have equal phase shift, but in opposite direction from each other. The slowdown amounts to three times at that time. So by, as drawn in Figure 1, a simple 3x-amp to add to the circuit can oscillate.

Filament-SYSTEM

Two RC networks and an amplifier stage, which is all we need for a sinus generator according to the Wien-bridge recipe. That sounds simple attractive, but due to the fact that in this case more than average demands on the shape of the produced sine up, there are a few points that deserve special attention. Thus, the amplifier used must be of impeccable quality. Furthermore, a sophisticated control system is desirable, which ensures that at all times there is enough gain to oscillate to launch and maintain, but simultaneously prevents the amplifier at any time could be overdriven. That would be the desired waveform fine because irreparable damage.
The first of the above issues can be resolved as a good opamp amplifier to apply. The second point, the control shows fine in practice achievable with the help of an ordinary incandescent bulb.

The actual Wien Bridge here consists R1, R2, C1 and C2 is at a frequency of 1 kHz dimensioned. The two resistors are 1% types. The MKT-capacitors C1 and C2 you will have them selectable on a tolerance of less than 1%, otherwise the chances that the circuit is not oscillating. Would you exakte a frequency of 1 kHz, these must also capacitors a value of 119.67 nF.

If amplifier is an OPA627 opamp of the type used. The reinforcement is required, as said, about a factor of three and this is also the dimensioning of the network against link P1/R3/R4/La1 tuned. What is the function of La1? Well, that bulb plays here the role of PTC. Because the filament has a temperature dependent resistance, cold state, the resistance around 25 Ohm in warm condition that value is a factor two higher. This property is gratefully used here, by the light directly into the network to flock to incorporate. Is it cold light, then the strengthening of IC1 mainly determined by the ratio between R3 and R4. Is the output voltage however, it increases the flow through the network and torque against the resistance of La1 far. The ratio of the network will change, such that the coupling increases and against the strengthening of IC1 (and hence the output voltage) decreases. This in turn is the current through the LED, so the versterkins of IC1 increases something ... etc., etc. Of course, after a short time balancing act, so the output voltage to a stable value remains "hanging".

To balance it in the lower branch of the torque against network using standing lamp is in the upper branch instelpotmeter one (P1) included. This is a fine adjustment of the "balance point" as possible. Furthermore, a system as stable as possible to get an additional current drive of the lamp used in R5. The latter resistance will be slightly adapted to the type of bulb used. In our prototype showed a value of 3k3 for R5 properly comply. Shows the output voltage in your case after a few minutes to run something, it's wise to R5 what value should be reduced. A decreasing output voltage requires slightly larger value of R5. As a matter of experimenting so!

SPEC'S GOOD

The presence of the light was of course necessary to the relatively low-ohmic resistors around IC1 dimensioning since there will be a reasonable flow through La1 flow to the PTC effect noticing. Such dimensioning impedance has the advantage that the noise contribution of the resistors is very low. This does have an opamp as konsekwentie that should be applied in a symmetrical supply voltage of + / -15 V can control at least 600 ohms.

The OPA627 is against this type of task more than cope and provide for an opamp with FET inputs also a very low input noise (5.6 nV / sqrt (Hz) at 1 kHz), low input offset (100 μV max) and an extremely low distortion. The actual THD consists solely of the second and third harmonic, which together no more than 0.00014% size.
Unfortunately, the relatively expensive OPA627 opamp. If you have no problem with a slightly higher distortion, then instead of this type is also a cheap (pin-compatible) NE5534 be taken.

CONSTRUCTION

Given the simplicity of the circuit is deliberately refrained from a print design. The title picture illustrates the sine generator to a fairly simple piece of plate hole is to accommodate.

Since the current consumption of the circuit is limited to approximately 10 mA, the (balanced) diet very modest in scope. The smallest transformer that delivers 2 x 15 V, a three-legged brugcel and two controls (78L15 and 79L15) will ease this chore done. Very suitable in June '92 Elex described "low-power balanced diet", which number 926,061 are still in print in the Elektor service available.

The adjusting of P1 one must take time. In practice, it proved beneficial to those in instelpotmeter to maximize output voltage. This yielded the lowest distortion, and so also prevents the output voltage after the adjustment of the system to an unexpected (and unwanted!) High value would increase.

Specifications
frequency: 1 kHz
output voltage max: 8 VRMS
Distortion (THD + noise): <0.0003%
voltage: 15 V V/-15
current: approximately 10 mA




Saturday, May 5, 2012

RF isn't Black Magic

Most people in the Embedded Electronics world view discrete RF Design as "Black Magic". I would agree RF is complicated, but it isn't Black Magic. The magic is that when you are dealing with signals in the RF frequency range the "small things" matter; my little experiment below proved that to me yet again!

I was inspired by VK2ZAY's LC Test Oscillator video and wanted to build one of my own. After a couple hours playing with LTSPICE, I soldered up a board and powered it up expecting to see a 50MHz sine wave on the output and I got nothing...
Now is when the learning started! I first checked all my JFETs DC Biasing and I was getting the expected current through all of the source resistors, so I knew my JFETs were On and ready to start amplifying. I then started to suspect my inductor. I was just using a small power inductor meant more for switching power supplies than a RF Oscillator. After kicking open my RF Circuit Design Book (which is an excellent book on discrete RF design) I had a hand wound air core 220nH inductor made for the LC Tank circuit and still nothing.....

I started to suspect my low cost capacitors I bought from a Thailand based supplier, so I bought an LCR Meter and checked them. They all measured to the right value...... Why isn't my RF Osc. Oscillating?

The last thing I tried was changing the capacitor in the LC Tank circuit from a through hole ceramic cap to two 1206 surface mount 470pf caps in series to get 235pF. I powered up the circuit and there was a beautiful 24MHz signal showing up on my scope. So the surface mount cap in the LC Tank circuit fixed my dead RF Oscillator, but why?


Just for kicks I hooked up a  through hole 10-120pF variable capacitor in parallel with the two series 470pF caps thinking I should now be able to adjust the frequency of the LC Tank circuit a bit. When I adjusted the variable cap the frequency stayed at 24MHz... that is when the light bulb came on. The through hole caps I was using weren't working because their lead inductance was preventing them from being "pure" capacitance in the LC Tank circuit. It makes sense now, I am dealing with a small amount of inductance in the tank (220nH) and any added inductance in the capacitor's leads are preventing the capacitor from working in the Tank circuit.
This was a pretty fun project. I've build opamp based oscillators before, but there is something satisfying about building something up with only discrete Transistors and passives and getting it to work!

Here is a link to my LTSpice File


Sunday, April 29, 2012

DIY Audio Function Generator Part 1

Most of my Blog posts involve short 3-4 hour projects/hacks that I just build up for learning and fun. I thought it was time to develop something a bit more involved and share my design process in a series of posts over the next few months.

I have lots of test equipment in my home lab from O-scopes, RF Signal Generators, a Spectrum Analyzer, RF Power Amps to a slew of Multimeters and DC Power supplies, but one piece that is missing is a simple low end Audio Function Generator. I searched eBay and anything worth wild was in the $200+ mark and to be honest I wasn't that impressed with their specs. Most $200 Function Generators only have a Sine Wave output spec'd at 1% THD....... 1% is ok for most uses, but I just got done building up Jim Williams Wien-Bridge Osc. and was able to get 0.024%. I want to be able to use the Sine Wave output to test ADC resolution and as a base band signal for RF projects and having very Low Total-Harmonic-Distortion (THD) would be nice.

So I've decided to build my own Function Generator. Most DIY Function Generators I found online start out with a Square Wave Oscillator feed into an integrator to get a triangle wave, then you feed the triangle wave into a wave shaper and you get a rough Sine Wave output. This is similar to a project I built up last year.
 
This method works, but the wave shaped Sine wave isn't going to have the low THD I was looking for, so I am taking the opposite approach and starting with a Sine Wave Generator based on the #327 Lamp Wien-bridge Circuit to get the low THD. I'll then feed that into a Comparator to produce the Square wave; I am then using the Square Wave to turn on/off a ramp generator circuit. I would rather have a ramp output vs a triangle wave. The ramp circuit will let me play around with different single & dual slope ADC concepts later on.

Below is a block diagram of my proposed design:
I've added a +3.3V Square wave output to be feed into a frequency counter, so I don't need to bother to add a display to the function generator. Mine as well make use of the Frequency counter I have for a display, also having a +3.3V square wave output would be nice for any micro projects later on.

I'll have a Freq. Adjust Pot, Freq. Range switch, Ramp Current Source Adjustment Pot, and an Output Amplitude Adjustment potentiometer. Below is a rough layout of the proposed design:

I really like the layout of the CEE Source Measurement unit, so I'll be mounting the PCB in a similar looking plexi top and bottom when it is all done.

After sketching out the concept drawings my next step was to test the Wien-Bridge Oscillator circuit I was basing this whole design around. I prototyped up the circuit with the Frequency Range Select switch and 10K pot and was pleasantly surprised to see everything worked well.


The three switch selectable frequency ranges I have are: 16Hz to 600Hz, 160Hz to 6kHz, and 1.6kHz to 60kHz with the 10K potentiometer adjusting the output frequency continuously through the ranges. The one downside with this Lamp based implementation is there is a settling time of several seconds needed after each major adjustment to allow time for the Lamp to thermally settle.... this is an ok tradeoff for me given I should be able to achieve very low 0.05% or lower THD.

The next step was to draft up the rest of the circuitry in LTSPICE to see if I could create the Square Wave and Ramp functions successfully.
After an afternoon of playing I settled on this circuit. It works well in simulation and now I'll have to build it up and see if it works for real.

Here is a link to the LTSPICE file:
A Link to the LTSPICE OSC file:

More Testing, DesignSpark PCB Layout, and prototyping to come...........................


Friday, April 6, 2012

Vichy DM4070 LCR Meter Teardown

A few weeks ago I was inspired by VK2ZAY's LC Test Oscillator video and wanted to build one of my own. So I jumped on ebay and bought a handful of J310 N-channel JFETs and started up LTSPICE to get a circuit sketched up.
The circuit simulated well and I jumped into prototyping.
Well long story short I couldn't get it working, so I started to suspect the inductors and caps I was using. The caps were el cheapo ebay bought parts and were shipped from Thailand, so I had little confidence they would hold up at 50MHz, also the inductors I was using weren't really suited for RF frequencies so I hand-wound my own aircore inductor. 

In the heat of debugging I decided I needed an LCR Meter to check out some of these components, so I went on to ebay and bought a Vichy DM4070 LCR Meter for $37.... I know this is an el cheapo ebay meter, but for home use it looked good. I have been pretty happy with it so far. It is not auto-ranging, but offers an adjustment pot to dial out any stray capacitance. It is well put together and looks sharp, which doesn't hurt :)

Upon tearing it open the first thing I noticed was the large amount of manual adjustment pots. Most of the higher priced LCR meters have a bit more of software calibration in them and don't have near as many pots as this one has.



There isn't a whole lot of protection circuitry; just some clamping diodes and a single varistor.... so don't be hooking up large voltages to this meter or smoke will come billowing out.



Not a lot to it, just a lot of passives, Analog Switches and Mux ICs. All the magic is under that epoxy blob, which is probably the Micro with internal ADC.

Now that I am armed with an LCR Meter hopefully I'll get that Oscillator up and running soon........

Saturday, January 28, 2012

Sword of Omens Hack

It is probably a good thing I have two little girls and no boys, because I have a little bit of an action figure toy fetish and I would go broke buying toys for me... I mean my boys if I had any. My downstairs office is covered with Starwars, Ironman, Thundercats, and Rambo action figures along with a vintage A-Team Mr. T. action figure I am pretty proud of :)

I just recently bought a Thundercats Deluxe Sword of Omens from ebay and even though it is pretty cool, one draw back is only the Thundercats logo side of the sword lights up; the Eye of Tundera side just hangs out and doesn't do anything. I just had to fix that......


I tore open the sword and found the 47 ohm series resistor and LED that light up the one side of the sword and I just tapped off that and soldered on another Red LED and 47 ohm resistor on the other side. I drilled a hole on the other side of the plastic and glued in the LED underneath the Eye of Thundera.
Now that both sides of the sword light up I can now save Third Earth from Ancient Spirits of Evil!!!

Arduino Battery Monitor Part II

In my last blog post I took an Adruino Uno and a Protoshield and made a simple battery monitor, so I could measure the voltage of a discharging 9V battery when it was drained through a constant 100mA load. Below is the 9V battery discharge curve:
The 100mA constant load was chosen because my ProtoStack Arduino Clone with LCD draws about 92mA and I wanted to write a sketch to display a battery bar and the approximate hours battery life left. Since all batteries have an internal equivalent series resistance (ESR), it is important to take that into account when only using a battery's voltage to monitor its state of charge. Since we discharged the battery through a load that is similar to the ProtoStack board with LCD, the ESR of the battery has automatically been accounted for in the voltage measurements.

With the plotted excel data from the discharge monitor I created a look-up table in software to approximate the battery life:

Battery Voltage               Hours Life Left                  Displayed Battery Bars
7.87V > Batt                        4.5hrs                                         4
7.45V > Batt <= 7.87V        4.0hrs                                         4
7.23V > Batt <= 7.45V        3.5hrs                                         4
7.08V > Batt <= 7.23V        3.0hrs                                         3
6.94V > Batt <= 7.08V        2.5hrs                                         3
6.77V > Batt <= 6.94V        2.0hrs                                         2
6.56V > Batt <= 6.77V        1.5hrs                                         2
6.30V > Batt <= 6.56V        1.0hrs                                         1
5.71V > Batt <= 6.30V        0.5hrs                                         1
              Batt <= 5.71V        mins left                                     0

Here is the sketch I wrote: link

I tied the input voltage through a resistor divider (220K Ohm series and 100K Ohm shunt) to the A0 pin on the micro.
One issue I ran into was the 9V battery can go down as low as 5.71V before it is completely dead. The ProtoStack board has a 1N4004 reverse polarity protection diode and a 7805 Linear Regulator to generate its 5V rail. These components require that the input voltage be greater than 7.8V in order to create the 5V rail properly.
So I replaced the 1N4004 diode with a schottky diode that has a much lower 0.2V forward voltage and used a L4941 5V linear regulator to replace the 7805. The L4941 has a drop out voltage of less than 0.45V when sourcing 1Amp. With these mods I was able to go down to 5.30V input voltage before the LCD stopped functioning.
I used the Parallax 16x2 LCD commands to create the custom characters for the "EH" and Full & Empty Battery Bar Segments. Here is a link to the spreadsheet I used to calculate the values for the custom characters.

This was a fun project to get myself familiar with the Arduino Analog pins. Now my ProtoStack Board is all ready for a future portable battery powered electronics project.

Monday, January 9, 2012

Arduino Based Battery Discharge Monitor

Trying to figure out the capacity left in a battery based on only its voltage is difficult. The equivalent-series-resistance (ESR) of the battery makes the cell's voltage a function of the current that is being drawn from it. For this reason I like to measure and plot the discharge of a battery, I am using, with a load current that matches my circuit. With this data I can estimate the capacity left in the battery at a given voltage.

I setup an Arduino Uno to measure a 9V battery's voltage along with a sense voltage to monitor the current leaving the battery through a 10 Ohm sense resistor.
I used the current sink from a previous project and set it to 100mA. I chose 100mA, because my Protostack Arduino Clone with LCD draws roughly 92mA from its DC input and the goal is to have this board estimate the battery capacity left based the 9V battery's measured voltage.
I modified my Adruino Protoshield to have two 220K Ohm (series) and 100K Ohm (shunt) voltage dividers put in front of the Analog Inputs AN0 and AN1. This will protect these pins from voltages higher than 5V and up to 15VDC. This protoshield also still has on the DS1307 RTC and CR2032 battery backup from my Arduino RTC project. This RTC will come in handy and allow me to reference my measured voltages to a given time on the DS1307.
 A little bit of hot glue acts as a strain-relief on the AN0, AN1 and GND wires.

The software is pretty straight forward. I grab the ADC counts read by AN0 & AN1 and then convert the counts to a voltage. I then have to scale the voltage based on the 220K & 100K Ohm resistor divider. After that I grab the Date and Time from the DS1307 RTC and print everything out the comport at 9600 baud. Then I wait a fixed length of time (1 second) and repeat everything,

My full sketch can be found here.

Below is my main loop routine:

void loop()
{
  // read the analog in value:
  BatteryValue  = analogRead(BatteryPin);
  SenseValue     = analogRead(SensePin);

  // convert the 0-1023 ADC value to a voltage (Note: 5V reference)
  BatteryValue  = BatteryValue/1023 * 5;
  SenseValue    = SenseValue/1023 * 5;
 
  // Compensate the Voltage for the external Resistor divider
  // (220K series, 100K shunt) in front of the AN0-1 pins
  BatteryValue  = BatteryValue / 0.315;
  SenseValue    = SenseValue / 0.315;
 
  CurrentValue = (BatteryValue - SenseValue) / SenseResistor;

  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);    

  // print the results to the serial monitor:
  Serial.print("\n" );
  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print("\t\t" );                      
  Serial.print(BatteryValue);     
  Serial.print("\t\t");     
  Serial.print(SenseValue);
  Serial.print("\t\t");     
  Serial.print(CurrentValue);   

  delay(60000);   // 1 min Delay
}


The sketch outputs all the data in a nice table format out the comport and into Hyper Terminal or your other favorite Terminal application:
This data can then be cut & pasted into Excel and plotted:
The 9V battery lasted a little better than 4.5 hours at 100mA discharge before it gave up. You can see that a constant 1V difference between the Battery Voltage and the Sense Voltage is shown. This confirms that a constant 100mA was pulled through the 10 Ohm sense resistor via the current sink

To be continued...... Next I'll be writing a sketch to display hours left on the 9V battery powering my ProtoStack Arduino Clone.

Part II here: http://embeddederic.blogspot.com/2012/01/arduino-battery-monitor-part-ii.html

Wednesday, January 4, 2012

HP 331A Distortion Analyzer Teardown

While messing with my RC Wien Bridge Oscillator I noticed I was getting some erratic readings now and then,  so I decided to do a bit of a teardown on my HP 331A Distortion analyzer. I did notice that some of the boards were connected with pins and sockets and they were pretty loose. Grabbing the soldering iron I hard soldered the wires to the boards in hopes my erratic behavior would go away.

Once I put the Distortion Analyzer back together I remeasured my RC Wien Bridge Oscillator Distortion and was getting a very repeatable 0.025-0.030%. I am still off from Jim's 0.0025%, but I think I am really pushing the resolution on this old piece of equipment that was last serviced in 1965 and last calibrated in 1987.




Below are picks from the HP 331A tear down: