Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Arduino with digipot AD5293

Status
Not open for further replies.

Rajiv Tyagi

Newbie level 4
Newbie level 4
Joined
Jan 10, 2015
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
35
Digipot AD5293 is giving me a lot of trouble. Below is my code. I don't know why I can't get this to work or what I'm doing wrong. Can someone help, please?

Code:
[syntax=cpp]
#include <SPI.h>

void setup(){

  pinMode(10, OUTPUT); //CS
  pinMode(11, OUTPUT); //MOSI
  pinMode(12, INPUT);  //MISO
  pinMode(13, OUTPUT); //SCK

  Serial.begin(115200);

  writeCommand;
}

void loop(){
  unsigned int val;
  for (val = 0; val <= 1023; val++) {
    writeDigipots(val);
    //delay(10);
  }

  for (val = 1023; val > 0; val--) {
    writeDigipots(val);
    //delay(10);
  }

}


void writeDigipots(unsigned int val){
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE1));
  digitalWrite(10, LOW);
  //SPI.transfer(0x18); //send command byte
  //SPI.transfer(0x03);
  byte highbyte = val >> 8 + 0x04; //high wiper byte + command
  byte lowbyte = val & 0xFF;
  SPI.transfer(highbyte); //send wiper data high byte
  SPI.transfer(lowbyte); //send wiper data low byte
  digitalWrite(10, HIGH);
  SPI.endTransaction();
}

void writeCommand() {
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE1));
  digitalWrite(10, LOW);
  SPI.transfer(0x18); //send command high byte
  SPI.transfer(0x03); //send command low byte
  digitalWrite(10, HIGH);
  SPI.endTransaction();
}
[/syntax]

On the oscilloscope I can see the MOSI changing values, SCK is present and stable, CS is correct. What am I doing wrong?

Rajiv
 


Looks like you did not include the header file for the microcontroller which is running the SPI protocol.Include the microcontroller header file also.Then,the system might work.
Also,are the functions digitalWrite,SPI.transfer,SPI.beginTransaction a part of <SPI.h>?
If not,then they will not work,if you haven't defined them anywhere in the program.
 

Yes, those are all SPI methods from the SPI Library built into the Arduino IDE. I am getting no compiler errors - everything compiles without any warning or error messages.

Could you please check if I am sending the data correctly? Starting with the 0x1803 control code and the masking of the two bytes I send in the writeDigipots() function? The Analog Devices datasheet is so sketchy, I wonder how people get their digipots working? Their help is almost non-existent - the designated helper on the AD line knows almost nothing about the device and just advises to compare waveforms with the datasheet... :(
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top