2014-01-07 61 views
0

我在控制AD5270 10位數字電位計時遇到了麻煩。看來無論我寫入寄存器,端子A和雨刮器之間的實際電阻值都不會改變。我假設我正在與「下降同步信號」具體問題,從data sheet第10頁:用Arduino控制AD5270 10位電位計

SYNC:下降沿同步信號。這是輸入數據的幀同步信號。當SYNC變爲低電平時,它使能移位寄存器,並在後續時鐘的下降沿傳輸數據。所選寄存器在第16個時鐘週期後的SYNC上升沿更新。如果SYNC在第16個時鐘週期之前變爲高電平,則SYNC的上升沿充當中斷,寫入序列將被RDAC忽略。

我一直在對待這個引腳很像一個SS引腳。到目前爲止,這是我必須儘可能的代碼有云:

#include <SPI.h> 

const int csPinCWF = 10; 

const byte enableUpdateMSB = 0x1C; //B00011100 
const byte enableUpdateLSB = 0x02; //B00000010 
const byte command = 0x04; //B00000100 

void setup() { 
    Serial.begin(9600); 
    Serial.println("Ready"); 

    SPI.begin(); 
    Serial.println("SPI Begin"); 
    SPI.setBitOrder(MSBFIRST); //We know this from the Data Sheet 
    SPI.setDataMode(SPI_MODE1); //Pg.7:Fig.3 states CPOL=0, CPHA=1 --> MODE1 

    pinMode(csPinCWF,OUTPUT); 
    Serial.println("Output Set"); 

    digitalWrite(csPinCWF, HIGH); 
    Serial.println("Set pin to HIGH"); 
} 

void loop() { 
for(int i=0; i<1023; i++) { 
    Serial.println(i); 
    enablePotWrite(csPinCWF); 
    digitalPotWrite(csPinCWF, i); 
    delay(5000); 
    } 
} 

void digitalPotWrite(int csPin, int value) { 
    Serial.println("In digitalPotWrite Now"); 
    digitalWrite(csPin, LOW); //select slave 
    Serial.println("Set csPin to LOW"); 

    Serial.print("Command Byte is: "); 
    Serial.println(command, BIN); 

    byte shfitedValue = (value >> 8); 
    Serial.print("Shifted bit value is: "); 
    Serial.println(shfitedValue, BIN); 

    byte byte1 = (command | shfitedValue); 
    Serial.print("Byte1 is: "); 
    Serial.println(byte1, BIN); 

    byte byte0 = (value & 0xFF); //0xFF = B11111111 trunicates value to 8 bits 
    Serial.print("Byte0 is: "); 
    Serial.println(byte0, BIN); 

    //Write to the RDAC Register to move the wiper 
    SPI.transfer(byte1); 
    SPI.transfer(byte0); 

    Serial.print("Transfered: "); 
    Serial.print(byte1, BIN); 
    Serial.print(" "); 
    Serial.println(byte0, BIN); 

    digitalWrite(csPin, HIGH); //de-select slave 
    Serial.println("Set csPin back to HIGH, end of digitalPotWrite"); 
} 

void enablePotWrite(int csPin) { //Enable Update of the Wiper position through the digital interface 
    digitalWrite(csPin, LOW); //select slave 

    Serial.print("Enable byte is: "); 
    Serial.print(enableUpdateMSB, BIN); 
    Serial.print(" "); 
    Serial.println(enableUpdateLSB, BIN); 

    SPI.transfer(enableUpdateMSB); 
    SPI.transfer(enableUpdateLSB); 

    digitalWrite(csPin, HIGH); //de-select slave 
} 

我已經過了很多次,好像數學是正確的,它傳遞了正確的字節,但是我沒有變端子A和雨刮器之間的任何變化。頁面19:data sheet的表11顯示了我應該傳送的16位字的格式。任何人都可以點亮我在這裏可能會缺少的東西嗎?任何幫助將不勝感激,謝謝!

編輯:更改了我的代碼以反映mpflaga的建議,但仍然沒有骰子不幸。

編輯2:SPI模式的確是SPI_MODE1。 PG。 7:數據手冊的圖3狀態CPOL = 0,CPHA = 1。編輯上面的代碼以反映更改。再次感謝@mpflaga。

回答

1

幾個問題:

首先 -

每數據表,第18頁:

