DAC, ADC Characterization with Arduino WIFI MKR 1010

Prof. Joerg Vollrath, 20.11.2023


Cost 27.- (2020), R2R DAC, PMOD DA2 20.-, AD2 20.-

Video Lecture: Laboratory


Länge: 01:06:27
0:0:0 Hello

0:0:34 Task until 23.11.2020

0:1:40 Review Laboratory

0:2:14 Task connect PMODs

0:3:2 3 DAC and 5 ADC for testing

0:5:27 Test with higher resolution

0:7:49 Load example data

0:8:45 Number of bits, offset, gaine error, LSB, INL, DNL

0:9:28 Paste log text in Excel

0:9:50 Text in columns

0:10:33 Header line

0:11:33 Insert graph point x-y

0:11:57 Resolution DAC 8 bits, ADC 10 bits

0:12:52 Minimum, maximum, average (mittelwert)

0:13:40 Offset, Maximum, gain error

0:17:58 Eliminate offset and gain error

0:18:56 Pivot table

0:19:31 Missing codes

0:21:46 115 codes

0:23:56 Second Arduino sketch including PMODs

0:25:1 Select data for FFT tool

0:26:33 Sine, FFT, INL, DNL

0:28:54 Signal to noise ratio

0:29:41 Missing codes

0:30:36 Number of bits 6

0:34:11 Start Code review

0:34:41 Sine lookup table, array OSC1..4

0:36:11 Setup code IOs, and serial

0:36:58 R2R DAC lines

0:37:21 Loop

0:38:57 More samples

0:39:52 Extended program

0:39:59 Ramp implementation

0:40:51 Write DAC, read ADC

0:41:33 Select waveform

Goals:

This project investigates ADC and DAC performance in an Arduino environment.
1 DAC and 4 ADCs internally of Arduino are investigated for sampling rate, resolution, offset error (minimum code and minimum voltage), full scale error (maximum code and maximum voltage), INL, DNL error and signal to noise ratio (SNR, FFT).
Additionally an R2R DAC and a DAC PMOD and ADC PMOD are controlled by the Arduino.
An Electronic Explorer board can provide signals with a function generator (AWG, DAC) and acquire data via oscilloscope channels (ADC).

The R2R performance should be measured and compared to measurements where one resistors is changed.
Error correction should be implemented in software and improvement should be measured.



-   Overview: Step by step


  1. Setting up Arduino environment:
    Getting started with the MKR WiFi 1010
    Blinking LED
  2. Realize wiring for
    • Arduino DAC and ADC
    • R2R DAC
    • PMOD ADC
    • PMOD DAC
  3. Performance investigation
    • Sampling rate and amplitude
    • Offset and full scale error
    • Ramp data INL, DNL
    • Sine data INL, DNL, FFT, SNR
  4. Change one resistor, measure and do error correction
  5. Summary



Pinout MKR WIFI 1010:


-   1. Setting up Environment

Download and Installation - Arduino IDE for Home



Arduino IDE is already installed in the laboratory.

L:\apps\Arduino click on Arduino


Installation of Win 10 executable.
Zip version is unpacked executable without install? (Device drivers?)

Configuration:
Datei -> Voreinstellung Zusätzliche Boardverwaltung URL's
File ->
URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Werkzeuge (Tools) -> Board -> Boardverwaltung ..
Arduino SAMD Boards(32-bits ARM Cortex M0+)
Werkzeuge (Tools) -> Board ->
Arduino MKR WIFI 1010

Connect Board via USB
Set COM port: Werkzeuge -> port -> COM..
Win 10: Gerätemanager -> Anschlüsse

C++ Source code LED blink

Datei -> Beispiele -> 01.Basics -> Blink
Sketch -> Hochladen or "button arrow"
Pfad: Dokumente/Arduino/Work



The LED is blinking and everything works.



+   2. Sine and Analog inputs to serial port


+   3. Analysis and FFT


-   4. Extension with R2R DAC, ADC and DAC PMODs

Part list

PartNumberCost (Euro)
Arduino MKR WIFI 1010130.-
Digilent PMOD AD2120.-
Digilent PMOD DA2120.-
Resistor 20k 8 (0)
Resistor 10k 7 (23)
Jumper wire (Drähte)32
Micro USB cable 1

