Using Digital Potentiometer

Hello everyone, I'm trying to use this digital potentiometer MCP4021 with an Arduino duemilanove you can see the datasheet at this web: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022386

in concrete the 5kohm one the comunication interface is up or down, so I have to implement the code to comunicate with this device. The communication is through 2 pins, which increment or decrement the value of the resistance of the wiper

The datasheet explains how to comunicate with this device, with this graph:

the times you see on this graph are defined in this table:

so I tried to code this with the following result

int ud=1;
int cs=2;
void setup(){
  pinMode(ud,OUTPUT);
  pinMode(cs,OUTPUT);

}
void loop(){
  digitalWrite(cs,HIGH);
  digitalWrite(ud,LOW);
  delay(1000)
  digitalWrite(ud,HIGH);
  delayMicroseconds(0.5);
  digitalWrite(cs,LOW);
  delayMicroseconds(0.5);
  digitalWrite(ud,LOW);
  delayMicroseconds(0.5);
  digitalWrite(ud,HIGH);
  delayMicroseconds(0.5);
  digitalWrite(ud,LOW);
  delayMicroseconds(0.5);
  digitalWrite(ud,HIGH);
  delayMicroseconds(0.5);
  digitalWrite(cs,HIGH);
  delayMicroseconds(0.5);
  digitalWrite(ud,LOW);
  digitalWrite(cs,LOW);
  delay(5000);
}

I have also tried to change the delayMicroseconds value, because 0.5 seemed it could represent an error, but same thing hapends, nothing, the resistance value doesn't move. See if you know what I'm doing wrong,

thanks for your attention.

I'd put the initialisation of the states of /CS and U/D into setup

delayMicroseconds doesn't take a fractional value, so that'll delay whatever the minimum delay is, about 3us IIRC.

The value in the datasheet timing (pg.6) are minimum times, so I'd go for longer pulses, since no maxima are specified.

Ok, i've been trying with different values and at the beginning it didn't work. But just thought that the pulses up for the ud are longer than the pulses down, so I played a little bit with the values and finally could increment the value of the wiper with the next code:

int ud=1;
int cs=2;
void setup(){
  pinMode(ud,OUTPUT);
  pinMode(cs,OUTPUT);
  digitalWrite(cs,HIGH);
  digitalWrite(ud,LOW);
  delay(8000);
}
void loop(){
  digitalWrite(ud,HIGH);
  delayMicroseconds(1);
  digitalWrite(cs,LOW);
  delayMicroseconds(2);
  digitalWrite(ud,LOW);
  delayMicroseconds(1);
  digitalWrite(ud,HIGH);
  delayMicroseconds(2);
  digitalWrite(ud,LOW);
  delayMicroseconds(1);
  digitalWrite(ud,HIGH);
  delayMicroseconds(1);
  digitalWrite(cs,HIGH);
  delayMicroseconds(1);
  digitalWrite(ud,LOW);
  digitalWrite(cs,LOW);
  delay(5000);
}

Now i'll do the decrement function,

Ok, finally done (both the increment and the decrement pulse). Wasn't really difficult but when I get nervous prefer asking than taking a harder look. Hope to solve many many problems of this kind, ;)

int ud=1;
int cs=2;
void setup(){
  pinMode(ud,OUTPUT);
  pinMode(cs,OUTPUT);
   digitalWrite(cs,HIGH);
  digitalWrite(ud,HIGH);
  delay(8000);
}
void loop(){
  digitalWrite(ud,LOW);
  delayMicroseconds(1);
  digitalWrite(cs,LOW);
  delayMicroseconds(3);
  digitalWrite(ud,HIGH);
  delayMicroseconds(1);
  digitalWrite(ud,LOW);
  delayMicroseconds(2);
  digitalWrite(ud,HIGH);
  delayMicroseconds(1);
  digitalWrite(cs,HIGH);
  delayMicroseconds(2);
  digitalWrite(cs,LOW);
  digitalWrite(ud,LOW);
  delay(5000);
}