LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with LIFA and TI ADS8319

Solved!
Go to solution

Nathan & Sammy, Thanks a lot!

0 Kudos
Message 11 of 24
(2,421 Views)

I am tryiing to implement the following code for my ADS8319 interfaced with ARDUINO UNO. This code is the same as given in the orignal post by "aazswapnil", except for the pin numbers are changed for my board accordingly. I am implementing this code directly on the hardware, but unfortunately i am not geting the right value for the output. I have used a 5V reference and i am trying to read 1V from the ADC output, but i am geting very strange values like 0 volts, 1,2 volts, 3 volts, 0 volts etc, and these values keeps on changing, whereas i i am giving a constant 1V input to the ADC.

#include <SPI.h>

#define CONVPIN 7

#define SELPIN 8

#define MISOPIN 12

#define SCLKPIN 13

int adcvalue;

byte byte1; byte byte2;

const float aRefVoltage = 5;

float volts = 0;

void setup() {

  // put your setup code here, to run once:

pinMode(SELPIN, OUTPUT);

pinMode(CONVPIN, OUTPUT);

pinMode(SCLKPIN, OUTPUT);

pinMode(MISOPIN, INPUT);

SPI.begin();

Serial.begin(9600);

}

void loop() {

  // put your main code here, to run repeatedly:

digitalWrite(CONVPIN, LOW);

digitalWrite(SELPIN, HIGH);

digitalWrite(CONVPIN, HIGH);

digitalWrite(SELPIN, LOW);

delay(1000);

byte1 = SPI.transfer(0x00);

byte2 = SPI.transfer(0x00);

adcvalue = (byte1 <<8) | (byte2 & 0xff);

Serial.print("Voltage Value: ");

Serial.println(adcvalue,BIN);

volts = (adcvalue*aRefVoltage/65535);

Serial.print(" Sensor Volts: ");

Serial.println(volts,5);

delay(1000);

}

I just want to make sure if the code is right, because i did my best to make the hardware perfect as recommended by the data sheet. I have pasted the schematic screenshot in which ADS8319 is connected with the reference IC, and its connections are shown with the micro-controller. (I have checked the values of input voltage to the ADC plus the reference valule to the ADC by Voltmetre and they are perfect

ads8319.png)

Please help !

0 Kudos
Message 12 of 24
(2,421 Views)

Your code looks fine to me. You could try lowering the delays from 1000ms to 100ms but I don't think that is the actual problem. Increasing the delay before SPI.transfer increases the Acquisition time of the ADC, but the datasheet only mentions the minimum limit for it, no maximum limit.

Also I should mention that, the first time I built the circuit, I too was getting wrong and inconstant output, from this code. But after some troubleshooting I found that it was caused by a cold solder on the GND pin of the ADC. I rebuilt the circuit again then it worked properly. But this may not be your problem either.

0 Kudos
Message 13 of 24
(2,421 Views)

ads.jpg

Yes i did try with 100ms delay, but the problem is the same, however if the code is right, i will try to troubleshoot my hardware, as there may be somthing wrong with it. One thing that is coming to my mind is that i have connected two ADCs together, and i am just trying to read the value of one adc (for now for test purpuse) by giving it an input. All the wires to both the ADCs are common from the microcontroller (SCK,MISO,CONVST) and only the MOSI is spererate for both the ADCs which works as SS. My schematic can be seen in the image above


SO right now all the circuit is connected, as i have soldered it already on the PCB, and i am just trying to read the value of ADC1 by connecting the SCK,MISO,CONVST and SDi1 wires with the micro-controller, and leaving SDi2 unconnected. May be the ambiguity in the values is because of that (although ADC 2 is supposed to give zero output as i havent given anything on its input). Do you think it could be a problem ? As already mentioned, all the connections have already been made on the PCB and components have been soldered, so i cannot test the single ADC1. I hope you got my point.
and thanks alot for your reply! i really appreciate that.

