6 Replies Latest reply on Aug 2, 2016 12:55 PM by user_1377889

    Problem With ADC C code

    rm3330_1699156

      Hello, I am running a very basic application of varying input voltage into an ADC and changing the LED color based on the voltage range. I keep receiving an error about not being able to define my variable adcSample (which is the result from the ADC).

         

       

         

      int main()
      {
          /* Initialize ADC. Conversion is not enabled yet. */
          void ADC_Start();

         

       

         

          /* Start ADC conversion. */
         void ADC_StartConvert();

         

         adcSample = ADC_GetResult16(uint32 0)

        • 1. Re: Problem With ADC C code
          user_1377889

          I cannot see a line like

             

          uint16 adcSample;

             

          or

             

          int adcSample;

             

          Additionally: You did not check whether a conversion result is already availlable. Check your ADC datasheet for the correct API.

             

           

             

          Bob

          • 2. Re: Problem With ADC C code
            rm3330_1699156

            I had not copied that part of the code. Here it is:

               

             

               

            /* ADC measurement status and result */
            int16 adcSample = 0;
            uint8 userRefresh = USER_LED_REFRESH - 1u;

               



            int main()
            {
                /* Initialize ADC. Conversion is not enabled yet. */
                void ADC_Start();

               

                
                    
                /* Start ADC conversion. */
               void ADC_StartConvert();

               

               adcSample = ADC_SAR_Seq_1_GetResult16(0x00u); 

            • 3. Re: Problem With ADC C code
              user_1377889

              Can you please post your actual complete project, so that we all can have a look at all of your settings. To do so, use
              Creator->File->Create Workspace Bundle (minimal)
              and attach the resulting file.

                 

               

                 

              Bob

              • 4. Re: Problem With ADC C code
                rm3330_1699156

                I have attached the minimal compression, please take a look and I would highly appreciate any advice greatly. Again, all I am trying to do is use the ADC output and compare it to 4 ranges which will light up 4 different LEDs. My device is a 4200 BLE

                • 5. Re: Problem With ADC C code
                  user_1377889

                  The line

                     

                     adcSample = ADC_SAR_Seq_1_GetResult16(0x00u);

                     


                  is only executed once, it is outside of your main loop. So adcSample will never change.

                     

                  Again: You did not check whether a conversion result is already available. Use ADC_SAR_Seq_1_IsEndConversion(), see datasheet.

                     

                  Project compiles without warnings, only 5 notes.

                     

                   

                     

                  Bob

                  • 6. Re: Problem With ADC C code
                    ahamed_1694551

                    Hello,

                       

                         

                       

                    try using this code..wait for the conversion of ADC is done

                       

                    ADC_Start();

                       

                    CyDelay(50);
                     ADC_StartConvert();
                       CyDelay(50);
                       
                            if(ADC_IsEndConversion(ADC_WAIT_FOR_RESULT))
                            {
                                adcSample =ADC_SAR_Seq_1_GetResult16(0);
                             

                       

                     

                       

                     

                       

                    from here u can continue the code snippet of yours