ADC - multi channel example

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Dear Infineon,

I have received some boot kit boards, XMC 1300 and XMC 1400 from you. Currently I am looking at the ADC application notes (AP32305). So far I am having a hard time getting to read two analog channels (pin 2.3 and 2.5). I would like to trigger reading from pin 2.3 and read from pin 2.5 asynchronously. This should be done without using the app's preferably. I have managed so far to get a conversion triggered on pin 2.3, but I fail to read pin 2.5 asynchronously.

I would appreciate some help getting through my mistake/misunderstanding of the documentation. Here is my code


const XMC_VADC_BACKGROUND_CONFIG_t g_bgn_handle =
{
.conv_start_mode = (uint32_t) XMC_VADC_STARTMODE_CIR,
.req_src_priority = (uint32_t) XMC_VADC_GROUP_RS_PRIORITY_1,
.trigger_signal = (uint32_t) XMC_VADC_REQ_TR_M,
.trigger_edge = (uint32_t) XMC_VADC_TRIGGER_EDGE_FALLING,
.gate_signal = (uint32_t) XMC_VADC_REQ_GT_A, /
.timer_mode = (uint32_t) 0,
.external_trigger = (uint32_t) 1,
.req_src_interrupt = (uint32_t) 1,
.enable_auto_scan = (uint32_t) 0,
.load_mode = (uint32_t) XMC_VADC_SCAN_LOAD_OVERWRITE
};

const XMC_VADC_GLOBAL_CONFIG_t g_global_handle = {};
const XMC_VADC_GLOBAL_CLASS_t global_iclass_config =
{
.conversion_mode_standard = (uint32_t) XMC_VADC_CONVMODE_12BIT,
.sample_time_std_conv = (uint32_t) 1,
};

/*Channel_A Result configuration structure*/
const XMC_VADC_RESULT_CONFIG_t g1_ch5_res_config =
{
.data_reduction_control = (uint8_t) 0, /* No Accumulation */
.post_processing_mode = (uint32_t) XMC_VADC_DMM_REDUCTION_MODE,
.wait_for_read_mode = (uint32_t) 0, /* Disabled */
.part_of_fifo = (uint32_t) 0 , /* No FIFO */
.event_gen_enable = (uint32_t) 1 /* Result event Enabled*/
};

/*Channel_A Result configuration structure*/
const XMC_VADC_RESULT_CONFIG_t g1_ch7_res_config =
{
.data_reduction_control = (uint8_t) 0, /* No Accumulation */
.post_processing_mode = (uint32_t) XMC_VADC_DMM_REDUCTION_MODE,
.wait_for_read_mode = (uint32_t) 0, /* Disabled */
.part_of_fifo = (uint32_t) 0 , /* No FIFO */
.event_gen_enable = (uint32_t) 0 /* Result event Disabled*/
};


(storing my measurements in registers 9 and 10)

XMC_VADC_GLOBAL_Init(VADC, &g_global_handle);
XMC_VADC_GROUP_Init(VADC_G1, &g_group_handle);
XMC_VADC_GROUP_SetPowerMode(VADC_G1, XMC_VADC_GROUP_POWERMODE_NORMAL);
XMC_VADC_GLOBAL_SHS_EnableAcceleratedMode(SHS0, XMC_VADC_GROUP_INDEX_1);
XMC_VADC_GLOBAL_StartupCalibration(VADC);
XMC_VADC_GLOBAL_InputClassInit(VADC,global_iclass_config, XMC_VADC_GROUP_CONV_STD,ADC_MEASUREMENT_ICLASS_NUM);
XMC_VADC_GLOBAL_BackgroundInit(VADC, &g_bgn_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G1, 5, &g_g1_ch5_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G1, 7, &g_g1_ch7_handle);
XMC_VADC_GROUP_ResultInit(VADC_G1, 10, &g1_ch5_res_config);
XMC_VADC_GROUP_ResultInit(VADC_G1, 9, &g1_ch7_res_config);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 5);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 7);


interrupt

NVIC_SetPriority(VADC0_G1_1_IRQn, 3);
XMC_VADC_GROUP_SetResultInterruptNode(VADC_G1,10,XMC_VADC_SR_GROUP_SR1);
NVIC_EnableIRQ(VADC0_G1_1_IRQn);


So I have the interrupt, and it works well, but when I try and read out the data for register 9 "XMC_VADC_GROUP_GetResult(VADC_G1,9)", in the while loop I get no result.

Thanks, L
0 Likes
3 Replies
User7282
Level 4
Level 4
Is it possible to post your project or the complete code? For me it would be easier if I could test the project.
0 Likes
lock attach
Attachments are accessible only for community members.
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi,

You might want to have a try on this example code.
0 Likes
Not applicable
Dear Travis,

Your example project has helped me, thank you.

Thanks, L
0 Likes