cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

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
Reply
1 Solution
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
Reply
4 Replies
Esteemed Contributor II

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

Happy coding

Bob

0 Likes
Reply
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
Reply
Esteemed Contributor II

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
Reply
Esteemed Contributor

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