Post Go back to editing

AD7699

Category: Software
Product Number: AD7699

Hi I am working with AD7699 and Raspberry pi. I want to read the data from the second channel and send it to raspberry pi using SPI communication. But I am struggling with it. I am using internal reference of 4.096V. Can anyone help me with the code please?

  • BMGuardian,

    Just a few quick comments that will hopefully get you started.  I'm going to assume that in this case you want to use the configuration mode to address the channel of interest for the conversion rather than use the sequencer.  However, if you do decide to use the sequencer the process doesn't really change significantly.

    1) The first thing to remember is that the configuration word you write should be left justified in a sixteen bit transfer such that the MSB is a logic 1'b1 to instruct the AD7699 that you wish to update the configuration.

    2) Secondly, the AD7699 has a single conversion latency (one-deep delay) between the configuration word write into the serial buffer before the buffer contents are moved into an internal register and applied to the subsequent conversion.

    So in this case we are going to attempt to read from channel 1 (second channel) and assume that we have the following configuration.

    • INCC:  Unipolar, with respect to COM   (3'b110)
    • INX:     Channel 1    (3'b001)
    • BW:     Full (1'b1)
    • REF:   INTERNAL, 4.096V Buffered (3'b001)
    • SEQ:  DISABLED (2'b00)
    • RB:    Disabled (1'b1)

    So the configuration word is  1_110_001_1_001_00_1 (0x38C9h) but we need to left justify this so the hex code becomes (0xE324h).

    To update and read the results of channel 1 we then follow the process:

    1. Execute a serial transfer (including toggling CNV) to write the content 0xE234h to the AD7699, being careful to observe the conversion timing for the device.
    2. Initiate a conversion and read back the data at the end of conversion.  The data read back shall correspond to the channel previously programmed by the configuration word.  At the end of the conversion the configuration word you wrote in step 1 will be loaded into internal memory and the device will initiate acquisition of channel 1.
    3. Initiate another conversion and read back the data at the end of conversion.  This time you should have data corresponding to channel 1.   

    To verify your sequence is working you can modify the RB bit to be a zero and then request an additional word of data after the conversion result.  The AD7699 should return the configuration word on SDO if successful.  Note the MSB will be forced to 0.

    I hope that helps get you back on track,


    Sean

  • Thank you Sean, 

         But I am still struggling previously i didn't know to do this left justify of the config. But now I have changed that.

    So my problem is this

    I am using raspberry pi which has the GPIO 13 should be high to power up the PCB which contains the AD7699.

    I have connected the AD7699 using SPI and CE0 as the chip select which is connected to CNV pin. 

    So right now i have set GPIO 13 high to power up the board.

    Configuration used as follows

    • CFG : overwrite the contents of config (1'b1)
    • INCC:  Unipolar, with respect to GND   (3'b111)
    • INX:     Channel 2    (3'b010)
    • BW:     Full (1'b1)
    • REF:   INTERNAL, 4.096V Buffered (3'b001)
    • SEQ:  DISABLED (2'b00)
    • RB:    Disabled (1'b1)

    CFG = 1_111_010_1_001_00_1 . Left Justified 1111 0101 0010 0100 converted to hex (0xF924)

    Here's the code i used

    This is the output i get 

    adc, data, voltage are getting printed as per the code

    Please help me with this

  • BMGuardian,

    So I'm assuming that you have not applied 1.2V to the input of channel 1 and thus why you are flagging this as not correct.

    What I would suggest is reorganizing your code slightly to separate the configuration and read functions as I think it will help you understand the AD7699 programming model more clearly.  It's important to remember that the chip select is also the convert start so that every time you execute a data transfer the rising edge of CS will trigger a conversion.

    So I would verify that the transfer only issues one-(1) edge for each transfer using a scope or logic analyzer.

    Then I would reorganize your code slightly as follows:

    try:

    // Set configuration Word

    spi.writebytes([0xF9,0x24]) #Config Byte

    time.sleep(0.1)

    while True:

          adc = spi.readbytes(2)  # reading two bytes

          data = (adc[0]<<8 | adc[1])

          ....

          time.sleep(0.1)

  • I have tried what you have suggested. But I am having a doubt that am I reading the data correctly?
    right now i am not giving any input to channel 2( which is considered as the input channel) now. In fact I have grounded it now. 

    Can you check this please?

    I am getting these random values as an output of the adc using spi.readbytes(2)

    [2,125]

    it is said that the output of DAC will be 16 bit binary directly if used unipolar mode.

  • BMGuardian,

    I agree the results appear strange.  I would suggest doing the following just so the part is in a known state.

    Tie all unused inputs and the COM pin to ground using a low impedance; note they don't have to be the same jumper but just put them all at the same potential.  Then I would supply Channel 1 with a non-zero value, preferably a variable source, such that we can sweep the input and verify we get reasonable performance.

    Let me know what happens when you try this and I will try to think of additional experiments in case this doesn't work.

    For my reference are you simply wiring your Rasp PI to the customer evaluation kit or do you have your own design?   If it is your own design please let me know if you can share the connectivity portion of the schematic with me so that I can check it over.


    Sean

  • I have tried the suggestion you have mentioned. But the results appear the same. I think the reading part is wrong can you suggest something there? And this was a working connection which was previously working with our design in which the code (in c++) was developed as complete application backend. Now I am trying to put the new code to read the pins with the same design.

  • BMGuardian,

    Can you take some scope captures of your timing and forward them.  That will help me debug your setup.

    Sean

  • BMGuardian,

    The following examples show how I connected a TEK scope with built-in logic analysis port to the AD7689 evaluation board.  If you don't have one a standard digital oscilloscope should work just fine as long as you have four channels.   The biggest thing to do is setup the trigger on the channel you connect to your chip select and trigger off of the falling edge.  You should get an output similar to what I've shown in the second image.

    Bench Setup

    Bench Setup

    Scope Capture Example

    Data Capture Example

    Sean

  • I have done this but we have only a two channel oscilloscope. I will attach the different combination images.

    1) CNV (yellow) and SCLK (red)

    2) CNV and MISO

    3)CNV and MOSI

    4) SCLK and MISO

    5) SCLK and MOSI

    These are the combinations of the pulses i have taken Please check them and let me know.