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

HI, I need to read values from multiple TI ADS8319 16-bit ADCs with a Arduino Mega2560 through SPI.

The datasheet of the ADC can be found here.

The timing diagram of the SPI interface is below.

Untitled.png

I tried it with following arduino code for a single ADC and it worked. But when I tried to recreate the code with LIFA, I couldn't get any data (sorry I cannot post the LIFA block diagram I tried at this moment, but I'll try to post it later).

So, can anyone give me a basic example of which I should try? Or any direction to some place I can look at?

#include <SPI.h>

#define CONVPIN 22

#define SELPIN 25

#define MISOPIN 50

#define SCLKPIN 52

int adcvalue;

byte byte1; byte byte2;

const float   aRefVoltage = 5;

float volts = 0;

float pressure = 0;

void setup() {

  pinMode(SELPIN, OUTPUT); // ADC's selection pin

  pinMode(CONVPIN, OUTPUT); // ADC's conversion pin

  pinMode(SCLKPIN, OUTPUT);// ADC's clock pin

  pinMode(MISOPIN, INPUT); // ADC's data out

  SPI.begin();

Serial.begin(115200);

}

void loop() {

  digitalWrite(CONVPIN, LOW);

  digitalWrite(SELPIN, HIGH);

  digitalWrite(CONVPIN, HIGH);

  digitalWrite(SELPIN, LOW);

delay (100); 

byte1 = SPI.transfer(0x00); //transfer (read) 8 bits from the adc chip D15-8

byte2 = SPI.transfer(0x00); //transfer (read) the second 8 bits. D7-0

adcvalue = (byte1 << 8 ) | (byte2 & 0xff); // combine the 2 bytes to make our 16 bit word

   Serial.print("Sensor value:  ");        

   Serial.print(adcvalue,BIN);           // display the HEX value also

volts = (adcvalue*aRefVoltage/65535);    // formula for figureing voltage

                                         // 65535 = the 16 bit "deciamal" value

pressure = ((adcvalue/(65535*0.004))+0.04);

   Serial.print("   Sensor volts:  ");     

   Serial.print(volts,5);

   Serial.print("    Pressure:    ");

   Serial.print(pressure,5);

   Serial.println(" kPa");

delay (100);

}

0 Kudos
Message 1 of 24
(8,408 Views)

Here's the VI I tried at first. But it returns no value at all.

0 Kudos
Message 2 of 24
(4,928 Views)

The first thing that I notice is that the Mega uses a baudrate of 9600 (it is hardcoded in the firmware) and I was never able to get it working any faster than that.

(Note that I have not yet looked over it thouroghly yet becasue I don't have LIFA installed on university computers)

Are you getting any errors?

Message 3 of 24
(4,928 Views)

Hey bk201,

In your LV code you are not actually transfering any data via SPI.  Create a byte array constant on the SPI Send Receive VI with 2 0x00s in it.  This will transfer the two dummy bytes to get your data back.  I think this might be all it takes, but let me know if that does not work (I only quickly glanced at this).

Thanks!

-Sam K

LIFA Developer

Message 4 of 24
(4,928 Views)

Thanks for your reply, Nathan & Sam.

I will try your suggestions and let you know.

0 Kudos
Message 5 of 24
(4,928 Views)

Hi,

Wehave tried with bit rate 9600 and added the array as sam suggested. Still there was no value with the previously uploaded VI. Then we tried with the another VI (attached) and then it gives a value of 53 when ADC is attached and 48 when disconnected when there should be none. Can't find out what's giving these values.

Here's the screenshot of the used VI,

test vi 02.PNG

When stopping this VI there comes up a list of errors, here's the screenshot:

55b2bf1c7bd822ec6018e6982c27c07f1525df17.jpg

We are at a bound for not understanding what is happening here. Please help regarding this situation and if possible provide some guidelines or example VI which we can try out.

Thanks

Message was edited by: bk201

0 Kudos
Message 6 of 24
(4,928 Views)
Solution
Accepted by topic author aazswapnil

I think the biggest issue here is probably the firmware.  I don't think the SPI function was correctly converted when Arduino went to version 1.0.  I believe that you need to change Serial.print to Serial.write in this code:

      // Send SPI Byte
      Serial.print(SPI.transfer(command[i+6]));    
      spiBytesSent++; 

Also, I've attached my version of your VI.  The SPI function in the firmware already toggles the CS pin for you so you don't need to do that manually.  Also note that I added the functions to take the two 8-bit integers to get the final resulting 16-bit integer (displayed as "adcvalue" which will correspond to the variable of the same name).

So, make the change to the firmware, upload it, and then test with my VI (the voltage and pressure calculations are just algebra from where I left it).

0 Kudos
Message 7 of 24
(4,928 Views)

Well, changing Serial.print to Serial.write in firmware did work. Now we are getting readings using the last VI bk201 posted screenshot of without changing anything to it. I couldn't try your VI as we have LabVIEW 2011, but I am downloading LV2012 trial version now to check your VI.

Thank you very much. Now we can complete our project in time.

0 Kudos
Message 8 of 24
(4,928 Views)

I've uploaded my version of the VI saved for 2009 so you should be able to open it now.

0 Kudos
Message 9 of 24
(4,928 Views)

This works flawlessly. Now I am going to complete rest of the VI. A lot of thanks for your support.

0 Kudos
Message 10 of 24
(4,928 Views)