ADC example in documentation - not working

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

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
Hi All,

I following the steps in the documentation contained in DAVE 4 for the "ADC_MEASUREMENT[4.1.12]" under the "Usage" tab, the example simply does not work.

Notes:
1) I adapted the example to work with the XMC1300 boot kit. Thus I used the potentiometer pin P2.5.
2) Checked on scope, the voltage level does change on change of the potentiometer.
3) I have attached the example for the XMC1300 boot kit.

Is there somewhere I can find a working example of using the ADC?

Regards,
Enigma
0 Likes
10 Replies
User7282
Level 4
Level 4
Looking at your code, seems that you adapted wrongly the code to your device.

Because you are using XMC13, you should have:
result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Channel_A);


instead of:
result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_0);
0 Likes
Not applicable
Hi,

I tried both ways, based on the documentation. Still does not work. Does it work for you? I can work with the ADC without using the APPs and can get reliable readings, but using the APP it fails.

Regards,
Enigma
0 Likes
Not applicable
Hello,

I work with the ADC-Measurement app and use:

ResultA = // Get result from ADC Channel A
XMC_VADC_GROUP_GetResult
(ADC_MEASUREMENT_Channel_A.group_handle,
ADC_MEASUREMENT_Channel_A.ch_handle->result_reg_number);

ResultB = // Get result from ADC Channel B
XMC_VADC_GROUP_GetResult
(ADC_MEASUREMENT_Channel_B.group_handle,
ADC_MEASUREMENT_Channel_B.ch_handle->result_reg_number);

to retrieve the results from two channels. It's working fine for me. Maybe you give this a try.

Regards
Kurt
0 Likes
User7282
Level 4
Level 4
enigmaldc wrote:
Hi,

I tried both ways, based on the documentation. Still does not work. Does it work for you? I can work with the ADC without using the APPs and can get reliable readings, but using the APP it fails.

Regards,
Enigma


I don't have right now the XMC1300 board with me, but I tested the example in a XMC4400 board and I got it working, no problems.

You can try to debug it step by step, maybe start to see if the interrupt is being executed.
0 Likes
lock attach
Attachments are accessible only for community members.
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
enigmaldc wrote:
Hi All,

I following the steps in the documentation contained in DAVE 4 for the "ADC_MEASUREMENT[4.1.12]" under the "Usage" tab, the example simply does not work.

Notes:
1) I adapted the example to work with the XMC1300 boot kit. Thus I used the potentiometer pin P2.5.
2) Checked on scope, the voltage level does change on change of the potentiometer.
3) I have attached the example for the XMC1300 boot kit.

Is there somewhere I can find a working example of using the ADC?

Regards,
Enigma


Hi,

You might want to give this code a try.
0 Likes
Not applicable
Hi All,

Thanks for all the replies. I just got back to playing with my new toys. I will give this example a try and let you know how it goes.

Regards
Enigma
0 Likes
Not applicable
Hi Travis,

I looked at your example, but maybe I am just not understanding what you did, but I find it very hard following your code. Here I have very simple code and it just does not work

const XMC_VADC_GLOBAL_CONFIG_t g_global_handle = { };

const XMC_VADC_GROUP_CONFIG_t g_group_handle = { };

const XMC_VADC_SCAN_CONFIG_t g_scan_handle = {
.trigger_signal = XMC_VADC_REQ_TR_A,
.trigger_edge = XMC_VADC_TRIGGER_EDGE_ANY,
.external_trigger = 1,
.req_src_interrupt = 1 };

// P2.3,G1CH5
const XMC_VADC_CHANNEL_CONFIG_t g_g1_ch5_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 5 };

// P2.4, G1CH6
const XMC_VADC_CHANNEL_CONFIG_t g_g1_ch6_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 6 };

// P2.5, G1CH7
const XMC_VADC_CHANNEL_CONFIG_t g_g1_ch7_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 7 };


