5 Replies Latest reply on Nov 29, 2018 12:56 AM by D.Sd_3235936

    ADC value read is 0xFFFF

    D.Sd_3235936

      hi

      Using the free run ADC sequential read, but occasionally get the reading 0xFFFF.

      using this flow in a loop :

       

      ADC_SAR_Seq_1_StartConvert();

       

      result = ADC_SAR_Seq_1_GetResult16(CHANNEL_0); -> here i read 0xFFFF

       

      cypress_result_mVolts  = ADC_SAR_Seq_1_CountsTo_mVolts(CHANNEL_0, result); -> here i get some abnormal value as well.

       

      ADC_SAR_Seq_1_StopConvert(); -> using this to save some power.

       

      the 0xFFFF read,

      Can i assume this is zero? or is it some kind of glitch?

      I don't think that a negative current can occur in my system.

        • 1. Re: ADC value read is 0xFFFF
          JoMe_264151

          After the StartConvert() you need to wait for a conversion result using IsEndConversion() API, see ADC datasheet.

           

          Bob

          • 2. Re: ADC value read is 0xFFFF
            MoTa_728816

            Hi,

             

            I tried similar test with following main.c with CY8CKIT-044

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

            #include "project.h"

            #include <stdio.h>

             

            char str[128] ; /* print buffer */

             

            #define CHANNEL_0 (0u)

             

            int main(void)

            {

                uint16_t result ;

                float    cypress_result_mVolts ;

             

                CyGlobalIntEnable; /* Enable global interrupts. */

                UART_Start() ;

             

                sprintf(str, "ADC Test (%s %s)\n", __DATE__, __TIME__) ;

                UART_UartPutString(str) ;

             

                ADC_SAR_Seq_1_Start() ; // (1)

             

                for(;;) {

                    ADC_SAR_Seq_1_StartConvert() ;

            //        ADC_SAR_Seq_1_IsEndConversion(ADC_SAR_Seq_1_WAIT_FOR_RESULT) ; // (2)

                    result = ADC_SAR_Seq_1_GetResult16(CHANNEL_0) ;

                    cypress_result_mVolts = ADC_SAR_Seq_1_CountsTo_mVolts(CHANNEL_0, result) ;

                    sprintf(str, "result: 0x%04X = %d.%03d mV\n",

                        result,

                        (int)cypress_result_mVolts,

                        ((int)(1000.0 * cypress_result_mVolts + 0.5))%1000) ;

                    UART_UartPutString(str) ;

                 

                    ADC_SAR_Seq_1_StopConvert() ;

                    CyDelay(1000) ;

                }

            }

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

             

            And the result was

            000-TeraTerm-log.JPG

            After the line of 0x06F0, I shorted the analog input to GND.

            So it may have said 0x0000 which is 0, 0xFFFF is -1, which is very small value for negative.

             

            Then I modified the schematic and let ADC have a negative reference

             

            003-ADC.JPG

             

            002-ADC_with_Vneg.JPG

            The result was

            001-with-Vneg.JPG

            Now the value for GND is 0xFFFF and 0x0000.

            So I think that we can treat 0xFFFF almost like 0x0000 ~= 0.0V (or GND)

            Note: In the configuration dialog, even if you set the result format as unsigned

            the format for Single Ended is "signed", therefore I'd think that we should treat

            values less or equal to zero as zero.

            if (value <=0) {

              value = 0 ;

            }

             

            So I modified the main.c as

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

            #include "project.h"

            #include <stdio.h>

             

            char str[128] ; /* print buffer */

             

            #define CHANNEL_0 (0u)

             

            int main(void)

            {

                int16_t result ; // <--- now it's int16_t instead of uint16_t before !

                float    cypress_result_mVolts ;

               

                CyGlobalIntEnable; /* Enable global interrupts. */

                UART_Start() ;

             

                sprintf(str, "ADC Test (%s %s)\n", __DATE__, __TIME__) ;

                UART_UartPutString(str) ;

               

                ADC_SAR_Seq_1_Start() ; // (1)

             

             

                for(;;) {

                    ADC_SAR_Seq_1_StartConvert() ;

                    ADC_SAR_Seq_1_IsEndConversion(ADC_SAR_Seq_1_WAIT_FOR_RESULT) ; // (2)

                    result = ADC_SAR_Seq_1_GetResult16(CHANNEL_0) ;

                    if (result <= 0) {         // added

                        result = 0 ;            // added

                    }                                // added

                    cypress_result_mVolts = ADC_SAR_Seq_1_CountsTo_mVolts(CHANNEL_0, result) ;

                    sprintf(str, "result: 0x%04X = %d.%03d mV\n",

                        result,

                        (int)cypress_result_mVolts,

                        ((int)(1000.0 * cypress_result_mVolts + 0.5))%1000) ;

                    UART_UartPutString(str) ;

                   

                    ADC_SAR_Seq_1_StopConvert() ;

                    CyDelay(1000) ;

                }

            }

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

            And the result was

             

            005-result.JPG

             

            Now GND is presented as 0.000mV

             

            moto

            • 3. Re: ADC value read is 0xFFFF
              D.Sd_3235936

              hi ,

              thanks for the reply!

               

              I see that you masked:

              ADC_SAR_Seq_1_IsEndConversion(ADC_SAR_Seq_1_WAIT_FOR_RESULT) ; // (2)

               

              will unmasking it help as suggested by Bob in his comment?

              • 4. Re: ADC value read is 0xFFFF
                MoTa_728816

                Hi,

                 

                I just tried to re-mask the line.

                In general it is reporting reasonable value,

                but from my experience time to time,

                when race condition arise we got surprising value(s).

                So, like Bob-san, I recommend you to activate this line.

                 

                moto

                P.S. Please note that in the first main.c,

                I masked that line, but in the second main.c

                it was not masked.

                • 5. Re: ADC value read is 0xFFFF
                  D.Sd_3235936

                  much appreciated!

                   

                  On Thu, 29 Nov 2018 at 10:13, Motoo Tanaka <community-manager@cypress.com>