UPC EETAC Bachelor's Degree in Aerospace Systems Engineering EEL



Laboratory 8

 Pulse width modulation (PWM), D/A conversion, analogue outputs, analogue filters



1. Specifications

Our first goal is to generate analogue voltages using (1) PWM techniques and (2) specific D/A chips. For instance, DC, triangular, ramp and sinusoidal waveforms at different frequencies.

We also aim conditioning analogue outputs (1) filtering high frequency noise associated to the D/A conversion process and (2) generating current outputs to drive devices such analogue panel needle meters or 4-20 mA current loops.

Symbol and block diagram

Fig. 1. Block diagram of several analogue output circuits from Arduino.

Single power supply 5V

Active 0dB first-order filter (-20 dB/dec), 5V rail-to-rail operation, cutoff frequency fC= 100 Hz.

Active 0dB second-order Butterworth response filter (-40 dB/dec), 5V rail-to-rail operation, cutoff frequency fC= 100 Hz

Modify and enhance the previous application LAB7 so that in a new state (waveforms) the following voltages and currents are calculated:

- Output VO6 generates the same analogue voltages acquired at VS1

- Output VO5 drives the needle panel indicator coil from 0 to 100%

Drive a 1 mA = IFS needle panel indicator from VO9.

Analogue values will update every TD = 2 s (distribution CLK period).

PWM signals

Pulse-width modulation Wikipedia page.

Digital to analogue converter peripheral

Digital-to-analog converter Wikipedia page.

Low-pass filer design

Wikipedia LPF reference.

Example of passive and active filter circuits.

Other references: Thomas, R. E., Rosa, A. T., Toussant, G. J, "The Analysis and Design of Linear Circuits", 7th ed, John Wiley & Sons, Inc., 2012

 TI, TLV237x: Rail-to-Rail input and output operational amplifiers with shutdown

TI, SBOA231: Single-supply, 2nd-order, multiple feedback low-pass filter circuit

TI, SNOA224A: AN779 National: A basic introduction to filters - active, passive, and switched capacitor

TI, SLOA049D: Active Low-Pass Filter Design.

Proteus: an introduction to active filters (ref.)

Current sources and voltage to current converter.

Let us drive a moving coil panel meter type SD38/0-1MA. as shown in Fig. 2. The meter scale can be customised to any quantity and span as shown in this reference page.

Analogue needle meter

Fig. 2. Panel analogue needle meter.

Let us drive the coil with a voltage controller current source. This are useful references from Texas Instruments on the design of Howland current sources (1), (2).


2. Planning


The idea is to continue expanding our previous project LAB7 adding jumpers to three specific pins so that they can be available as analogue outputs disconnecting the LED.

For example, we can connect a D/A converter type MCP4921 by means of the SPI bus.


Fig. 3. MCP4921 breakout (12-bit D/A) for Arduino (ref. including the circuit).

Or instead, in a similar way, an external D/A type MCP4725 can be connected by means of the I2C bus.

MCP4725 Microchip breakout board

Fig. 4. MCP4725 breakout board (12-bit D/A) for Arduino or Raspberry Pi circuits.

Arduino circuits will include the D/A and the analogue filters.

Output filters and SPI D/A converter

Fig. 5. Arduino connections to add analogue filters to the three PWM outputs 5, 6, and 9, and also an MCP4921 breakout board.

To design the 1st-order LPF5 and LPF6, as shown in Fig. 6, we can choose between two models based on OpAmps. We need to analyse its transfer function H(s) in the Laplace domain in order to locate the pole in the required position on the real axis of the left half of the s-plane diagram.

First-order active filterç

Fig. 6. First-order active LPF.

To design the 2nd-order LPF9 we can choose a multiple-feedback configuration as represented in Fig. 7. We need to calculate its transfer function H(s) and be able to locate the conjugate poles so that the frequency response is maximally flat in the bandpass (Butterworth response). 

Second-order LPF

Fig. 7. This is a proposed second order low-pass filter (-40 dB/dec).

To design a voltage to current converter (or transconductance amplifier) we can use the Howland current source shown in Fig. 8 and adjunct it to our requirements to drive the needle panel indicator proposed in Fig. 2. 

Voltage controlled current source

Fig. 8. An example idea on the design of a voltage controlled current source.



Function analog_write() function to generate analogue signals.

Interfacing SPI MCP4921 chip, example page.

Interfacing I2C MCP4725 chip, example page.

To start experimenting with analogue output generation we will add another state "waveforms" to our FSM.

Project location:



3. Development and 4. testing


Fig. 9 shows the virtual simulation first-order filters: filters_freq_response_1st_order.pdsprj.

This is the virtual simulation second-order filters: filters_freq_response_2nd_order.pdsprj.

Second-order filter

Fig. 9. Second order filter captured as a subcircuit in Proteus. It can be tested using instruments and advanced graphical analysis. To obtain the filter frequency response we can simplify the OpAmp using it ideal model.

This is the virtual simulation of the voltage to current converter: Howland_current_source.pdsprj.

Fig. 10 shows the new board enhanced from LAB7 including the digital to analogue new blocks. It includes the software program: Temp_meter_LCD_DA.zip.

Temperature meter with LCD and D/A signal generation

Fig. 10. Application captured in Proteus. Ready for simulation and a first version of the PCB design.


We have to add a new state to generate correctly the D/A signals at the given distribution CLK.


Fig. 9. Modified state diagram.


Topics in EMC



5. Prototyping



6. Reporting

Modify and enhance the application so that in the new state (waveforms) another voltage is calculated:

- Output VO9 generates an analogue voltage corresponding to the mean value of the three analogue inputs.

Finally, while the FSM is running, generate an audible 1 kHz sinusoidal waveform output VO from the SPI D/A converter.


Annex: Fourier series of a PWM waveform

We can represent a rectangular PWM waveform using a Fourier series, an infinite number of harmonic.

Fourier series of a PWM waveform
Waveform Fourier series PWM

Fig. 1. Fourier representation of a PWM waveform (ref.)

In this way, it is easy to visualise how choosing correctly the cutoff frequency of a LPF we can generate the waveform mean value.

Spectral representation

Fig. 2. Mean value of the PWM waveform filtering all the harmonics.