ad space

Generate Sine Wave using Arduino DAC and RC Low Pass Filter

 Here we demonstrate how to generate a sine wave using Arduino Due DAC with Simulink and RC Low Pass Filter. We will be using Simulink to generate DAC signal from Arduino Due. This is then low pass filtered using 1st order RC LPF, 2nd order RC LPF and 3rd order RC LPF. We will see that as the order of filter increases the signal waveform gets better but the signal amplitude is attenuated. The filtered signal from the low pass filter then captured using Arduino Uno ADC(Analog to Digital Converter) and using simulink the captured waveform is displayed on a time scope. 

 

What you can learn here:

- how to generate sine wave using DAC of Arduino Due

- how to create simple RC low pass filter

- how to use ADC of Arduino

- how to use simulink

- Effect of increasing order of RC passive filter

- Effect of sampling frequency


Hardware Configuration & Simulink Modeling

Hardware Setup

The overall process of generating DAC signal from Arduino Due board, filtering using RC filter to get sine wave and capturing the signal using Arduino Uno ADC is illustrated below.

arduino RC LPF on breadboard

 In the picture above, the RC Low Pass Filter is a 3 stage low pass filter with each capacitor having a value of 113nF and each resistor have a value of 12KOhm. This gives a cutoff frequency of 117Hz.


Simulink model setup

The overall simulink model that generates DAC signal using Arduino Due and captures the analog signal using Arduino Uno is shown below.


 Note: 

During this demonstration it is necessary that you switch the hardware board for Arduino Due or Arduino Uno in the simulink model. This is demonstrated in the video provided below.

 

Video Demonstration

Below video demonstrates how to configure Simulink to upload code to the Arduino Due and Arduino Uno, how the signal processing and filtering looks like.


DAC sine wave signal

As shown below, we generate sine wave at the DAC0 of Arduino Due board using a sine wave generator. The sine wave generator is configured to generate sine wave with frequency of 100Hz at a sampling frequency of 1KHz equivalent to sampling time of 1/1000 or 0.001 seconds. The amplitude is set to 1. We use the Data Type Conversion block to convert the signal data type generated by the sine wave to uint16 because DAC0 block accepts uint16 data type.

Sine Wave using Arduino Due DAC
 

RC Low Pass Filter Design

The DAC0 output is a signal of amplitude 1V and frequency of 100Hz. We need to filter this signal in order to get smooth sine signal. The equation of cutoff frequency for RC low pass filter is given by,

 

\(f_c = \frac{1}{2\pi RC}\)


Here for filtering 100Hz signal we have used cutoff frequency of 117Hz. For this we have used a resistor of value 12KOhm and a capacitor of value 113nF. 

The designed 3rd order RC low pass filter on breadboard is as shown below.

RC Low Pass Filter breadboard

ADC for capturing filtered signal

After the signal is filtered using RC filter, we use Arduino Uno to capture the signal using its ADC. In simulink the components are as shown below.

 

Arduino Uno Analog Input in Simulink

The gain block is used to converts the analog signal samples which can have values from 0 to 1023 for Arduino Uno to 0V to 5V range. Thus the gain block setting is 5/(2^10-1).


 Result

Using the time scope block we can view the captured signal. Below picture shows the resulting signal on time scope.

sine wave captured using arduino

Other results

We show below some of the resulting signal obtained using 1st order, 2nd order and 3rd order RC filter along with varying sampling rates.

 

1st Order RC filter

1st order RC LPF on breadboard is shown below.

1st Order RC filtered Sine wave signal at sampling frequency of 1KHz is shown below.

 As you can see the 1st order RC filtered sine wave has amplitude around 1.6V. The sine wave is not so smooth.

2nd Order RC filter

2nd order RC LPF on breadboard is shown below. 

2nd Order RC filtered Sine wave signal at sampling frequency of 1KHz

1st Order filtered Sine wave signal at sampling frequency of 1KHz

 As you can see, the 2nd order RC filter reduces amplitude further than the 1st order filter. The amplitude in this case is around 1.6V. But the sine wave waveform is smoother than from the 1st order filter.

3rd Order RC filter

3rd order RC LPF on breadboard is shown below.


3rd Order RC filtered Sine wave signal at sampling frequency of 1KHz 

 

3rd Order filtered Sine wave signal at sampling frequency of 1KHz

 As can be seen the 3rd order RC filter produces much smoother sine wave but the amplitude decreases as the order of the filter increases. Here the amplitude is around 0.7V.

 

3rd Order RC Low Pass Filter with Varying sampling frequency

3rd Order RC filtered Sine wave signal at sampling frequency of 1.2KHz 

3rd Order RC filtered Sine wave signal

3rd Order RC filtered Sine wave signal at sampling frequency of 1.3KHz

3rd Order RC filtered Sine wave signal

3rd Order RC filtered Sine wave signal at sampling frequency of 1.4KHz

3rd Order RC filtered Sine wave signal

3rd Order RC filtered Sine wave signal at sampling frequency of 1.5KHz

3rd Order RC filtered Sine wave signal


3rd Order RC filtered Sine wave signal at sampling frequency of 1.7KHz

3rd Order RC filtered Sine wave signal

3rd Order RC filtered Sine wave signal at sampling frequency of 2KHz


Summary & Conclusion

We illustrated how to generate 100Hz sine wave signal using Arduino Due DAC(Digital to Analog Converter) and RC Low pass filter. We used Arduino Uno to capture the sine wave and display on Time scope using Simulink. We have shown how the 1st order, 2nd order and 3rd order RC filter performs. We illustrated that the sine wave signal gets smoother using higher order filter but that the signal amplitude gets attenuated as the order of the filter increases. This attenuation of amplitude is one of the disadvantages of passive filter like the RC filter we have used here. The attenuation can be compensated using Active Filters where transistors or op-amps are used.

2 Comments

Previous Post Next Post