Design and Analysis of a Low Cost Wave Generator Based on Direct Digital Synthesis

,


Introduction
Signal generators are widely utilized in experimental courses [1][2][3][4][5][6][7][8].Furthermore, square wave and sine wave signals generated by signal generators are extensively used in a wide range of applications, usually as a standard signal in electronic circuit testing, parameter measurement, or demonstration in experimental courses.However, due to the high cost, fixed working mode and poor extensibility combine the programmable functions for generating arbitrary waveforms and other functions cannot be fully played out in the teaching experiments of common signal generator; a cheap and small signal generator which can meet common signal output functions and be suitable for experimental courses was needed [9][10][11][12].Based on DDS technology, an economic signal generator with small size and high precision was developed.Square wave signal with tunable frequency, pulse width, and duration and high precision sine signal with adjustable amplitude and frequency can be produced to satisfy the requirements in teaching experiments.Some reports focus on developing signal generator by DDS technology in theory.There are still few reports about manufacturing of the signal generator by DDS technology.

The Overall Design Scheme of the Signal Generator
2.1.Basic Principle of DDS Technology.The basic principle of DDS is using the phase concept to carry out frequency synthesis [2], which allows signals changing with phase to be obtained according to the variation of given signals under different amplitude.Phase accumulator is formed by cascaded -bit adder with -bit accumulator register.For each arriving clock pulse  MCLK , the adder sums up the control word () with the accumulated phase data produced by the phase accumulator register, and the result is sent back to the input port of the accumulator register, so that the adder continuously sums up the frequency control word under the effect of the subsequent clock pulse.The phase adder continuously performs linear adding of the frequency control word in an accumulative fashion under the effect of the clock input.As shown in Figure 1, a sine wave is regarded as oscillation of a phase cycle in a rotating vector manner, and each given point on the phase wheel corresponds to an angular division point on a sine wave in a 0∼2 cycle.Every time a vector turns around a phase circle at a constant speed, a complete cycle of sine wave is produced.It can be seen that the phase accumulator adds the control word once following each clock input, the output data of the phase accumulator is the phase of the synthesized signal, and the output frequency of the phase accumulator is the signal frequency of the DDS output.The frequency control word determines the number of division points that can jump on the phase cycle in each time clock cycle.More division points lead to faster overflow of the phase accumulator and shorter time to complete equal sine wave cycles; thus changing the value of the control word () can alter the output frequency [4].The output data of the phase accumulator serves as the phase sampling address of a waveform memory (ROM).A phase/amplitude conversion is completed after retrieving the binary waveform sample values stored in the waveform memory using a lookup table.SCM system, DDS waveform generator module, amplitude adjustment module, square wave generator module, relay output module, and so on.The power supply system provides 2.5 V, 3.3 V, ±5 V, and ±15 V power supply voltage.The +5 V input of the power supply system goes through an integrated three-terminal voltage regulator to obtain 2.5 V and 3.3 V voltage and then uses a DC-DC power supply module for conversion to +5 V and +15 V.The SCM system is employed to control the operation of the human-machine interface, read keyboard, display on LCD, and adjust the output sine wave amplitude.It also undertakes programming of the DDS device to produce the corresponding frequency signal, to control the relays and switch sine and square wave outputs.

Hardware Design of the Signal Generator
3.1.Design of the Power Supply Circuit.As shown in Figure 3, the inputs and outputs of AS1117-2.5,AS1117-3.3,and the DC-DC module use 330 F and 0.1 F capacitors for frequency compensation, to prevent the regulator from generating high-frequency self-excited oscillation and to suppress highfrequency interference in the circuit.The output terminals of the A05S05-2W and A05S15-1W power modules have resistors and capacitors to form a low-pass filter, which can smooth power output spikes and reduce interference to the subsequent circuit chip.The reverse protection design is also used in the power supply circuit, where a diode D3 is in cut-off state under normal power supply.If the input voltage is reversed, the diode conducts and the current from the external power supply flows through the FUSE and diode D3 into the negative terminal of the power supply.Since the diode forward resistance is very small, the current increases sharply and burns out the FUSE, disconnects the circuit, and thus protects the internal circuit from being damaged.

