You are on page 1of 23

EE 318 Electronic Design Lab Report SC CAPACITOR FILTER BASED SINUSOIDAL OSCILLATOR

Group No: 15 Roll Nos & Names :


NIKHIL SHETTY 01007007 AMEYA POTADAR 01007017 VIJAY AYYAR - 01007101

ABSTRACT :
The project basically entailed generating low frequency sine waves having low harmonic distortion. The project was split into 3 modules : User Interface, Main Block, and Output Stage. We successfully achieved the purpose stated with frequencies ranging from 10Hz to 12 Khz .The range selection had 5 bands 0.1Hz, 1Hz, 10hz, 100hz, 1Khz . The multiplier had 9 choices ranging from 1-9 . Hence we achieve frequency change in the resolution of 0.1Hz, 0.2Hz ; 1Hz, 2Hzand so on. Amplitude variation was achieved with the help of a potentiometer. The really low frequencies were achieved using an SC filter which works on the principle that by switching off two capacitors, resistors can be simulated.

1. INTRODUCTION :
A low distortion sine wave can be easily generated by passing the output of a simple square wave oscillator through a sharp cut off low pass filter to attenuate the odd harmonic components. A problem is that most filters have a fixed cut off frequency hence such a sine wave source is restricted to a small frequency range. The switched capacitor filter, however is one type in which the cut off frequency can be controlled by the frequency of a clock running at a multiple of the cut off frequency. Using this filter, the circuit forms a variable frequency sine wave oscillator which can be tuned, at constant output level, over a frequency range of 10 Hz to 12 kHz. An SC filter was used to precisely enable us to work with low frequencies. With normal oscillators, large values of resistors are not stable. Hence a switched capacitor filter is used.

2. DESIGN & TESTS :


Chips used : uC89c52, TL084, LMF100, LM311 The Design can be broken up into 3 stage, namely : USER INTERFACE, MAIN BLOCK, AND POWER AMPLIFIER STAGE.

2.1 USER INTERFACE ( Microcontoller 89c52 ) The microcontroller was used as a user interface to receive inputs as well as to generate clock for the SC filter. This particular microcontroller was used for its ability to work with high frequencies. It was enabled to show which frequency range and multiplier were selected. Since, debounce keys were used, a debounce mechanism was prepared with a 25-30 ms delay .One feature imposed was that if a key were pressed continuously for more than 2 sec, the increase in range or multiplier would be continuous. The concept of 2 keys being pressed simultaneously or even 1 key being pressed continuously and the other key pressed, was made invalid. A problem of noise was encountered due to the 12Mhz crystal with a considerable amplitude of 0.5V p-p . This was eliminated by connecting a large electrolytic capacitor between Vcc and ground. 2.1.1 Port Config. : Port 1 was the main port used. Pin 1.0 is the clock out, 1.1 is used for changing frequency range, and 1.2 changes frequency multiplier. Port 2 was used for output and Port 0 was completely free. In port 3, pin 3.1 was used for switching between Divide by 50 or Divide by 100. Range and multiplier description : The range selection had 5 bands 10Hz, 100Hz, 1Khz, 10Khz, 100Khz . The multiplier had 9 choices ranging from 1-9 . For the first 4 bands, the Divide by 100 option was used, while for the last band Divide by 50 was used. Timer 2 was used on the microcontroller. The lowest frequency on the SC filter is 0.1 Hz. By using the option of divide by 100 , we get a lowest frequency of 0.1 x 100 = 10 Hz. Now, 1 count = 1 us The lowest frequency we can get by the ISR is : 1 / ( 2 x 2^16) = 1 / (2 x 65536) = 7.63 Hz We can use loops in the ISR to generate lower frequencies than this. The highest frequency is : 500 Khz . But there are some overheads due to the ISR. Hence the highest frequency is around 125 Khz. For the SC filter a maximum of 12 Khz was required ( 12 x 50 = 600Khz ) . For this a particular ability of Timer 2 - Clock out mode , was used . This generates the clock directly at the pin ( in this case pin 1.0 ) . But the Clock out mode was not used for the 1st range, since the lowest frequency possible was 45 Hz. 2

