Go Down

Topic: Arduino Due interfacing with AD7705 problem? (Read 827 times) previous topic - next topic

mark07

Jan 17, 2018, 09:12 pm Last Edit: Jan 18, 2018, 10:09 am by robtillaart
Hello geek

I have wrote a code of interfacing AD7705 with Arduino due,i am not getting any errors thou!
but i am unable to get any output.Can anyone highlight me where i am going wrong and what need to changed in the code

Here is the code:

Code: [Select]

#include <SPI.h>
 uint32_t pwmPin = 6;                                                                           
uint32_t maxDutyCount = 42000000/2000000; //2;
uint32_t clkAFreq = 42000000ul;
uint32_t pwmFreq = 42000000ul;

//const int drdy = 6;

//const int cs = 10;

//const int freqOutputPin = 3;
#define CS 10
#define DOUT 11
#define DIN 12
#define SCLK 13
#define DRDY 7


//const int ocr2aval  = 3;

 

 

//const int prescale  = 1;

//const float period    = 2.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6);

//const float freq      = 1.0e6 / period;

 

 

void setup()

{

  //pinMode(freqOutputPin, OUTPUT);

  Serial.begin(9600);

  SPI.begin();

  //SPI.beginTransaction(SPISettings(200,MSBFIRST,SPI_MODE0));

  pinMode(DRDY,INPUT);

  pinMode(CS,OUTPUT);

  digitalWrite(CS,LOW);



  pmc_enable_periph_clk(PWM_INTERFACE_ID);
  PWMC_ConfigureClocks(clkAFreq, 0, 2*clkAFreq); //VARIANT_MCK);
  PIO_Configure(
    g_APinDescription[pwmPin].pPort,
    g_APinDescription[pwmPin].ulPinType,
    g_APinDescription[pwmPin].ulPin,
    g_APinDescription[pwmPin].ulPinConfiguration);
  uint32_t channel = g_APinDescription[pwmPin].ulPWMChannel;
  PWMC_ConfigureChannel(PWM_INTERFACE, channel , pwmFreq, 0, 0);
  PWMC_SetPeriod(PWM_INTERFACE, channel, maxDutyCount);
  PWMC_EnableChannel(PWM_INTERFACE, channel);
  PWMC_SetDutyCycle(PWM_INTERFACE, channel, maxDutyCount/2); //1);
  pmc_mck_set_prescaler(42);
}

void loop()
{


  writetoadc(0x20);

  delay(100);

  writetoadc(0x03);

  delay(100);

  writetoadc(0x10);

  delay(100);

  writetoadc(0x40);

  delay(100);


 

 

//void loop()

//{
while(digitalRead(DRDY) == 1)
  //while(digitalRead(drdy)==1);

  writetoadc(0x38);

  int value = getadcdata();

  //Serial.print("Value:");

  //Serial.println(value);

}

 

 

void writetoadc(byte command)

{

  SPI.transfer(command);

  //SPI.endTransaction();

  digitalWrite(MOSI,HIGH);

  return;

}

 

 

int getadcdata()

{

  unsigned int result = 0;

  byte input = 0;

  result = SPI.transfer(0x00);

  result = result << 8;

  input = SPI.transfer(0x00);

  result = result | input;

  //SPI.endTransaction();

  //digitalWrite(MOSI,HIGH);

  return (result);

}

mark07

Hello guys

I am finding a problem getting a output for the interfacing AD7705.i have a written a code,thou there is no error.
Please anyone can guide me through my mistakes and can give any suggestion.would be great help for me.
Thank you

Code: [Select]
#include <SPI.h>
 uint32_t pwmPin = 6;                                                                           
uint32_t maxDutyCount = 42000000/2000000; //2;
uint32_t clkAFreq = 42000000ul;
uint32_t pwmFreq = 42000000ul;

//const int drdy = 6;

//const int cs = 10;

//const int freqOutputPin = 3;
#define CS 10
#define DOUT 11
#define DIN 12
#define SCLK 13
#define DRDY 7


//const int ocr2aval  = 3;

 

 

//const int prescale  = 1;

//const float period    = 2.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6);

//const float freq      = 1.0e6 / period;

 

 

void setup()

