Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

AD5206 Digi Pot with SPI code....?


  • Please log in to reply
9 replies to this topic

#1 CableGuy

CableGuy

    New Member

  • Members
  • Pip
  • 5 posts

Posted 04 August 2011 - 11:37 PM

Is there code for the AD5206 on the Netduino? I found it here on the Arduino but I know .Net and dont want to learn another language and Im not getting too far with the Netduino. (Still leaning the Netduino SDK.) http://www.arduino.c...l/SPIDigitalPot Thanks everyone!

#2 CableGuy

CableGuy

    New Member

  • Members
  • Pip
  • 5 posts

Posted 06 August 2011 - 02:54 PM

So I cant figure out how to control this thing....


According to the arduino info I found, I need to send it two bytes, one with the channel, the other the level but I cant figure it out.

While reading the arduino code and other sources it seems you need to send a signal to the SPI device to start to "read" and then when you are done you send it another signal to stop it. I couldnt find any info in the SPI-Netduino Wiki so does the Netduino do this automatically?

ex.:

// take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin,LOW);
  //  send in the address and value via SPI:
  SPI.transfer(address);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);

Any ideas?


The AD5206 is SPI-compatible,and to command it, you send two bytes,
one with the channel number (0 - 5) and one with the resistance value for the
channel (0 - 255).



SPI.Configuration Device1 = new SPI.Configuration(
               Pins.GPIO_PIN_D10, // SS-pin
               true,             // SS-pin active state
               0,                 // The setup time for the SS port
               0,                 // The hold time for the SS port
               true,              // The idle state of the clock
               false,             // The sampling clock edge
               1000,              // The SPI clock rate in KHz
               SPI_Devices.SPI1    // The used SPI bus (refers to a MOSI MISO and SCLK pinset)
           );

            SPI SPIBus = new SPI(Device1);

            byte[] WriteBuffer = new byte[1];
            WriteBuffer[0] = (0); // I'm just trying to control the first channel.
            byte[] WriteBuffer1 = new byte[1];
            WriteBuffer[0] = (255); // I've set this to various values from 0-255 while testing.

            SPIBus.Write(WriteBuffer); //Writing byte 1??
            SPIBus.Write(WriteBuffer1); //Writing byte 2??


#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 06 August 2011 - 04:01 PM

Hi CableGuy, and welcome in the forum.

Let's take a look at the AD5206 specs...
Pages 8-9:
  • you must feed at least 11 bits to set the pot accordingly;
  • the MSB must be the first bit fed;
  • the /CS must be tied low to feed the data;
  • the CLK samples the SDI pin on every positive (rising) edge.
I guess we have enough!

Now, let's try to review your code:

SPI.Configuration Device1 = new SPI.Configuration(
               Pins.GPIO_PIN_D10, // the /CS pin
               false,             // the /CS must tied LOW
               0,                 // don't mind (leave zero)
               0,                 // don't mind (leave zero)
               false,             // when idle, we want the clock low
               true,              // the data will be sampled on the rising edge
               1000,              // The SPI clock rate in KHz
               SPI_Devices.SPI1    // The used SPI bus (refers to a MOSI MISO and SCLK pinset)
           );

            SPI SPIBus = new SPI(Device1);

            byte[] WriteBuffer = new byte[2];
            WriteBuffer[0] = (0); // I'm just trying to control the first channel.
            WriteBuffer[1] = (255); // I've set this to various values from 0-255 while testing.

            SPIBus.Write(WriteBuffer); //should work
Assuming you have correctly connected the SPI wires between Netduino and the shield, you may try.
Cheers
Biggest fault of Netduino? It runs by electricity.

#4 CableGuy

CableGuy

    New Member

  • Members
  • Pip
  • 5 posts

Posted 06 August 2011 - 05:28 PM

I tried your code and it didnt work... so I was like "hummmmm". I started to re-read and look at the Arduino code and wiring scheme again and found an error in their drawing. They have a wiring in the drawing going to 12 and not 11, even though he/she says pin 11 for SDI (Not 12). As soon as I did this change, I rebooted the Netduino and it worked!! Thanks a ton Mario! As you can see I am new to this SPI + Netduino combo. I took the SPI code off the of SPI Wiki and didnt know where to go from there. Thanks again! Adam :D

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 06 August 2011 - 06:02 PM

It seems to me that the ability to control a digital pot, as the AD5206 is, should be a really interesting task for the Netduino world. As soon you have collected enough experience around this chip, why don't you write a small tutorial for the Wiki section? How much did you pay the AD? Cheers
Biggest fault of Netduino? It runs by electricity.

#6 CableGuy

CableGuy

    New Member

  • Members
  • Pip
  • 5 posts

Posted 07 August 2011 - 03:45 AM

It seems to me that the ability to control a digital pot, as the AD5206 is, should be a really interesting task for the Netduino world. As soon you have collected enough experience around this chip, why don't you write a small tutorial for the Wiki section?
How much did you pay the AD?
Cheers



I would like to do that - I am still messing around with loops and ways on how to use this chip exactly.

I got the chips from digikey for around $5 US dollars + shipping. I actually just found out that I need a 100ohm chip and I am currently using a 10ohm chip so I just ordered another one but in a 100ohm setting for the same price.

Thanks again and I'll keep you updated.

Adam

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 August 2011 - 04:03 AM

Very good! I ask you the price, just because the chip would be used by other people only when has a reasonable price. I know AD makes very good chips, but it's far from being at low price! Okay, let stay in touch. Cheers
Biggest fault of Netduino? It runs by electricity.

#8 Inquisitor

Inquisitor

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationAtlanta, Georgia, USA

Posted 08 August 2011 - 10:23 AM

CableGuy, Mario, I'll second on the wiki tutorial. Pardon my ignorance… my curiosity has gotten hold of me... from my 10,000 foot view I see this is a "digital potentiometer". Could either of you hi-light a typical real world use for this? You see… I am a mechanical, real-world kind of guy and I love the idea of interacting with the physical world through a Netduino and to/from C# code! I intuitively “get” a person turning a pot (or reading some other kind of sensor) and getting a value to use in my C# code. Since this digital potentiometer task warrants some large factory to create these, I understand it must be useful. Unfortunately, I’m missing that real-world use case. Thanks!
Doing my best to keep the smoke in the little black boxes.
If my message helped you... how 'bout giving me a Posted Image
www.MessingWithReality.com

#9 Mike P

Mike P

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • LocationAuckland, New Zealand

Posted 29 August 2011 - 12:36 PM

Hi CableGuy, I have added some info on SPI to the Wiki since you first posted. I hope you will find it useful. search for SPI on the wiki.

#10 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 01 January 2012 - 02:58 PM

If it is of any help I already use this device in a real world instalation with my netduino to emulate a engine gas pedal position for the open development WIKISpeed project. I am a VB coder but i can drop in the code snippet if you want it. Cheers Pete.
I was going to change the world, then I discovered Netduino.
The world will have to wait.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.