Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

Sinewave generation

1 Problem statement

The goal of this project is to generate a sinusoidal waveform with the Arduino. Software is provided and

outputs a binary sinewave signal on pins D8-D11 which is converted to an analog voltage using a special

type of digital to analog converter, called an R-2R ladder. The sinewave’s frequency is roughly 200 Hz.

Your task is to design and construct both the R-2R ladder and a reconstruction filter which converts the

staircase” output of the R-2R DAC into a smooth” sinusoidal signal of amplitude 3 Vpk–pk and mean

value zero.

2 Background

Many modern devices utilise digital circuits for analysing and processing data but still require an interface

to the analog world to, for example, drive a speaker or control a motor’s speed. The conversion of digital

data to analog voltages is performed with a circuit known as a digital to analog converter, or DAC. In this

project you will be implementing a simple DAC circuit built solely of resistors, called the R-2R ladder.

To generate an analog signal DACs will update their output at a specified frequency known as the sample

rate. The DAC’s output voltage will only change value once per sample, resulting in a staircase” looking

waveform. In order to produce a smooth waveform a circuit known as a reconstruction filter is used. There

are many different ways of implementing this filter but in this project you will use a combination of active

(op-amp based) low-pass and high-pass filters.

2.1 R-2R ladder

The R-2R ladder DAC uses a network of resistors to convert a binary number to an analog voltage. The

digital number is given from the Arduino by the digital output pins. In fact these pins act as a controlled

voltage source. If a bit in the 4-bit binary represented number is 1, the corresponding output pin is set

HIGH and acts as a voltage source. If the bit is 0 on the other hand, the corresponding output pin is set

LOW and acts as a ground connection.

Although simple this circuit has several limitations. Specifically, it has a high output impedance (ie: the

Thevenin equivalent resistance is high) and the precision of the output voltage is limited by the low number

of bits and the precision of the resistors chosen. The 1% tolerance resistors available in the lab become the

limiting factor beyond 6 bits so this DAC architecture is rarely used for high precision DACs (10+ bits).

In this project you can use op-amp circuits to act as buffers to compensate for the high output impedance

of the R-2R ladder. The precision of the output will be limited by the chosen 4-bit bit depth and will result

in noise” on the output (ie: random voltage amplitude errors) which are impractical to remove. None the

less a smooth-looking waveform should still be possible to generate.

The basic circuit is shown in Figure 1.

Exercise 1. Find expressions for the output (Vout) in terms of the input (ax) of a 2-bit ladder for all four

possible input combinations. In what range will the output voltage lie?

As you found out while doing the exercise the voltage does not depend on the resistors chosen so in an ideal

sense you could choose any value for R. However, there are other limitations that play into the design of

this circuit such as the maximum current output of the Arduino and desired output impedance. For the

Arduino the absolute maximum current that can be supplied by each pin is 40 mA and the total current

from all pins combined can not be larger than 200 mA. While these are the absolute maximum ratings you

are able to draw, it is highly recommended to stay below half of these ratings.

Exercise 2. Consider the 2-bit ladder. What is the current drawn from each input and in total? Derive

an equation for each pin’s output current in terms of R assuming that nothing is connected to Vout.

Page 1 of 7

Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

As mentioned before the R-2R ladder has a high output impedance. This is required because lowering the

output impedance means using small resistors which will damage the Arduino. In your design you will need

to compromise between the output impedance of the R-2R ladder, the current consumption (which should

be minimised) and the input impedance of your filter circuit (which will be explained later).

Exercise 3. What does a high output impedance mean for your circuit? Qualitatively, What happens if a

load, RL is connected to the ladder between Vout and GND if R >> RL? What could be used to separate

the R-2R ladder from the filter circuit that is cascaded (connected in series) later on? (Hint: Lab 2)

a0

2R

a1

2R

Vout

R 2R

(a) 2-bit ladder.

a0

2R

a1

2R

…

an

2R

Vout

R … 2R

(b) n-bit ladder.

Figure 1: R-2R ladder

2.2 Filtering

Filtering is a core concept in Engineering. The fundamental idea is that any real signal contains a spectrum

of frequency content and a filter is a system which allows some frequencies to pass while rejecting others.

Signal smoothing is one filtering operation where higher frequency content gets rejected, you can think of it

as turning down the treble when listening to music. In contrast the process of sharpening an image is done

by amplifying high frequency content.

The principle of superposition is the foundation of separating a signal into different frequencies. Each frequency is a particular sine function with specific amplitude and phase and the full signal is the superposition

of these sine waves. In future study you will learn the concept of linearity which is the generalised extension

of the superposition principle.

In the R-2R ladder’s output the sharp steps contain a significant amount of high frequency content as the

voltage changes rapidly at each step. Low pass filtering the staircase signal can help to smooth out the

sharp edges of these steps.

When analysing signals the frequency spectrum is frequently plotted on a graph of frequency Vs. amplitude.

Figure 2 shows the time (left) and frequency (right) domain plots of a signal consisting of three sinusoidal