{

  //pinMode(freqOutputPin, OUTPUT);

  Serial.begin(9600);

  SPI.begin();

  //SPI.beginTransaction(SPISettings(200,MSBFIRST,SPI_MODE0));

  pinMode(DRDY,INPUT);

  pinMode(CS,OUTPUT);

  digitalWrite(CS,LOW);



  pmc_enable_periph_clk(PWM_INTERFACE_ID);
  PWMC_ConfigureClocks(clkAFreq, 0, 2*clkAFreq); //VARIANT_MCK);
  PIO_Configure(
    g_APinDescription[pwmPin].pPort,
    g_APinDescription[pwmPin].ulPinType,
    g_APinDescription[pwmPin].ulPin,
    g_APinDescription[pwmPin].ulPinConfiguration);
  uint32_t channel = g_APinDescription[pwmPin].ulPWMChannel;
  PWMC_ConfigureChannel(PWM_INTERFACE, channel , pwmFreq, 0, 0);
  PWMC_SetPeriod(PWM_INTERFACE, channel, maxDutyCount);
  PWMC_EnableChannel(PWM_INTERFACE, channel);
  PWMC_SetDutyCycle(PWM_INTERFACE, channel, maxDutyCount/2); //1);
  pmc_mck_set_prescaler(42);
}

void loop()
{


  writetoadc(0x20);

  delay(100);

  writetoadc(0x03);

  delay(100);

  writetoadc(0x10);

  delay(100);

  writetoadc(0x40);

  delay(100);


 

 

//void loop()

//{
while(digitalRead(DRDY) == 1)
  //while(digitalRead(drdy)==1);

  writetoadc(0x38);

  int value = getadcdata();

  //Serial.print("Value:");

  //Serial.println(value);

}

 

 

void writetoadc(byte command)

{

  SPI.transfer(command);

  //SPI.endTransaction();

  digitalWrite(MOSI,HIGH);

  return;

}

 

 

int getadcdata()

{

  unsigned int result = 0;

  byte input = 0;

  result = SPI.transfer(0x00);

  result = result << 8;

  input = SPI.transfer(0x00);

  result = result | input;

  //SPI.endTransaction();

  //digitalWrite(MOSI,HIGH);

  return (result);

}

KG_DK

You don't tell us where you are expecting an output?
The AD7705 is an ADC and expect analog input and will give a digital output to the DUE.

artisticforge

Hello guys

I am finding a problem getting a output for the interfacing AD7705.i have a written a code,thou there is no error.
Please anyone can guide me through my mistakes and can give any suggestion.would be great help for me.
Thank you

Backup a little and tell us exactly what you are attempting to do.
A Wiring diagram would be good to have.

also using the Arduino IDE there is an option to format the sketch/code for the forums.

formatted sketch/code is easier to read without having to reformat it myself.
><>

ard_newbie

#4
Jan 18, 2018, 05:51 am Last Edit: Jan 18, 2018, 06:54 am by ard_newbie
There is an Instructable for interfacing AD7705 with an UNO, this might help:
http://www.instructables.com/id/Arduino-16-bit-500SPS-Dual-Channel-DAQ/

Provided you really need 16-bit ADC conversions at 500 sps, you can achieve this with your builtin ADC channels on the DUE. You will have to oversample and average accordingly to obtain 16-bit conversions from 12-bit conversions.

From the Silicon Labs Application Note AN118(IMPROVING ADC RESOLUTION BY OVERSAMPLING AND AVERAGING):


Assume a system is using a 12-bit ADC to output a
temperature value once every second (1 Hz). To
increase the resolution of the measurement to 16-
bits, we calculate the oversampling frequency as
follows:

fos = 4pow4 * 1Hz = 256Hz

Thus, if we oversample the temperature sensor at
fs=256 Hz, we will collect enough samples within
the required sampling period to average them and
can now use 16-bits of the output data for a 16-bit
measurement. To do so, we accumulate (add 256
consecutive samples together), then divide the total
by 256. Such a process
is commonly referred to as decimation.
This results in 16-bits of useful data. Such an operation
is referred to as accumulate and dump.


If fs = 500 Hz, fos = 128 KHz, well below the maximum conversion frequency of your builtin ADCs.

robtillaart

Moderator mode: added code tags - please check how to post code (in firsts topic in every section)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


aarg

What is the explanation for all the commented out lines?
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up