8 Bit ADC Question

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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
    }
}

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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

   

 

   

    

   

          

   

“File”                                                           Designer

   

“Archive Project”

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes