ADC_read

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

cross mob
Anonymous
Not applicable

Hi,

Hi,

I doing a very simple ADC read - but I am getting random values. The codes is below.  The ADC is configured as a 10-bit single-ended.

#include "project.h"

uint16 output;

int main(void)

{

    ADC_DelSig_1_Start();

    ADC_DelSig_1_StartConvert();

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)

    {

   output = ADC_DelSig_1_Read16();

    }

   }

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi Bob

I have tried that - without any results.. It did actually work once, but not any more. I have attached my code file.

- Thanks

View solution in original post

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You should wait for a conversion ready using ADC_DelSig_1_IsEndConversion(). See parameters in datasheet

Happy coding

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi Bob

I have tried that - without any results.. It did actually work once, but not any more. I have attached my code file.

- Thanks

0 Likes

Instead of

{
        if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS))
{

use

    ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);

and define the variable output as int16, not as uint,

Furthermore I suggest you to call at first

CyGlobalIntEnable;   //    Iallow any interrupt

Bob

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

You seem to set the sample mode to "single sample"

000-ADC-Config.JPG

Then you need to start conversion each time.

So how about changing the main.c like ...

==========================

#include <project.h>

uint16 output = 0 ;

int main()

{

     CyGlobalIntEnable;  // Bob-san's suggestion, and I agree with it

    

    /* Start the components */

    ADC_DelSig_1_Start();

   /* Display the value of ADC output on LCD */

   /* Start the ADC conversion */

   ADC_DelSig_1_StartConvert();

   for (;;) {

        if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS)) {

             output = ADC_DelSig_1_GetResult16() ;

             /* Start next ADC conversion */

            ADC_DelSig_1_StartConvert();

        }

    }

}

==========================

moto