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?