Pin Assignments



R2R DAC


Build the R2R DAC on the board. Connect the output to OSC4, A4 and OSC2, A2, .
Pin ArduinoNameNameR2R
D0 D0 D0 D0
D1 D1 D1 D1
D2 D2 D2 D2
D3 D3 D3 D3
D4 D4 D4 D4
D5 D5 D5 D5
D6 D6 D6 D6
D13 D13 D7 D7
A4 OSC4 Output R2R Output R2R

R2R DAC First test


Connect DAC and OSC1 pin on Arduino.
The sine signal from DAC is sampled with OSC1.

Connect the USB cable of the MKR WIFI 1010.
Start the Arduino IDE from: L:\apps\Arduino\Arduino.exe
Start COM tool IDE from: L:\apps\Arduino\Com Port
Select correct board: Werkzeuge (Tools) -> Board
Select correct COM port: Werkzeuge (Tools) -> Port
Compile and upload sketch: Sketch -> Upload
Open serial monitor: Werkzeuge (Tools) -> Serial monitor
You should see generated values and readout of ADCs.

Option 1:
Use serial monitor
Disable Autoscroll
Select data with mouse
Copy data with <STRG><C> or <CTRL><C>
Paste data with <STRG><V> or <CTRL><V>
Use serial plotter for graphical ouptut to check waveform

Option 2:
Close serial monitor.
For data logging open Hyperterminal: L.\apps\Hyperterminal\hypertrm.exe
Select COM port.
Put in baud rate 115200.
Start logging data: Übertragung -> Text aufzeichnen
Select a path and file name (Durchsuchen) and start logging (Starten).
After gathering needed data do stop logging (Beenden)

You can analyze the logged data at home with Excel or the FFT tool.

PMOD DA2 ( 2 Channel, 12-Bit, 125kHz, 8 µs)


Connect DA2 to the Arduino.


Pin ArduinoNameNamePin PMOD DA2
D9 SCK CLK 4
D8 MOSI D1 2
D21 D21 CS 1
GND GND GND 5
+3V3 VCC VDD 6

Only Output Vout1 is used for signal generation.

Digilent: PMOD DA2 20.-
Texas Instruments DAC121S101 8us settling 12-Bit 16.5 MS/s $1.-

30 MHz SCLK

PMOD AD2


Connect AD2 to the Arduino.


Pin ArduinoNameNamePin PMOD AD2
D12 SCL SCL 1
D11 SDA SDA 2
GND GND GND 3
+3V3 VCC VDD 4

Only Input V1 is used for data acquisition.

Digilent: PMOD AD2 20.-
Analog devices AD7991 4 channel, I2C, 1us conversion time, 12-bit

Arduino sketch:


There is a new sketch available: DataConverterCharV2.ino
There is no ADC data buffer used in the program any more, since the memory size of variables is limited to 32kByte.
ADC readings are directly transfered via serial interface. This gives a sampling rate of 233 Samples/s.
Column sequence of output is different: index, ramp/sine value, ADC(AD2), ADC(Osc1), ADC(Osc2), ADC(Osc3), ADC(Osc4)
16k data blocks are generated for ramp or sine analysis usable for 12 bit data converters.

This outputs waveform from PMOD DA2 at Vout1 and reads V1 from the PMOD AD2.
Connect Output PMOD DA2 to oscilloscope channel 4.
Inside of the program the variable freq sets the waveform.

variable freq 100300500700900
Output Ramp1 sine11 sine101 sine1001 sine

The variable oscConfig changes the number of simultaneous measurements and output columns. This can speed up acquisition.

variable oscConfig 1234
Output AD2,OSC1,OSC2,OSC3,OSC4AD2,OSC1AD2OSC1


This configuration makes it possible to connect any DAC to any ADC to study system behaviour, INL, DNL and SNR.
A given sine signal code is fed to DAC and sampled with ADC giving an integer output code at the serial interface for further analysis.

What is the maximum sampling frequency?
How does the signal and FFT look at higher frequencies?
Is there any jitter present?

Tasks


