Principle Of Generating Waveforms Information Technology Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

The objective of the project is to design a working arbitrary waveform generator for undergraduate teaching purposes. The system is operated by batteries. It can generate different electronic waveform. The waveform which generated by user can be adjusted in limited range frequency. It can be displayed on the oscilloscope then the characteristics of the waveforms can be analyzed. All the arithmetic and algorithms are made by microcontroller to generate the desire signal. The signal will be saved in microcontroller. Then the signal will go through the digital to analog convertor, and then the digital (binary) code will become analog signal.

The major purpose of my project is for undergraduate teaching. The student can use arbitrary waveform generator to generate any waveform so that they can analyze the characteristics from oscilloscope. Then it will give students the chance to learn to set up an oscilloscope properly on a complicated waveform. This is the introduction for undergraduate students about electronic engineering. So the students can learn how to use the oscilloscope and characteristics of waveforms.

Chapter 1


1.1 Project background

Waveform generators are electronic test equipment device which can be used to produce electrical waveforms. These waveforms can be repeated or single-wave to use in some kind of triggering source. When the resulting waveforms process through the device, it can be inserted into a device in test and analyzed to confirm the correct operation of the device or check a fault in the device. The waveform generator contains an internal oscillator or a processor consisted with a digital to analog converter. Then it enables the waveforms to be generated and then output. [1]

Waveform generators are required for a wide range of industrial applications. For example the standard waveform, sinusoidal, square, sawtooth and triangular, are widely used to test electronic instrumentation. Because of their special requirements, only a small number of nonstandard waveform generators have been developed. In most cases these waveform generators require rather expensive hardware and are capable only for generating a very limited number of waveform.

There are a lot of applications for arbitrary waveform generator in real life. An arbitrary waveform generator is electronic test equipment which used to generate electrical waveforms. When Designers and testing engineers are designing and verifying the systems, for the worst case happened, the waveform generator will be often used. [2] It can produce accurate signal for testing, designing, manufacturing electronic components and systems.

In real practice situation, most of the signals are periodical. The different discrete waveforms of varying situation are collected from one period. Then they are encoded by the principle of binary to get the corresponding wave code of every waveform. These wave codes are stored in memory. The single wave code will be selected to output using the circuit control. Then through the Digital to analog convertor and amplifiers, it will become continuously vary waveform. For sinusoidal signals, it is difficult to get the waveform data as fast as the waveform is output, and working on a small cheap computer. And its waveform can be represented by smaller amounts of data. The waveform data can be collected from a periodic signal. The data will be stored as the basic waveform data in PIC program memory. [3]

1.2 principle of generating waveforms

The sinusoidal waveform can be generated using different methods. One possible technique is to generate a Taylor series expansion for the sine function. It requires relatively long computation time. The method will be used in this project is the look-up table. Predetermined values of the sine function are calculated and loaded on a square memory bank. Each time a value is selected and outputted to the output port. Through the timer, the value of this waveform in the look-up table will be output periodically. This process will be repeated. Then we will get the waveform. The more the data generated the better the waveform. But it takes more computation time. The frequency can be varied by having a different delay for different frequencies. When the original value of timer changed, the delay of waveform between the two adjacent points changed. Then the frequency of waveform will be varied. [4]

The square wave signal can be generated by picking a appropriate digital logic, fix to the required analog output, and to generate it to the port for a required time. The frequency of the output waveform can be defined by varying the delay time. It can be completed by keeping the output constant. Different values of the duty cycle can be obtained be having different delays for levels of voltage. [4]

The triangular waveform can be achieved by the combination of linearly increasing the output and decreasing the output. One the 8-bit digital signal reached peak value of output, or a peak level, a linear decreasing output combination can be exported to the output port through a D/A convertor. The frequency of the signal can be varied by the delay which is called after the output of waveform. [4]

The sawtooth can be generated in a similar method comparing a triangular waveform is that once the output digital signal reached a maximum output through a DAC, a sudden drop of voltage is outputted to a negative voltage level; this is finished by immediately changing the output voltage from positive voltage to negative voltage. Also the frequency of the signal can be varied by changing the delay which is used every time a digital signal is exported to the output port. [4]

D0 to D7

(R/2R ladder)

RB0 to RB2

(Switches)1.3 Proposed approach


8-bits DAC

R/2R ladder



Switches for user input

Figure 1. Principle of waveform generator

The figure 1 shows the block diagram of the Principle waveform generator. The circuit is built with a microcontroller PIC18F46K20 to generate different waveforms. The circuit uses an R/2R ladder as a digital to analog converter to convert the digital signal from the microcontroller to the analog signal. There are three switches using for the user input.

Chapter 2

Literature review

Waveform generator

