This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: ADC14 trigger time settings

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi, I wonder how to set the correct Sample time of ADC14 I need.

Here's the code:

void ADC14_Init(void)
{
Timer_A_PWMConfig timerA_PWM;

/* Configuring pins for peripheral/crystal usage for output */
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
GPIO_PIN3 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);

/* Starting HFXT in non-bypass mode without a timeout. Before we start
* we have to change VCORE to 1 to support the 48MHz frequency */
MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);

/* Just in case the user wants to use the getACLK, getMCLK, etc. functions,
* let's set the clock frequency in the code.
*/
CS_setExternalClockSourceFrequency(32768,48000000);
CS_startHFXT(false);

/* Initializing MCLK to HFXT (effectively 48MHz) */
MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2);
MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);

/* Initializing ADC (MCLK/1/1) */
MAP_ADC14_enableModule();
MAP_ADC14_initModule(ADC_CLOCKSOURCE_SMCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
ADC_MAPINTCH3);

/* Configuring GPIOs (5.5 A0) */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
GPIO_TERTIARY_MODULE_FUNCTION);

/* Configuring ADC Memory */
MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A0, false);

timerA_PWM.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
timerA_PWM.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
timerA_PWM.timerPeriod = 239;
timerA_PWM.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
timerA_PWM.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;
timerA_PWM.dutyCycle = 120;
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &timerA_PWM);
// MAP_Timer_A_stopTimer(TIMER_A0_BASE);

/* Configuring the sample trigger to be sourced from Timer_A0 and setting it
* to automatic iteration after it is triggered*/
MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false);

/* Enabling the interrupt when a conversion on channel 1 is complete and
* enabling conversions */
MAP_ADC14_enableInterrupt(ADC_INT0);
MAP_ADC14_enableConversion();

/* Enabling Interrupts */
MAP_Interrupt_enableInterrupt(INT_ADC14);
MAP_Interrupt_enableMaster();
}

/* This interrupt is fired whenever a conversion is completed and placed in
* ADC_MEM0 */
void ADC14_IRQHandler(void)
{
uint64_t status;
status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status);
if (status & ADC_INT0)
{
resultsBuffer[resPos++] = MAP_ADC14_getResult(ADC_MEM0);
if(resPos==UINT8_MAX)
resPos = 0;
LED1_TOGGLE;
}
}

When there occurs an interrupt, LED toggles. I observe the wave on LED output pin to get the sample time of ADC.

I set the SMCLK to 24000000Hz, imerA_PWM.timerPeriod = 239, so PWM has a frequency of 240/24 = 10us, and I observed a period wave with 10us high level and low level on oscilloscope, which likes my suppose.

But when I set imerA_PWM.timerPeriod = 23, timerA_PWM.dutyCycle = 12, desiring a PWM of 24/24 = 1us, I got a period wave with 7us high level and low level.

Why?

  • The LED measures the period of the ADC ISR, not the timer. 1us (48 MCLKs) isn't long enough to do all that work, so the ISR is being overrun.

    Your 7us measurement gives a first approximation to how long the ISR is actually taking, though there are some confounding effects due to resetting the IFG in the middle. (My guess would be more like 2-3usec.)
  • Thanks for replying.
    Do you mean that the ISR can't solve interrupt in this high speed, so it slows down the sample process?
  • Yes. You have reached (and gone beyond) a threshold where it takes longer to process a sample than it does to produce one, i.e. by the time the ISR finishes there's already another sample ready. In this condition you will eventually lose samples.

    There's another threshold (you haven't reached it yet) where the period is so small the ADC doesn't have time to complete the conversion before the next is triggered. As I recall, in this case the "start" request is ignored, which is another way of losing a sample.

    Once you get beyond a simple example, you'll probably want to actually do something useful with the data, which itself will take CPU cycles. This imposes yet another practical limit on your sample period.
  • Thanks a lot.
    1MHz SPS is the highest one of the precision ADC in MSP432, I guess sample frequency exceeding 1MHz may cause the sencond way of losing a sample, whereas I don't do this.
    I change my way of dealing the sample data, using DMA to transmit them and I observed PWM output pin outputing a 1MHz wave.I think I correctly set a sample frequency of 1MHz,do I?
  • From what you're describing, it sounds as though you're indeed triggering at 1Msps.
  • Thanks for your help.

**Attention** This is a public forum