0
\$\begingroup\$

With help from efox29 I worked out to control the MAX5483, 10-bit digital potentiometer (data sheet here) with an arduino using SPI. Now how can I trigger more than one value?

I tried to do that with a simple for-loop, but it doesn't work. To be precise it produces a strange resistance value (68 Ohm). And even just putting a delay seems to cause the same issues..

For example

digitalPotWrite(197); //  
delay(10000); 
digitalPotWrite(60); //  
delay(10000); 

Should change the resistance between 2.1k Ohm and 688 Ohm. I assume that, since by putting just

digitalPotWrite(197);

or

digitalPotWrite(60); 

alone without delay(10000); I can measure this values with my multimeter between the pin 10 and 11 of MAX5483. But by putting it all together like I tried above, I strangely measure only 65-68 Ohm. This doesn't change by only putting the following lines:

digitalPotWrite(197); //  
delay(10000);

Here the measured value (between pin 10 and 11) is still 68 Ohm.. Here is the complete code:

#include <SPI.h> 
const int csPin = 3;
const int selPin = 2;  

void setup() {

 SPI.begin();
 SPI.setBitOrder(MSBFIRST); //We know this from the Data Sheet
 SPI.setDataMode(SPI_MODE2);

 pinMode(csPin,OUTPUT); 
 digitalWrite(csPin, LOW);

 pinMode(selPin,OUTPUT);
 digitalWrite(selPin, HIGH); 

}

void loop()
{     
    //"sweep" small range (from 1.7 to 2.1 KOhm)
    // 158 to 197
//    
//    for (int i=158; i < 211; i++){
//    delay(1000);
//    digitalPotWrite(i); //  
//   } 

digitalPotWrite(197); //  
delay(100); // seems to cause issues.. without this line it works

}

void digitalPotWrite(int value) {
digitalWrite(csPin, LOW);
delay(1);
byte command=0x0;
byte byte0 = (value & 0x03) << 6;
byte byte1 = (value & 0x3FC) >> 2;
SPI.transfer(command);
SPI.transfer(byte1);
SPI.transfer(byte0);
delay(1);
digitalWrite(csPin, HIGH);
}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Being more specific about "does not work" and "seems to cause issues" would be good. \$\endgroup\$
    – us2012
    Commented Jul 3, 2013 at 15:10
  • \$\begingroup\$ I edited a bit and made the question more precise. Thanks! \$\endgroup\$ Commented Jul 4, 2013 at 7:38
  • \$\begingroup\$ Have you tried triggering the resistance changes via external interrupts (e.g., button presses) rather than the delay timer? [I can't imagine why that would make a difference, but I think it's worth trying.] Also, how are you measuring these values? It's easy to slip with your probes (and potentially short something that shouldn't be shorted) when you use standard DMM probes on small SMD packages... \$\endgroup\$
    – us2012
    Commented Jul 4, 2013 at 12:09
  • \$\begingroup\$ The multimeter works with a ICL7106/7 petervis.com/electronics%20guides/ICL7106%20and%20ICL7107/… \$\endgroup\$ Commented Jul 4, 2013 at 20:55

2 Answers 2

1
\$\begingroup\$

This is shooting in the dark because I do not know what 'does not work' means.

But if I were to guess, I'd say that it is working. If you can load a sketch where its a fixed value, and you see the resistance as expected, then it seems its a problem with your delay - meaning that it's too fast. With the delay(100), its essentially changing the resistance every 100ms. Can your meter pick that up well ? Can your eyes pick that up well ?

Change your delay(100) to delay(10000) which would give you a 10 second window to check the resistance. If you want more, try a higher ms value for your delay function.

If you provide more information, we can maybe give you a bit more insight as to why something is 'not working'.

edit from additional information

Perhaps the SPI mode is incorrect.

From the datasheet

Drive CS low to load the data at DIN(U/D) synchronously into the shift register on each SCLK(INC) rising edge.

It seems that SPI.setDataMode(SPI_MODE2) is incorrect. Because MODE 2 is base of the clock is high, and data is captured on the falling edge.

Change your SPI.setDataMode(SPI_MODE2) to SPI.setDataMode(SPI_MODE3) and see if you have better results.

\$\endgroup\$
5
  • \$\begingroup\$ I edited the question. So now it is more clear. I as well tried to put delay(10000) but does not change the strange value of only 68 Ohm.. \$\endgroup\$ Commented Jul 4, 2013 at 8:04
  • \$\begingroup\$ Do you have anything else connected to pin 10 and pin 11 or are they not connected and you are measuring the resistance directly off the pins with nothing else connected ? \$\endgroup\$
    – efox29
    Commented Jul 4, 2013 at 16:02
  • \$\begingroup\$ I changed the mode from 2 to 3, but same results. I am measuring the resistance directly off the pins with nothing else connected.. \$\endgroup\$ Commented Jul 4, 2013 at 20:30
  • \$\begingroup\$ I got it! It works with SPI.setDataMode(SPI_MODE0); I can't explain why, but it works! \$\endgroup\$ Commented Jul 4, 2013 at 21:23
  • \$\begingroup\$ glad to hear it. \$\endgroup\$
    – efox29
    Commented Jul 4, 2013 at 22:20
1
\$\begingroup\$

In void setup() you need to change the line

SPI.setDataMode(SPI_MODE2); 

into

SPI.setDataMode(SPI_MODE0); 
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.