Design of LCD Module.
The liquid crystal display module was built on LCM1602 that has 2 × 16 characters and internal font.The interface is shown in Figure 4, where  12  potentiometer can be used to adjust the potential of feet 3 to change the contrast of the LCD display.

Design of Keyboard Circuit.
The front panel of the signal generator is shown in Figure 5.By means of pressing the left or right buttons to select each bit of data to be transferred and then using add or subtract settings, the number of buttons can be reduced and remained the same when the data for transmission needs to be extended.This allows the circuit to be very flexible since appropriate changes can be made in the software.The circuit output functions can be selected by "sine/square wave" buttons.The output signal frequency can be configured under a square wave output state, whilst for a sine wave output state, the signal frequency or amplitude can be set or modified through the "Mode" button.
As shown in Figure 6, the "sine/square wave" is designed with a locking switch, whilst the "Add," "Reduce," "Shift left," "Shift right," and "Mode" buttons are designed without locking switch.The output is high level 3.3 V when SW1∼SW5 are released and low level when pressing them.When Switch6 is released, PIN2 connects to PIN3 and PIN5 connects to PIN6, while PIN1 is hanging, SIN/REC is high level, and LED SIN lights up, indicating the output is sine wave.When it is pressed, SIN/REC is low level, and PIN4 connects to PIN6, and LED REC lights up, showing the output is squared wave signals.AD9833 made by Analog Devices, Inc. (ADI), which is 25 MHz with active crystal as a reference clock.

Design of the Sine Wave Amplitude Modulation Circuit.
According to the required sinusoidal amplitude which is input by the keyboard, the D/A port of the microcontroller produces a corresponding DC signal, then feeds it to the multiplier, and multiplies it with a fixed amplitude sinusoidal signal, to achieve the function of regulating the amplitude, as shown in Figure 8.The multiplier is selected to be MPY634, which is powered by ±15 V voltage, and can adopt a single-ended input (±10 V) or a differential input (±11 V), while the output voltage can reach ±11 V.The relation of output voltage and input voltage is given by Since the multiplier has internal negative feedback and  out is limited, the amplification factor () is infinite in theory and is at least 85 dB in practice; therefore, The sinusoidal wave amplitude ranges from 0.038 V to 0.650 V; thus the DC component (  ) is 0.344 V.The output from the multiplier must be the sine wave without DC component, so the DC component should be subtracted using circuit shown in Figure 8.The resistor  27 is linked between port  1 and port OUT, and resistor  26 is linked between ports  1 and  2 .
Assuming the resistances of  26 and  27 are  and , then out is the output voltage of multiplier, and the following can be concluded: Therefore, Assuming that 0 is the gain of the multiplier of the two differential inputs, The current of the multiplier output cannot output directly because of its weakness of driving power, so a high speed operational amplifier must be set before the input of the multiplier to increase the output current.
The circuit of regulating the sinusoidal amplitude.Taking  30 = 2 KΩ,  31 = 1 KΩ,  32 = 1 KΩ, the amplifier multiple is  = 1 +  31 / 30 = 3; then The output voltage of DAC of the MCU is ranging from 0 to 2.4 V and the sinusoidal waveform of DDS is ranging from 0 to 0.65 V, so the DC component of sinusoidal waveform (  ) is 0.344 V.
Reducing the DC component at  input of MPY634, the amplitude of sinusoidal waveform is Multiplying the two differential inputs  and  gives 2.4 * 0.306 = 0.7344, so it is required to get the amplitude of sinusoidal waveform more than 4 V; the gain must be chosen above 4/0.7344= 5.4.
The way of the circuit connection decides the value of 1/SF.
When Port SF is hanging, the amplification factor is SF = 10 V which is accurately modified by laser in the integrated circuit and the error is 0.1% or less.
Through resistor  SF linking between PIN SF and PIN −  , the value of SF can be changed: Defining  = 136 KΩ,  = 4 KΩ, then Because of the amplifier providing ±5 V in practice, the output voltage can only reach about ±4.5 V.
The amplitude of sinusoidal waveform ranges from 0.038 V to 0.650 V and its DC component is 0.344 V, which is obtained by resistor divider.As shown in Figure 9, the AS1117-2.5three-port voltage stabilizer provides the voltage of 2.5 V, providing the offset voltage of 0.344 V through resistor dividing.
Taking  1 = 60 KΩ,  2 = 10KΩ,  3 = 10 KΩ, the output scope of reference voltage is Therefore, the output scope of reference voltage ranges from 0.3125 V to 0.6250 V, and it is possible through adjusting potentiometer to get the offset voltage of 0.344 V. Therefore it is possible to eliminate the DC component of sinusoidal waveform from DDS output.Introducing a positive feedback to the circuit constitutes a hysteresis comparator, through adding a branch of voltage divider from comparator output to in-phase input.This can be seen from the schematic in Figure 10(a).
When input voltage   is gradually increased from zero but is less than or equal to   , which is called ceiling trigger level,   =  + om , When the input voltage   is greater than   ,   =  − om , and the triggering level is changed into    which is called the lower trigger level:  The threshold voltage is From Figure 10(b) of voltage transmission characteristics of the hysteresis comparator, it can be seen that the comparison voltage is different between the direction of increment and the direction in input voltage, and the interference within the hysteresis range will not affect the output voltage.
The circuit of generating square waveform is shown in Figure 11.Port  REF provides 2.5 V voltage for the voltage regulator module, the voltage can be regulated by adjusting a potentiometer, and the comparator outputs about 4 V of high level.So the backlash voltage of the circuit is