The formula used for calculating the count for all frequencies is : 12 Mhz / 4 ( 2^16 - count ) = frequency 3 Mhz / ( 2^16 - count ) = frequency One problem faced is that as we go on increasing the frequency, for higher frequencies, the resolution decreases. In the sense, suppose we want a frequency of 700 Hz , we get 650 etc . With our configuration, the multiplier which presently operates as a range of 1-9 , can be easily extended upto 256 with minor changes in the ISR.

2.1.2 Amplitude variation : Initially a arrangement using switching of resistors was thought of which whereby a resistor would be switched on if the input at that port were 0 and would not be included in the circuit if the input was 1. But this was discarded due to the fact that if the voltage at any resistor that was connected to the circuit were negative, then even if the pin was open, the resistor gets grounded through that pin and the functionality is lost. For varying amplitudes, it was decided to switch between resistor values and use an Analog MUX 4052. Digital inputs to the MUX were provided by the microcontroller. Thus we could switch between 16 levels. But for simplicity, our guide, Prof. P.C.Pandey suggested that a potentiometer be used . Hence that was done, and a potentiometer of value 100Kohm was used .

2.2 MAIN BLOCK ( Use of SC filter with Hard limiter ) : The SC filter LMF 100 was used because of its ability to work at low frequencies. There was a choice of using 2 modes of operation Mode 1 or Mode 1a . Mode 1a was used because it gave an option of choosing either 10 times the output or a normal unpeturbed output which would be useful . Config : f / f = 10 ; Gain = 10 . First a basic 2nd order filter was constructed. For F clk = 10 Khz , F0 = 10 Khz / 100 = 100 Hz Input sine wave magnitude = 80mV peak

FREQUENCY ( Hz) 0 ( DC ) 1 10 20 60 70 80 90 95 97 200 300 400 500 Table 1 : 2nd order SC filter

MAGNITUDE (mV) 0 --- Small , 0 --- beyond 0 --- oscilloscope 0 --- range 13 16 26 56 100 120 14 12 8 6

On changing magnitude, the output starts getting clipped around 720 mV . Further, when Vin is a square wave/ triangular wave , the output remains almost the same with the higher frequency components (multiples of fundamental) being slightly greater in magnitude. The above was just a second order filter.

To get a better Band Pass filter , two 2nd order filters were connected to get a 4th order filter. But from the first stage to the second , 10 times the output of 1st stage could not be connected as the output was getting clipped. Hence the normal output was used.

Fclk = 1Khz Fo = 10 Hz FREQUENCY ( Hz) 10 10.1 10.2 10.3 10.4 10.5 10.6 20 30

Input sine wave = 80mV

MAGNITUDE (mV) 90 80 80 70 60 50 30 7 7

Table 2 : 4th order SC filter

Compared to the previous 2nd order filter, this graph shows that the 4th order filter has a greater gain and hence the components at multiples of the fundamental frequency have a lower value. The filtering obtained is hence of a better quality. Due to this the sine wave that will be obtained from the oscillator will be pure in terms of the frequency components. Again, when Vin is a square wave/ triangular wave , the output remains almost the same with the higher frequency components (multiples of fundamental) being slightly greater in magnitude.

Now , an LM311 was used as a hardlimiter in the feed back loop as shown in fig 1. This positive feedback through the hardlimiter was used because through the feedback, it limits the input to the filter at +/- 5V and hence the output also will not exceed +/5V and we get a stable output.

Fig 1. LMF100 with LM311

The ground of LM311 was connected to -5V to obtain oscillations for open loop between +/- 5V . If the ground of LM311 were connected to ground only 0-5V range would be obtained and also a DC component that would have had to be filtered would be found. This was definitely not desirable. When the unity bandpass output was connected to the LM311, a band was obtained. However, on connecting the output of 10 times the BP output , a nice sinusoid was obtained . On making the output of LM311 oscillate between -5 & 5, it was observed that the length of the positive and negative intervals were same. This however gave a slightly clipped output at the final stage. An obvious step to remove to remove saturation was to reduce the gain. 6

But it was observed that though the saturation problem was solved, the filter was not behaving well as a BP filter. Next, division of the output was tried out. Again , saturation was removed successfully, but the output seemed to have a varying amplitude. Also the input S1 of the BP filter needs a low source impedance of 1Kohm. A division of voltage by 10 was then used . Now, it worked well .

Fclk Fo P-P ( 10 times) V 20 Hz 0.2 Hz 2.2 100 Hz 1 Hz 2.3 1 Khz 9.2 Hz 2.3 10 Khz 95 Hz 2.3 100 Khz 945 Hz 2.3 Table 3 : 4th order after division of output . But then, for a short period LM 324 was used as shown in fig 2.

