Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
adc_demo1/main.c

===== Description =====

This demo shows how to use the ADC (Analog to Digital) converter on SBC66 Netcruzer boards. The SBC66 Netcruzer boards have 12 Analog input ports, port 0-5 and 30-35 (old port names X0-X5, and Y0-Y5). For details see modtronix.com/product/sbc66ec/ For this demo, port 1 (X1) is configured as an Analog Inputs. By default the ADC is configured for voltages between 0 - 2.5V (To configure it for 3.3V inputs, see nz_analog.h file). For this demo, when the input goes above 2.0V, output 38 (Y8) is turned on (3.3V). Else port 38 (old port name Y8) is off (0V). Additionally the System LED blinks every second.

===== Required Hardware =====

This project can be run on any of our SBC66 Netcruzer boards. For prototyping, we recommend combining this board with a Prototyping Board, like the PT66ECI for example. This low cost prototyping board makes all the I/O ports of the SBC66 board available via marked labels on the PCB. It also provides a reset and firmware button that simplifies prototyping.

===== Building Project =====

This project is located in the "src/demos/adc/adc_demo1" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66ECL_R2" for the SBC66ECL Revision 2 board. For details click here

===== Programming Board =====

After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.

===== File History =====

2012-08-08, David H. (DH):

#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h" //Required for all Netcruzer projects
int main(void)
{
WORD tmrFlashLed = 0; //Timer for flashing system LED
nzSysInitDefault(); //Default initialization. All ports inputs. All analog features disabled. Tick 1ms
DIR_SYSLED = OUTPUT_PIN; //Set System LED port as outputs
DIR_38 = OUTPUT_PIN; //Set Port 38 (old port name Y8) as an output pin
//Configure port 1 (old port name X1) as ADC channels
adcOpen(ADC_OPEN_A1);
while(1)
{
nzSysTaskDefault(); //Main netcruzer task, call in main loop.
//If port 1 (old port name X1) analog input is above 2.0V (2000mV), set port 38 (old port name Y8) to 3.3V, else to 0V
if (adcReadChanMv(ADC_CH_A1) > 2000)
PIN_38 = 1;
else
PIN_38 = 0;
//Flash system LED every 500ms
if (tick16TestTmr(tmrFlashLed)) {
tick16UpdateTmrMS(tmrFlashLed, 200); //Update timer to expire in 200ms again
LAT_SYSLED = !LAT_SYSLED; //Toggle System LED
}
}//end while
return 0;
}//end main