爲了使RDAC寄存器進行編程,寫保護位(位 C1)的控制寄存器首先必須通過用命令7加載 串行數據輸入寄存器來編程。

每數據片20頁表14中,示出了由缺省C1爲0,

0 =在50-TP存儲器(默認)冷凍至值抽頭位置 ,或中間電平如果先前未程序性。

請參閱表12的示例序列,通過最初發送0x1C03來移動事物。我相信你可以用0x1C02替代,如果你不想啓用編程,只想在飛行中更新。


二 -

而且看起來像從數據表中的Din的在時鐘的下降沿被採樣。您需要在設置中的以下內容

SPI.setDataMode(SPI_MODE1); 

在哪裏經常可能看起來在MODE0(默認)下工作,數據速率較慢。

+0

啊......我現在明白了。我們需要發送0x1C02 00 0111 0000000010. 雖然我仍然沒有得到迴應。發送每個單詞後,是否需要將SS引腳拉高? – swbooking

+1

每頁18 ...當SYNC返回高電平時,串行數據字根據表11中的說明解碼 – mpflaga

+0

謝謝!我更新了上面的代碼以反映您的建議和一些更改,但遺憾的是阻力仍然沒有變化。 – swbooking

0

我只是碰巧與AD5271(同樣的事情,但8位),我終於得到它在Arduino Duemilanove工作。

下面是測試代碼,我寫的工作副本:

#include <SPI.h> 

const int SS_PIN = 10; 
const int MOSI_PIN = 11; 
const int MISO_PIN = 12; 
const int CLK_PIN = 13; 

// Writes to the control register enabling the RDAC register write access. 
void initRheostat() { 
    Serial.println("Writing Control Reg"); 
    byte upper = 0x1C; 
    byte lower = 0x02; 
    digitalWrite(SS_PIN, LOW); 
    SPI.transfer(upper); 
    SPI.transfer(lower); 
    digitalWrite(SS_PIN, HIGH); 
} 

// Writes the value to the RDAC register. 
void writeRheostat(byte val) { 
    Serial.print("Writing to Rheostat... "); 
    Serial.println(val); 
    byte command = 0x01; 
    byte upper = (command << 2) | (val >> 6); 
    byte lower = val << 2; 
    digitalWrite(SS_PIN, LOW); 
    SPI.transfer(upper); 
    SPI.transfer(lower); 
    digitalWrite(SS_PIN, HIGH); 
} 

// Readsd the value in the RDAC register. 
void readRheostat() { 
    Serial.println("Reading rheostat..."); 
    digitalWrite(SS_PIN, LOW); 
    byte upper = 0x80; 
    byte response = SPI.transfer(upper); 
    // Print the raw byte response. 
    Serial.println(response, HEX); 
    digitalWrite(SS_PIN, HIGH); 
    digitalWrite(SS_PIN, LOW); 
    byte lower = 0x00; 
    // Print the raw byte response. 
    byte secondResponse = SPI.transfer(lower); 
    Serial.println(secondResponse, HEX); 
    // Calculate the actual value and print it out. 
    int value = ((response & 0x03) << 6) | (secondResponse >> 2); 
    Serial.print("Actual Value: "); 
    Serial.println(value); 
    digitalWrite(SS_PIN, HIGH); 
} 

void setup() { 
    Serial.begin(9600); 
    // Initialize SPI 
    pinMode(SS_PIN, OUTPUT); 
    SPI.begin(); 
    // SPI_MODE1 (CPOL = 0, CPHA = 1) - From the datasheet 
    SPI.setDataMode(SPI_MODE1); 
    // MSBFIRST - From the data sheet 
    SPI.setBitOrder(MSBFIRST); 
    // Call to init and enable RDAC register write access. 
    initRheostat(); 
} 

void loop() { 
    // Serial listener that sets the wiper to the specified value. 
    while (Serial.available() > 0) { 
     char inChar = Serial.read(); 
     writeRheostat(inChar); 
     readRheostat(); 
    } 
} 

另外,還要確保你的電路接線是否正確。您必須對10位的writeRheostat函數中的位移進行一些更改。

  • 的EXT_CAP應具有連接到VSS
  • 一個1uF電容VDD需要與10uF的電容器和0.1uF電容
  • SDO需要有一個上拉電阻器進行去耦。

希望有幫助。