A waveform generator usually consists of five main sections. Firstly, an analog output section comprising of one or more digital to analog converters, amplifiers and reconstruction filters. Reconstruction filters are low-pass filters. It can be used to remove the high frequency steps on the waveform, and then produce a smoother signal. The DAC devices receive the waveform data from the waveform generator memory as a series of binary amplitude levels. The DAC converts these to analog voltage waveform. It feeds to the output amplifiers and reconstruction filters. [5]

Secondly, a memory section can be used to store binary waveform data to transfer value to DAC temporarily. [5]

After that, a bus section is a electrical interface to the post computer. It transfer commands to the waveform generator for setting up the output. Also it controls the waveform generator when it processes the output. It receives the waveform data from the host PC. [5]

In addition, a clock section generates a clock signal. It determines the sample rate of DAC and also provides internal bus synchronization. Then it refreshes the onboard memory devices. [5]

Finally, a control section is used to control the other four sections. It transfers the data from bus to the onboard memory. [5]

Purpose of waveform generator

2.2 Digital to analog converter

In electronics, a digital to analog converter is a device to convert a digital or binary code to analog signal such as current, voltage or electric charge.

When the inputs of a certain number of binary bits go through the DAC and it produces an output voltage level that is proportional to the input number. There are many different versions with different numbers of input bits and output ranges in DACs. The D/A converters could cost low price with high-quality. [7]

The DACs process parallel data words and errors. There are two most common errors: offset error, gain error.[7]

figure2. DAC errors

Offset error is the deviation from the minimum voltage during the minimum code is applied. Gain error is the deviation in the slope of the transfer function after the offset error is took off, from the ideal. [7]

A DAC must have fast settling time. Settling time for a DAC is the passed time between a new input code and the time when the analog output falls within a specified difference. The settling time can change with the magnitude of change in the input word.[7]

There are some other major performance characteristics of digital to analog converter. Firstly, the resolution is the correlative of the number of discrete steps in the output and it can be given as the number of bits which are converted. Then accuracy is a comparison of the actual output to the expected output and is showed as a percentage of the maximum output voltage. After that, a linear error is the deviation from the ideal straight line output. [8]

2.3 Application of D/A convertor


Most audio signals are stored in digital form and converted into analog signal for hearing through speakers. DACs can be found in many electronic products such as CD players and PC sound cards. They can be found in high-end hi-fi systems. These take the digital output of a CD player and convert the signal into a line-level output. Then it can be fed into a pre-amplifier stage. [9]


Video signals must be converted to analog form from a digital source if they are displayed on an analog monitor. From 2007, the analog inputs are more widely used than digital. But it may vary as flat panel displays with DVI and HDMI connections become more widespread. A video DAC can be found in any digital video player with analog outputs. The digitally controlled potentiometer is distantly related to the DAC used to control an analog signal digitally. [9]

2.4 R/2R Ladder

In my project, an R/2R Ladder is used as a digital to analog convertor. An R/2R Ladder is a simple and cheap way to generate digital-to-analog conversion, using repeated arrangements of precision resistor networks. A resistor ladder is an electrical circuit contained repeating units of resistors. The R/2R ladder has the advantage that it only uses two values of resistors. It is the more widely used type of DACs. A simple R/2R ladder is showed on the following graph. [10]

figure3. R/2R ladder DAC

Many D/A converters are constructed with an internal resistor network driven by digital output drivers. The resistors are wired in a ladder fashion, with resistors of the same value being used for the rails, and resistors with 2x that value being used for the digital port outputs.

The R/2R ladder includes the reference voltage, a set of binary switches, and an output amplifier. The basis of this kind of converter is a ladder network constructed with resistors of two values, R and 2R.

Equation1. R/2R ladder output voltage formula

Where the D (0) takes the value 0 or 1.

The weighting factors can be obtained by a Thevenin analysis of each input point. A common reference voltage is used because of the change in voltage will be produced by logic 1 or 0. Logic 1 closes the switch and applies Vref to the summing junction. Logic 0 leaves then the input grounded.

In each bit position of the network, one resistor (2R) is in series with the bit switch, and the other(R) is in the summing line, so that the combination forms a pi network. The current produced in the network by closing a bit switch is reduced by half value when it passes through each node on the way to the end of the ladder. [10]

The R/2R ladder is easy to manufacture, because there are only two resistor values are needed.

2.5 Summing amplifier

An operational amplifier is often called an op-amp. It is a DC-coupled high gain electronic voltage amplifier with differential inputs and single output. The operational amplifiers can be used to combine signals using the summing-amplifier circuit. It can be used to add a number of voltages when connected as a multi-input inverting amplifier. The inputs can be used on either the inverting or non-inverting input sides. And there are an equal number of both with equivalent resistors. All the inputs to this circuit should be connected to a signal source or to ground if it is not used. [11]

