SAM C21 Sigma-Delta ADC Example Project

 Objective

This page provides a simple SAM C21 Sigma-Delta ADC (SDADC) GCC code example for the ATSAMC21J18A MCU.

The application code configures the SDADC module, then manually triggers conversions of a light sensor signal connected to the development board. The project is intended to be run in debug mode, with a program memory breakpoint set and hit every time a conversion is completed, so the result can be examined in the Atmel Studio 7 IDE.

The application is designed to work using the SAM C21 Xplained PRO Evaluation Kit which contains the ATSAMC21J18A Arm® Cortex®-M0+ MCU. The IO1 Xplained Pro Extension Header is used to provide the light sensor input signal.

samc21-xplained-pro-io1-xplained-pro.png


This application uses:

  • Sigma-Delta Analog-to-Digital Converter (ADC) Module
  • PB13 (LED Output, to the IO1 Xplained Pro)
  • PB09 (ADC+ Input, from the Light Sensor circuit on IO1 Xplained Pro)
  • PB08 (ADC- Input, from the RC filter on IO1 Xplained Pro)
  • PB13 (PWM Out, to the RC filter on IO1 Xplained Pro)


This code example uses a direct/indirect MCU register C-coding style (i.e., no software framework) and is built using the GCC compiler toolchain within Atmel Studio 7 IDE.

Visit the following page to see a detailed description of how the SDADC registers are configured for this application:

 
Sigma-Delta ADC Configuration
Learn more >

 Materials

Hardware Tools

Tool About Purchase
atsamc21-xpro-50px.png
SAM C21 Xplained Pro
Evaluation Kit
ATIO1-XPRO-50px.png
I/O1 Xplained Pro
Extension Kit

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
swtool-28px.png
Atmel® Studio
Integrated Development Environment

Exercise Files

File Download
Installation
Instructions
Windows Linux Mac OSX
Example Project

We recommend extracting the ZIP file to your C:\ folder.
You should see the folder C:\MTT\32arm\samc21\code-examples-gcc\sdadc\sdadc-example-project containing the solution sdadc-example-project.atsln.

 Connection Diagram

SAM C21 Xplained Pro contains an Embedded Debugger (EDBG) that can be used to program and debug the ATSAMC21J18A using Serial Wire Debug (SWD) interface. The EDBG also includes a Virtual Com port interface over UART, a Data Gateway Interface (DGI) over SPI and TWI, and it monitors four of the SAM C21 GPIOs. Atmel Studio 7 is used as a front-end for the EDBG.

The application is connected to an LED output and light sensor circuit on the IO1 Xplained Pro (ATIO1-XPRO), which is connected to the EXT1 pin connections as shown:

samc21-sdadc-example-project-connected-picture.png


The ATIO1-XPRO board provides a light sensor that is connected to the ADC(+) input on the SAM C21. The light sensor is a single-ended analog output, but the SDADC has a differential input, so an ADC(-) input is also needed. On the ATIO1-XPRO board, the ADC(-) pin is connected to the output of an RC filter that can be driven by a PWM signal. In our case, we want the ADC(-) input to be grounded to work with the single-ended light sensor, so we will not use the PWM. Instead, we will drive that pin low to provide a ground reference to the ADC (-) input.

Here is a simplified equivalent circuit:

xpro-diagram-sdadc-example-project.png

VCC Selection Header

The SAM C21 Xplained Pro has a 3-pin header labeled VCC-SEL on the board. This header can be used to select between 3.3 V and 5.0 V as the supply voltage for the ATSAMC21J18A, peripherals, and extension headers by placing a jumper on the left (3.3 V) or right (5.0 V). Selecting 5.0 V supplies the kit directly from the USB or an external 5.0 V source. Selecting 3.3 V supplies the kit from an onboard regulator.

Select 3.3 V as VCC by jumpering the left 2 pins on this header as shown by the red box on the following image:

samc21-xplained-pro-vcc-jumper-3v3.png

 Procedure

Attach the IO1 Xplained Pro Extension header to EXT1. Set the VCC jumper on the SAM C21 Xplained Pro board to 3.3 V and then attach it to your computer using a USB A-to-MicroB cable as shown in the image above.

Start Atmel Studio 7.

If the board has been successfully enumerated, you should see the board image come up in Atmel Studio which also identifies the IO1 Xplained Pro Extension as connected:

samc21-xplained-pro-enum-success.png

The board is identified by the last four digits of its serial number (see the sticker on the bottom of the board). In this example, the last four digits are "3514".

1

Open the Solution

Select File > Open > Project/Solution….

as7-open-sdadc-example-project-solution.png


Navigate to the solution folder and select the sdadc-example-project.atsln solution file:

as7-open-sdadc-example-project-solution-detail.png

2

Configure the Debugger

Next, you need to configure the debugger in Atmel Studio to discover and to connect to the target EDBG IC on your Xplained Pro board.

First, select the project in the Solution Explorer window, then select Project > Properties as shown:

as7-config-debugger-1.png

Next, under the project's 'Tool' settings, select your EDBG target from the pull-down. Select 'SWD' as the interface:

as7-config-debugger-2.png

Save the tool setting by clicking the Save All button:

as7-config-debugger-sdadc-example-project-3.png

3

Rebuild/Program the Target for Debugging

Click on the Start Debugging and Break icon in Atmel Studio which creates a debug project build, downloads it into the SAM C21 on-board, and prepares the debugger in Atmel Studio to interact with this code.

as7-start-debugging-and-break.png

If prompted, upgrade the EDBG firmware on the board:

as7-edbg-firmware-upgrade.png

You may need to click on Start Debugging and Break icon again after a EDBG firmware upgrade in order to rebuild/program the debug code into the target.

You should see a set of debug controls displayed in the IDE, and the debug program counter position (yellow arrow) pointing to the start of the main( ) function:

as7-debug-controls.png

4

Set Program Breakpoint for Debugging

In main.c, scroll down to the __NOP() instruction on line 147 then click once in the left column as shown until you see a red dot as shown:

as7-debug-set-breakpoint.png

The program will run once around the while(1) loop and stop here after the light sensor signal is digitized.

5

Open Watch Window to Examine the Result

To see the digitized value in the local variable result, open a "Locals" debug window to display the value of result. Select Debug > Windows > Locals as shown:

as7-debug-open-locals-window.png

The "Locals" watch window, showing the value of local variable result should be displayed:

as7-debug-locals-window-displayed.png

The initial value of result will be whatever was in the stack RAM memory at power up. It will be nonsensical.

 Results

Cover the light sensor with your hand, then press the Continue button:

as7-continue.png

The value of result should be in the high-end of an uint16_t result, since the light is being blocked, and the pull-up resistor will pull the signal voltage to 3.3 V:

result-covered.png


Uncover the light sensor, then press the Continue button again.
The value of result should be in the low-end of an uint16_t result, since the light is being absorbed by the phototransistor, causing a current flow, and pulling the signal voltage to 0.0 V:

result-uncovered.png


The measured values of result for covered and uncovered conditions vary based on your light source and sensor coverage.

 Conclusions

This project has provided a simple example of how to set up and use SDADC on the SAM C21 MCU. Follow the links below to learn more about this module.

 Learn More

 
Sigma-Delta ADC Overview
Learn more >
 
Sigma-Delta vs. SAR ADCs
Learn more >
 
Sigma-Delta ADC Configuration
Learn more >
© 2018 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.