int main(void)
{
uint32_t result[16] = {};

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_StartupCalibration(VADC);

XMC_VADC_GROUP_ScanInit(VADC_G1, &g_scan_handle);

XMC_VADC_GROUP_ChannelInit(VADC_G1, 5, &g_g1_ch5_handle); // P2.3
XMC_VADC_GROUP_ChannelInit(VADC_G1, 6, &g_g1_ch6_handle); // P2.4
XMC_VADC_GROUP_ChannelInit(VADC_G1, 7, &g_g1_ch7_handle); // P2.5
XMC_VADC_GROUP_ScanAddChannelToSequence(VADC_G1, 5); // P2.3
XMC_VADC_GROUP_ScanAddChannelToSequence(VADC_G1, 6); // P2.4
XMC_VADC_GROUP_ScanAddChannelToSequence(VADC_G1, 7); // P2.5

// enable continuous mode - autoscan feature
XMC_VADC_GLOBAL_BackgroundEnableContinuousMode(VADC);
// conversion is triggered by software
XMC_VADC_GLOBAL_BackgroundTriggerConversion(VADC);


while (1U) {
result[7] = XMC_VADC_GROUP_GetResult(VADC_G1, 5);
result[1] = XMC_VADC_GROUP_GetResult(VADC_G1, 6);
result[0] = XMC_VADC_GROUP_GetResult(VADC_G1, 7);
}

}


I just want to monitor pins P2.3, P2.4 and P2.5 in this example continuously, but this simple example of mine fails. Can you spot my mistake? I can monitor these channels with the following code

#include 

// uses standard values
const XMC_VADC_GLOBAL_CONFIG_t g_global_handle = { };

// uses standard values
const XMC_VADC_GROUP_CONFIG_t g_group_handle = { };

// uses standard values
const XMC_VADC_BACKGROUND_CONFIG_t g_bgn_handle = { };

// P2.3,G1CH5
const XMC_VADC_CHANNEL_CONFIG_t g_g1_ch5_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 5 };

// P2.4, G1CH6
const XMC_VADC_CHANNEL_CONFIG_t g_g1_ch6_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 6 };

// P2.5, G1CH7
const XMC_VADC_CHANNEL_CONFIG_t g_g1_ch7_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 7 };

int main(void)
{
uint32_t result[16] = {};

// init ADC, set the clock and VADC
XMC_VADC_GLOBAL_Init(VADC, &g_global_handle);
XMC_VADC_GROUP_Init(VADC_G1, &g_group_handle);

// set power mode
XMC_VADC_GROUP_SetPowerMode(VADC_G1, XMC_VADC_GROUP_POWERMODE_NORMAL);
// start calibration
XMC_VADC_GLOBAL_StartupCalibration(VADC);


XMC_VADC_GLOBAL_BackgroundInit(VADC, &g_bgn_handle);
//init ch before adding it to the group
XMC_VADC_GROUP_ChannelInit(VADC_G1, 5, &g_g1_ch5_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G1, 6, &g_g1_ch6_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G1, 7, &g_g1_ch7_handle);

// add ch to background source
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 5);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 6);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 7);

// enable continuous mode - autoscan feature
XMC_VADC_GLOBAL_BackgroundEnableContinuousMode(VADC);
// conversion is triggered by software
XMC_VADC_GLOBAL_BackgroundTriggerConversion(VADC);

while(1U)
{
// readout the result from the ADc reading - value between [0,2^8-1] for 12 bit reading
result[7] = XMC_VADC_GROUP_GetResult(VADC_G1, 5);
result[1] = XMC_VADC_GROUP_GetResult(VADC_G1, 6);
result[0] = XMC_VADC_GROUP_GetResult(VADC_G1, 7);
}
}


but this uses the background method. What is the core difference between using "Background" and "Scan"?

Regards
Enigma
0 Likes
lock attach
Attachments are accessible only for community members.
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi,

I had programmed the VADC for P2.3, P2.4 and P2.5 using the Queue source.

And you can use below API to start the conversion, please give this a try.


//Software trigger
XMC_VADC_GROUP_QueueTriggerConversion(VADC_G1);
0 Likes
Not applicable
Hi Travis,

Thanks, I will have a look tomorrow and let you know how it went.

Regards
Enigma
0 Likes
Not applicable
Hi Travis,

Thanks, it works and I have come across my own mistake now.

It does not seems to me that there is really any difference in the background method or the scan method. Could you elaborate on the two methods?

Regards
Enigma
0 Likes