AD5206 Digi Pot with SPI code....?
Posted 04 August 2011 - 11:37 PM
Posted 06 August 2011 - 02:54 PM
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?
// 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);
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; WriteBuffer = (0); // I'm just trying to control the first channel. byte WriteBuffer1 = new byte; WriteBuffer = (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??
Posted 06 August 2011 - 04:01 PM
Let's take a look at the AD5206 specs...
- 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.
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; WriteBuffer = (0); // I'm just trying to control the first channel. WriteBuffer = (255); // I've set this to various values from 0-255 while testing. SPIBus.Write(WriteBuffer); //should workAssuming you have correctly connected the SPI wires between Netduino and the shield, you may try.
Posted 06 August 2011 - 05:28 PM
Posted 06 August 2011 - 06:02 PM
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?
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.
Posted 07 August 2011 - 04:03 AM
Posted 08 August 2011 - 10:23 AM
If my message helped you... how 'bout giving me a
Posted 29 August 2011 - 12:36 PM
Posted 01 January 2012 - 02:58 PM
The world will have to wait.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users