The Design of Controlling Circuit of Relay Output.
As shown in Figure 12, the relay module UA2 is equivalent to a double-pole double-throw switch.The control sides PIN1 and PIN8 are, respectively, connected to the +5 V supply and sine/square waveform changeover switch, PIN2, PIN3, PIN4 are the switch for final wave output switching, and PIN6, PIN7, PIN8 are the switch for shifting sine wave to hysteresis comparator to produce a square wave.Diode D1 is for current limiting to prevent excessive current impact on the circuit.When the sine/square waveform switch is released, SIN/REC becomes high level, and there is no current through the relay coil or the current is very small, which means that it does not produce magnetic force.The connection of PIN6 and PIN7 will put the sinusoidal signal into the comparator to create square waveform.Then, the square signal will input into PIN2 of the decay, which would sent to external interface because of the connection of PIN2 and PIN3.When the sine/square waveform switch is pressed, SIN/REC changes to low level; thus the relay coil generates a magnetic force.The connection of PIN5 and PIN6 separates the sine wave signal from the comparator to prevent generating interference.The connected PIN4 and PIN3 deliver the sine signal generated from the amplitude to the external output interface.

The Design of MCU Controlling Circuit. As shown in
Figure 13, a CYGNAL C8051F series MCU was chosen to   implement the functions of reading keyboard, displaying LCD, programming DDS chip, and adjusting the amplitude of the sinusoidal signal.Considering the rules of microcontroller pin configuration, the internal digital resources start from P0 port; therefore when assigning peripheral device port, the MCU starts assigning from P3 port to reserve P0 port for the internal resources.

The Deployment of PCB and Anti-Interference Design.
Because of the hybrid-system of digital circuit and analog circuit, and its high operating frequency, much attention should be put to the deployment of PCB and its antiinterference design.Considering the cost and the size, the PCB board is designed with double-layer plate and double wiring.Separate the digital circuit and analog circuit in PCB  layout and wiring.In general, we should adopt the way of separating digital signal ground with analog signal ground and connecting them at a point.For the part of analog circuit, which includes DDS chip, multiplier, and relay, it should use the way of linking grounds, respectively, and linking the ground at a point, thicken the ground line at the same time.
The clock circuit of DDS wave generator is a critical part in the design, which can be easily interfered and have great influence on the quality of the output wave, so we should pay special attention to this part.In order to reach the purpose of isolation, the crystal oscillator should be close to the pin of DDS chip, thicken the line of crystal oscillator and the power, add cuprum to the shell of the crystal oscillator.The PCB design diagram of AD9833 is shown in Figure 14.
We should make the power line bold as large as possible because of its high current and take the impedance into consideration.The STAR structure is used in the power wiring.In fact, in this design, it is designed into the shortest structure by manual wiring at first, which must control the width of the conducting wire.Then, for each current channel of their device, the conducting wire must guarantee more than 20 mils.Finally, the circuit will be fulfilled into STAR structure.Finally fulfill the circuit into STAR structure.The whole PCB design diagram is shown in Figure 15.16, which is based on the idea of structured and modular design.The initialization section mainly deals with writing operation on a few special function registers, to set the mode and initial value of each module and initialize variables used.Then, output the default waveform, and restore the last working state if reset source is the watchdog or the missing clock detector.Scanning of the keyboard is controlled by timer T0, implemented into different subfunctions according to different waveforms and waveform generating mode.

The Software Design of Signal
Generator.AD9833 is programmable DDS signal generator with two 28-bit frequency registers inside and two 12-bit phase registers.The software block diagram is shown in Figure 17.
Firstly, write 16-bit operating mode command word to determine working conditions and select the frequency register and phase register, and, secondly, write one or two frequency control words to control the output frequency.Finally, write phase control word, so that the DDS signal generator can output waveforms corresponding to a frequency determined by the value of the frequency register, and the phase determined by the value in the mode register.The sequence chart of data writing is shown in Figure 18.  and 21(b), set the character and cursor to blink, and adjust the lowest bit by default and adjust the cursor by the left and right keys.The lowest bit to the right will move the cursor to the highest level, and the highest bit to the left will move the cursor to the lowest position.The data size is changed by the Add and Subtract keys; if the most significant bit to adjust the data size is limited to be only 0 or 1, the amplitude can not be higher  than the magnitude of 10 V, and the frequency can not be set higher than the value of 20 MHz.Sinusoidal amplitude modulation is shown in Figures 20(c) and 21(c), the same case as the FM mode.

The State of Square Wave.
Using the keys is the only way to adjust the frequency under the condition of the square wave, so there are only two modes in this state: normal mode and FM mode.If it is the normal mode as shown in Figure 22(a), then turn off the LCD cursor and character blinking, display "REC WAVE" in the first line, and show the current frequency in the second line, while the high bit 0 is not displayed.If it is the FM mode, as shown in Figure 22(b), the process is the same as the process occurring in the state of sinusoidal FM mode.

Experimental Data and Analysis
Among the above,  MCLK = 25 MHz.The most significant deviation of the frequency control word is 0.5, so the frequency resolution is frequency variation, the output signal waveform distortion also changes.The waveform distortion contrast chart is shown in Figure 23, and the normal sine wave output is shown in Figure 22(a).When the frequency control word and the output frequency are increased, the sampling points will be reduced and the output waveform can be distorted, as shown in Figure 22(b).
This paper presents the maximum and minimum output signal waveform distortion: The frequency testing data curves are as shown in Figure 24.

