3.2 Performing an AD Scan

Description

An A/D scan is similar to an A/D sample except that it performs several conversions on a specified range of input channels with each function call. SAMD51 function for performing an A/D scan is DSCSAM_ADScan.‌

Step-By-Step Instructions

Create and initialize an A/D settings structure (DSCSAM_ADSETTINGS).‌

Call DSCSAM_ADSetSettings and pass it a pointer to this structure in order to setup the driver for A/D operations.‌

Create and initialize a sample buffer of type SWORD.‌

Call DSCSAM_ADScan() and pass it a pointer to your scan buffer - this will generate an A/D conversion for each channel in your scan range and the results will be stored in the buffer you passed as argument to DSCSAM_ADScan().‌

NOTE: You must always remember to allocate enough memory for your sample buffer (in this case, SWORD sample_values). The driver assumes that your application has allocated at least the amount of memory given in the following formula:‌

Memory = sizeof(SWORD) * ( high_channel - low_channel + 1 )‌

Example of Usage for A/D Scan

...

DSCSAM_ADSETTINGS dscadsettings; // structure containing A/D conversion settings
ERRPARAMS errparams;  // structure for returning error code and error string
SWORD *sample = NULL;

...

/* Step 1 */ 

// These are example values; your application will vary. 
// See DSCADSETTINGS struct and hardware manuals for details. 

dscadsettings.Adchset =1;
dscadsettings.Lowch=0;
dscadsettings.Highch=5;
dscadsettings.Sedi=0;
dscadsettings.ScanEnable = 1;
dscadsettings.Adtrig=0;
dscadsettings.Adref=0;
dscadsettings.Adres=0;
dscadsettings.Adsamples=1;
dscadsettings.Adres=0;
dscadsettings.Adtag=0;

/* Step 2 */ 

if( DSCSAM_ADSetSettings(&dscadsettings ) != DE_NONE )
{
    DSCGetLastError ( &errparams );
    printf ( "DSCSAM_ADSetSettings error: %s %s\n", DSCGetErrorString ( errparams.ErrCode ), errparams.errstring );
    return 0;
}

/* Step 3 */ 

sample =(SWORD *) malloc(sizeof(SWORD) *(dscadscan.high_channel - dscadscan.low_channel + 1));
memset(sample , 0, sizeof(SWORD) *(dscadscan.high_channel - dscadscan.low_channel + 1));

/* Step 4 */ 

if( DSCSAM_ADScan(sample ) != DE_NONE )
{
    DSCGetLastError ( &errparams );
    printf ( "DSCSAM_ADScan error: %s %s\n", DSCGetErrorString ( errparams.ErrCode ), errparams.errstring );
    return 0;
}

...

Last updated