Difference: ADCAndDACExercises (1 vs. 3)

Revision 32021-07-05 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Exercises"

Exercise 9: ADC and DAC

Introduction

Line: 47 to 47
 
<--/commentPlugin-->
Changed:
<
<
META FILEATTACHMENT attachment="expected.png" attr="" comment="" date="1596208855" name="expected.png" path="expected.png" size="34510" user="UliRaich" version="1"
>
>
META FILEATTACHMENT attachment="expected.png" attr="" comment="" date="1625508090" name="expected.png" path="expected.png" size="37915" user="UliRaich" version="2"
 
META FILEATTACHMENT attachment="sinewave.png" attr="" comment="" date="1596209635" name="sinewave.png" path="sinewave.png" size="40387" user="UliRaich" version="1"
META FILEATTACHMENT attachment="triangular.png" attr="" comment="" date="1596209636" name="triangular.png" path="triangular.png" size="41403" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sawtooth.png" attr="" comment="" date="1596209636" name="sawtooth.png" path="sawtooth.png" size="39378" user="UliRaich" version="1"

Revision 22020-08-09 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Exercises"

Exercise 9: ADC and DAC

Introduction

Line: 37 to 37
  sinewave.png
Added:
>
>
The exercise sheet in odt format:

https://iotworkshop.africa/pub/IoT_Course_English/ADCAndDACExercises/exercise_9.odt

 -- Uli Raich - 2020-07-31

Comments

Line: 48 to 52
 
META FILEATTACHMENT attachment="triangular.png" attr="" comment="" date="1596209636" name="triangular.png" path="triangular.png" size="41403" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sawtooth.png" attr="" comment="" date="1596209636" name="sawtooth.png" path="sawtooth.png" size="39378" user="UliRaich" version="1"
META FILEATTACHMENT attachment="rectWaveform.png" attr="" comment="" date="1596209636" name="rectWaveform.png" path="rectWaveform.png" size="37766" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="exercise_9.odt" attr="" comment="" date="1596963795" name="exercise_9.odt" path="exercise_9.odt" size="211134" user="UliRaich" version="1"

Revision 12020-07-31 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Exercises"

Exercise 9: ADC and DAC

Introduction

The ESP32 comes with two 12 bit ADCs and two 8 bit DACs. In this exercise we will see how to use them and what their limitations are.

Exercise 1: Basic ADC use

Read the ADC and DAC descriptions on this TWiki: ADC and DAC. Connect the analogue joystick to the ADC channels on pin 32 and 34 on the CPU card (not on the WeMos D1 mini bus!). Set the ADC attenuation to 11 dB. Read both joystick channels (hor and ver) once per second and print the results.

Exercise 2: Linearity check

Connect the DAC (pin D0 or GPIO 26 ) to the ADC (pin A0 or GPIO 36). Set the ADC attenuation to 11 dB. Write a program which ramps up the DAC from 0 to its max value 255 and which reads the ADC at each step. Write the ADC values to a file, transfer it to your laptop and plot the result.

This is what you would expect to get:

expected.png

Exercise 3: Check with external ADC

You will see in exercise 2 that the DAC/ADC system is not linear. Try to find out if it is the DAC or the ADC which introduces the non-linear behavior replacing the ESP32 ADC by an external ADS1115 16 bit ADC. You can find the driver software for the ADS1115 at https://github.com/robert-hh/ads1x15.

Exercise 4: Compensating the non-linearity by software

As you will see in exercise 3 that the non-linearity comes from the ADC and that the DAC is perfectly linear, you can compensate the non-linearity by software. On the TWiki page ADC and DAC it is explained how this is done. Follow the explication and create a polynomial fit to the inverse of the ADC vs DAC curve. Use this polynomial to do the correction. Try another ADC vs DAC measurement applying the correction and make sure that you correction works.

Exercise 5: A simple pulse generator

The DAC can be used to create a simple pulse generator for different wave forms. Create a Python program that pre-calculates a

  • sine
  • rectangular
  • sawtooth
  • triangual
wave form and sends these data to the DAC. The wave forms are pre-calculated such that the values stored in a list can be sent to the DAC quickly and at regular intervals (different time intervals due to different calculation times are eliminated). Observe the wave forms on an oscilloscope. This is what you would get:

rectWaveform.png

sawtooth.png

triangular.png

sinewave.png

-- Uli Raich - 2020-07-31

Comments

<--/commentPlugin-->

META FILEATTACHMENT attachment="expected.png" attr="" comment="" date="1596208855" name="expected.png" path="expected.png" size="34510" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sinewave.png" attr="" comment="" date="1596209635" name="sinewave.png" path="sinewave.png" size="40387" user="UliRaich" version="1"
META FILEATTACHMENT attachment="triangular.png" attr="" comment="" date="1596209636" name="triangular.png" path="triangular.png" size="41403" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sawtooth.png" attr="" comment="" date="1596209636" name="sawtooth.png" path="sawtooth.png" size="39378" user="UliRaich" version="1"
META FILEATTACHMENT attachment="rectWaveform.png" attr="" comment="" date="1596209636" name="rectWaveform.png" path="rectWaveform.png" size="37766" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback