08-26-2021 08:19 AM
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
08-26-2021 08:31 AM
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.
08-26-2021 08:54 AM
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
08-26-2021 10:10 AM
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.
08-26-2021 03:38 PM
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
08-26-2021 08:06 PM
I spent some time understanding what the examples were doing and here is my summary,
Let us look at ADS833x EVM.vi
Now, having said these, in order to implement for your use case, list down the following,
08-27-2021 05:02 AM - edited 08-27-2021 05:05 AM
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_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_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_INIT
2. The operating mode is the FIFO mode (or continuouse mode): register 0x0A
Mode_selection
3. The FIFO output registers are 0x3E & 0x3F:
FIFO_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
08-29-2021 06:01 PM - edited 08-29-2021 06:01 PM
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"
streaming
- Michael
08-30-2021 06:39 PM
Few questions,
My understanding is you need at least 2 bytes, because you have the high and low bytes on a multi-byte read
09-01-2021 04:41 AM - edited 09-01-2021 04:48 AM
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)
Frontpanel
Blockdiagram
- 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 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
- 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