afry-south / dragonfly-fcb

ÅF Dragonfly Quadrotor UAV Project
Other
7 stars 3 forks source link

Improve sensor reading using interrupt and DMA #7

Open stenbergd opened 9 years ago

stenbergd commented 9 years ago

Improve the sensor data reading from accelerometer, magnetometer and gyroscope.

By using an interrupt for when sensor data is ready (DRDY pin/INT1/IN2 pins from sensors) and reading it through DMA - much more efficient sensor reading and CPU usage.

Read more: http://letanphuc.net/2014/06/stm32-mpu6050-dma-i2c/

adam-at-epsilon commented 9 years ago

Using the INT1 pin to send an interrupt to CPU now works, but we really want one of the acc or mag interrupts to go through the DRDY pin on the LSM303DLHC.

adam-at-epsilon commented 9 years ago

The pulse width of the INT1 set to DRDY1 using the oscilloscope is 750microseconds.

The actual time to read the accelerometer is 480 microseconds, as measured on GPIO pin & oscilloscope. This is the time it takes for BSP_ACCELERO_GetXYZ to execute, reading only 1 value at a time instead of 6 in one go.

The interval between the flanks of the INT1 and "accelerometer read" pulses is about 25 microseconds. This is the time it takes to send a message to a queue from the ISR, the message to leave the queue.

adam-at-epsilon commented 9 years ago

According to chapter "I2C Operation" in LSM303DLHC" Data Sheet, multiple read/write seem possible though the current STM32Cube code does not appear to take advantage of this.

adam-at-epsilon commented 9 years ago

Interrupts now work for Gyroscope, Accelerometer and Magnetometer.

Still work to do according to previous comment and also with DMA:

It takes about half a millisecond to read the magnetometer and accelerometer respectively.

http://letanphuc.net/2014/06/how-to-use-stm32-dma/

http://letanphuc.net/2014/06/stm32-mpu6050-dma-i2c/

adam-at-epsilon commented 9 years ago

yet another link

http://www.embedds.com/using-direct-memory-access-dma-in-stm23-projects/