Pages: [1]   Go Down
Author Topic: SPI / 3Wire Interface HELP, Trying to wrap my head around it.  (Read 754 times)
0 Members and 1 Guest are viewing this topic.
Hamilton Ontario
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm looking for some knowledge/assistance and some dumbing down to help me grasp this concept.

Ok, first off I am trying to make a Audio Amplifier controlled by a touch screen. I started off writing the Touch Screen Code with the Arduino, and its working good.  Then I found an built the Amp, Step 2 done. Now, also where I am stuck, getting the Arduino to control the audio.  I have looked around allot and decided to go with a digital Pot.  Specifically Maxim's DS1868. This is a 10k Pot with 255 positions that uses 3Wire Interface.  Wiper positions are set by two 8-bit values, these values are written to a 17-bit I/O shift register.

My problem is I can't seam to wrap my head around how to use the Shift Register.
Ok, I get that there is a RESET a CLOCK and a DATA pin.  I also get that the RESET pin needs to go HIGH to start accepting data, and that each bit will only be accepted on the rising edge of the clock, when the data is done transmitting drop the RESET pin LOW again.
But here is where I get lost.
There is a Stack bit that needs to be sent first, basically saying weather it is using more then one chip, then send the first 8 bits for Pot1 then the next 8 bits for Pot0.  I can't figure out how to do this in Arduino. 
Like how do I know if the data is being sent on the raising or falling edge of the clock pulse?
There is the SIP Libary and the Shiftout() command.  I'm thinking I will have more luck with Shiftout() but I am to confused as to how it all works.
What should the data at each step look like? Most of the examples steps through 255 positions but if I want to jump by 5's or have preset positions to jump to what are those values? Binary 000000101 ?? hex? 
 
 for (int j = 0; j < 256; j++) {
    digitalWrite(ResetPin, HIGH);
    shiftOut(dataPin, clockPin, MSBFIRST, j); 
    digitalWrite(ResetPin, LOW);
}

Like for j can I just put in 256 or 125 and it will know to send out the 8Bit equivalent?
And would this only cover the one pot?  do I need to add the Stack Bit and other pot like so?

    digitalWrite(ResetPin, HIGH);
   shiftOut(dataPin, clockPin, MSBFIRST, 1); 
 for (int j = 0; j < 256; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, j); 
}
 for (int j = 0; j < 256; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, j); 
}
    digitalWrite(ResetPin, LOW);
Or am I WAY OFF THE WALL here??  ANY HELP, would be GREATLY appreciated.  Thanks

The project I am trying to recreate here is from this website
http://embedded-lab.com/blog/?p=2969
But the code is written in a compiler language, so it might as well be Japanese. (By the way I don't know Japanese or C)
Logged

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

Quote
Like for j can I just put in 256 or 125 and it will know to send out the 8Bit equivalent?

0-255 (=256 steps) but yes, computers only deal with binary, and anything else is just for us humons, so you could do a simple for loop, deal with decimal numbers and set the step to increment by 5's it should work fine ... ie

Code:
for (int j = 0; j < 256; j+=5)

Quote
And would this only cover the one pot?  do I need to add the Stack Bit and other pot like so?

um not exactly, according to the datasheet that extra bit at the start allows you to take the 2 pots (in the 1 chip) and stack them together in series, so you get a larger value pot with 512 position (and I think then it only effects Sout)

you need to send the clock from low to high, then that bit, drop the clock and then go nuts with shiftOut(), and I would wrap it all in a function so you dont have to type all that crap out every time for example

Code:
void setVolume(volume)
{
    digitalWrite(clockPin, HIGH);
    digitalWrite(dataPin, LOW); // it might already be low, it probably will, but to be safe for now...
    digitalWrite(clockPin, HIGH);
    shiftOut(dataPin, clockPin, LSBFIRST, volume);
}

I changed it to LSB first cause ...

Quote
Bit 1 will contain the MSB of the wiper setting for potentiometer-1 and bit 8 the LSB for the wiper

so if you have 00000001 and sent it lsb it should be 10000000 which is what the pot wants (but I always get confused)

edit:
PS:
I have a thing against Maximum, I always find their datasheets so sparse ...



« Last Edit: February 25, 2012, 12:51:40 am by Osgeld » Logged


Hamilton Ontario
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Osgeld, I can't tell you how much you've helped.
First
Quote
0-255 (=256 steps) but yes, computers only deal with binary, and anything else is just for us humons, so you could do a simple for loop, deal with decimal numbers and set the step to increment by 5's it should work fine ... ie
I know that computers talk in Binary, i just wasn't sure how the shiftout() used it, weather it needed to be converted to hex or Bin or just left as Character.  Like with Serial communication.
But thanks, I now know if I want the volume at half I can preset it to 128.
As for the actual use of shift out. It took me a bit more tuning and found it works best like this.
Code:
 
void setVolume(int volume){
    digitalWrite(Reset, HIGH);
    digitalWrite(Clock, HIGH);
    digitalWrite(Data, LOW);
    digitalWrite(Clock, HIGH);
    shiftOut(Data, Clock, LSBFIRST, volume);
    digitalWrite(Reset, LOW);
}
And you were right the LSB was the way to go.  Only catch is it seams to change both pots in the chip to the same level at the same time.  Any idea how I would get them to change individually?  Kind of a Balance function?
Logged

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

well ... trial and error I guess

try sending 2 shiftOut()

Code:
void setVolume(int volumeOne, int volumeTwo){
    digitalWrite(Reset, HIGH);
    digitalWrite(Clock, HIGH);
    digitalWrite(Data, LOW);
    digitalWrite(Clock, HIGH);
    shiftOut(Data, Clock, LSBFIRST, volumeOne);
    shiftOut(Data, Clock, LSBFIRST, volumeTwo);
    digitalWrite(Reset, LOW);
}

if that does not work try sending the set bit as HIGH

Code:
void setVolume(int volumeOne, int volumeTwo){
    digitalWrite(Reset, HIGH);
    digitalWrite(Clock, HIGH);
    digitalWrite(Data, HIGH);
    digitalWrite(Clock, HIGH);
    shiftOut(Data, Clock, LSBFIRST, volumeOne);
    shiftOut(Data, Clock, LSBFIRST, volumeTwo);
    digitalWrite(Reset, LOW);
}

its got to be one of the two, you will finger it out ...
Logged


Pages: [1]   Go Up
Jump to: