Hi,
Here's my code modified from example adc_pal_mpc5746r.
#define ADC_CHAN_INDEX_CONNECTED2 (2)
#define ADC_CHAN_INDEX_CONNECTED1 (1)
#define ADC_CHAN_INDEX_CONNECTED0 (0)
/* Flag used to store if an ADC PAL conversion group has finished executing */
volatile bool groupConvDone = false;
/* Flag used to store the offset of the most recent result in the result buffer */
volatile uint32_t resultLastOffset = 0;
void adc_pal1_callback00(const adc_callback_info_t * const callbackInfo, void * userData)
{
(void) userData;
groupConvDone = true;
resultLastOffset = callbackInfo->resultBufferTail;
}
/*
* Description: Convert a float to null terminated char array
*/
static void floatToStr (const float *srcValue, char *destStr, uint8_t maxLen);
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
status_t status;
uint8_t selectedGroupIndex;
const uint16_t adcMax = (1u << 12u); /* Resolution is 12bits for all ADC instances */
float resVolts0;
float resVolts1;
float resVolts2;
/* Buffer used to store processed data for serial communication */
char msg[255] =
{ 0, };
status = CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
DEV_ASSERT(status == STATUS_SUCCESS);
status = CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
DEV_ASSERT(status == STATUS_SUCCESS);
/* Initialize pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* Initialize the ADC PAL
* - See ADC PAL component for the configuration details
*/
status = ADC_Init(&adc_pal1_instance, &adc_pal1_InitConfig0);
DEV_ASSERT(status == STATUS_SUCCESS);
/***************************************************************
* Part 1 of the example: software triggered conversion group
***************************************************************/
selectedGroupIndex = 0u; /* Select the index of a SW triggered group of conversions (see ADC PAL component) */
/* Start the selected SW triggered group of conversions */
status = ADC_StartGroupConversion(&adc_pal1_instance, selectedGroupIndex);
DEV_ASSERT(status == STATUS_SUCCESS);
/* Called only for demonstration purpose - it is not necessary and doesn't influence application functionality. */
status = ADC_StartGroupConversion(&adc_pal1_instance, 1u); /* Starting another SW triggered group while other is running will return BUSY. */
/* Do not place any breakpoints or run step-by-step between the start of the first conversion group
* at line ADC_StartGroupConversion(&adc_pal1_instance, selectedGroupIndex) and line with DEV_ASSERT(status
== STATUS_BUSY).
* Otherwise the DEV_ASSERT will fail because of timing restrictions: previous conversion list finishes execution before the second call to
* ADC_StartGroupConversion() => will return different status than expected. */
DEV_ASSERT(status == STATUS_BUSY);
uint8_t iter = 0;
while(true)
{
/* Wait for group to finish */
if(groupConvDone == true)
{
resVolts0 = ((float) adc_pal1_Results00[ADC_CHAN_INDEX_CONNECTED2] / adcMax) * VREF;
floatToStr(&resVolts0, msg, 5);
resVolts1 = ((float) adc_pal1_Results00[ADC_CHAN_INDEX_CONNECTED1] / adcMax) * VREF;
floatToStr(&resVolts1, msg, 5);
resVolts2 = ((float) adc_pal1_Results00[ADC_CHAN_INDEX_CONNECTED0] / adcMax) * VREF;
floatToStr(&resVolts2, msg, 5); *****I set breakpoint at here to watch 3 resVolt value, if there's no breakpoint, it will be empty in variables.
/* Reset flag for group conversion status */
groupConvDone = false;
iter ++;
OSIF_TimeDelay(100);
/* Restart the SW triggered group of conversions */
status = ADC_StartGroupConversion(&adc_pal1_instance, selectedGroupIndex); /* Restart can be avoided if SW triggered group is configured to run in continuous mode */
DEV_ASSERT(status == STATUS_SUCCESS);
}
}
status = ADC_Deinit(&adc_pal1_instance);
DEV_ASSERT(status == STATUS_SUCCESS);
for(;;)
{
if(exit_code != 0)
{
break;
}
}
return exit_code;
}
I've already finished pinsettings and component inspector in adc_pal1 (both are shown in figure), now I can receive voltage conversion results once from motherboard shown in variables.But I need to receive changing voltage conversion results continuously, how can I make it work? Thanks.
Best Regards,
Xantia