P-P ( unity ) mV 220 250 230 230 230

Fig 2. LMF100 with LM324 Temporary use of LM 324 was done because : - LM 324 is a quad opamp, and we needed opamps in the next stage as gain which also needed 5V supply . - Opamp 741 was used for amplification which required 15V supply.

Since it was possible to substitute all this by one LM324, it was done and it also helped in getting a common power supply of 5V . However, since LM324 doesnt work well at around 5 Khz and it was required that the oscillator work upto 12 Khz, TL084 was used (fig 3) which is pin to pin compatible & can work upto 100 Khz.

Fig 3 . LMF100 with TL084

When the output of the hardlimiter was given to the SC filter , it was a 5 V peak. The : 6 fundamental component = (4/ )* 5 = 20 / This will get saturated. So, again it needed to be divided before being given as feedback. ( fig 3.)

Since input S1 of the BP filter needs a low source impedance, as already mentioned, the divider needed to be appropriately designed ( fig 4)

Fig 4. Divider Circuit

After all the experiments with opamps was done, the final circuit was obtained as below :

Fig 5. Final circuit of SC filter

Finally, interfacing with the microcontroller was done, and a lot of noise was obtained at the output. This was removed by using a low pass source :

Fig 6. Low Pass Source

2.3 FINAL BLOCK AND CIRCUIT DIAGRAM :

10

11

3. POWER AMPLIFIER STAGE : A Class AB power amplifier was used at the output stage .

Fig 7. Power Amplifier For small input voltage, both transistors conduct, and as Vi is increased or decreased, one of the two transistors takes over the operation. Since the transition is a smooth one, crossover distortion wil almost be totally eliminated. The crossover distortion of the output stage can be reduced substantially by employing a high gain opamp and overall negative feedback. The +/- 0.7V dead band is reduced to +/-0.7 / Ao , where Ao is the DC gain of the opamp. Nevertheless, the slew rate limitation of the opamp will cause the alternate turning on and off of the output transistors to be noticeable, especially at high frequencies. In our case, Crossover distortion was virtually eliminated by biasing the complementary output transistors at a small, nonzero current. Biasing was done by using a 100ohm resistor and a diode. With regard to the circuit, the 2.2ohm power resistors were used to limit the current. For biasing the npn transistor, a diode was used and for biasing the pnp transistor a 100ohm resistor was used. The 1.2 Kohm resistors were used to limit the biasing current.

4. POWER SUPPLY DESIGN :

12

Basically we require +/- 5 V . A centre tap transformer was used with the centre tap used as ground and the other 2 terminals with respect to the centre tap give AC of 9V peak. A bridge rectifier is used . The two terminals of the transformer are fed to the bridge rectifier . So we get a rectified wave of peak 9V with harmonic content of 50 Hz. To remove that, 2 electrolytic capacitors are used. Hence the DC wave gets smoothened output. Non-electrolytic capacitors are used in parallel with the electrolytic capacitors, to bypasss the higher frequency components if any. The +/- 9V are fed to 7805 & 7905 chips respectively. At the output of these chips we obtain +/5V . There might be fluctuations in this output due to the line regulation. To remove this, in the output we connect 2 electrolytic capacitors . 2 diodes are connected in the reverse bias mode , to restrict any current injection into the 7805 & 7905 chips . In other words, they protect regulator chips.

Fig 8. Power Supply

5. LIST OF COMPONENTS USED :

13

1) 2) 3) 4) 5) 6) 7) 8)

89c52 microcontroller LMF100 SC filter TL084 quad opamp Resistor values : 56k, 1k, 10k, 100k, 2.2ohm, 100ohm, 1.2k, 120k, 200ohm Capacitor values : 470 uF, 0.1uF CD29 diodes IN4001 diodes Potentiometer 100K

6. CONCLUSION : Finally, a stable oscillator was obtained with minimal crossover distortion. A broad range of frequencies were covered from 0.1 Hz to 12 Khz and an amplitude range of 4V p-p was achieved with no load condition. A sinusoid is obtained having very few high frequency components. Further, the noise in the output has been brought down to a suitably low value, this yielding a clean sinusoid.

7. FUTURE SCOPE : Presently, LEDs are used to display the frequency range and multiplier. If we could improve display by using 7-segment displays, it should help a lot. This oscillator can generate sine waves presently. By adding more modules, it can be extended to give us square and triangular waves also. A particular feature which allows one to sweep a range of frequencies in a particular time limit can be implemented and used in hearing aid circuits. Also, the switching action of the LMF100 produces a staircase like wave at the output. This can be smoothened by using filters calibrated for each range. These filters can be switched by using microcontroller code and analog switches. 8. FINAL H/W STATUS : Finally, a working model was obtained on a printed circuit board (PCB). Various frequency ranges and multipliers were shown on the board using LEDs and an output sine waveform was obtained on the oscilloscope. Although a completely packaged product was what was expected , the box couldnt be designed due to time constraints.

9. MICROCONTROLLER CODE LISTING :

14

;this is key dbounce wth using software time delay(not timer interrupts) ;input for freq range at 1.1 and freq multiplier at 1.2 ;port 1.0 is an output port and port 2 shows freq is chosen ;change delays value to 01h for simulation purposes else offh ;port 2 give the upper nibble frq ranges(1=0.1 hz,2=0.5 hz) lower nibble gives freq multi(1=1 ,2=2) bounce equ 01h next equ 0ffh newkey equ 60h var1 equ 61h var2 equ 62h flag equ 00h delay equ 01h flabt equ 01h ;value1 equ 20h ;value2 equ 40h org 0000h jmp main ;corresponiding key is pressed calculate app values ;corresponiding key is pressed calculate app values org 002bh mov 0c8h,#04h djnz r6,netx mov r6,#0ah cpl p1.0 netx: reti

;r4,r5 used to store the multipliers for freq ;r2, r3 used for timer tlo and tho main: mov 08h,#00h mov sp,#30h mov r4,#00h mov r5,#00h mov r0,#0ffh mov r3,#0ech mov r2,#78h mov r7,#00h ;data pointer for the look up table mov dptr,#0200h call settime getkey: mov p3,#0ffh clr p3.0 mov p2,#0eeh scan1: clr flabt scan: call keydown jz scan1 call convert jbc flag,scan1

15

mov newkey,a mov b,#00h mov a,#bounce call softtime call keydown jz scan1 call convert jbc flag,scan1 cjne a,newkey,scan call vendit mov a,#bounce call softtime jb flabt,scan

wait1:mov 08,#00h wait: ; call keydown ; jnz wait mov b,#00h ; mov a,#bounce call softtime inc 08h mov a,08h cjne a,#14h,otwt1 otwt: setb flabt jmp scan otwt1: call keydown jnz wait jmp scan1 keydown: mov a,p1 cpl a anl a,#0feh ret

convert: clr flag mov a,p1 setb c rrc a mov r1,a clr a cjne r1,#0feh,one jmp good one: inc a cjne r1,#0fdh,bad;two jmp good

;two: ; inc a ; cjne r1,#0fbh,three ; jmp good ;three: ; inc a ; cjne r1,#0f7h,four

16

jmp good

;four: ; inc a ; cjne r1,#0efh,five ; jmp good ;five: ; inc a ; cjne r1,#0dfh,six ; jmp good ;six: ; inc a ; cjne r1,#0bfh,bad good: ret bad: setb flag clr flabt ret

softtime: cjne a,#00h,ok jmp done ok: mov var1,#bounce timer: mov var2,#delay

onemil: djnz var2,onemil djnz var1,timer done: ret

vendit: ;the code to be excuted when particular key is pressed shud be written between cjne and ret command(eg mov p3,a used here) exzero: cjne r1,#0feh,exone inc r4 ;p3.7 connected to 50/100 select clr p3.0

17

cjne r4,#04h,ox setb p3.0 ;this jmp is for wrap around of freq range ox: cjne r4,#05h,cont1 mov r4,#00h cont1: mov r0,04h mov a,#10h mov b,r4 mul ab add a,r5 mov b,a movc a,@a+dptr mov r2,a mov a,b ;outputting freq multipliers to port 2 add a,#11h cpl a mov p2,a cpl a add a,#3fh movc a,@a+dptr mov r3,a cjne r0,#00h,t20 mov r6,#0ah call settime ret t20: call timer2 ret exone: cjne r1,#0fdh,extwo inc r5 cjne r4,#04h,ox1 cjne r5,#0ch,cont2 mov r5,#00h jmp cont2 ;this jmp is for wrap around of freq multi ox1: cjne r5,#09h,cont2 mov r5,#00h cont2: mov r0,04h mov a,#10h mov b,r4 mul ab add a,r5 mov b,a movc a,@a+dptr mov r2,a mov a,b ;outputtin freq multipliers to port 2 add a,#11h cpl a mov p2,a cpl a add a,#3fh movc a,@a+dptr mov r3,a cjne r0,#00h,t21

