LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx and SPI Timing

I really need two things for the timing:

 

1.) I need a constant delta time between samples.  I understand that normal operating systems (i.e. windows, mac, linux) can only resolve time to the nearest millisecond which means I can really only get 1 kHz sampling which is ok for now.  Eventually, I will need 2 kHz sampling and will use hardware timed application but for now I am trying to determine differences between the digital and analog accelerometer capability as it relates to our post processing of the signal.  For our application, we need to know applied force (determined from a hammer connected to the NI 9233), strains (strain gages on the NI 9236), and acceleration (analog connected to 9233 and digital connected to USB-8452).  The reason we need to investigate digital accelerometers is due to size constraints...analog sensors are just too large.  Otherwise I would just use analog sensor and be done.

 

2.) I need all data points taken at the same time (or as close as possible).

 

The 1st item is probably more important since we will be performing discrete fourier transforms which require constant delta time.

0 Kudos
Message 11 of 42
(1,575 Views)

Can you use the NI-845x Streaming API and connect a DAQ signal to the DRDY input? This would cause the NI-8452 to perform an SPI transaction each time DRDY asserts.

0 Kudos
Message 12 of 42
(1,569 Views)

I haven't tried the SPI streaming API and I'm not too familiar with it.

0 Kudos
Message 13 of 42
(1,567 Views)

It is a more complicated API, but if you are generally using SPI to just read from an SPI slave (possibly sending the same N bits before the data), than the API would work and may allow you to have good synchronization with DAQMx. You can look at the online documentation and some of the examples to help get started.

0 Kudos
Message 14 of 42
(1,565 Views)

What you described is exactly what I am doing with the SPI digital accelerometer.  I will investigate that approach.  Thanks.

0 Kudos
Message 15 of 42
(1,563 Views)

I've tried to get SPI streaming to work but still having some difficulty.  I have looked at the examples...most heavily the TI ADS833x example (which is more complicated than my device) and also reading the NI tutorial for it (located here).  I have changed the SPI stream parameters for my device using the datasheet but I can't seem to get anything.  I am using the CS line right now for control.  It seems the CS line is not toggling between high and low which might be messing up my data.

 

The summary is I need to send the 8 bit read command (which includes the register address to start reading and 6 extra bytes to read the 6 data addresses).  Which I think I have defined correctly on the stream parameters.

 

I have attached my vi which has removed all the daqmx items in order to simplify and only focus on the SPI interface.  Also, the data sheet for accel is attached.  Hopefully, I am just doing something silly with the stream commands.  Any ideas?

Download All
0 Kudos
Message 16 of 42
(1,547 Views)

Hi lgbav8r,

 

Have you been able to read the Device ID, and Register Status from the first three Read/Writes? I have been looking through the datasheet and it looks like First Data Address corresponds to the INT1_CFG register which you are writing all zeroes to. I cannot find the 11100000 register that you are reading from. I may just not have seen it in the datasheet. Also, what does E8 correspond to on the SPI Stream Configuration?

 

Also, it looks like you are going to need to read the low and high bits for each axis starting from register OUT_X_L and ending with register OUT_Z_H. 

 

Best,

tannerite

Tannerite
National Instruments
0 Kudos
Message 17 of 42
(1,523 Views)

Tannerite,

 

Thanks for the reply.  I think there is some confusion on data register access.  This particular sensor takes 8 bits to access the register for reading or writing.  The first bit is the read/write bit (1 for read and 0 for write).  The second bit is multi-byte reading or writing (1 for multi-byte and 0 for single byte).  The last 6 bits are the address.  All addresses for SPI for this sensor are 6 bit addresses.

 

On the First Data Address, I think you missed a 0 (you only have 4 but there are 5).  The binary entry is 01100000 (leading zero is not displayed in labview).  Leading 0 for write command. The second bit is 1 for multi-byte operation and the last 6 bits are 100000 (0x20) which is the CTRL_REG1 register.

 

I have been able to set all the control registers and get the device ID.  The streaming part seems to be where my problem is.

 

The 0xE8 that I have as the first byte in the SPI stream configuration is 11101000 in binary.  Bits 1 and 2 are multi-byte reading while bits 3-8 are the OUT_X_L register (101000 or 0x28).  I then follow this with 6 bytes of all 1's to read each of the 6 data registers.

 

I did change the number of bytes per read on the spi stream read vi to 7 as I think I was missing the low byte of the Z data by only having 6 since the first byte is the address.  I seem to be getting the correct initial values for accelerations.

 

However, I am not really seeing any data come through as a result of moving the sensor around.  I think this is because the 8452 is running much too quick for my needs and taking a lot of data points over a very small time, and it is taking awhile to fill the buffer of the 8452 which is then sent to labview.  The maximum this sensor can sample is 5 kHz.  Do you have any thoughts on how I can control this?  I tried doing this with wait until next ms.vi but that seems to be operating independently of the SPI stream read.  I am thinking I will have to incorporate the data ready signal somehow but not quite sure where/how to incorporate it.

 

Updated vi attached

0 Kudos
Message 18 of 42
(1,514 Views)

jgbav8r,

 

It looks like the accelerometer needs to be setup to stream data as well. In Section 5.1 it speaks about stream mode where the X,Y, and Z measurements are stored in a FIFO and you read directly from the FIFO. It looks like there are several control registers that need to be configured for this to take place. As for more information about SPI Streaming, here is a link to the 845x Hardware and Software Manual. Page 14-1 explains how the API functions in great detail.

 

Warm Regards,

tannerite

Tannerite
National Instruments
0 Kudos
Message 19 of 42
(1,498 Views)

Using the FIFO streaming on the sensor I am able to get the 8452 SPI streaming to work.  However, I was hoping to just poll the accelerometer value at a specific time.  The FIFO streaming on this sensor has 32 entries to fill.  The timing will be consistent (which is one thing I need) as the FIFO buffer is filled by the accelerometer and its own internal clock.  I guess I will have to increase the complexity of my consumer loop to handle 32 entries and poll when all 32 entries are full.

 

I tried polling just a single entry (set of 6 bytes by changing the number of bytes to read on the SPI Stream Read.vi) and I am only able to get one set of 32 readings from the FIFO buffer of the sensor.  Reading all 32 entries in the FIFO does show data that is consistent with the accelerometer position...just the timing is slowed down tremendously.  Would this have something to do with my setting of 56 bits working with the wait until next ms.vi located in the while loop in a way I am not expecting?

0 Kudos
Message 20 of 42
(1,492 Views)