(1) Task: PMOD ADC log data min, max, FFT, 1 Period, more periods,
Compare channel 1, 2, 3, 4, FFT SNR
(2) Task: Ramp test 0..255
Calculate INL, DNL

Data processing


Data can be copied from serial monitor disabling Autoscroll.
Selecting all data with <Strg><a>.
Copying selected data with <Strg><c>.
Inserting data into Excel via Start, Insert, Textconversion, delimited, Delimiter: comma, "=".
Data can be then selected and copied for FFT to Javascript FFT tool .
For ramp data another column in Excel is generated using verketten, concatenate (concatenate(A2,";",C2))to generate lines like: 23;56
.
Time (s);C2 (V)
0;0
1;0
2;0
..
DAC ramp data can then be copied and analyzed with Javascript read oscilloscope data tool .

Questions


What is the SNR for the digital sine data?
What is the SNR for Arduino DAC measured with PMOD AD2 and Arduino ADC?
What is the SNR for R2R DAC measured with PMOD AD2 and Arduino ADC?
What is the difference in SNR using windowing?
What is the INL, DNL for a ramp test of R2R, Arduino DAC, PMOD DAC measured with PMOD ADC and Arduino ADC?
3 measurement setups with 2 output data each.
Do a histogram test of Arduino ADC with PMOD DA2 as signal generator.



-   5. New Analysis Tool


There is a browser based experimental application available for controlling the Arduino MKRWIFI1010 for DAC analysis.

AWG1: Ideal digital data fed to PMOD DA2 and DAC0/A0 Arduino pin

C1: PMOD ADC

C2: Arduino pin A1

C3: Arduino pin A2

C4: Arduino pin A3


A NodeEEBench_V07.zip file containing nodejs with npm and the HTML and webserver files can be downloaded.
Copy the files into C:\temp. All files should then be in the directory C:\temp\NodeEEBench.
The Arduino needs the sketch: DataConverterCharV4.ino in the directory C:\temp\NodeEEBench\Arduino\DataConverterCharV4.
After downloading the sketch to the Arduino find the COM Port associated with the Arduino board.
Edit line 47 of C:\temp\NodeEEBench\ServerA.js and insert correct COM port.
An Internetapplication can than be started by clicking on:
C:\temp\NodeEEBench\StartServerAx.bat

A command window will open starting a internet page. Then the browser should open the internet address http://localhost:3000
with the application to control the Arduino board.
At the end of your session please stop the nodejs server with a <STRG>C keyboard entry.

Operation


Waveform Selection


Select a waveform in the waveform generator AWG tab and start the generator 'Run'.
You can see the feed back about the waveform at the configuration tab under the sent command section.

Waveform Acquisition


Change to the oscilloscope tab and click 'Run'. Data is gathered. The Arduino is very slow and therefore data is slowly gathered and the graph is updated.
Below the graph the running number shows the acquisition process.
Each waveform can be activated or deactivated.
Data can be extracted clicking on the Save button in the oscilloscope tab, selecting the data and copying them to a text file or into a spreadsheet program.
This data is taken when you click on the button and not updated until again clicking on the button.
The hide button removes the data list.

If the sine waveform is activated a FFT is generated after acquisition of 16k data.
If the triangle waveform is activated a INL, DNL plot is generated after acquisition of 4k data.


FFT tab


Pressing the run button activates FFT display. All selected waveforms in the oscilloscope window are plotted.
Only FFT of a sine signal makes sense for ADC, DAC Analysis.
A table with signal magnitude and total noise magnitude can be activated by selecting a "Channel".
The number of considered points can be reduced py a power of 2.
Take screenshots for documentation.

Ramp Test INL, DNL tab


By selecting Calculate for Channel and update of the data is initiated.
By default 256 codes in the range of 0 to 255 with step size 1 is considered.
Calculating a best case lookup table can be activated.

Lookup Table


A lookup table can be downloaded to the Arduino.
It has 256 comma separated values in the range from 0..255.
All generated waveform codes will use the lookup table to get a real code for the 8 bit DAC.
The button reset table resets the table to default state without lookup.
Here you can explore different error correction schemes.
Having less codes gives a smaller range and sine wave generator and Ramp Tes range have to be adjusted.

