Difference: ADCAndDAC (5 vs. 6)

Revision 62020-08-01 - UliRaich

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

Exercise 9: Analogue to Digital (ADC) and Digital to Analogue (DAC) conversion

Introduction

Line: 10 to 10
 

The DAC

The DACs are accessible on pins 25 and 26. Since there is no description in the manual, here is the way how to access the DAC:

Added:
>
>


 
Changed:
<
<
  from machine import Pin,DAC
from time import sleep_ms

dac = DAC(Pin(26))
print("Running a triangular wave form with a frequency of ~ 1 Hz on pin 26")
while True:
    for i in range(256):
        dac.write(i)
        sleep_ms(2)
    for i in range(256):
        dac.write(256-i-1)
        sleep_ms(2)
   
>
>
from machine import Pin,DAC
from time import sleep_ms

dac = DAC(Pin(26))
print("Running a triangular wave form with a frequency of ~ 1 Hz on pin 26")
while True:
    for i in range(256):
        dac.write(i)
        sleep_ms(2)
    for i in range(256):
        dac.write(256-i-1)
        sleep_ms(2)
   
  This will generate a slow triangular wave form that can be observed on a multi-meter.

Checking linearity

Line: 48 to 49
  fit.png
Changed:
<
<
The fit gives up the coefficients (a..e) of the polynomial and we can use this to correct for linearity. Instead of returning the raw ADC value we enter it into the polynomial and return the calculated value multiplied by 16 to get 0..4096 instead of 0..256.
>
>
The fit returns the coefficients (a..e) of the polynomial and we can use this to correct for linearity. Instead of returning the raw ADC value we enter it into the polynomial and return the calculated value multiplied by 16 to get 0..4096 instead of 0..256.
  Here is the DAC versus ADC measurement on the ESP32 ADC after correction:
 
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