Go Down

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

Osgeld

#15
Mar 30, 2010, 07:35 pm Last Edit: Mar 30, 2010, 07:38 pm by Osgeld Reason: 1
yours says something about memory too, but basic functionality should be close enough

I dunno we will see later when I have time to sit down and look it all over in detail
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

Indeed.  With the same manufacturer, I would assume the SPI communication is near identical.

On a side note (that i don't feel like starting a new topic over), does anyone know where I can get some Hydrochloric (Muriatic) Acid?

I'm looking to make some etchant so I can start making my own PCBs, but all of my nearby hardware stores seem to be out of stock.  I found about 32 Oz of it on eBay for about 20 bucks, but that's a ripoff considering at Lowes 1 gallon only costs about 7 bucks...

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

TchnclFl

Oooh I never thought of that.  I'll have to check if there are any nearby..

Thanks.

Dan Steingart

Quote
That's a bit overkill for my situation (unless in the future I want to have multiple outputs on the supply), so I found what looks to be a similar version (it's similar and uses SPI like the AD5206).  It's the MCP4131.  Here's the datasheet:


We're using a microchip pot and it works well with the arduino.  My grad student wrote some SPI code that works quite well.  Hit me up if you'd like it, we haven't released it publicly just yet (it's part of a large project), but that code is ready to go.

Dan Steingart

Here's the code for the Microchip MCP4261 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en531252.  

Right now it's in bit banging mode (as in note using native spi, but it's very, very fast).



Code: [Select]
//Barry's hacky functions

byte value;

byte sendBit(boolean state)
{
 digitalWrite(SPICLOCK,LOW);
 delayMicroseconds(10);
 digitalWrite(DATAOUT,state);
 digitalWrite(SPICLOCK,HIGH);
 delayMicroseconds(10);
}

byte sendValue(int wiper, int val)
//tested cycle time for this function is ~565 microseconds.
{
 value =  byte(val);
 //digitalWrite(SPICLOCK,LOW);
 //digitalWrite(DATAOUT,LOW);
 digitalWrite(SLAVESELECTP,LOW);
 delayMicroseconds(10);

 //Select wiper
 for(int i=0;i<3;i++){
   sendBit(false);
 }
 sendBit(wiper);

 //write command
 for(int i=0;i<4;i++){
   sendBit(false);
 }
 //data
 sendBit(HIGH && (value & B10000000));
 sendBit(HIGH && (value & B01000000));
 sendBit(HIGH && (value & B00100000));
 sendBit(HIGH && (value & B00010000));
 sendBit(HIGH && (value & B00001000));
 sendBit(HIGH && (value & B00000100));
 sendBit(HIGH && (value & B00000010));
 sendBit(HIGH && (value & B00000001));
 //sendBit(true);  //fudge
 digitalWrite(SLAVESELECTP,HIGH);
 //Serial.println(in);
 delayMicroseconds(10);
}

byte readWiper()
{
 //send read command
 digitalWrite(SLAVESELECTP,LOW);
 delayMicroseconds(10);
 sendBit(false);
 sendBit(false);
 sendBit(false);
 sendBit(false);
 sendBit(true);
 sendBit(true);

 //get data
 int data[9];
 Serial.print("  ");
 for(int i=0;i<9;i++)
 {
   digitalWrite(SPICLOCK,LOW);
   delayMicroseconds(10);
   digitalWrite(DATAOUT,LOW);
   delayMicroseconds(10);
   data[i] = digitalRead(DATAIN);
   digitalWrite(SPICLOCK,HIGH);
   delayMicroseconds(10);
   Serial.print(data[i]);
 }
 digitalWrite(SLAVESELECTP,HIGH);
}

KenH

TchnclFl: wish you were close - I've got a 1/2 gallon of HCl left I'd be happy to share - been using out of it for a yr for PCB etching.  Stuff is cheap at local hardware store.  I'd expect shipping to be a bugger due to being acid?

Ken H.

TchnclFl

Yeah I think you have to get a permit or something to ship it :(.

KenH

BTW. there was a comment made about one pot having 256 vs other pot having 257 positions - is that not the same number of positions?  8 bit? from 0 to 256 which "is" 257 by counting 0 as the first position.

I will be following this thread hoping to learn some - as I've said, I'm a slow learner! :'(

Ken H.

TchnclFl

Quote
BTW. there was a comment made about one pot having 256 vs other pot having 257 positions - is that not the same number of positions?  8 bit? from 0 to 256 which "is" 257 by counting 0 as the first position.


Yeah sounds like it.  But maybe the 256 doesn't have a "0" (no resistance) position.  Perhaps it only has a low position (which, if my calculations are correct, would be about 40 Ohms on an 8-bit pot).

KenH

I don't "think" the zero indicates a "zero" ohms - is 0 not the first position of binary? as in 0, 1, 2, 4, 8,..... 256? and when those positions are counted, there is actually 257 points.

Same as the discussion on 10 bit ADC in the m168 chip - 1023 or 1024 counts?  The count is 0 to 1023 which is 1024 "pieces".

Ken H>

Osgeld

Quote
Here's the code for the Microchip MCP4261 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en531252.  

Right now it's in bit banging mode (as in note using native spi, but it's very, very fast).


cool thanks, that will definitely save some head scratching tonight!
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

cr0sh

Quote
Oooh I never thought of that.  I'll have to check if there are any nearby..


I was just asking my wife last night if we knew anybody with a non-salt water pool; I was wanting to buy some HCl myself for the same purpose, but I didn't want to store 2 gallons worth (for pools, they typically come in a box with two 1 gallon jugs). I only want about 32 oz.

You can typically find the stuff anywhere pool stuff is sold; I know our local Albertsons carries it; Frys (groceries) carries it; Safeway has it too. You might also be able to find it in higher concentrations at a janitorial supply or hardware store as a concrete cleaner/etchant...

:)
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

TchnclFl

I just found out my local Lowes just got it back it stock.  I snagged it online and just picked it up.

It's a full gallon, but at least I know I won't need more ;D!

Osgeld

#29
Mar 31, 2010, 05:48 am Last Edit: Mar 31, 2010, 05:53 am by Osgeld Reason: 1
the mcp42xxx family are almost identical, and I have it working on my 42100, it should work the same on a 42x1 (I have not looked at the single pot models much since I do not have one, and the x2 models are slightly different more)

the only confusion I have about it is pin 11, on mine its marked reset, and needs to stay high unless you want both pots to goto default 50% wiper pos

on your chip is marked (overscore) WP, which skimming that HUGE data sheet many times, never found out what that really means, try leaving it disconnected, and if it does not work ...

also the wording on microchips website is odd for your chip, it claims 7 bit 129 position, but in the chart below it declares 257, the data sheet as a whole covers the entire mcp4YxxZ family

the following produces a sawtooth wave, and is easily seen with a multimeter using a MCP42100, data output is treated the same way as a 74HC595 (only using 1 channel)

pins
1 -CS to DIGITAL PIN 2 (same as latch)
2 -SCK to DIGITAL PIN 3 (clock)
3 -DTA to DIGITAL PIN 4 (data)
4 & 5 GROUND
6 NC (channel 2 wiper)
7 +5v
8 +5v
9 + of multimeter
10 GROUND
11 on mine +5v, good luck
12 +5v
13 NC (daisy chain output)
14 +5v

script
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(9600);
}

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);
   delay(100);
 }
}


read the first parts of

http://ww1.microchip.com/downloads/en/AppNotes/00746a.pdf

along with appendix F for a schematic
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