Hi Leute,
ich versuch ein digitales Poti (AD5292) mit dem Arduino Uno per SPI
anzusteuern , aber seit Stunden bekomm ich es nicht hin, dass sich der
Widerstandswert ändert.
Es gibt einige gute Diskussionen z.B.
Beitrag "Ansteuerung des AD5292" und
http://www.edaboard.com/thread164603.html , aber irgendwie fehlt mir der
letzte Schritt.
Vielleicht hat jemand schon einmal damit gearbeitet und sieht auf dem
ersten Blick woran es hapert. Bin für jede Hilfe echt dankbar!
Anbei ein simpler Code, der zwischen zwei Poti-Einstellungen hin und
herschalten sollte, und wo "resistanceValue" (welcher vom Arduino ADC
"A0" ausgelesen wird) jedoch leider unverändert bleibt:
1 | #include <SPI.h>
|
2 |
|
3 | int resistorPin = A0; // select the input pin for the potentiometer
|
4 | int resistanceValue; // variable to store the value coming from the sensor
|
5 | const int slaveSelectPin = 10; // set pin 10 as the slave select for the digital pot
|
6 |
|
7 | //int COMMAND_1 = 0x0400; //Write contents of serial data to RDAC; muesste danach die 1024 positionen sein
|
8 | //int COMMAND_2 = 0x0800; //Read RDCAC wiper setting from the SDO ouput in the next frame 800 VS 803
|
9 | //int COMMAND_3 = 0x0C00; //Store wiper settings
|
10 | int COMMAND_6 = 0x1802; //serial data to control register; Table 13 & 14 for details; 1802 or 1803
|
11 | //int COMMAND_7 =0x1C00; //read control register from SDO output in next frame
|
12 |
|
13 |
|
14 | void setup(){
|
15 | Serial.begin(9600); // initialize serial communication at 9600 bits per second
|
16 | pinMode (slaveSelectPin, OUTPUT); // set the slaveSelectPin as an output
|
17 |
|
18 | // initialize SPI (page 9 in datasheet & http://www.arduino.cc/en/Reference/SPI)
|
19 | SPI.setDataMode(SPI_MODE3); //low clock polarity (low idle) & low phase (falling edge)
|
20 | SPI.setBitOrder(MSBFIRST); //either LSBFIRST or MSBFIRST ; looks like MSB from datasheet
|
21 | // SPI.setClockDivider(SPI_CLOCK_DIV16); //shouldnt matter much here
|
22 | SPI.begin();
|
23 | }
|
24 |
|
25 |
|
26 | void loop(){
|
27 | //change the resistance on this channel from min to max:
|
28 | for (int level = 0; level < 1023; level++){
|
29 | digitalPotWrite(level); //send info for SPI communication
|
30 | // read out the value from the changed resistance back into the arduino ADC:
|
31 | resistanceValue= analogRead(resistorPin);
|
32 | }
|
33 | }
|
34 |
|
35 |
|
36 | void digitalPotWrite(int DataBits){
|
37 | int new_poti_pos;
|
38 | digitalWrite(slaveSelectPin,LOW); // take the SS pin low to select the chip:
|
39 | SPI.transfer(COMMAND_6); // allow update of wiper position through digital interface
|
40 | delay(200);
|
41 | if ( DataBits % 2 ==1){
|
42 | new_poti_pos=0x0402; //Poti position #1
|
43 | }
|
44 | else{
|
45 | new_poti_pos=0x06C2; //Poti position #2
|
46 | }
|
47 | SPI.transfer(new_poti_pos); //send this position to the Poti
|
48 | digitalWrite(slaveSelectPin,HIGH); // take the SS pin high to de-select the chip:
|
49 | }
|