Trying to control an AD5142 potentiometer with an Arduino UNO

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
Hello everyone,

This IC has me stumped. I have tried every combination I can come up with and there is nothing I can do to make it work.
Here's the schematic:
AD5142_SCHEMATIC.PNG

Here's the actual layout with the programming probe pads with the corresponding arduino terminals (CS=SS):

AD5142_LAYOUT.PNG



Here are the signals being sent for writting a 1 to pot 0 on falling edge of clock:

AD5142_LOGICANALYZER.PNG

Thinking that it might be an issue with the -INDEP pin I have tried floating -INDEP, connecting it to ground and to +5V with no luck.
Thinking it might be the CPOL or CPHA I have tried all 4 modes of SPI_MODE0 to SPI_MODE3.
Tried also clock speeds from 10KHz to 1 MHz

Here's a sample of a simple program I've tried that works in a similar part from the same family:

#include <SPI.h>
void setup() {
// pin 10 is the slave select for the digital pot
pinMode( SS, OUTPUT); // set the slaveSelectPin as an output
// MISO input needs to be ;ulled up for the AD5142
pinMode( MISO, INPUT_PULLUP);
SPI.begin(); // initialize SPI
// set SPI speed to 500 kHertz, MSB, NORMAL LOW CLK and FALLING EDGE
SPI.beginTransaction (SPISettings (500000, MSBFIRST, SPI_MODE1));
}

void loop() {

digitalWrite(SS, LOW);// take the SS pin low to select the chip
SPI.transfer(0b00010000); // command 1 = set pot value, pot selected = 0
SPI.transfer(0b00000001); // pot value to set = 1
digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip
}

Here's a link to the AD5142 Datasheet.

And here's the pinout:

AD5142_PINOUT.PNG

The wiper starts in the middle of the pot range as expected by default from factory but I can't get it to respond in any way.
I made a circuit with only the IC and no luck, I even soldered small wires to each pin to the IC by itself to make sure the connections were correct but no luck.

I tried the code with another IC from the same family and it worked perfectly fine.
This code on SPI mode 0 works fine on an AD5204 that uses raising edge clock from the same family.

I know it'll be some tiny little detail I forgot or missed that will make it work but I'm stumped right now.

If you have any experience with this particular IC any help will be appreciated.
 

aromring

Joined Jul 22, 2015
28
Look at Table 18 on page 26 in the datasheet. Bit D0 in Control Register could be accidentally set to "RDAC write protect".
If not, then write a short program to list the contents of entire EEPROM. Examine values to verify these are as expected.
Good luck.
 

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
Hi aromring,

Thanks for the suggestion.
I don't have a way to read the eeprom because it doesn't respond in any way no even for reading back.
Despite that just in case it took it I did try writting to the Control Register with D2= 0 = potentiometer mode, D1=1 = enables EEPROM programing, D0=1 = allow update of wiper position.

Here's the code that I used:

Code:
#include <SPI.h>
void setup() {
  // pin 10 is the slave select for the digital pot
  pinMode( SS, OUTPUT); // set the slaveSelectPin as an output
  digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip

  // MISO input needs to be ;ulled up for the AD5142
  pinMode( MISO, INPUT_PULLUP);

  SPI.begin();  // initialize SPI
  // set SPI speed to 500 kHertz, MSB, NORMAL LOW CLK and FALLING EDGE
  SPI.beginTransaction (SPISettings (500000, MSBFIRST, SPI_MODE1));


  digitalWrite(SS, LOW);// take the SS pin low to select the chip
  SPI.transfer(0b11010000); // Copy serial register data to control register command
  SPI.transfer(0b00000011); // D2= 0 = potentiometer mode, D1=1 = enables EEPROM programing, D0=1 = allow update of wiper position
  digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip

}

void loop() {
  writeOne();
  delay(10);
}

void writeOne(){
  digitalWrite(SS, LOW);// take the SS pin low to select the chip
  SPI.transfer(0b00010000); // command 1= set pot, pot selected= 0
  SPI.transfer(0b00000001); // pot value= 1
  digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip

}
But no luck it didnt change anything.

Thanks for the suggestion though. I had missed that possibility and it was worth testing it.
 

aromring

Joined Jul 22, 2015
28
I don't have experience with your particular brand, but I've recently harnessed a digital pot MCP414X from Microchip to my Arduino project. Here are some other things to try:

1) The 500 kHz clock speed would be too fast for MCP414X when both read and write operations are involved. Thus, I had to lower it to 250 kHz.

2) Try an external pull-up resistor (10k) on the SDO pin instead of relying on Arduino's INPUT_PULLUP.

3) I am still not sure why you can't read pot's registers. Are you using command 3 from Table 16? Arduino's SPI may be a bit tricky, when the read command is shifted to the device, device's response is shifted back simultaneously. The response is returned by SPI.transfer(). Here is an example:

byte in1=0, in2=0;
digitalWrite(SS, LOW);// take the SS pin low to select the chip
in1=SPI.transfer(0b00110AAA); // Use command 3 to read, "AAA" are address bits - replace by 0/1 accordingly
in2=SPI.transfer(0b111111DD); // Send data bits, "DD" determine contents type - replace by 0/1 accordingly
digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip

Chip response will be contained in bytes in1 and in2. Using "AAA" in a loop you can list an entire contents of chip's memory. By the way, this way I learned that my MCP chip came from a factory with EEPROM location 6 set to some random number. No harm done, but this could be a control register instead.
 

aromring

Joined Jul 22, 2015
28
Oh, one more thing I forgot to mention: this is my _second_ MCP414X. The first one was working fine until I co-connected an SD card reader to the same SPI (with different SS pin, of course) and something got screwed up. Well, it was I who screwed up, most likely. ;)
Afterwards, this MCP414X looked like being in perfect working order, responding to commands, setting and reading right values to/from registers, etc. However, its wiper was actually stuck at 0 all the time. It took me quite a while to diagnose. I replaced it with a new one and my circuit started working again...
This might be your case, too - a defective unit that pretends to work.
 

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
1) The 500 kHz clock speed would be too fast for MCP414X when both read and write operations are involved. Thus, I had to lower it to 250 kHz.
On the original post I mentioned: "Tried also clock speeds from 10KHz to 1 MHz" so I have tried lower speeds. The specs call for a minimum 20 ns of SCLK cycle time so it could theoretically work at up to 50MHz. I've used some of the same family at 1MHz without any problems.


2) Try an external pull-up resistor (10k) on the SDO pin instead of relying on Arduino's INPUT_PULLUP.
I also tried that and made no difference.


3) I am still not sure why you can't read pot's registers. Are you using command 3 from Table 16? Arduino's SPI may be a bit tricky, when the read command is shifted to the device, device's response is shifted back simultaneously. The response is returned by SPI.transfer().
Yes I'm using command 3 from table 16. Here's the code I used for reading. I have used this code before too:
Code:
  // enable Slave Select
  digitalWrite(SS, LOW);    // SS is pin 10 to low to select

    SPI.transfer16 (0B0011000000000011); // command 0011 read value, 0000 pot 0, 00000011 from RDAC
    delayMicroseconds(30); // Wait for pot to be ready to reply as per timing specs just in case
    potVal1 = byte( SPI.transfer16 (0) ); // LSB BYTE (ACTUAL POT VALUE)

  // disable Slave Select
  digitalWrite(SS, HIGH);    // SS pin 10 to high to deselect
If you look at the circuit there's a 2k resistor connected to the top of the pots and to 5V. The other side of the pots are connected to ground.
When the device powers up it loads 80h by default from factory so the wiper is in the middle of the travel or (5K) and I get 5 * 5/(10+2) or about 2V at the wiper so apparently the IC is working correctly as a pot but nothing I send to the IC via SPI changes that voltage or returns any values.

I also monitor the MISO line with a scope and it remains pulled up high when I try to read via SPI commands so I get 255 as a result from a read RDAC command via SPI. To test the protocol I manually short the MISO line to ground and the SPI returns 0 as expected so the arduino SPI side seems to be working.

Keep in mind that I have tried connecting an IC by itself in the air with small wires soldered to the pins and ground pad with no pc board just to make sure visually it's correctly connected and still doesn't work.

Here's a pic of an earlier version of the board's IC footprint so you can see what the grounding vias look like:
pcb.jpeg
 

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
Last edited:

aromring

Joined Jul 22, 2015
28
Sorry, I've run our of ideas. At least for now. If you can read pot's memory and everything looks fine, then all I can think of is that you've got a defective unit. It resembles the case of my first MCP414X which responded very nicely to all SPI commands, but was stuck at 0 nevertheless. Yours seems to be stuck at 80h...
 

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
Sorry, I've run our of ideas. At least for now. If you can read pot's memory and everything looks fine, then all I can think of is that you've got a defective unit. It resembles the case of my first MCP414X which responded very nicely to all SPI commands, but was stuck at 0 nevertheless. Yours seems to be stuck at 80h...
I have tried several of the ICs so unless the whole roll they came from is defective I don't see how that could be.

I also ran out of ideas and that's why I posted here to see if anyone had something I missed and I really appreciate the time you spent trying to help me. It's always a good idea to have more that one person look at a problem for a different perspective.

I bit the bullet and ordered their $108 combo of demo board and System Demonstration Platform (SDP-S). It's a shame it's windows based so I'll have to monitor the signals sent to the IC to see what I have missed.

If I figure out what I was doing wrong I'll post my findings here.
 

aromring

Joined Jul 22, 2015
28
Umm, I didn't know you bought the whole enchilada. That gives me a new idea: contact Analog Devices, describe your problem and ask your money back. Let them - best experts on AD5142 - resolve this problem. ;)
 

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
I just bought it. I should have it for the weekend.

I was looking at the daughter board's artwork and it seems to be used the same way as mine so the only thing left is looking at the signals that go into the demo part
BoardArtwork.png
 

Thread Starter

DigitalDeath

Joined Jun 29, 2016
7
Mystery solved.
The evaluation kit's daughter-board worked with the PC software and the logic analyzer's SPI waveforms and timing were identical to the ones coming from the my Arduino so I unplugged the daughter-board from the motherboard and connected the pins to the Arduino and it worked on the first try.
Turned out I wasn't doing anything wrong, it was just bad parts. :confused:
That's 6 parts from a cut-tape that were defective. First time this ever happens to me.
Had to throw them out so I wouldn't use them by mistake and ordered more form a different supplier.

I guess the only good thing about this is that this thread now works as a tutorial for controlling the AD5142 with and Arduino UNO via SPI.
 
Top