4 Replies Latest reply on Nov 5, 2018 3:37 PM by user_13463998

    ADC_read

    valskibuda_1466811

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

       

       

          }

       

       

       

       

         }

        • 1. Re: ADC_read
          bob.marlowe

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

           

          Happy coding

          Bob

          • 2. Re: ADC_read
            valskibuda_1466811

            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

            • 3. Re: ADC_read
              bob.marlowe

              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

              • 4. Re: ADC_read
                user_13463998

                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

                1 of 1 people found this helpful