The rest of the tutorial is presented as follows:
To complete this tutorial, you'll need the following items:
| PART DESCRIPTION | VENDOR | PART | PRICE (1999) | QTY | |
| Netburner Development Kit | Netburner Inc. | MOD5213 | $99.00 | 1 | |
| 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.
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.
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>
//****** 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" );
}
}
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