HELP anybody!!! AD7888 & ATmega128.
![Oleg](https://images.v-cdn.net/banned_large.png)
Hello!
There is a problem to programme AD7888(analog to digital converter) and ATmega128. Does anybody have some text examples of AD7888 applications? I need any examples of code how to programme this thing using any microcontroller not exactly Atmel. I`ll be appreciate for any help: if you`ll give me some reference or an advice.
There is an attachement of AD7888.
Sorry for my english, I`m a foreigner.
There is a problem to programme AD7888(analog to digital converter) and ATmega128. Does anybody have some text examples of AD7888 applications? I need any examples of code how to programme this thing using any microcontroller not exactly Atmel. I`ll be appreciate for any help: if you`ll give me some reference or an advice.
There is an attachement of AD7888.
Sorry for my english, I`m a foreigner.
pdf
![](/plugins/FileUpload/images/file.png)
185K
Comments
http://www.avrfreaks.net/
that may be your best bet
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DTQ
In sum, an 8 channel ADC is a bit tricky and a hard place to get started.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Everything in the world is purchased by labour; and our passions are the only causes of labor." -- David·Hume (1711-76)········
Post Edited (Kramer) : 6/25/2007 3:39:11 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
What part don't you understand? The serial interface, the selection of adc inputs, wiring the part? I will note the data sheet cautions against over voltage on any of it's input pins so make sure you don't exceed the limits or the part will fry.
I would start by connecting the part like the diagram shows and then get the serial interface up and running. If I had one I would give it a go, looks pretty easy to do.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
|_|
|_|--...(and it does not depends on voltage·on any pin)
You write the ADD2 ADD1 and ADD2 bits in the control register according to the chart on page 9.
Those three bits (bits 5, 4, and 3) for example written to 000 will select AIN1 input channel and 111 would select AIN8.
So you write the control register and the next conversion you request will be from that input. It is saying you can write that while a conversion is taking place on the previous channel (whatever those bits wer set at when the previous conversion started)
The specifics on communication, number of bits to send etc are listed on page 11 under the various modes of operation.
What are you programming the 128 with? Is it a Futurlec board or a single chip?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
It was simplier than I thought.·Looks like it`s getting work like it should. I don`t know what does·Futurlec means. I have a·circuit board and there are some more·other things. I`ll·make an attachement·of a·circuit axactly for ATmega128 and AD7888.
I`m programming in CodevisionAVR.·There is a code:
#include <mega128.h>
#include <spi.h>
#include <stdio.h>
#include <delay.h>
#define CS PORTB.0
#define DOUT PINB.3
#define DIN PORTB.2
#define SCK PINB.1··
#define SPIF 7
unsigned int n;
union adcu
{
· unsigned char byte[noparse][[/noparse]2];
· unsigned int word;
};
unsigned int SPI_MasterTransmit(int data)
{
· union adcu adc_data;
· int timer;
· timer=0;
· SPDR=data;
· /*while(timer!=4)//That`s how I was·trying to make that data convertion·started after 4 cycles. It seems to be unuseful part.
· {···················· //If my ADC works and give quite·precision results so I`ll make·a conclusion -·this is right function in common.
· if (SCK==1)······ //But I·don`t understand why it works so because I`m doing nothing to tell·ATmega taking result after 4 cycles.
· timer++;
· };*/
· while(!(SPSR & (1<<SPIF))){};
··adc_data.byte[noparse][[/noparse]1]=SPDR;
· SPDR=0b00000000;
· while(!(SPSR & (1<<SPIF))){};
· adc_data.byte[noparse][[/noparse]0]=SPDR;
· return (adc_data.word);
·
}·
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0b01110111;
PORTC=0x00;
DDRC=0b00100000;
SPCR=0b01010011;
SPSR=0x00;
while (1)
····· {
····· CS=0;
····· n=SPI_MasterTransmit(0b00111100);//I`m using binary for more·obviousness. Bit·2 for external reference·must be 1.
······CS=1;
····· if(n>2030)··········//This part checks the result precision using LED connected to PINC.5. The LED will blink if·I put certain·voltage level to AINx.
····· {····················· //For example in this case I put on 2.5 V to AIN8. 4096*2.5/5=2048·and diode is blinking.
····· PORTC.5=1;
····· delay_ms(300);
····· PORTC.5=0;
····· delay_ms(300);
····· };
······};
}