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

cross mob
GarageDirt
Level 3
Level 3
5 questions asked 25 sign-ins First solution authored

In learning to use the XMC4500 lite, I am working through the Infineon Tutorials.  With Lesson #8, ADC Measurement, the result of the analog to digital conversion is stored in a variable called "result".  In the lesson, the actual value of the result is not  found, nor it is possible to find out what it is as far as I can tell.  Instead it is compared to some number and turns on or off an LED.  An ADC result is pretty useless if it is impossible to know what it is.  I know this is a pretty basic question, but the answer is not at all obvious.  Can use some help here.

0 Likes
1 Solution

I forgot a couple of things.

Make sure you have both ADC_Measurement and UART up and running.  They are  Infineon Dave lessons #7 and  #21.  I got both to work on my XMC 45 Relax Lite board.  

Second, it seems a small wait is required.

In the ADC_Measurement_Handler loop.  I was getting the wrong answer until I put the following  short wait loop:     for(n = 0;n<1000;n++) {}     in front of the 4 added lines.  

Hope this works for you.  

View solution in original post

0 Likes
5 Replies
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @GarageDirt ,

As per my understanding you want to see the result values.

It is possible with two ways.

As you are familiar with Dave IDE please put an break point at the variable "result" so when performing the debugging, every time you press the Run symbol you can see the result value in the variable window.

Please refer to the below figure.

ppn_0-1692276279858.png

The other method we are suggesting is create an UART communication between the board and the PC and then transmit the value of variable "Result".

By transmitting the result value you can see the Result value  in the Tera Term on your PC.

Hope this helps and let me know if you need any further information.

Best Regards
Pradeep.

0 Likes

Pradeep,

My first thought was to combine my working UART and working ADC into one program as you suggested.  I tried many ways to combine the two programs.  Nothing seems to work.   There must be some little piece of information that I am lacking.  Any suggestions or sample code?

0 Likes

Did some more work on the problem with UART.  I did the following, without success.

Starting with a working ADC program that turns on LEDs with changing voltage to P14.6 pin.

  1. Click UART App.
  2. Add pins P5.0 and P5.1 (send and receive) to project.
  3. Configure baud to 57,600.
  4. Try to debug…  it won’t.
  5. Turn off Dave to blank screen.
  6. Restart Dave.  Program will now debug.
  7. Add one line of code as   UART_STATUS_t  UART_t_Transmit( Config……  etc).
  8. Debug puts red X in front of this line, but debugs anyway.
  9. Removed the line with red X.  Debugs no errors.  Don’t know it that line is
  10. necessary.  Was not a part of the main body of UART code in UART.h.

 

Placed the following code in “main” directly below the working ADC code.  Taken directly from

UART.h.

  UART_STATUS_t init_status;

     uint8_t Send_Data[] = "Infineon DAVE application.";

     uint8_t NewData[] = "New data message";

          init_status = (UART_STATUS_t)UART_Init(&UART_0);

          if(init_status == UART_STATUS_SUCCESS)

          {

            UART_Transmit(&UART_0, Send_Data, sizeof(Send_Data));

            if(UART_0.runtime->tx_busy)

            {

              if(UART_AbortTransmit(&UART_0) == UART_STATUS_SUCCESS)

              {

                UART_Transmit(&UART_0, NewData, sizeof(NewData));

               while(UART_0.runtime->tx_busy);

              }

            }

            while(1)

           {

            }

          }

          else

          {

           XMC_DEBUG("main: Application initialization failed");

           while(1U)

           {

           }

          }

           return 1U;

       }

  1.  Code builds fine, but will not debug. Exit DAVE to blank screen.
  2. Restarted DAVE. Does debug now.
  3. ADC part of program works, but UART does not.
  4. Have correct com port and baud rate, but nothing on RealTerm.
  5. Stuck now, don’t know what else to try.
0 Likes

Ok,  after working a few more days on this problem, I have come up with a solution.  Perhaps not the best solution, but it works.  

In the forum, I asked about getting the numbers generated by onboard ADC. I was struggling, as you are right now. Very frustrating.

Here is how you can do it. Get an Arduino Uno board (a few dollars).
Locate Infineon Dave Lesson #21 Video ( ADC_Measurement ) on the net. Get up and running.
It is kind of cryptic, but if you are patient, it will work.

First, do this
**********************
On your Uno, write the following program (8 lines of code) and leave the board powered up.
This will grab whatever data is incoming and send it out to your terminal program.
**********************

int incomingByte = 0;
void setup()
{
Serial.begin(57600); // opens serial port, sets data rate to 57600 bps
}
void loop()
{
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
incomingByte = Serial.read(); // read the incoming byte:
Serial.println(incomingByte, DEC);
}
}

Second, do this
***********************
Now, if you have successfully gotten the Infineion Dave ADC_Measurement program up and running, type the following 4 lines of code directly before the line .... ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);...... in the void Adc_Measurement_Handler() function.
***********************

UART_STATUS_t init_status;
uint8_t SendData = result;
init_status = (UART_STATUS_t)UART_Init(&UART_0);
UART_TransmitWord(&UART_0,SendData); // This is 8 bit data

Third, do this
*******************
Connect a ground wire between the Uno board and the XMC 47... board.
Connect a wire from Pin 14,6 on the XMC 47.. board to the Rx pin on the Uno
board (labeled pin 0).
*******************

Fourth, do this
************************


Build, debug, and run the ADC_MEASUREMENT program on the XMC 47.. board. Using the attached poteniometer, rotate the shaft. If your system is the same as described above, you will see ADC numbers on the terminal. Keep in mind, the displayed numbers are zero to 255. When the value of "result" is greater than 255, the displayed result will "roll over" to 1 and continue upward again.
************************

 

 

 

0 Likes

I forgot a couple of things.

Make sure you have both ADC_Measurement and UART up and running.  They are  Infineon Dave lessons #7 and  #21.  I got both to work on my XMC 45 Relax Lite board.  

Second, it seems a small wait is required.

In the ADC_Measurement_Handler loop.  I was getting the wrong answer until I put the following  short wait loop:     for(n = 0;n<1000;n++) {}     in front of the 4 added lines.  

Hope this works for you.  

0 Likes