LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB-8452 data streaming from MEMS sensor

Hi,

 

I tried to read out the accelerating values (x-,y-, z-axis) from the FIFO register of the LSM6DSL with SPI scripting. I am able to read out the values ... but not continuously. I lose data..

I think the best solution is to use the SPI streaming. But I couldn't find a good example how to do this.

 

The approach to read out the FIFO should be:

- configure the sensor (write the necessary values to the registers)

Then in a while loop (countinuously):

- read out the number of unread words stored in FIFO (register: 0x3A & 0x3B)

- read out the entire FIFO (0x3E)

 

Can someone help me with the SPI streaming of the NI USB-8452?

 

Thank You in advance!

 

Best

Michael

0 Kudos
Message 1 of 12
(3,582 Views)

Unfortunately, 8452 cannot do continuous streaming, it can execute multiple scripts but there will be a non-deterministic delay (induced by the automation like LabVIEW, Python etc.,) between each script execution, you can try to include all the streaming into a single script but it will be limited in duration.

 

8452 is not a full-fledged instrument to support streaming, unlike other DAQ instruments, HSDIO, Digital Pattern instruments. My understanding is that 8452 was meant to be used for register peek-poke and not a continuous stream for signal capture (you could do but limited in feature).

 

In your described approach, based on loop duration, DUT FIFO may be overflowing and already lost some data before the next read, either slow down the sampling rate of the sensor so that you are confident that FIFO does not fill up before your next read or get a high-speed instrument to stream the data.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 2 of 12
(3,580 Views)

I understand that the SPI scripting is not for continuous streaming. 

My problem with the scpriting is that I need at least two scripts (one for read out the unread words in the FIFO and one to read out the FIFO). I need to run the first script and extract the data (unread words in the FIFO). With this value I run the second script and extract the accelerating values. The problem could be that I open and close the script reference for each script.

 

But then there is the streaming SPI. On page 384 ("Using the NI-8452x SPI Stream API") there is a short description that says:

"This API is ideal for reading high-speed streaming data from an SPI slave device, such as an analog-to-digital converter (ADC)." (see attached file).

That sounds like it is exactly the right thing for my project.

 

The FIFO buffer of the sensor is 4096 bytes. I think small delays are not a problem, aren't they? That's actually what the FIFO buffer is for. As long as it doesn't overflow everything should be fine.

 

- Michael

0 Kudos
Message 3 of 12
(3,573 Views)

My sincere apologies for overlooking that feature. I learnt something new about 8452 (in fact I have one on hand but never realized that this feature exists).

 

Found these examples for the SPI streaming feature, please give it a try.

santo_13_0-1629990643134.png

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 4 of 12
(3,552 Views)

Never mind!

 

I also found these examples. I just don't know exactly how to use streaming for my sensor. I can't see where I can enter the register address and the number of bytes to be read out? 

With streaming I can enter the address and the number of bytes to be read.

 

- Michael

0 Kudos
Message 5 of 12
(3,539 Views)

I spent some time understanding what the examples were doing and here is my summary,

 

Let us look at ADS833x EVM.vi

  1. This section configures the registers on the DUT for streaming mode, like register to read the data, other configurations required for conversion and this uses the normal SPI communication not the Script or Stream, because it is enough
    santo_13_0-1630025869708.png

     

  2. This section configures the 8452 to start the streaming, here you configure the timing diagram of the SPI signal used in streaming, there are many values because to enable high speed streaming a lot things have to be tweaked, usually you get these numbers from DUT datasheet and cross-referring them with the 845x user manual
    santo_13_1-1630025932685.png

     

  3. To answer your question of telling which register to read - this happens in two places

    1. Inside the normal configure VI, they reset and setup the register to read from
      santo_13_2-1630026097998.png

       

    2. Next is what data to provide to read each sample in streaming mode, in their case 0xD is required to put into read and 0x000 required to read 12bits of data
      santo_13_3-1630026135613.png

       

  4. Next comes the important part, start the streaming and start reading data, here they read in multiples of 512 bytes to match USB packet size and speed up the process
    santo_13_4-1630026218847.png

     

 

Now, having said these, in order to implement for your use case, list down the following,

  1. What registers have to be set up before you start reading from FIFO?
  2. What mode the FIFO has to operate in? there were multiple modes
  3. What registers to read the FIFO data from?
  4. How many bytes to read at a time?
  5. What are the timing values to configure the stream mode - this determines the clock speed for stream mode, keep in mind these are multiples of 10ns since the 8452 runs off 100MHz base clock

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 6 of 12
(3,533 Views)

First of all thank you for your efforts!

 

So I try to adapt the "ADS833x EVM.vi" for my LSM6DSL:

   1. I did the NI-8452 SPI Configuration: 

NI8452SPI_ConfigNI8452SPI_Config

   2. I did the SPI Stream Configuration: here I am not sure what I sould use for "NumBitsPerSample" and for "Wave1.Data"

 

SPI_Stream_ConfigSPI_Stream_Config

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now your questions:

1. I need to set these registers of the LSM6DSL (first I have to go to the bypass mode, to clear the FIFO and then I can go to FIFO mode)

 Register_INITRegister_INIT

 

2. The operating mode is the FIFO mode (or continuouse mode): register 0x0A

Mode_selectionMode_selection

3. The FIFO output registers are 0x3E & 0x3F:

FIFO_output_registerFIFO_output_register

 

4. I want to read all bytes which are stored in the FIFO at this time (for the number of words stored in FIFO the register 0x3A & 0x3B can be use)

 

5. I think I give an answer to this question at the beginning

 

 

- Michael

0 Kudos
Message 7 of 12
(3,515 Views)

Hi Santo,

 

I tried a little more and have now come a few steps further! I can read x-, y- and z-values ​​from the FIFO.

When I run the program, it reads out all the values ​​for me. However, the FIFO runs full and then stops measuring. So it's not working properly yet. But now I can't get any further. Can you look over again?

 

The program can be found in the appendix.The main program is the "LSM6DSL Streaming.vi"

 

streamingstreaming

 

- Michael

0 Kudos
Message 8 of 12
(3,484 Views)

Few questions,

  • Why 56 bits (7 bytes)?
    As per the documentation, each sample is 16 bits (2 bytes), FIFO data contains 4 sets of 3-axis data (6 bytes) which mean 24-byte comprise a single bunch of data (depends on how you configure the FIFO)
    santo_13_0-1630366043181.png

     

  • What is the purpose of these two write operations?
    santo_13_1-1630366159211.png

     

  • To know the number of unread words, you need to read FIFO_STATUS1 (3Ah) [7:0] and FIFO_STATUS2 (3Bh)[2:0] but you seem to read only the 8 bits
    santo_13_2-1630366343083.png

     

  • Could you please explain the purpose (in words like this configures this register to this mode etc.,) of this data written to the registers?
    santo_13_3-1630366483306.png

     

  • This does not make sense to me, for each FIFO read you need to read 0 bytes???
    santo_13_4-1630366552604.png

    My understanding is you need at least 2 bytes, because you have the high and low bytes on a multi-byte read

  • I would read all the available bytes in the FIFO (which you already have in FIFO level in words)
    santo_13_5-1630366711005.png

     

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 9 of 12
(3,460 Views)

Answers to your questions:

I have used numbers in the pictures to give you an overview, so that you know what I am talking about (No. 1 - 4)

FrontpanelFrontpanel

BlockdiagramBlockdiagram

 

- Why 56 bits (7 bytes)?

You can set what should be saved in the FIFO register. I only store the acceleration values ​​in the FIFO (2nd FIFO data set).

That sould be 6 bytes (2 bytes per axis). 6 bytes x 8 bits = 48 bits. And + 6 bits because the first byte is an empty byte (see No. 1) & 2) in the screenshot).

 

- What is the purpose of these two write operations?

Could you please explain the purpose (in words like this configures this register to this mode etc.,) of this data written to the registers?

Register InitRegister Init

The purpose of these two write operations is to initialize the register of the LSM6DSL. The first puts the sensor in bypass mode. The FIFO buffer is emptied in the process. The second brings the sensor into FIFO mode. Only the last three bits of register 0x0A are changed.

0x08: write the accelerometer values in FIFO

0x0A: set the FIFO output data rate to 6,66kHz and the sensor to the bypass-mode or FIFO-mode

0x10: set the accelerometer output data rate to 6,66kHz

0x12: set BDU and IF_INC bit to 1 (recommended in application note of LSM6DSL)

          - BDU: block data update: if set to 1: output registers not updated until MSB and LSB have been read)

          - IF_INC: Register address automatically incremented during a multiple byte access with a serial interface 

5_bdu_ifinc.PNG

- To know the number of unread words, you need to read FIFO_STATUS1 (3Ah) [7:0] and FIFO_STATUS2 (3Bh)[2:0] but you seem to read only the 8 bits.

I read two bytes from address 0x3A. So 0x3A and 0x3B. 

 

- This does not make sense to me, for each FIFO read you need to read 0 bytes???

The number does not have any effect. See No. 3) on the screenshot. I tried out several values. But it doesn't change anything. It just sets a number of dummy/empty bytes.

 

- I would read all the available bytes in the FIFO (which you already have in FIFO level in words)

Yes that is correct. Now I read out all the available bytes which are stored in the FIFO (see No. 4)).

I divide the value by 3 and round this number down. with this I only read entire data sets (X-Y-Z).

 

In the appendix:

- newest version of the labview project (main vi is "LSM6DSL_Streaming.vi")

- application note LSM6DSL

 

- Michael

0 Kudos
Message 10 of 12
(3,444 Views)