CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

bitbanging the ADS7822 12 bit serial ADC

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
epv



Joined: 23 Feb 2008
Posts: 8

View user's profile Send private message

bitbanging the ADS7822 12 bit serial ADC
PostPosted: Wed Feb 27, 2008 8:12 am     Reply with quote

Having puzzled out this chip's weirdness, I thought others might find it useful. Seems to work fine. Loosely based on the ads8390 example code, but the 7822 operates differently.

Code:

#define ADS7822_CLK  PIN_B4
#define ADS7822_DOUT PIN_B1
#define ADS7822_CS   PIN_B3

void init_ext_adc()
{
        output_high(ADS7822_CS);
        output_high(ADS7822_CLK);
}

long read_ext_adc()
{
        int i;
        long data;

        data=0;
        output_low(ADS7822_CLK); // IMPORTANT!
        output_low(ADS7822_CS);  // CLK *must* drop just _before_ CS
        delay_us(1);
        output_high(ADS7822_CLK); // Start the conversion,
        delay_us(1);
        output_low(ADS7822_CLK);  // and throw away the next
        delay_us(1);
        output_high(ADS7822_CLK); // three clocks, then you
        delay_us(1);
        output_low(ADS7822_CLK);  // can collect the output
        delay_us(1);
        delay_us(1);

        for(i=0;i<12;++i) {           // Now we shift out valid data.
                output_low(ADS7822_CLK);
                delay_us(1);
                shift_left(&data,2,input(ADS7822_DOUT));
                output_high(ADS7822_CLK);
                delay_us(1);
        }
        output_high(ADS7822_CS);
        return(data);
}
enzo84



Joined: 11 Jun 2011
Posts: 1

View user's profile Send private message

Re: bitbanging the ADS7822 12 bit serial ADC
PostPosted: Sat Jun 11, 2011 4:13 pm     Reply with quote

Hi, epv, I tested this code using a PIC16F876 to read the ads7822, and it worked but I found a problem. The value received was half what it should be. Looking at your code and ads7822's datasheet I found that it lacked a rising edge, so I added that pulse and now the code worked well, got the expected value by reading the ADC. This works. The code is:

Code:

#define ADS7822_CLK  PIN_B0
#define ADS7822_DOUT PIN_B1
#define ADS7822_CS   PIN_B2

void init_ext_adc()
{
        output_high(ADS7822_CS);
        output_high(ADS7822_CLK);
}

long read_ext_adc()
{
        int i;
        long data;

        data=0;
        output_low(ADS7822_CLK); // IMPORTANT!
        output_low(ADS7822_CS);  // CLK *must* drop just _before_ CS
        delay_us(1);
        output_high(ADS7822_CLK); // Start the conversion,
        delay_us(1);
        output_low(ADS7822_CLK);  // primer flanco descendente
        delay_us(1);
        output_high(ADS7822_CLK);
        delay_us(1);
        output_low(ADS7822_CLK);  // segundo flanco descendente (bit nulo)
        delay_us(1);
        output_high(ADS7822_CLK); // <--- pulso que faltaba
        delay_us(1);              // en el próximo flanco descendente
                                  //se obtiene el primer bit (msb)
        for(i=0;i<12;++i) {           // Now we shift out valid data.
                output_low(ADS7822_CLK);
                delay_us(1);
                shift_left(&data,2,input(ADS7822_DOUT));
                output_high(ADS7822_CLK);
                delay_us(1);
        }
        output_high(ADS7822_CS);
        return(data);
}


Regards, Enzo.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group