Further Instructions


Please give feedback about the operation of the program.
What is missing in the instructions?
Is anything not working?
Are the calculations correct?
What features are missing?
Please assess severity of these issues.
Are there any benefits or good features of this application?
Do you like this application?

DAC Characterization


Use ADCs (serial port) and Electronic Explorer oscilloscope input (Export data) for acquiring signals

ADC Characterization


Generate ramp with Electronic Explorer AWG1 or PMOD DAC
Use ADCs (serial port) and Electronic Explorer oscilloscope input (Export data) for acquiring signals



-   6. Task: Interface Electronics 2023

DAC characterization

Use 12-bit PMOD ADC for measurement acquisition.

ADC characterization

Use 12-bit PMOD DAC for signal generation.
Change on resistor of the R2R DAC.
Measure INL, DNL and FFT
Implement software error correction in a lookup table
Measure INL, DNL and FFT improvement

Document your results in a final report.
Deadline for the report is:


-   7. Additional information


Optimization of Arduino DAC & ADC Resolution


Since Arduino DAC and ADCs are set to 10 bits by default, but their resolution can be increased by accessing them via IDE sketch. The resolution of Arduino DAC is increased from 10bits to 12 bits by using the code;
analogWriteResolution(bits);
This sketch line is written before the [analogWrite(DAC, sine12);], here sine 12 given as input to let the DAC generate signal that can be tested by 12-bit ADC and then compare with the external 12-bit Pmod DAC. Below is the modified Arduino sketch for optimization of the Arduino DAC.
<!-- Arduino IDE DAC optimization Sketch -->

analogWriteResolution(12);     // Arduino DAC Resolution Change     
     analogWrite(DAC, sine12); //  //Writing Analogue to arduino DAC//

Similarly, the resolution of the ADC is increased from 10 bits to 12 and 16 bits. The results of 12-bit optimized combination are realistic and included in the report. However, it was observed that Arduino MKR WIFI 1010 has maximum accessible resolution of 12 bits, although 65,536 steps (quantization) were achieved but arduino was padding the extra bits with zeros. The following addition was made in the sketch before the serial print argument to increase the ADCs resolution.
<!-- Arduino IDE ADC optimization Sketch -->

analogReadResolution(bits);     // Arduino ADC Resolution Change     

Optimization of Arduino DAC & ADC Speed


DMA allows the faster transfer from data to and from the ADC, DAC to memory. This can speed up waveform generation.

A DAC DMA Exaple was found here.
Sketch ZeroDMA_DAC.ino can be downloaded.
Setting the variable period to 199 gives a sine signal with 32 samples at a sample rate of 240 kHz.

The library Adafruit ZeroDMA gives an example sketch ZeroDMA.ino for reading 256 ADC samples at high speed (2 MHz).

Unfortunately it is difficult to merge the libraries. Change the DAC sampling to ZeroDMA library was not successful.
A general description of SAM DMA can be found here .

IRQ with ADC A4 and DAC A0

The sketch Timer_IRQ.ino realizes a 15.9 kHz sample rate with an ADC input range of 1..1.65V and DAC range from 0..3.3V.
256 8-bit values are calculated for sine lookup.

ToDo

  1. Increase DAC samples to 256, 4096 or more
  2. Increase ADC samples to 4096 or more
  3. Make a fast synchronous DMA for IOs for R2R DAC
  4. Elimante ZeroDMA library for ADC DMA sampling and merge sampling and generation
  5. Making a nice signal generator and oscilloscope interface
  6. Can more than one ADC input be sampled using DMA?
  7. Adapting other boards using DMA?
  8. Use interrupt ISR for ADC reading and DAC writing
YetAnother USB Oscilloscope

Arduino getting stuck and USB device problems


The Arduino can get stuck with infinite loops and IRQ disabled.
Pressing "RST" button twice changes COM address of the Arduino. Then downloading the Sketch 'Basic' 'Minimum' makes the Arduino again operational at the previous COM port.

Board not listed in COM Ports

Disconnect breadboard from Arduino and look if the board is recognized. A short on the breadboard can disable COM port recognition.
Inspect power connections.

Timeline of Realization