The inverting-amplifier input node is called the summing junction. The current are summed at this node and forced through the feedback resistor. Any number of inputs can be connected to the summing junction through additional resistors. Then a simple digital to analog converter is formed. [12]

2.6 Operational amplifier

Chapter 3



R/2R ladder

Resistor networkHardware overview



Figure2. System block diagram

In this project, there are two main categories, hardware and software. For the hardware, it consists of the Microcontroller, R/2R ladder and amplifier, the Switch and the power supply circuit.

The microcontroller is the most important part of the waveform generator. It can control the interrupt instructions and the function of inputs/outputs. For the R/2R ladder and amplifier circuit, the main purpose of it is to convert the digital signals into analog signals. For the switches circuit, it can control the input to the microcontroller. When the switch is pressed, the signal will be sent to input pin of the microcontroller. After that, the waveform will be varied by the microcontroller.

On the microcontroller board, it consists of PIC18F46K20 microcontroller, 3.3V voltage regulator, switches, amplifier and other components. The power supply can get form batteries or the PICKIT2. If the batteries are used, it will go through a voltage regulator to regulate the voltage from 9V to 3.3V. The LED can show whether there is power supply in the circuit.

For PIC18F46K20 microcontroller, the Port A, B, C and D are the input/output pin of the microcontroller. PortB[RB0:RB2] is used by the Switch input circuit. PortD[RD0:RD7] is assigned for the digital output which are connected to R/2R ladder.

3.1 Resistors

Figure11: R/2R ladder in hardware connection

The R/2R ladder is normally connected to PIC as shown in figure (10). Implementation of an R/2R ladder can be very inexpensive. In this project, 8-bit R/2R networks can also be manually constructed using 16 discrete resistors. Then it reduced high frequency harmonics, eliminating the needs for a low pass filter in most design.

Microchip's microcontrollers have I/O pins with very low drive impedance for both driving logic '1' and '0'. This allows direct connection to the R/2R ladder without any external transistor drivers. To achieve 1 LSB accuracy using an 8-bit D/A, it is important to select resistors whose source impedance (in this project, 34k and 68k) is much greater the driver source impedance. [14]

3.2 Switch

In normal condition, the MCLR (pin1) is always HI. It has to be set to LO in order to reset the PIC. When the switch, S1 is pressed, the current will choose a less resistance path through the switch to the ground instead of passing through R1. As a result, the potential in MCLR pin is pulled down to 0V and the PIC is reset.

The switch S1 in this project is used to reset the PIC microcontroller. Then S2 S3 used to adjust the frequency of the waveforms. The S4 used to change the waveform. These switches used for programming interrupt so that they can control the waveforms. When the switch is pressed, the input will be 3.3V. As the figure (12) shown, there are three resistors connected with the switches. These resistors are known as the pull-down resistors. They hold the potential of the connected pins to 0V so the PIC will not detect any input if the switch is not pressed.

figure12. Switch circuit with pull-down resistor

3.4 Microcontroller

Microcontroller is used to control the operation of a device or a system. It is a small computer on a single integrate circuit or embedded devices.

There is an 8/16/32-bit microprocessor (CPU) consist of a small amount of RAM, ROM, programmable flash memory, watchdog, input or output ports, crystal oscillator, timer, and Analog to Digital conversion.

Figure14: Basic Mircocontroller Architecture

Microcontrollers are used to in a automatically controlled products and devices. The design of separate microprocessor, memory, and input/output devices are for reducing the size and cost. Mixed signal microcontrollers are common, integrating analog components used to control non-digital electronic systems. [15]

In this project, the pic18f46k20 is a high end 40-pin enhanced flash microcontroller. It provides for more memory and advanced peripherals, including USE, Ethernet and CAN connectivity. It is designed to support C programming.[15]



Operating Frequency


Program Memory (Bytes)


Program Memory (Instructions)


Data Memory (Bytes)


Data EEPROM Memory (Bytes)


Interrupt Sources


I/O ports

Port A, B, C, D, E



3.5 Amplifier

The op-amp ANALOG DEVICES OP77G is used in this project. The OP77's outstanding gain of 10000000 or more is maintained over the full 10V output range. This exceptional gain-linearity eliminates incorrect system nonlinearities and provides superior performance in high closed-loop gain applications. Also its outstanding characteristics make suited for high-resolution instrumentation and other tight error budget systems. [27]

figure15. Op-amp OP77G

Chapter 4

Software overview

4.3 ways to generate waveform

Most computers can not directly calculate the sine of a given value. They use the CORDIC algorithm or a complex formula such as Taylor series to compute the value of sine to a high degree of precision. [16]

(for x close to 0) Equation2. Taylor series.

