What has happened?
At the moment I'm playing around with a Wien Bridge Oscillator, or to say it better I have tried the last two days to get it working.I have found an application note from Analog Devices (AN580) which describes an circuit of the Wien Bridge Oscillator with two diodes for the stabilization of the output swing. In the schematic of the application note are also two digital potentiometers used to set the frequency and to manipulate the size of the output swing. This two potentiometers could be replaced by common potentiometers.
On this page I have found additional informations about this circuit which also helped me to finally get it run.
The Circuit
Some notes for the schematic:- The values for R1 and R2 must be equal and also the values for C1 and C2.
- By increasing or decreasing the values of C1,C2 or R1, R2 the frequency can be changed. I would recommend a linear stereo potentiometer for R1 and R2 this makes it easy to change the values simultaneously.
- If the capacitance or the resistance gets larger the frequency becomes slower.
- LED1 and LED2 control the amplitude of the output swing. As higher the forward voltage of the LEDs the higher the amplitude of the output swing.
- Set the gain with the potentiometer R4 so that the LEDs (both) just begin to light up. If the gain is to large the distortion will be very high.
In the schematic I also have implemented a voltage divider to connect my Arduino Leonardo. ATTENTION both, the Arduino and the Wien Bridge Oscillator are powered form independent and insulated power sources. Only in this case it is possible to connect the negative 12V to the GND of the Arduino.
YOU CAN KILL YOUR USB PORT AND/OR YOUR COMPLETE PC !!!
To make sure that both power supplies are independent from each other Measure the voltage between the GND pin of the Arduino while it is connected to its power source (USB-Port) and the three supply rails (+12V GND -12V) of the Wien Bridge Oscillator. The Voltage in this case should be very close to 0 (I have measured values below 20mV for each line).
DO !NOT! CONNECT THE GND OF THE ARDUINO TO THE GND OF THE WIEN BRIDGE OSCILLATOR. THE ARDUINO IS GOING TO BE KILLED!!
The next important part is to make sure that the output of the voltage divider (R6, R7) never can have more than 5V otherwise you are going to kill the Arduino.
The calculation for the voltage divider is quite simple. To calculate the voltage divider the maximum possible voltage (even in a case of failure) between the GND of the Arduino and the the OUT of the Oscillator must be known. In this case the GND of the Arduino is connected to the -12V of the Oscillator. The maximum positive voltage is +12V both together have 24V.
Vmax / (R6+R7) * R7
24V / (39k+10k) * 10k = 4.9V
With a maximum output voltage of 4.9V after the voltage divider it would be no problem to connect the Arduino.
The Problem
The main problem was that I was not able to see the waveform of the output, which makes it more or less impossible to see if the output swing of the OPAMP goes to its positive or negative maximum values so that the result is more like a square wave with sinus parts at the rise and fall.Due to the fact that I only want to use very low frequencies (<500Hz and in this sample approximately 160Hz) I thought it could be possible that the analog inputs of an AVR are fast enough to get a rough look at the waveform.
After first tests I have figured out that I'm able to measure approximately 8 times per ms (each 120ns) which is a sampling rate of 8330 kHz. For me it would be OK to use this for frequencies below 500Hz because at 500Hz we still have more than 10 Measure points per period. With 10 measured points per period a sinus signal does not look very beautiful but it could be identified as a sinus signal.
I assume that the speed could be increased if the analog value is measured directly without the Arduino libraries. The datasheet of the ATmega32U4 says that a sample rate of up to 15k samples per second is possible at full resolution (10Bit). And in the datasheet of the ATmega328 is the same statement for the full 10Bit measurements.
The Waveform Viewer
To make it short: Here is the code it can be downloaded from my Github repository.The code itself is quite simple. My first attempt was to sample 255 times the analog value into an array and then send the array formatted to the Arduino serial monitor so that I only have to make copy and paste into the spreadsheet.
This has worked very well but I am lazy. So I remembered that I have an Arduino Leonardo in the drawer which could type the values directly into the spreadsheet.
I've added the keyboard code to the sketch and programmed it to my Arduino Leonardo and it worked more or less instantly.
Now the life got very easy, I only have to push one button to get all the values including the time stamp into the spreadsheet. The next step would be to just look onto the Arduino to start the sampling :-)
After the values have been entered into the spreadsheet I have made a graph from the values to watch the waveform.
Here I have the OpenOffice file which I have used to show the graph. To let the Arduino enter the values into the sheet just select the box A1 and press the startButton (pull pin 7 to GND). You can repeat this as often as you want because the graph automatically changes after the values have been entered, just push the button again.
No comments:
Post a Comment