ads.png

0 Kudos
Message 14 of 24
(2,421 Views)

So basically what i am trying to say is that i have set up my connections on the board for the following configuration

pdf.jpg

However for the testing purpose, i am just trying to read the value from ADC1 for now, as i am not giving any signal to sdi2 (ADC2) from my micro-controller.

is this the right way to test ? could this be a problem ? Or should i test both the adcs together ?

0 Kudos
Message 15 of 24
(2,421 Views)

If you have already wired 2 ADCs together in "4 Wire CS Mode Without Busy Indicator" then you'll have to connect the SDI2 (the SDI on second ADC) and put it in the correct state. Otherwise while reading the SPI data from first ADC the SDO on the second ADC will not go to three state, and interfere with the transfer.

Try with this code, with the two additional lines I've added. Remember to put the correct pin number for SELPIN2.

#include <SPI.h>

#define CONVPIN 7

#define SELPIN 8

#define SELPIN2 9 // or the Arduino pin your second ADC's SDI is connected to.

#define MISOPIN 12

#define SCLKPIN 13

int adcvalue;

byte byte1; byte byte2;

const float aRefVoltage = 5;

float volts = 0;

void setup() {

  // put your setup code here, to run once:

pinMode(SELPIN, OUTPUT);

pinMode(SELPIN2, OUTPUT); // Forgot to put this one last time.

pinMode(CONVPIN, OUTPUT);

pinMode(SCLKPIN, OUTPUT);

pinMode(MISOPIN, INPUT);

SPI.begin();

Serial.begin(9600);

}

void loop() {

  // put your main code here, to run repeatedly:

digitalWrite(CONVPIN, LOW);

digitalWrite(SELPIN, HIGH);

digitalWrite(SELPIN2, HIGH);

digitalWrite(CONVPIN, HIGH);

digitalWrite(SELPIN, LOW);

delay(1000);

byte1 = SPI.transfer(0x00);

byte2 = SPI.transfer(0x00);

delay(100);

digitalWrite(SELPIN2, LOW); // Not necessary as we are reading data from only the first ADC.

adcvalue = (byte1 <<8) | (byte2 & 0xff);

Serial.print("Voltage Value: ");

Serial.println(adcvalue,BIN);

volts = (adcvalue*aRefVoltage/65535);

Serial.print(" Sensor Volts: ");

Serial.println(volts,5);

delay(1000);

}

Message was edited by: aazswapnil

0 Kudos
Message 16 of 24
(2,421 Views)

Will try it tomorrow for sure and will let you know. Thanks alot man, i had a little hope that youll reply after so many years and help me out

0 Kudos
Message 17 of 24
(2,421 Views)

Can you please share your hardware schematic with me ? I just want to see what values of resistors and capacitor are you using at the input of the ADC . I think there is something wrong with my harwdare, because the code that you gave me seems to be correct. I am using 5ohm 1nF and 5ohm at the input of the ADC, just as recommended by the ADC data sheet.

0 Kudos
Message 18 of 24
(2,421 Views)

Saw your other reply on email. You are correct about the line to set SELPIN2 as output. But you shouldn't bring SELPIN2 low right after SELPIN was brought low. Both being low during SPI.transfer will defeat the purpose. It's not necessary to bing SELPIN2 low at any part of the loop if you are only reading the value from first ADC. But if you want to do that, bring SELPIN2 low after the SPI.transfer. I've edited my last post to show it.

And here's the schematic. But the one you've posted should work fine too. Also remember, when I had a similar problem, I found that it was caused by a cold solder joint on one of the ADC pin.Untitled.png

0 Kudos
Message 19 of 24
(2,421 Views)

yes you are right about SELPIN2 LOW, i got that after posting it, so that is why i deleted that post. I will recheck my solder connections to see if anything is wrong with them.

0 Kudos
Message 20 of 24
(2,421 Views)