Using microprocessor, the sine function can be generated at the output by incrementing x at every point and outputting the sine value of the x to the DAC. The sine x can be calculated be software or by floating point arithmetic cards. Because this method is complicated, the easier method is to make the look up table. The value for each x is stored in memory. For outputting code to the DAC, the memory for the x is then accessed. [16]

Memory address



Sin (x)


Binary value

(Base 80h+Bits)

Hex value




0000 0000

1000 0000





0000 0011

1000 0011





0000 0110

1000 0110





0000 1001

1000 1001





0000 1101

1000 1101


Table 2: sine wave look up wable

Example: The second row calculation

x = 360/256 * 1 = 1.41

Sin (x) = 0.024

Bits = sinx * 128 = 3.14

Therefore the digital before decimal point is 3.14 = 3 (decimal) = 0000 0011 (binary, Bits)

Binary value to be stored to ROM is

= 1000 0000 (Base value of DAC) + 0000 0011 = 1000 0011 (83h)

Square wave

The square waveform is calculated using the algorithm way. The data of the waveform will be separate into two equal parts. In the first part, the output of PORTD is set to 0xff, which is the maximum amplitude of output. Then the output of PORTD will be set to 0x00 in the second part so that the second part of output will be the minimum amplitude.

Figure 14.square wave code

As Figure14 shown, there are 256 points of waveform data. The first 128 points was generated as a linear line which the amplitude was the maximum value of PORTD output. Then the others were also the linear line which the amplitude was the minimum value of PORTD output. The varying of the frequency depended on the time delay variable k.

Triangular waveform

The triangular waveform is achieved by the combination of linearly increasing and decreasing output. One periodic triangular waveform of will separate into two parts. The first part of output was linearly increasing to reach to peak value and then it will be also linearly decreasing to the lowest value. The waveform will continuously be generated to be a triangular waveform. The frequency of the waveform is varied by setting a delay after the output of the waveform.

Figure15. Triangular waveform

As Figure15 shown, the signal increased linearly by the constant 10. When it reached the peak value, the signal decreased linearly by the constant -10. Also the varying of the frequency depended on the time delay variable k.

Sawtooth waveform

The sawtooth waveform is similar with the triangular waveform. It also increases linearly with a constant slope. However, when it reaches the peak value, it will suddenly drop to reach the lowest value of output.

4.4 programming explanations

4.4.1 Timer

Timer overflow





Figure10. Timer block diagram

The Timer is generated by collected the signal of system clock. The frequency of this signal can be the same as the frequency of system clock.

The Timer0 module is timer/counter peripheral of the PIC18F46K20 microcontroller. It is used to count oscillator clock cycles or external events. The instruction clock cycle TCY is the Fosc oscillator clock/4.

Chapter 5

Test and result

Chapter 6

Project plan and management

Task name



Project planning



Information sourcing



Background reading



Basic resources finding



Order special parts



Circuit design



Hardware construction



PIC controller programming work



PCB board design



Test and debug the program



Improvement and enhancement



Test whole system



Writing final report



Preparation of project exhibition



Table2 project task with schedule

From the table shown, the main tasks of the project finished in second semester. This was not the planning at the beginning of the project. The management of the schedule was not good enough to handle this project. Many tasks of this project should be finished followed the planning. Then there would be more remaining time for the improvement work. One reason might be the knowledge of programming PIC using Code. It took more than two months to finish designing. After spending the time on studying C-code, the programming work was not finished. Then the coding was not able to achieve to the requirement. Because the remaining time was limited, the testing and improvement were not able to improve the project. Also it caused some of the tasks were not finished before the deadline.

Chapter 7


7.1 Future work and improvement

In order to make the display of frequency and the type of the waveform, the LCD display should be employed. The LCD should display the frequency of waveforms and the type of waveform with backlight mode.

figure16. LCD display circuit

To make this project more presentable, the case of the waveform generator should be made. It will contain the PCB board, LCD and batteries. There are a lot of materials to make a good case of waveform generator. One good way is to make the case using ABS as the material.

7.2 Summary

In conclusion, the purpose of this project is to design a waveform generator. The frequency of the waveforms can be varied and there are 4 waveforms can be selected. There are some mistakes I made in this project. Firstly, to be honest, I cannot manage the schedule appropriately as the planning. Therefore the project cannot have more time to improve it. The schedule should be organized as the planning. Then the project might be finish better than expect. I left some of tasks in last month to finish. From this experience, I hope I would manage the time more appropriately during future working or studying.

When I worked on the final year project, I learned a lot of knowledge of hardware and software of electrical and electronic engineering. Because of my little experience on hardware and software, I felt difficult to design the circuit. Also the programming is the most difficult part for me. I haven't learned any C-language before. So I needed lots of time to study the C-code and test it on the microcontroller. There are many suggestions from my supervisor in programming work. Also I did a lot of research on the hardware component which might be used in this project.

Chapter 8