Pages: 1 2 [3] 4   Go Down
Author Topic: Need some advice on a Digital Potentiometer  (Read 5955 times)
0 Members and 2 Guests are viewing this topic.
B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome.  I may just have to order some then smiley.
Logged

B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
« Last Edit: April 17, 2010, 12:03:10 pm by Tchnclfl » Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#define commandData B00010001

first go back and look at the generic application note for the family (page 1)
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:
data += byte(1);

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

Code:
 
  B111111110
+ B000000001
 -------------
Logged


B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
« Last Edit: April 21, 2010, 05:53:39 pm by Tchnclfl » Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i dunno, I will go poke at it in a few (eating pizza!)
Logged


B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what happens if you send the last 2 bits of the command byte as 11 (both pots)
Logged


B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-razz.
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  :smiley

Logged


B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nope so stick around  ;D
Logged


Pages: 1 2 [3] 4   Go Up
Jump to: