Shop OBEX P1 Docs P2 Docs Learn Events
HELP anybody!!! AD7888 & ATmega128. — Parallax Forums

HELP anybody!!! AD7888 & ATmega128.

OlegOleg Posts: 4
edited 2007-06-27 11:16 in General Discussion
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.

Comments

  • kb2hapkb2hap Posts: 218
    edited 2007-06-25 12:15
    did you try

    http://www.avrfreaks.net/

    that may be your best bet

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DTQ
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-06-25 15:20
    In part, your difficulties would get a lot simpler if you avoided learning on an 8 channel device. If you start with a one or two channel device, you would get a better idea of how ADCs work. Then you could sort out all the specialized code for jumping from one channel to another channel.

    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)········
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 6/25/2007 3:39:11 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-06-25 15:26
    This thread is being moved from the SX Forum to the Sandbox Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • metron9metron9 Posts: 1,100
    edited 2007-06-25 17:20
    I read most of the data sheet. It seems very thorough with bit banging examples as well for processors without a serial interface.
    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!
  • OlegOleg Posts: 4
    edited 2007-06-26 11:46
    I didn`t undrestand how to programme according the·datasheet says:"In other words the user must write the channel address for the next conversion while the present conversion is in progress." It sounds simple but I can`t realize this thing. I can`t write function of read·properly. And there is a moment. According ATmega128 there is a·WCOL·(flag in SPSR) - is set if the SPDR (SPI data register) is written during·a data transfer.When I check pins using oscilloscope there are SCLK and MOSI but there is no MISO or MISO always the same like something: |
    |_|
    |_|--...(and it does not depends on voltage·on any pin)smhair.gif· I suppose I didn`t fry AD7888 yet, it must be working.
  • metron9metron9 Posts: 1,100
    edited 2007-06-26 13:53
    How about posting a circuit, how do you have it connected. I have a maga128 as well if you post your code that might help.

    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!
  • OlegOleg Posts: 4
    edited 2007-06-27 11:16
    Thank`s for help!!!

    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);
    ····· };
    ······};
    }
Sign In or Register to comment.