Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

SPI connection to AD8400
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SPI connection to AD8400

by RainySun on Mon Jan 17, 2022 8:28 pm

Hey, I am using AD8400 (a digital potentiometer), and Itsybitsy M0 Express. As there are no libraries for AD8400, I was only able to write code up to what I know.
Datasheet of AD8400: https://www.analog.com/media/en/technical-documentation/data-sheets/AD8400_8402_8403.pdf

Not sure what to put inside SPI.write(?)
I hope to hear your response.

Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio

spi = busio.SPI(board.SCK, MOSI=board.MOSI)
cs = digitalio.DigitalInOut(board.D7)

while not spi.try_lock():
    pass
try:
    spi.configure(baudrate=1000000, polarity=0, phase=0)
    cs.value = False
    spi.write(...)
    cs.value = True
finally:
    spi.unlock()

RainySun
 
Posts: 67
Joined: Thu Nov 18, 2021 2:55 pm

Re: SPI connection to AD8400

by RainySun on Tue Jan 18, 2022 1:33 am

UPDATE:
I thought I came close to finding a solution but when I read the digital potentiometer output, I don't see any changes.
Below is the update code. Not sure what is wrong here.

Code: Select all | TOGGLE FULL SIZE
# Write your code here :-)
import board
import busio
import digitalio


cs = digitalio.DigitalInOut(board.D7)
cs.direction = digitalio.Direction.OUTPUT
cs.value = True

spi = busio.SPI(board.SCK, MOSI=board.MOSI)
while not spi.try_lock():
    pass

spi.configure(baudrate=5000000, polarity=0, phase=0)

try:
    while True:
        cs.value = False
        spi.write(bytes(0xFF))
        cs.value = True

finally:
    spi.unlock()


RainySun
 
Posts: 67
Joined: Thu Nov 18, 2021 2:55 pm

Re: SPI connection to AD8400

by danhalbert on Tue Jan 18, 2022 9:59 am

Quoting from the datasheet:
Changing the programmed VR setting is accomplished
by clocking in a 10-bit serial data-word into the SDI (Serial
Data Input) pin. The format of this data-word is two address
bits, MSB first, followed by eight data bits, also MSB first.
Table 6 provides the serial register data-word format. The
AD8400/AD8402/AD8403 have the following address assignments for the ADDR decoder, which determines the location
of the VR latch receiving the serial register data in Bit B7 to
Bit B0:
VR# = A1 × 2 + A0 + 1 (1)
The single-channel AD8400 requires A1 = A0 = 0. The dualchannel AD8402 requires A1 = 0. VR settings can be changed
one at a time in random sequence. A serial clock running at
10 MHz makes it possible to load all four VRs under 4 μs
(10 × 4 × 100 ns) for AD8403. The exact timing requirements
are shown in Figure 3, Figure 4, and Figure 5.

So you need to write a zero-byte followed by the value byte:
so something like
Code: Select all | TOGGLE FULL SIZE
spi.write(bytes([0, value]))

Here is a MicroPython driver: https://github.com/dsiggi/micropython-a ... /ad840x.py. The details are different, but you can see what data is being written.

danhalbert
 
Posts: 3179
Joined: Tue Aug 08, 2017 12:37 pm

Re: SPI connection to AD8400

by RainySun on Tue Jan 18, 2022 2:47 pm

I was able to change the digital potentiometer resistance using the following command:
spi.write(bytes([0, 255])) gives me 50ohm
spi.write(bytes([0, 0])) gives me 1.2Kohm

I am using a 1Kohm digital potentiometer, and the minimum resistance I can get using the command is 50ohm, and maximum of 1.2Kohm.
Since the digital potentiometer has 256 tap, shouldn't I get minimum resistance of 1000/256 = 3.9ohm. Am i wrong about this?

There is one other thing that been bothering me. Even after reading the paragraph from datasheet that you showed in the earlier post, I still do not know how to comprehend it; Can you recommend me a book that will help me understand this.
Attachments
tap.PNG
tap.PNG (9 KiB) Viewed 32 times

RainySun
 
Posts: 67
Joined: Thu Nov 18, 2021 2:55 pm

Re: SPI connection to AD8400

by danhalbert on Tue Jan 18, 2022 2:52 pm

The data sheet says that the "Wiper Resistance" is typically 50 ohms. So I think that is what you are seeing.

danhalbert
 
Posts: 3179
Joined: Tue Aug 08, 2017 12:37 pm

Re: SPI connection to AD8400

by RainySun on Tue Jan 18, 2022 4:25 pm

Thank you DanHalbert!!!
I am able to control the digital potentiometer.
Can you recommend me anything (book or blog) that would help me understand the following paragraph. I have read it and I am still confused.
Attachments
Data.PNG
Data.PNG (46.39 KiB) Viewed 30 times

RainySun
 
Posts: 67
Joined: Thu Nov 18, 2021 2:55 pm

Please be positive and constructive with your questions and comments.