Netburner Tutorial 3:

Utilizing the A/D Converter on the MOD5213

Keywords: A/D Converter, ADC, ADC on DSP


Motivation and Audience

This tutorial's motivation is to teach the basics of the A/D Converter driver within the MOD5213 chip. Readers of this tutorial assumes the reader has the following background and interests:

The rest of the tutorial is presented as follows:

Parts List and Sources

US-based vendors to obtain material to complete this tutorial is the Embedded Netburner Development Kit (the MOD5213), found here.

To complete this tutorial, you'll need the following items:

TABLE 1: Parts needed to build (fill in the blank)
PART DESCRIPTIONVENDORPARTPRICE (1999)QTY
Netburner Development Kit Netburner Inc.MOD5213 $99.001
USB to Serial Adapter*--------$10 and up 1 

 *If your computer does not have a 9 pin RS-232 Serial port, you will need to purchase a USB Adapter. They can be found almost anywhere on the internet, or in a computer store near you.

Construction

This section gives step-by-step instructions along with photos to build the ADC circuit and tutorial. A schematic to construct the analog input is shown here, wir this on a breadboard to the pins on the development board.  Note: On the development board, there were no places to hook up jumper wires, so I placed two 20 pin header sockets on either side of the MOD5213 Chip.  Click link here to view the modification. 

Step 1

Create a Project File for the ADC project.  Label is as you wish, I used ADC_Debug as the project file name. (If you need further help with building the project, refer to the PIN IO Tutorial.

Step 2

Once the project file is created, expand the project file and navigate to the main.cpp file, and double click it.  This will open in the primary window with the basic code needed to run the MOD5213. 

Step 3

Under the include files at the top of the main.cpp code file, add the files: "<pins.h> <a2d.h> <bsp.h> <..\MOD5213\system\sim5213.h> and <utils.h>" (less the quotation marks).  These header files are used for the pin definition (<pins.h>) and for accessing the registers to enable and set up the PWM. (<..\MOD5213\system\sim5213.h>)  See the program code section below for setting the registers.  I included print statements after the line of code to debug when the register is set when ran in the processor.

Your header to the main.cpp program should look like this (The header files marked in blue are the ones to be added to the pre-built project):

#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <basictypes.h>
#include <serialirq.h>
#include <system.h>
#include <constants.h>
#include <ucos.h>
#include <SerialUpdate.h>
#include <a2d.h>
#include <pins.h>
#include <bsp.h>
#include <..\MOD5213\system\sim5213.h>
#include <utils.h>

Programming

The source code to the ADC Debug Program is provided below:


To be compiled with the Netburner Eclipse IDE
Note: download main.cpp rather than cutting and pasting from below.

//****** MOD 5213 ADC Demo ******** 
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <basictypes.h>
#include <serialirq.h>
#include <system.h>
#include <constants.h>
#include <ucos.h>
#include <SerialUpdate.h>
#include <a2d.h>
#include <pins.h>
#include <bsp.h>
#include <..\MOD5213\system\sim5213.h>
#include <utils.h>

extern "C" {
void UserMain(void * pd);
}

const char * AppName="ADC_Debug";

void UserMain(void * pd) {
	SimpleUart(0,SystemBaud); 
	assign_stdio(0);
	OSChangePrio(MAIN_PRIO);
	EnableSerialUpdate();

	// Configure the Analog to Digital Pins
	Pins[11].function( PIN11_AN2 );
	Pins[12].function( PIN12_AN1 );
	Pins[13].function( PIN13_AN0 );
	Pins[14].function( PIN14_AN3 );
	Pins[15].function( PIN15_AN7 );
	Pins[16].function( PIN16_AN6 );
	Pins[17].function( PIN17_AN5 );
	Pins[18].function( PIN18_AN4 );
	iprintf("ADC Pins configured.\n");

	EnableAD();
	iprintf("ADC Enabled.\n");

	iprintf("Application started\n");
	while (1) {
		iprintf( "Hit any key to display the A2D readings.\r\n");
		char c = sgetchar( 0 );
		for ( int i = 0; i < 8; i++ )
		{
			int counts = ReadA2DResult( i ) >> 3;
			float volts = ( (float)counts / (4095.0)) * 3.3;
			printf( "AD[%d] = %d counts, %f volts\r\n", i, counts, volts );
		}
		iprintf( "\r\n" );
	}
}



main.cpp Fuller Code Description

The main.cpp code above sets the A/D registers by calling the function (from the pins.h file) the Pins[xx].function ( ...).  Once the Pins are set, the EnableAD(); is called, activating the ADC.  The ADC will operate separate from the main processor, updating at approximately 90kHz.  The basic operation of the program in the while loop operates by waiting for a character in the UART buffer (from the computer) and will display the readings from the ADC.

Final Words

This tutorial's objective was to get acquainted with setting the registers to access the ADC Module on the DSP.  Once the concepts were conveyed the reader could use the ADC Module and the registers to monitor a wide variety of inputs, from voltage signals in the circuit to sensors like Accelerometers and IMU's (Inertial Measurement units).

Speculating future work, derived from this tutorial, includes data acquisition for a typical robotics based sensor using a standard serial UART to communicate.

Click here to email me