LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-8451 SPI interface with analog devices isensor

Does anyone has example VI using USB-8451 with analog devices isensor? I am new to SPI interface and very slowly learning how to use labview in conjunction with USB-8451 to do SPI sensor reading.

Any help would be appreciated. I'm using labview 8.5. 

0 Kudos
Message 1 of 30
(5,627 Views)
Have you looked at the examples that ship with the 8451 software?
Message Edited by smercurio_fc on 09-24-2009 11:15 PM
0 Kudos
Message 2 of 30
(5,617 Views)

Yes, but none of them is done for a sensor. the example is for a eeprom.

 

I saw this tutorial, but need the vi also in order to understand/play with it more.

http://zone.ni.com/devzone/cda/tut/p/id/9931 

 

It'll be helpful to see someone with a VI done for data acquisition for one of those isensor from analog devices.

 

 

0 Kudos
Message 3 of 30
(5,612 Views)
It doesn't really matter whether it's an EEPROM or a sensor - SPI is SPI. You need to look at the datasheet for the sensor to see what its byte sequences are for controlling it or getting data from it. Sometimes datasheets are not so lucid, so if you are having trouble figuring that out, then provide a link to the datasheet (or just attach it in a reply) and someone can help you decipher it.
0 Kudos
Message 4 of 30
(5,610 Views)

Ok then, I'll ask my questions on this board instead. 

here is the datasheet

http://www.analog.com/static/imported-files/data_sheets/ADIS16400_16405.pdf

 

My questions are:

- with the write/read module, is the read array data 8-bit long?

- In order to continually read the data, do i need to create a while loop? or is there a more efficient way?

- In the tutorial linked in my previous post, i don't understand the post-processing from 14bit unsigned to signed subroutine. Can someone help enlighten me?

 

0 Kudos
Message 5 of 30
(5,599 Views)

elpiar wrote:

Ok then, I'll ask my questions on this board instead. 

here is the datasheet

http://www.analog.com/static/imported-files/data_sheets/ADIS16400_16405.pdf


OK. Looks like a pretty standard SPI device.

 


My questions are:

- with the write/read module, is the read array data 8-bit long?


It's 16 bits. To read data from the device you send 2 bytes, which is the command to read, then you follow that up with another 16 clocks which is the actual data read from the device. 

 


- In order to continually read the data, do i need to create a while loop? or is there a more efficient way?


You would need a loop. Data only gets transmitted by the device on clocks, and the controller (the 8451) has to generate these. If you want to read a sequence of registers you can use the burts mode, as explained in the data sheet. This allows you to read successive registers by sending out sequential 8-clock "bursts". With each one the address counter in the device gets incremented, so the next one will be read. However, you would need to restart the sequence to read another batch of data.

 


- In the tutorial linked in my previous post, i don't understand the post-processing from 14bit unsigned to signed subroutine. Can someone help enlighten me?


That was specific to the data obtained from that particular device. The data was available in the lower 14 bits of the 16 bits read from the device (as 2 bytes), in 2's complement format. The code included scaling, based on the datasheet from the device. Your device has similar characteristics, so you would need to do a similar operation. Be aware, though, that not all registers have the same data format. Table 9 in the datasheet indicates how the information is provided for each type of measurement that you want to make. Also, the code shown in the tutorial can be simplified a bit by using the Type Cast function instead of the Index Array and Join Numbers.

 

Unfortunately, I don't have time this morning to whip up an example for you to read a specific register from the device. I'll try to put something together later today. 

 

 

 

0 Kudos
Message 6 of 30
(5,587 Views)

I've attached a simple example which should allow you to read the XGYRO_OUT register of the sensor. See if it works for you.

 

You had asked about the post-processing from 14-bit to signed. This is required since the data for the particular register that's being read is 14-bits, not 16 bits, but the data packet from the SPI is 16 bits. The first 2 bits are ND and EA. The To Word Integer function will automatically convert a 16-bit 2's complement unsigned number to a 16-bit signed value. However, the data you get is either 14-bits or 12-bits, depending on which register you read. Thus, you need to extend the 14-bit or 12-bit value to 16 bits so you can convert it to a signed value. Let's take the 14-bit example. For a 2's complement number the most significant bit is a zero if it's a negative number. Thus, if bit 14 is a 1 it means the register's data indicates a negative number. To extend the 14-bit value to a 16-bit value we just need to set the first 2 bits to a 1. If bit 14 is a zero it means the register's data indicates a positive number, and to extend the 14-bit value to a 16-bit value we just need to set the first 2 bits to a 0. That's what the code with the AND and OR functions is doing. You would need to perform a similar operation for 12-bit values, but the values of 3FFF, 2000, and C000 would change to 0FFF, 0800, and F000.

0 Kudos
Message 7 of 30
(5,574 Views)

Thanks for the example. It helps a lot. I will study the 14 bit sign extension later.

 

It's working!

 

Now if I read the data is burst mode, will the output be automatically be arranged in an array of 8-bit length words? You mention something about send out out 8 clock burst. I'm not sure how I do this. 

0 Kudos
Message 8 of 30
(5,568 Views)

elpiar wrote:
It's working!

Well, I realized I made a small mistake in the example. The number of bytes in the array constant should be 4, not 2. The device is full duplex, meaning you can write and read from it at the same time. The NI-845x SPI Write Read VI returns the same number of bytes as the number of bytes that were written. Thus, with just 2 bytes you will not actually get the current value of the register. You would get the values from the previous command. See attached mod.

 


Now if I read the data is burst mode, will the output be automatically be arranged in an array of 8-bit length words? You mention something about send out out 8 clock burst. I'm not sure how I do this. 

For burst mode you have to send out more bytes so you get clocks generated for the read to occur. The burst mode command is 3E00. That needs to be followed by 12 16-bit numbers for the device to return all the registers from SUPPLY_OUT to AUX_ADC. The actual bytes after the 3E00 are irrelevant for a write. The NI-845x SPI Write Read VI should then return 26 bytes (2 bytes that line up with the 3E00 command, followed by 2 bytes per register, for 12 registers). You can convert this into an array of U16 values and do the conversions based on which register you're actually reading. I've attached a VI to get you started. The example converts the SUPPLY_OUT register and each of the GYRO_OUT registers. You can finish the VI. Note that you should make the 14-bit to 16-bit extension a subVI so you're not duplicating code. 

 

NOTE: As with all example code that is provided you should verify that the numbers you get are correct. We don't have the hardware, so we can't verify correct operation. 

 

Download All
0 Kudos
Message 9 of 30
(5,555 Views)
Thanks again for the help. I just got back from vacation and try it out sometime this week.
0 Kudos
Message 10 of 30
(5,465 Views)