4 Replies Latest reply on Oct 31, 2014 8:44 AM by user_14586677

    8 Bit ADC Question

    alan.martin

      Hello,

         

      Just getting started in Psoc and using the CY3210-Eval kit. I have an 8 Bit ADC generating values to use for the pulse width of an 8 Bit PWM, reading the 0-5V pot output . Have a scope on the PWM out and the pulse width changes as I would expect. Then I decided to print the ADC results to the LCD and I am seeing counts of 130 to 980. I was expecting to see 0-256. Can you see what is wrong. Also if there ia amore elegent way of doing this please comment. Code follows.

         

       

         

      #include <m8c.h>        // part specific constants and macros
      #include "PSoCAPI.h"    // PSoC API definitions for all User Modules


      void main(void)
      {
          unsigned int bADCdata;// holds the ADC Data
          unsigned int i;
          char adc_val[12];
          M8C_EnableGInt; // enable global interupts
          PGA_1_Start(PGA_1_HIGHPOWER); // Start Programable Amp
          ADCINC_1_Start(ADCINC_1_HIGHPOWER);// Start ADC
          ADCINC_1_GetSamples(0); // Get samples continously
          PWM8_1_Start();// Start PWM
          LCD_1_Start();
          while (1)
          {
              if (ADCINC_1_fIsDataAvailable() !=0)// Check is data ia available from the ADC conversion
                  bADCdata = ADCINC_1_bGetData(); // Put ADC Data into a variable
                  PWM8_1_WritePulseWidth(bADCdata); // write the ADC Data to the Pulse Width Register in PWM
                  itoa(adc_val,bADCdata,10);//convert ADC data to a Char
                  LCD_1_Position(0,0);
                  LCD_1_PrString(adc_val);// Print the Char to LCD
                  ADCINC_1_fClearFlag();// Clear the flag for the next ADC conversion
          }
      }

        • 1. Re: 8 Bit ADC Question
          user_1377889

          You should

             

          1st Clear the display by writing some spaces to erase the previous characters

             

          2nd Insert a delay into the loop because you write much faster than the human eye may follow

             

           

             

          Bob

          • 2. Re: 8 Bit ADC Question
            user_14586677

            Consider posting your project so all settings can be looked at -

               

             

               

                

               

                      

               

            “File”                                                           Designer

               

            “Archive Project”

               

             

               

            Regards, Dana.

            • 3. Re: 8 Bit ADC Question
              alan.martin

              Bob,

                 

               

                 

              Thanks , sending spaces to clear the LCD fixed the display problem , I also added a delay loop.  Is it true there is no CLEAR command to clear and home the LCD?

                 

               

                 

              Thanks,

                 

               

                 

              Alan

              • 4. Re: 8 Bit ADC Question
                user_14586677

                You clear the display by writing spaces to it.

                   

                 

                   

                Easiest way is to create an array, say if display is X 16, that is 17 in length and

                   

                init it with spaces -

                   

                 

                   

                unsigned char LCDclear[ 17 ] = "                 ";

                   

                 

                   

                and just print the string to each row.

                   

                 

                   

                Regards, Dana.