Go Down

Topic: Need some advice on a Digital Potentiometer (Read 6 times) previous topic - next topic

TchnclFl

Awesome.  I may just have to order some then :).

TchnclFl

#31
Apr 17, 2010, 06:57 pm Last Edit: Apr 17, 2010, 07:03 pm by Tchnclfl Reason: 1
Followup!  I'm looking at your code again, Osgeld.  I need to make a digikey order anyways, so I find myself again looking at Digital Pots.

Looks like you did pretty well, but I'm still kind of confused.

Code: [Select]
#define sLatch 2
#define sClock 3
#define sOdata 4
[glow]#define commandData B00010001[/glow] // command = write to pot 0

byte data;

void setup()
{
 pinMode(sLatch, OUTPUT);
 pinMode(sClock, OUTPUT);
 pinMode(sOdata, OUTPUT);
 Serial.begin(9600);
}

void loop()
{
 for(int i = 0; i < 255; i++)
 {
   [glow]data += byte(1)[/glow];
   
   digitalWrite(sLatch, LOW);
     shiftOut(sOdata, sClock, MSBFIRST, commandData);
     shiftOut(sOdata, sClock, MSBFIRST, data);
   digitalWrite(sLatch, HIGH);
   
   Serial.println(data, BIN);
   delay(100);
 }
}



The highlighted bits are the ones I don't understand.  First up, the "B00010001".  I understand from your code that this is you addressing wiper 0, but what I don't understand is how to address the other pot.  Is that somewhere in the datasheet?  If so, I don't see it anywhere.

Secondly, what is the "data += byte(1)"?  What is the function of that?

Thanks!

PS:  I did some more searching and I found this about the WP pin:

Quote
The WP pin is used to force the non-volatile memory to
be write protected.


I still don't know if it's active low or active high, but I suppose I can figure it out.

PPS:  I found this now:

Quote
High Voltage commands are required to enable and
disable the nonvolatile WP bit.


So I assume that it is off by default, but could be activated?  I suppose it should be left NC then.

Osgeld

Code: [Select]
#define commandData B00010001

first go back and look at the generic application note for the family (page 1)
http://
http://ww1.microchip.com/downloads/en/AppNotes/00746a.pdf


look at figure 1, theres 2 bytes that has to be sent to the digipot when you want to change it, the first byte is the command, the second is data

from the left ... the first 2 bits of the command byte doesnt do anything, bit 3 puts the pot in a shutdown mode if high, bit 4 says write data if high

bits 5 & 6 are dont care just like bits 1 and 2

bits 7 & 8 choose which pot you want to write to in a dual pot package

Code: [Select]
data += byte(1);

byte() is a typecast function, so lets say you have data as B11111110, this would be the same as

Code: [Select]
 
 B111111110
+ B000000001
-------------
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

TchnclFl

Ahhh Ok, I fully get it now.  Thanks for the help, I'll be placing an order later today :).

TchnclFl

#34
Apr 22, 2010, 12:52 am Last Edit: Apr 22, 2010, 12:53 am by Tchnclfl Reason: 1
Grr.  I've received my chips, and everything seemed to be going fine, but I can't seem to write data to potentiometer 0.

I'm using your code, Osgeld, which works fine for Potentiometer 1 (B00010010), but for some strange reason when I try the same with Potentiometer 0 (B00010001), it fails to work, and the potentiometer appears to be stuck on 127 (half on/off).

Any ideas?  Here's the code:

Code: [Select]
#define sLatch 2
#define sClock 3
#define sOdata 4
#define commandData B00010001 // command = write to pot 0

byte data;

void setup()
{
 pinMode(sLatch, OUTPUT);
 pinMode(sClock, OUTPUT);
 pinMode(sOdata, OUTPUT);
 Serial.begin(115200);
}

void loop()
{
 for(int i = 0; i < 255; i++)
 {
   data += byte(1);
   
   digitalWrite(sLatch, LOW);
     shiftOut(sOdata, sClock, MSBFIRST, commandData);
     shiftOut(sOdata, sClock, MSBFIRST, data);
   digitalWrite(sLatch, HIGH);
   
   Serial.println(data, BIN);
   Serial.println(analogRead(0));
   delay(50);
 }
}



By the way, I've got the wiper plugged into analog input 0 for debugging purposes, that's why you see an analogRead() thrown in there.

Osgeld

i dunno, I will go poke at it in a few (eating pizza!)
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

TchnclFl

OK thanks :).  I'm still fiddling around with the code and wiring, trying to make it work.

Osgeld

what happens if you send the last 2 bits of the command byte as 11 (both pots)
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

TchnclFl

Oh sorry, thought I posted that (I posted it on my blog, not here).

If I send the last two as 11, Pot0 appears to still be on 127, and Pot1 appears to be on 255, and don't change.

Osgeld

Im about to upload the sketch, just wondering have you monitored the outputs with a meter?

analog read should be right but a meter is going to be right, just a random thought that popped in ma head
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Osgeld

well on my 42xxx its working as expected, the "datasheet" (man I hate their datasheets) has some conflicting information (despite what the majority of their app notes say) about the command structure

I dunno, I will look it over meanwhile its on the datasheet linked on your blog page 47, obiously were looking at the 16 bit data structure
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

TchnclFl

No, I haven't tried with a DMM yet, but I'll get on it.  I'll also check out the Datasheet, but let me know if you find anything interesting.  I may try some trial and error guessing while I'm at it :P.

Osgeld

I have it just about worked out, its totally different from the 42xxx series

but it has some advantages, but kinda irritated that their general guides dont make a clear distinction  ::)

http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

TchnclFl

Wait so you're close to figuring out the mcp4251?  That's impressive considering you don't even have any (or do you?) :O.

Osgeld

http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Go Up