cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling frequency issue

LuizF_Ferro
Associate III

Hello,

I am using an STM32U585CIU6 with LSM6DSOX to sample acceleration values, in order to use it in a project on NanoEdge.

 

I am facing an issue while trying to sample higher frequencies. My accelerometer is set to operate at 833Hz. By printing the number of measurements taken by LSM on Serial interface, I could  manually get the real sampling frequency, which was about 333Hz.

 

My baudrate is set to 230400 bits/s, and my LSM6DSOX communicates via I2C, which was set to Standard Mode (100KHz). By switching I2C to Fast Mode or Fast Mode Plus, I could measure a new sampling frequency near 500Hz, meaning there is something still limiting the communication speed. I couldn't adjust the baud rate to a higher value because the ioc configuration would automatically adjust it back to 230400, as if that's the limit for some reason.

 

I'm lastly suspicious of the clock configuration in my project, which are all set at 4MHz (for Cortex System timer, peripherals, and everything else). However, I'm not really sure about which clock frequency I should change among the different options, as I tried to solve a similar problem in the past, but didn't manage to do it back then.

 

My goal is simply to find out where is the bottleneck, and address this issue so I can use the accelerometer at higher frequencies.

 

Sincerely,

L.F.

3 REPLIES 3
KnarfB
Principal III

 I couldn't adjust the baud rate to a higher value because the ioc configuration would automatically adjust it back to 230400, as if that's the limit for some reason.

The reason is the low clock rate of 4 MHz which seems to be the default setting in STM32CubeMX. Increae that clock to allow higher baud rates.

Also, make some calculations of how many bit/s your design is transmitting on the I²C and UART serial busses as a function of the sample rate to find the bottlenecks.

 

hth

KnarfB

LuizF_Ferro
Associate III

Hello,

Thanks for your reply. I managed to get a 833Hz sampling rate by adjusting the Cortex System timer to 8MHz. Furthermore, I started switching my I2C, UART and System Clock to find out which setup is enough to sample data at 6667Hz, the maximum value possible for LSM6DSOX.

I am noticing still a bottleneck even with the "best" configuration possible, which is:

I2C at Fast Mode Plus (1Mbit/s), 921600 baud rate, 160MHz clock rate

I'm printing the counter of samples on serial each 1000 measures to avoid excessive writing. Nevertheless, I still get a sampling frequency nearby 4200Hz.

Some calculations I did:

- A single accelerometer sample has 16 bits resolution per data, and captures 3 axis. Hence, at 6667Hz, the rate of bits/s is (16 x 3) x 6667 = 320.016 bits/s

- I2C at 1Mbps should be more than enough

- UART at 921600 baud rate. Assuming 8 bits + 1 start + 1 stop, and no parity bit, the transmission rate would be 92160 bytes/s or 737280 bits/s, which should also be enough

With this setup, I don't know what could be causing the bottleneck in this situation. Would you have any idea?

 

Sincerely,

L.F.

How do you write on UART? printf is slow. HAL API? Are you using DMA? For finding the bottleneck, you may decompose your project and send dummy data via UART without using the sensor and/or use I2C only. A cheap logic 8-channel analyzer (~$10) may be useful for watching the data on the wires.

hth

KnarfB