11 posts / 0 new
Author
Message

Hi !

I'm measuring constant voltages(voltage divider) by AD7888 8 channel adc.

ATmega324PA 8MHz

First of all I'm not sure what is SPI mode of this adc.

I think it's SPI MODE 3.

Can someone confirm me on this?

...so hard to put this information on 1st page of datasheet.

What happens is form time to time i get  00 00  or FF FF  and variations of 00 and FF form adc.

Here is code:

```uint8_t a;
a = 2;
a <<= 3;

DDRB |= 0xA0;
//SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPHA) | (1 << SPR1) | (1 << SPR0);
SPCR0 = 0x5F;

gpio_clr(GPIO_6);

for (int j=0;j<20;j++)
{
for (int i=0;i<200;i++)
{
asm("nop");
}

SPDR0 = a;									// read byte 1
while( !(SPSR0&(1<<SPIF0)) );
data48[j*2] = SPDR0;

SPDR0 = a;									// read byte 2
while( !(SPSR0&(1<<SPIF0)) );
data48[j*2+1] = SPDR0;
}

gpio_set(GPIO_6);```

So I set SPI MODE 3

```DDRB |= 0xA0;
//SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPHA) | (1 << SPR1) | (1 << SPR0);
SPCR0 = 0x5F;```

CS for ADC is GPIO_6

Little pause at the beginning of each measurement

```for (int i=0;i<200;i++)
{
asm("nop");
}```

There are 20 measurements on 3rd channel (a=2<<3;) and after that I write them out on USART

07 8D 07 8C 07 8D 07 8D 07 8D 07 8C 00 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF F0 FF

07 8D and similar is OK

I don't perform CS before each measurement because I think it's not necessary.

Thank you !

In the DS on the second or third page it says:

Loads data on rising edge of clock, so that is mode 0, if I read that right.

Try that and see what happens.

Jim

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

Hi Jim !

tried with SPI MODE 0, same thing happens.

Then take a look at how your using CS.

The timing diagrams in the DS show CS is used to start conversion and frame the data transfer as well.

Jim

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

What I usually do is take the device timing diagram

...and then match it to the AVR's timing diagram for the different modes:

Kind of an old part.  Not cheap; ~\$10/qty. 1

What does this ['324 + AD7888 => over \$10] give you versus say an Xmega of about the same pin count at a few bucks?

There is a prior discussion on this part.  No code, but the OP there said it works.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Same results, but 00 and FF come not that frequently as before

```DDRB |= 0xA0;
//SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPHA) | (1 << SPR1) | (1 << SPR0);
SPCR0 = 0x53;       // SPI MODE 0

for (int j=0;j<20;j++)
{
gpio_clr(GPIO_6);

for (int i=0;i<200;i++)
{
asm("nop");
}

SPDR0 = a;									// read byte 1
while( !(SPSR0&(1<<SPIF0)) );
data48[j*2] = SPDR0;

SPDR0 = a;									// read byte 2
while( !(SPSR0&(1<<SPIF0)) );
data48[j*2+1] = SPDR0;

gpio_set(GPIO_6);

for (int i=0;i<200;i++)
{
asm("nop");
}
}```

```for (int i=0;i<200;i++)
{
asm("nop");
}```

That code may be optimized out, i.e. not giving you the delay you expect, I would use a Logic Analyzer to verify it.

I'll let the GCC experts here confirm that.

Jim

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

ki0bk wrote:

```for (int i=0;i<200;i++)
{
asm("nop");
}```

That code may be optimized out, i.e. not giving you the delay you expect, I would use a Logic Analyzer to verify it.

I'll let the GCC experts here confirm that.

Jim

I 've been using this for long time, haven't noticed any problems with it

[Re]:

Kind of an old part.  Not cheap; ~\$10/qty. 1

What does this ['324 + AD7888 => over \$10] give you versus say an Xmega of about the same pin count at a few bucks?

There is a prior discussion on this part.  No code, but the OP there said it works.

uC and adc are not on the same PCB.

I have 2 boards connected with 30-pin flat cable.

Till now I've been using TS7003 ADC with LTC1391 analog MUX.

I would like to have ADC and MUX in one chip.

So AD7888 is not written in stone, it can be some other similar chip.

theusch, can you recommend some other chip which you have tried ?

Thanx !

At least consider putting a suitable microcontroller to do the job.  [is the conversion work done with 3V or 5V?]

For example, an ATxmega8E5 costs a couple bucks in low quantity and has

...so you could communicate with USART or SPI or whatever.  You have to tell us what ADC parameters are important.  Then there will be many microcontrollers that will fit those parameters.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

uC and ADC work on 3,3V

[Re:]You have to tell us what ADC parameters are important

1) ADC has to work on 3,3V

2) 12-bit resolution

3) ADC must have an internal reference

4) at least 100kSPS