Design and Implementation of a Multi-function Generator Rana Ramli and Alaa Elkhair Electrical and Electronics Engineering Department University of Khartoum Khartoum, Sudan rana_ramli@yahoo.com, lola-sun07@hotmail.com Abstract— This paper describes the design, implementation and testing of a low cost multi-function generator that is able to generate sinusoidal wave, triangle wave and square waves. The user can select the desired waveform. Moreover, the user can change the amplitude of the generated signal easily over a wide range. In-addition, the user can change the frequency for the generated signal over an acceptable range for several applications. One last feature is the ability of measuring both the frequency and the amplitude of the selected signal and display them on an LCD, this eliminate the need for another device, to measure or display the amplitude and the frequency of the signal. The multi-function generator was designed by using two methods microcontrollers and op-amp Keywords-Functiongenerator;Frequency;Amplitude;Oscillator. I. INTRODUCTION A function generator is usually a piece of electronic test equipment or software used to generate different types of electrical waveforms over a wide range of frequencies [1]. It is considered as a vital component in testing and developing electronic systems, whether in service bench or in research laboratory. Function generators have variety of application, such as checking the stage gain, frequency response and alignment in receivers, providing an excitation to the electronic measurement systems as well as providing carrier frequency in many of modulation techniques. Function generators are well none since 20 years ago but all the available ones have limitations. The high cost, the need of other devices such as an oscilloscope to display the signal and the non-accurate results that may obtained leads to further investigation and research to develop new methods and designs to implement multi-function generators. Even, the available multi-function generators' designs are usually hidden from researchers so that they need to use their own knowledge and background to innovate their own designs. When attempting to design a multi-function generator, the designers should focus on the integration between hardware and software implementation. The hardware portion is responsible for generating the signals while the software part is responsible for calibrating, measuring and displaying the amplitude and the frequency of these signals. The proposed multi-function generator was designed and implemented from the scratch with the aid of the standard methods and techniques known to generate the signals. The integration of the software with the hardware was upgraded using a common and powerful component which is the Microcontroller. The proposed system model is composed from (1) the generator stage, (2) electronic circuit stage and finally (3) the microcontroller stage. In these paper we emphasized on the part that is related to the measuring and displaying the parameters of the generated signal as this is a new feature with is not found in all the available generators. The rest of this paper is organized as follows: some background knowledge about the characteristics oscillators and multivibrators is given in Section II below. The design part is explained in Section III. Experimental results are discussed in Section IV. Finally the paper is concluded in Section VII. II. BACKGROUND A signal generator consists of two important main blocks: oscillator and attenuator [2]. Generally the oscillator uses an active device such as an operational amplifier, the output is fed back in phase with input and this positive feedback causes regeneration action resulting in an oscillation. When an electronic circuit is activated, there are electrical noises present that span the electrical frequency spectrum. If the noise is amplified and the output of the amplifier is connected to a positive feedback network, an oscillator can be created [3]. The positive feedback network is designed to select a signal at one frequency. This signal is coupled back to the input in proper phase so it reinforces the signal present at the input. As this process of amplifying and positive feedback continues, the selected frequency becomes the dominant signal in the circuit; the result is a sinusoidal signal. The building block of the non-sinusoidal oscillators is a special electronic circuit called multivibrator, multivibrators belong to a class of regenerative or positive feedback circuits that have two states[4], based on these two states multivibrator are classified into several types one of these types is known as Astable or free-running multivibrators which have two quasistable output states and the circuit switches back and forth from one state to another, remaining in each state for aperiodic time determined by the circuit element [5]. Because of this switching action of voltage or current between two states astable multivibrators generate square waveforms. As it is known, to adjust the shape of the required signal and to set its amplitude and frequency , usually we connect the generator with oscilloscope ,in this new designed function generator we eliminate the use of oscilloscope by allowing the user to select the shape of the signal and to enter the desired amplitude and frequency by keypad. III. DESIGN The block diagram illustrates the high level design of the multifunction generator is shown in Fig.1, which consists of several blocks. Generate the signal and select the shape Change the amplitude and the frequency Measure and display the frequency Measure and display the amplitude Possible combination of A0 and A1 are shown in the table below: TABLE1. COMBINATIONS OF A0 AND A1. A0 0 0 1 1 A1 0 1 0 1 Output Sinusoidal Square Triangle None After one of the signals was selected by using the multiplexer it is necessary to change the amplitude of the signal, to accomplish this, the signal was applied to a noninverting op-amp with variable feedback resistor. For the triangle and square wave the frequency was changed using by a potentiometer(R16) and by adjusting its value together with a capacitor (C2) the frequency of the signal can be changed, that is because the capacitor which is connect to the positive input of the op-amp(figure 2), will charge through (R16) and the voltage across it will rise exponentially with a time constant of RC when the positive input of the opamp reaches the threshold voltage ,the capacitor will start to discharge and its voltage will decrease exponentially, so by changing the value of the capacitor and potentiometer the time constant well change causing a change in the frequency. VDD Figure1. Multi-function generator block diagram. A. Signal generations, frequency and amplitude change using hardware components:. In this design three types of signals (sine wave, triangle wave and square wave) were generated from three circuits then an analog multiplexer was used to select one of them. Two approaches were used to generate the signal; the first approach rely on hardware components to build an oscillator circuit, in the second approach the microcontroller was used to generate the signal The design that used the first approach based mainly on the oscillation principles as three types of oscillators were used to generate three shapes of signals. Several sinusoidal oscillators were tested both in simulation and laboratory, Wien bridge oscillators was noted for high stability and low distortion, thus it was used to generate the sinusoidal waveform. To generate the square and the triangle waves two op-amps were used, the first op-amp is like an Astable multivibrator that will generate a square wave from the triangle wave. A second op-amp is set up as an integrator that creates a triangle wave from the square wave. After generating the signals from the circuits they were combined as inputs to the analog multiplexer then one of them can be selected as output. To accomplish this, ADG509F analog multiplexer was used. The ADG509F switches one of four differential inputs to a common differential output as determined by the 2-bit binary address lines A0 and A1. R8 C4 15V VDD 7 14 6 100k Ω 16nF R6 VCC 100k Ω 0 C3 15V VCC 7 16nF 1 5 U3 3 6 8 2 2 D1 R 10 0 10k Ω 4 9 R5 10k Ω Ke y =A R7 10 10k Ω 50% VEE 12 VEE -15V 1NR4001 9 1147k DΩ 2 0 741 4 S1A 5 S2A 6 S3A 7 S4A 13 S1B 12 S2B 11 S3B 10 S4B 1 A0 16 A1 R VCC 1 15V VCC VCC 15V VCC U2 7 4 0 R3 14 1 5 U1 3 47k Ω 5 OPAMP_3T _BASIC 1 741 R2 150nF 50% Key=A 15 0 -15V VCC 15V VCC 7 1 5 U5 3 6 15 2 16 10k Ω 0 VSS VSS C1 1uF 13 R 14 10k Ω R 13 4 9 GND 3 15V 0 C2 DB ADG509F VCC 6 2 8 17 VSS R11 50kΩ DA DCD VCC 2 EN 1N 4001 10k Ω 50% Ke y =A U4 VDD R 12 50k Ω 50% Ke y =A 4 8 18 VEE AD507JH VEE -15V 100k Ω 3 R15 100kΩ 50% Key=A Figure 2 . The final design B. Signal generations, frequency and amplitude change using software. In the previous work the signal was created using op-amp and its frequency and amplitude were changed using several components, now the signal can be generated by using ATMEGA32 microcontroller with the ability to select the waveform of the signal , its frequency and amplitude using keypad. The function that was used to generate the square wave is: Void send- square- wave { float dt,t,x,v, y; X=period*y V=0.0 T=0.0 Dt=delay-time-us*1.0e-6; Continue transmitting=1; While( continue transmitting= =1) {v=AMP*t/period THE REMAINING OF THE LOOP GRANTEES THE INCREAING OF THE AMPLITUDE.} The user will enter amp and t to select the amplitude and the frequency respectively. With the same procedure a second and third functions were written to generate the sinusoidal and the saw tooth waves the only different is in the variables period and v For the sinsoudal signal Period =1.0/freq V=0.5*amp*(1=sin(t*2*freq) For the saw tooth V=amp*t/period In general the code contains the following main functions: Name Purpose Keypad read Read the numbers entered by the keypad Select letter, forward and Allow the user to press the back space letters 7,8,9 to select the shape of the signal IsNumeric Checks whether the buffer contains only numeric values, return 1 if all characters in the range 0-0 Return 0 if any is not numeric Get-Item string Allows the user to enter, through the keypad the string for given data item Square, triangle and sine Generate the various types of waves Perform-Data-Entry Allows the user to enter all the data items need for the operation of dispening ,machine To conclude, the operation is as follows: At the first the saw tooth signal will be generated as default then the user should press 7,8,9 ( this will be displayed on the LCD as 1,2 and 3) to select sinusoidal signal, square signal and saw tooth signal respectively, to switch from one signal to another the push bottom should be pressed finally press(+). C. Amplitude and frequency measurement and display . However to make the use of the designed function generator more convenient another new feature was added , this feature is that the device can measure the amplitude and the frequency of the signal and display them on an LCD. To measure the frequency, the Timer1 (TMR1) in PIC16F877microcontroller was used to Count the 'zero' crossings of an input signal applied to RC0 pin (15), for 1 second therefore counting the frequency of the signal. The input signal's frequency is then displayed on a 16*2 LCD. The 1s delay is created by generating a perfect 1,000,000 cycles (it takes 1μs for one cycle at 4.000000 MHz).this was illustrated in the following piece of the program void main ( ) { int cycles8, cycles; int32 freq; int32 RealFreq; long freqc_high; long freqc_low; while (TRUE) { cycles8=0; cycles=0; freqc_high=0; t1_overflow=0; set_timer1(0); setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); while (cycles!=0xFF) { //true=3, false=4 cycles8=0; //1 cycle // start inner loop while (cycles8!=0xFF) { //true=3, false=4 if (t1_overflow)//true=2,false=3 t1_overflow=0;freqc_high++;}//6 cycles else {delay_cycles(5);} delay_cycles(1); //x cycles8++; //1 } This research used a HD44780 based character LCD to display the measured amplitude. The voltage to be measured is fed to one of the 8 analog channels. The reference voltage for A/D conversion was chosen to be the supply voltage Vdd (+5 V). Since the PIC port cannot take more than 5v input directly, the input voltage was scaled down using a simple resistor divider network. A 5.1V zener diode connected in parallel between the port pin AN2 and the ground provides protection to the PIC pin in case the input voltage accidentally goes beyond 20V. The following piece of code illustrate the measuring of the amplitude unsigned int ADC_Value, DisplayVolt; char *volt = "00.0"; Do{ ADC_Value = ADC_Read(2); DisplayVolt = ADC_Value *3; volt[0] = DisplayVolt/1000 + 48; volt[1] = (DisplayVolt/100)%10 + 48; volt[3] = (DisplayVolt/10)%10 + 48; Lcd_Out(2,5,volt); delay_ms(100); } while(1); The remaining part of the code is the ASCII representation of characters to be displayed on LCD. By integrating all the above parts and microcontroller a powerful new multifunction generator was designed, the final stage is to implement this design. IV. (a) RESULTS AND DISCUSSION The proposed system has been implemented and testing actions were performed to ensure its functionality. Signal generation, signal shaping and frequency and amplitude measurement and display have been verified. Results of each section have been clarified. A. Signal generation by hardware component For the sinusoidal generation the potentiometer (R5) was adjusted until the oscillation start to grow. It was noticed that changing the value of the potentiometer caused the resistor between the two diodes to decrease thus resulting in destroying the shape of the signal. It was found that the value that gives the purest shape is 20% from the value of the potentiometer. For the triangle and square waves it was noticed that the value of the potentiometer (R1) affects the shape of the signal adding some sort of signal distortion. . It was found that when the potentiometer value was 50% the signal would have the best shape. B. Signal generation using microcontroller The microcontroller circuit was implemented successfully in laboratory and tested for a wide range of frequencies it was found to be very accurate. When all the parts that of the designed multi-function generator were integrated together, the overall circuit was implemented successfully and found to work in a good an accurate way. The below pictures demonstrate the functionality of the system (b) Figure 3. Displaying the frequency and the amplitude VII. CONCLUSION With the completion of this research a multi-function generator has been successfully designed and implemented and it has worked as expected. The final design was successfully implemented and it is found the output frequency and amplitude of the signal is very stable and can be controllable from low values to relatively large values, also the output signal is distortion free. It was noticed that the signal generator provides very low spurious i.e. noise is negligible. The amplitude and frequency of output signal can easily be change over a wide range. The function generator gives accurate measurements for the amplitude and the frequency of the signal. ACKNOWLEDGMENT The authors would like to thanks Dr.Sharif.F Babikir, DEEE, UofK for his kind support and motivation. The authors would also like to thank H.Hamza and Y. Osman, UofK, for their support of this research work. Finally the authors would like to thanks all the technicians in EEE department, UofK. REFERENCES [1] http://en.wikipedia.org/wiki/Function_generator, accessed on 9 September 2012. [2]U.A.Bakshi, A.V.Bakshi, K.A.Bakshi, "Electronic Measurement and Instrumentation", Forth revised edition- 2009. [3] James Cox, " Fundamental of Linear Electronics: Integrated and Discrete ", second edition-2001. [4]Adel S.Sedra , University of Waterloo, Kenneth C. Smith, University of Toronto, " Microelectronic circuits ", 2004. [5] Paul Horwitz Winfielf Hill " The Art of Electronics " second edition 1989.