The application requires that all of the ADC pins be sampled continuously. From this post, the continuous function of the ADCs will act as a pseudo-simultaneous sample for ADCA, ADCB, and ADCC since the period between reading the result registers will far higher than that of the ADCs maximum sample period in the final application. Ideally, the ADC would be configured for continuous operation, started, and then the result registers could be read periodically without the need for ADC interrupt checking or waiting for the end of a conversion. Is this possible?
The following code, based on the adc_soc_continuous example in the bitfield examples, seems to only sample one time. What's preventing continuous sampling?
//
// Included Files
//
#include "F28x_Project.h"
//
// Function Prototypes
//
void ConfigureADC(void);
void initADCContinuous(void);
//
// Defines
//
#define RESULTS_BUFFER_SIZE 16 //buffer for storing conversion results
//(size must be multiple of 16)
//
// Globals
//
Uint16 AdcaResults[RESULTS_BUFFER_SIZE];
Uint16 AdcbResults[RESULTS_BUFFER_SIZE];
Uint16 AdccResults[RESULTS_BUFFER_SIZE];
Uint16 resultsIndex;
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio(); // Skipped for this example
//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;
//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
//
InitPieCtrl();
//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
IER = 0x0000;
IFR = 0x0000;
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
InitPieVectTable();
//
// Configure the ADC and power it up
//
ConfigureADC();
//
// Setup the ADC for continuous conversions
//
initADCContinuous();
//
// Enable global Interrupts and higher priority real-time debug events:
//
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//
// Initialize results buffer
//
for(resultsIndex = 0; resultsIndex < RESULTS_BUFFER_SIZE; resultsIndex++)
{
AdcaResults[resultsIndex] = 0;
AdcbResults[resultsIndex] = 0;
AdccResults[resultsIndex] = 0;
}
resultsIndex = 0;
//
// take conversions indefinitely in loop
//
AdcaRegs.ADCSOCFRC1.all = 0xFFFF;
AdcbRegs.ADCSOCFRC1.all = 0x00FF;
AdccRegs.ADCSOCFRC1.all = 0x00FF;
do
{
//
//initialize results index
//
resultsIndex = 0;
//
//software force start SOC0 to SOC7
//
AdcaResults[0] = AdcaResultRegs.ADCRESULT0;
AdcaResults[1] = AdcaResultRegs.ADCRESULT1;
AdcaResults[2] = AdcaResultRegs.ADCRESULT2;
AdcaResults[3] = AdcaResultRegs.ADCRESULT3;
AdcaResults[4] = AdcaResultRegs.ADCRESULT4;
AdcaResults[5] = AdcaResultRegs.ADCRESULT5;
AdcbResults[2] = AdcbResultRegs.ADCRESULT2;
AdcbResults[3] = AdcbResultRegs.ADCRESULT3;
AdcbResults[4] = AdcbResultRegs.ADCRESULT4;
AdcbResults[5] = AdcbResultRegs.ADCRESULT5;
AdccResults[2] = AdccResultRegs.ADCRESULT2;
AdccResults[3] = AdccResultRegs.ADCRESULT3;
AdccResults[4] = AdccResultRegs.ADCRESULT4;
AdccResults[5] = AdccResultRegs.ADCRESULT5;
AdcaResults[14] = AdcaResultRegs.ADCRESULT14;
AdcaResults[15] = AdcaResultRegs.ADCRESULT15;
}while(1);
}
//
// ConfigureADC - Write ADC configurations and power up the ADC for both
// ADC A and ADC B
//
void ConfigureADC(void)
{
EALLOW;
//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_16BIT, ADC_SIGNALMODE_SINGLE);
AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCB, ADC_RESOLUTION_16BIT, ADC_SIGNALMODE_SINGLE);
AdccRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCC, ADC_RESOLUTION_16BIT, ADC_SIGNALMODE_SINGLE);
//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdccRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//
//power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;
AdccRegs.ADCCTL1.bit.ADCPWDNZ = 1;
//
//delay for 1ms to allow ADC time to power up
//
DELAY_US(1000);
EDIS;
}
//
// SetupADCContinuous - setup the ADC to continuously convert on one channel
//
void initADCContinuous(void)
{
Uint16 acqps;
//
// Determine minimum acquisition window (in SYSCLKS) based on resolution
//
if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
{
acqps = 14; //75ns
}
else //resolution is 16-bit
{
acqps = 63; //320ns
}
EALLOW;
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC will convert on channel
AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC will convert on channel
AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC will convert on channel
AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC will convert on channel
AdcaRegs.ADCSOC4CTL.bit.CHSEL = 4; //SOC will convert on channel
AdcaRegs.ADCSOC5CTL.bit.CHSEL = 5; //SOC will convert on channel
AdcaRegs.ADCSOC14CTL.bit.CHSEL = 14; //SOC will convert on channel
AdcaRegs.ADCSOC15CTL.bit.CHSEL = 15; //SOC will convert on channel
AdcbRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC will convert on channel
AdcbRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC will convert on channel
AdcbRegs.ADCSOC4CTL.bit.CHSEL = 4; //SOC will convert on channel
AdcbRegs.ADCSOC5CTL.bit.CHSEL = 5; //SOC will convert on channel
AdccRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC will convert on channel
AdccRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC will convert on channel
AdccRegs.ADCSOC4CTL.bit.CHSEL = 4; //SOC will convert on channel
AdccRegs.ADCSOC5CTL.bit.CHSEL = 5; //SOC will convert on channel
AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC6CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC7CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC8CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC9CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC10CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC11CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC12CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC13CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC14CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC15CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC6CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC7CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC8CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC9CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC10CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC11CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC12CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC13CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
//1 SYSCLK cycles
AdccRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC6CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC7CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC8CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC9CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC10CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC11CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC12CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC13CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
AdcaRegs.ADCINTSEL1N2.bit.INT2CONT = 1;
AdcaRegs.ADCINTSEL3N4.bit.INT3CONT = 1;
AdcaRegs.ADCINTSEL3N4.bit.INT4CONT = 1;
AdcbRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
AdcbRegs.ADCINTSEL1N2.bit.INT2CONT = 1;
AdcbRegs.ADCINTSEL3N4.bit.INT3CONT = 1;
AdcbRegs.ADCINTSEL3N4.bit.INT4CONT = 1;
AdccRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
AdccRegs.ADCINTSEL1N2.bit.INT2CONT = 1;
AdccRegs.ADCINTSEL3N4.bit.INT3CONT = 1;
AdccRegs.ADCINTSEL3N4.bit.INT4CONT = 1;
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 6; //end of SOC6 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT2SEL = 14; //end of SOC14 will set INT2 flag
AdcaRegs.ADCINTSEL3N4.bit.INT3SEL = 7; //end of SOC7 will set INT3 flag
AdcaRegs.ADCINTSEL3N4.bit.INT4SEL = 15; //end of SOC15 will set INT4 flag
AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 6; //end of SOC6 will set INT1 flag
AdcbRegs.ADCINTSEL1N2.bit.INT2SEL = 14; //end of SOC14 will set INT2 flag
AdcbRegs.ADCINTSEL3N4.bit.INT3SEL = 7; //end of SOC7 will set INT3 flag
AdcbRegs.ADCINTSEL3N4.bit.INT4SEL = 15; //end of SOC15 will set INT4 flag
AdccRegs.ADCINTSEL1N2.bit.INT1SEL = 6; //end of SOC6 will set INT1 flag
AdccRegs.ADCINTSEL1N2.bit.INT2SEL = 14; //end of SOC14 will set INT2 flag
AdccRegs.ADCINTSEL3N4.bit.INT3SEL = 7; //end of SOC7 will set INT3 flag
AdccRegs.ADCINTSEL3N4.bit.INT4SEL = 15; //end of SOC15 will set INT4 flag
//
//ADCINT2 will trigger first 8 SOCs
//
AdcaRegs.ADCINTSOCSEL1.bit.SOC0 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC1 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC2 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC3 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC4 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC5 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC6 = 2;
AdcaRegs.ADCINTSOCSEL1.bit.SOC7 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC0 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC1 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC2 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC3 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC4 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC5 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC6 = 2;
AdcbRegs.ADCINTSOCSEL1.bit.SOC7 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC0 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC1 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC2 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC3 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC4 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC5 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC6 = 2;
AdccRegs.ADCINTSOCSEL1.bit.SOC7 = 2;
//
//ADCINT1 will trigger second 8 SOCs
//
AdcaRegs.ADCINTSOCSEL2.bit.SOC8 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC9 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC10 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC11 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC12 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC13 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC14 = 1;
AdcaRegs.ADCINTSOCSEL2.bit.SOC15 = 1;
AdcbRegs.ADCINTSOCSEL2.bit.SOC8 = 1;
AdcbRegs.ADCINTSOCSEL2.bit.SOC9 = 1;
AdcbRegs.ADCINTSOCSEL2.bit.SOC10 = 1;
AdcbRegs.ADCINTSOCSEL2.bit.SOC11 = 1;
AdcbRegs.ADCINTSOCSEL2.bit.SOC12 = 1;
AdcbRegs.ADCINTSOCSEL2.bit.SOC13 = 1;
AdccRegs.ADCINTSOCSEL2.bit.SOC8 = 1;
AdccRegs.ADCINTSOCSEL2.bit.SOC9 = 1;
AdccRegs.ADCINTSOCSEL2.bit.SOC10 = 1;
AdccRegs.ADCINTSOCSEL2.bit.SOC11 = 1;
AdccRegs.ADCINTSOCSEL2.bit.SOC12 = 1;
AdccRegs.ADCINTSOCSEL2.bit.SOC13 = 1;
EDIS;
//
//software force start SOC0 to SOC15 on A for ADCIN14 and ADCIN15
//
AdcaRegs.ADCSOCFRC1.all = 0xFFFF;
AdcbRegs.ADCSOCFRC1.all = 0x00FF;
AdccRegs.ADCSOCFRC1.all = 0x00FF;
}
//
// End of file
//