Reading analog input using IO001

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

cross mob
Not applicable
Hello all,

I am a beginner with xmc and am using xmc4500 relax lite kit. I'm trying to read a simple analog input but it just won't work.
My code is very simply:

pins[0] = IO001_ReadPin(IO001_Handle0);
pins[1] = IO001_ReadPin(IO001_Handle1);
pins[2] = IO001_ReadPin(IO001_Handle2);
pins[3] = IO001_ReadPin(IO001_Handle3);
pins[4] = IO001_ReadPin(IO001_Handle4);
pins[5] = IO001_ReadPin(IO001_Handle5);
pins[6] = IO001_ReadPin(IO001_Handle6);

When I check the contents of the array they are 1.0 at all times. regardless of the input I set (which should be 2V).

What a, I doing wrong?
0 Likes
4 Replies
User10215
Level 4
Level 4
First like received
Hi AElGarem,

it's a long time ago that I used DAVE 3...those functions you have there look very much like functions to read out the digital state of a pin. 2 Volts should be above the threshold for the xmc4500 to recognice a digital '1' so that's why your array is filled with ones.
In order to read out analog values you would need to use the ADC (Analog Digital Converter) of the xmc4500. Unfortunately I have no idea how to do that in DAVE 3.
I think there should be APP-examples for DAVE 3 somewhere. Just google for "Dave 3 analog example" or similar and you will find examples from Infineon.

Regards,
Niclas
0 Likes
Not applicable
Hi Niclas,

I tried what you said and used the ADC001 but unfortunately this has the exact opposite effect...the only output I get is 0, regardless of the input I have...any Ideas?

Thanks
0 Likes
User10215
Level 4
Level 4
First like received
Hi AElGarem,

are you still using the function "IO001_ReadPin" to get the result? That won't work! You need the functions that DAVE gives you in order to get the analog result from the ADC! Try to find the help in DAVE and see what functions the App "ADC001" gives you.
There should be some function along the line of "ADC_GetResult" or something like that (as I said I'm not familiar with DAVE 3 so I have no idea how the function is called there). Could you also please describe how you configured the "ADC001"-App?

Just a sidenote here: do you have to use DAVE 3? I would advise to install DAVE 4...it gives you much cleaner generated code and the Help for the APPs are pretty good and even come with examples.

Regards,
Niclas
0 Likes
Not applicable
No I did not use ReadPin, I used the result in an if...else. Now the results don't make any sense, I have input set to 0v but the results of the ADC keep changing to anything between 0 and 4000.
The ADC001 App is configured to do background scans (auto scanning on) and it is connected to an NVIC (once the result is ready I read the result using getresult) and then do the if else statements based on the results.

I'm not sure; I'm working under someone's supervision so I'd have to ask if he offered me DAVE3 because I have to use it or if I can change it.

Cheers,
Ahmed
0 Likes