18

mov r6,#0ah call settime ret t21: call timer2 ret ;extwo: cjne r1,#0fbh,exthree inc r7 mov p0,r7 mov p3,newkey ret ;exthree: cjne r1,#0f7h,exfour dec r7 mov p0,r7 mov p3,newkey ret ;exfour: cjne r1,#0efh,exfive mov p2,newkey ret ;exfive: cjne r1,#0dfh,exsix mov p2,newkey ret ;exsix: mov p2,newkey ret

;r2 lower timer byte r3 higher byte timer2: ;without inteupt ;setting timer 2 mov ie,#00h mov 0c8h,#00h mov 0cah,r2 mov 0cbh,r3 mov 0cch,r2 mov 0cdh,r3 mov 0c8h,#04h mov 0c9h,#02h ret

;r2 lower timer byte r3 higher byte settime: ;as we are using up counter we hav subtract the time frm ffff h

19

;with interrupt mov 0c8h,#00h mov 0c9h,#00h mov 0cah,r2 mov 0cbh,r3 mov 0cch,r2 mov 0cdh,r3 mov ie,#0a0h mov 0c8h,#04h mov r6,#0ah ret ;lower count bytes org 0200h ; here we hav to enter lower bytes of counts for timer 2 in isr mode ;freqs 0.1*10*100 ,0.2*10*100 ; 0.1 hz db 078h db 03ch db 07dh db 01eh db 018h db 0bfh db 036h db 08fh db 0d4h org 0210h ; 1 hz db 0d0h db 068h db 0f0h db 0b4h db 090h db 078h db 042h db 05ah db 0fbh org 0220h ; 10 hz db 048h db 024h db 018h db 012h db 0a8h db 00ch db 053h db 089h db 0b3h org 0230h ; 100 hz db 0d4h db 06ah db 09ch db 0b5h db 0c4h

20

db db db db

0ceh 0d5h 0dbh 0dfh

org 0240h ; 1000 hz db 0e2h db 0f1h db 0f6h db 0f8h db 0fah db 0fbh db 0fch db 0fch db 0fdh

;corresponding higher bytes org 0250h ; 0.1 hz db 0ech db 0f6h db 0f9h db 0fbh db 0fch db 0fch db 0fdh db 0fdh db 0fdh org 0260h ; 1 hz db 08ah db 0c5h db 0d8h db 0e2h db 0e8h db 0ech db 0efh db 0f1h db 0f2h org 0270h ; 10 hz db 0f4h db 0fah db 0fch db 0fdh db 0fdh db 0feh db 0feh db 0feh db 0feh org 0280h ; 100 hz

21

db db db db db db db db db

0feh 0ffh 0ffh 0ffh 0ffh 0ffh 0ffh 0ffh 0ffh

org 0290h ; 1000 hz db 0ffh db 0ffh db 0ffh db 0ffh db 0ffh db 0ffh db 0ffh db 0ffh db 0ffh

end

10. REFERENCES : 1) http://www4.tpgi.com.au/users/ldbutler/AudioOsc.htm , Lloyd Butler VK5BR 22

gives description of an oscillator which makes use of a switched capacitor filter to shape square waves into low distortion sine waves over a frequency range of 2 Hz to 20 kHz.

2) Microelectronic Circuits Sedra & Smith Was used to get some information about switched capacitor theory and Power amplifier. 3) 8051 Microcontroller Architecture Ayala Programming of the 89c52 was done using reference from this book. 4) http://www.kit.we.ly/data/at89c52.pdf , Datasheet for the 89c52 microcontroller was obtained from this site. 5) http://www.national.com/ds/LM/LMF100.pdf, Datasheet for the SC filter LMF100 was obtained from this site. 6) http://focus.ti.com/lit/ds/symlink/tl084.pdf, Datasheet for the quad opamp TL084 was obtained from this site.

23

You might also like