Analysis of Frequency Error
(1) The Error of Phase Truncation.In order to obtain highfrequency resolution, the digit of phase accumulator  is generally rather large.However since ROM capacity is limited, the -bit phase accumulator output only employs the high  bit for addressing ROM ( > ), and the low bit ( − ) is rounded, resulting in a phase truncation error.Spectrum emission caused by phase truncation is mainly about the spectrum of spurious signal staying at the spectrum on both sides of the output signal, and the spurious spectrum is the combination of the reference clock and output frequency; the spurious spectral amplitude varies with the function of   ().According to the theoretical analysis, the main spectrum  and the magnitude of the strongest stray spectrum  spur satisfy the following relationship: whereby  is the digit of phase accumulator and  is the discarded digit.The value of ( − ) decides the level of the strongest truncated spectrum relative to the main spectrum which is caused by phase deduction.The design of the DDS module in this study uses a 28-bit phase accumulator and 12line ROM address, and the rounded digit in the accumulator is  = 16.From (16) it can be calculated that the level of the strongest truncated spectrum relative to the main spectrum is more than −72 dB.
(2) Amplitude Quantization Error.Because the ROM stores the coding samples of waveform amplitude, these code words are represented by finite-bit binary data, which introduces amplitude quantization error.In general, the amplitude of the quantization noise signal is much smaller than the amplitude of the spurious signal caused by the phase truncation and  amplitude begins to decay due to bandwidth limitations of the multiplier.Although nonlinear compensation algorithm has been used in the system software to enlarge bandwidth to some extent, further improvements are still needed.

Figure 1 :
Figure 1: Diagrammatic sketch of the operating principle of phase accumulator.

Figure 2 :
Figure 2: Block diagram of the signal generator based on DDS.

Figure 3 :
Figure 3: Circuit of the power supply.

3. 4 . 1 .
The Circuit Design of Sine Wave Generator.As is shown in Figure7, the signal generator is based on a DDS chip

Figure 4 :Figure 5 :
Figure 4: The interface circuit of LCD.

Figure 7 :
Figure 7: The circuit of wave generator.

Figure 9 :
Figure 9: The circuit of offset voltage of the amplifier.

Figure 11 :
Figure 11: The circuit of generating square waveform.

Figure 12 :
Figure 12: The circuit of relay controller.

Figure 13 :
Figure 13: The controlling circuit of MCU.

Figure 14 :
Figure 14: The PCB design diagram of AD9833.

Figure 15 :
Figure 15: The whole PCB design diagram.

4. 1 .
The Overall Design of Software.The main program diagram of SCM software is shown in Figure

4. 3 .
The Software Design of Keyboard Inputting.The block diagram of keyboard scanning is as shown in Figure19.Use the 10 ms interrupt of timer T0 to implement keyboard scanning, and eliminate keyboard dither according to the number of interruption.In the timer several operations are governed such as mode switching, data adding, data reduction, and left or right shift of data to be configured.In different modes, the range of the input data can be limited to prevent the input out of range.If no keyboard action can be detected beyond seven seconds, it will automatically exit the FM or AM mode and return to normal waveform generation status.4.4.The SoftwareDesign of LCD Displaying 4.4.1.The State of Sine Condition.In different modes, the LCD must display different interface for the user.If it is the normal sinusoidal waveform generation mode, as demonstrated in Figures 20(a) and 21(a), then turn off the LCD blinking of cursor and character, display the current amplitude in the first line, and show current frequency in the second line.The high bit 0 is not displayed.If it is sinusoidal FM mode, as shown in Figures 20(b )

Figure 18 :
Figure 18: The sequence chart of DDS writing data.
Figure 26: Sinusoidal signal output waveform with different frequency and fixed amplitude.
Figure 27: Sinusoidal signal output waveform with different amplitude and fixed frequency.
Figure 17: The block diagram of DDS writing data.
The control word Δ generated from the microcontroller is an integer, so it is calculated using floating point operation and then transferred into an integer and written into the DDS chip.Ignoring the decimal part during integer conversion, therefore the error Δ is ±1 and the frequency resolution is 5.1.Frequency Characteristics.