|
|
View previous topic :: View next topic |
Author |
Message |
epv
Joined: 23 Feb 2008 Posts: 8
|
bitbanging the ADS7822 12 bit serial ADC |
Posted: Wed Feb 27, 2008 8:12 am |
|
|
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
|
Re: bitbanging the ADS7822 12 bit serial ADC |
Posted: Sat Jun 11, 2011 4:13 pm |
|
|
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. |
|
|
|
|
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
|