functions at 100 Hz, 250 Hz, and 500 Hz. Note that the frequency plot is three discrete points.

By filtering the signal in Figure 2 it would be possible to reduce the amplitude of one or two of the constituent

sine waves. For example if the signal was high-pass filtered the 100 Hz and 250 Hz components could be

attenuated (ie: reduced in amplitude) to insignificant levels, leaving just a 500 Hz signal.

Filters are classified by the general shape they make on a bode plot (graph of frequency Vs amplitude, aka

the frequency response of a filter). Filter design is an incredibly complicated topic so only a small subset of

filter types will be covered here: the low-pass, high-pass and band-pass.

Page 2 of 7

Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

–6 –4 –2 –10 |
2 4 6 ·10–2 |

10 | Time Voltage |

AssignmentTutorOnline

(a) Time signal. The solid line shows the superimposed

voltage.

100 200 300 400 500

4 2

Frequency

Amplitude

(b) Frequency plot. The dots show the various frequencies present in the time signal.

Figure 2: Sinusoidal wave and frequency plot for three superimposed voltage signals.

• Low-pass filter: This filter design is specified by a single frequency, f0, above which frequencies are

attenuated (decreased in amplitude). If applied to the example in Figure 2 the 100 Hz signal could

be isolated from the others.

• High-pass filter: This is the inverse of a low-pass filter, frequencies below the cut-off frequency, f0,

are attenuated while high frequencies are unaffected. If applied to the example above we could, say,

remove the 100 Hz and 250 Hz wave forms leaving only the 500 Hz one.

• Band-pass filter: This filter is created by combining the low and high pass filters. It is specified by two

frequencies, fc;low and fc;high. Frequencies between fc;low and fc;high are passed while those above

and below are attenuated. This filter could be used to isolate the 250 Hz signal from Figure 2.

fc

1 | Frequency |

Gain |

(a) Low pass filter

fc

1 | Gain |

Frequency |

(b) High pass filter

fc;low fc;high

1 | Frequen | Gain |

(c) Band pass filter

Figure 3: Ideal filter behaviour.

The filter frequency response plots in Figure 3 are ideal. The filter instantly changes from passing to stopping

at a discrete frequency. Such a filter is physically impossible to build, so engineers have to make do with

approximations such as that shown in Figure 4. Better approximations are made from higher order filters.

The order is an advanced mathematical concept but for now just know that 1st order filters are the most

basic and contain one reactive component (ie: capacitor or inductor). 2nd order filters contain two reactive

components, 3rd order three etc.

When designing a filter you need to choose a filter order which is required to meet a given specification.

Higher orders are more complicated (to design and build) but more closely approximate the ideal filters in

Figure 3, so as in all engineering applications there is a trade-off between the complexity, price, robustness,

and performance of the design.

Page 3 of 7

Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

fc

1 | Freque | Gain |

Figure 4: Example of non-ideal low pass filters. The actual curve depends on the filter design.

In this project, it is your task to decide the filter types you want to use and their cut-off frequencies.

Remember that the desired output signal of the Arduino will be around 200 Hz. You can choose whether

you prefer to build a first order filter or a 2nd order Sallen-Key filter. The Sallen-key filter is a specific

topology of a second order filter and hence more complicated, but gives a better performance.

2.2.1 Active first order filter

The simplest filter is a passive filter consisting of a capacitor and a resistor. There are certainly applications

where a passive 1st order filter gets the job done but unfortunately this project is not one of them. You

are welcome to try building one but the output impedance of the R-2R ladder is so high that the output

waveform’s amplitude cannot meet the 3 Vpk–pk, 0 V average specification.

Instead it is recommended that an active filter be used. This is one which uses powered components such

as an op-amp in order to maintain a high output amplitude.

Basic active high pass and low pass filters are shown in Figures 5 and 6. In both cases the cut-off frequency

is determined by the resistor and capacitor and is given by

fc

=

1

2πCR : (1)

The feedback resistor network (Rf and Rg) can be used to apply gain to the output signal (NB: being a

non-inverting topology this circuit cannot attenuate).

– +

out

– + Vd + – Vout |
C R |

R

g

Rf

+ –

Vin

Figure 5: First order active high-pass filter

In order to build a band pass filter you can cascade (ie: connect in series) a low pass and high pass filter.

Page 4 of 7

Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

– +

out

– + Vd + – Vout |
R C |

R

g

Rf

+ –

Vin

Figure 6: First order active low-pass filter

Exercise 4. Is the low frequency of a band-pass filter given by the frequency of the high-pass or the low-pass

filter when connecting the two together?

2.3 Bonus worth 10%

2.3.1 Sallen-Key Filter

A Sallen-Key filter is a common topology for a second-order active filter. It utilises an operational amplifier,

two resistors, and two capacitors. The general circuit is shown in Figure 7.

As for the first order filter the placing of the resistors and capacitors defines the type of the filter. To build

a low-pass filter Z1 and Z2 are resistors, while Z3 and Z4 are capacitors. On the other hand to build a

high-pass filter Z1 and Z2 are capacitors, while Z3 and Z4 are resistors. Often the two resistors are chosen

equal and the two capacitors are chosen equal. In that case, for both the high- and low-pass filter, the

cut-off frequency is given by

fc

=

1

2πCR: (2)

Similar as for the first order filters, a band pass filter, can be built by cascading (connecting in series) a

low pass and a high pass filter. The cut-off frequencies of the band pass filter are the individual cut-off

frequencies of the two separate filters.

2.3.2 Other possible ideas to try out

• You could change the frequency within a region.

• You can superimpose multiple sinewaves, similar to the Example in Figure 2.

• You could build an equalizer, which is used in home stereo systems, loudspekers and other appliances.

These devices can be used to amplify or attenuate different parts of the frequency spectrum. Looking

at the Example in Figure 2, it would be possible to attenuate the 500 Hz component and amplify the

100 Hz component in such a way that all three components have the same amplitude.

3 Additional Material

The data-sheet of the operational amplifier you were given: http://www.ti.com/lit/ds/sbos058a/sbos058a.pdf

Page 5 of 7

Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

– + out |

Z1 |

Z2 |

Z4 |

Vin

Z3

Vout

Figure 7: Sallen-key topology with unity gain.

Arduino reference: https://www.arduino.cc/en/Reference/HomePage

Another reference for operational amplifiers is Hayt Chapter 6.

A reference to filtering is Hayt Chapter 16.7 (very detailed).

4 Project Specifications

In this project you will design a R-2R ladder and a filter (either 1st order or Sallen-key) to produce a

smooth sine wave at the output. The Arduino board is programmed to output a 4-bit sine wave on pins

D8 to D11, where D11 is the highest bit and D7 the lowest. It’s frequency is around 200 Hz. You can

choose between two codes for the Arduino, which are both provided to you. The first program is a very

simple program that outputs the closest discretised value of the sinewave to the 4 output pins. The second

program implements a more advanced method (far beyond this course) to obtain a sinewave at the output

pins. The idea behind this more advanced method is that the output switches fast between two discrete

values to achieve, on average, a value closer to the true sinewave. So while you will see a stepped sinewave

in the first case, with the second program you will see a much more noisy sinewave. You can work with

either of the two programs.

Your design should fulfill the following specifications:

• The current drawn from each pin should be less than 15 mA.

• The total positive current drawn from the Arduino should be less than 80 mA.

• The maximum positive current flowing into any of the Arduino pins (often called sink current) should

be less than 8 mA.

• The total positive current flowing into the Arduino, should be less than 50 mA.

• The output voltage should have an amplitude of 3 V peak to peak.

• The output voltage should have no DC offset.

Page 6 of 7

Project: Sinewave generation, August 11, 2017 ELEC1310- Electrical Engineering 1

• Use only resistors in the E24 series.

5 Marking

You are expected to write a report about your project (you can use LTSpice simulations to illustrate some

ideas) submitted online at the end of week 11 and give a presentation in week 12 during the Lab time. The

report counts 5% of the mark, while the presentation counts 10%.

The report has the following style restrictions:

• No more than 3 pages including figures and references.

• 12pt font.

• Margins should be larger than: left 32mm, right 20mm, top 18mm, bottom 20mm.

• Header should contain: Project title, date, and course specification.

• Footer should contain: authors (including student number) and page numbers.

A template style is given in LATEX but you can use any word processing software you like.

For both the report and the presentation, you are awarded marks depending on whether the specifications

are fulfilled, your justification for your design choices, as well as your understanding of the drawbacks and

advantages of your design within the limits of this course. A large part of the marks focuses on your

understanding. Also, note that the marks for the group members do not have to be identical.

6 Some useful tips

• Try to look at certain parts individually. So in a first step check your R-2R ladder. Then, separately

test your amplifier circuit, not connected to the ladder set-up. If you are happy with both parts you

can connect them together and check whether they still work as you expect.

• You can use LTSpice to simulate isolated parts of the circuits and get a “feel for them”. For example,

you can make the R-2R ladder and change the resistor values or input voltage to see in simulation

what happens to the output voltage and the currents. It does not have to be an exact representation

of the complete circuit.

• If something does not work as you expect, try to isolate the problem. Is it a broken component? Are

all resistor values what you thought they are or is there a wrong resistor value connected? Is there a

wrong connection?

• If you need any help or something is not clear. Do not hesitate to ask the tutors. You can also ask

the tutor during Help Desk in regard to the project. Or the lecturer during the consultation hours.

We will try our best to point you in the right direction.

Page 7 of 7

- Assignment status: Already Solved By Our Experts
*(USA, AUS, UK & CA PhD. Writers)***CLICK HERE TO GET A PROFESSIONAL WRITER TO WORK ON THIS PAPER AND OTHER SIMILAR PAPERS, GET A NON PLAGIARIZED PAPER FROM OUR EXPERTS**

**NO PLAGIARISM**– CUSTOM PAPER