This video shows the result of experiment's to get acquainted with the maths of 3-axis accelerometers.
The formulas were taken from app notes: "Freescale AN-3461" & "Analog Devices AN-1057", from these the formulas for Pitch, Roll, Absolute Angle & Total G's were used.
I used an ADXL345 connected to an ATMega88 using SPI (4-Wire), With ADXL set to 12.5Hz, 2G.
Display is an OLED 0.96" 128 x 64 SSD1308 (similar to SSD1306) using SPI (Bit-Banged).
First portion of video is the ATMega running at 4Mhz second at 1Mhz.
My initial idea was to use Pitch & Roll to rotate a virtual cube but I failed, the problems arised when trying to rotate past the 'equator', 'Roll without any Pitch' or 'Pitch without any Roll' can rotate OK but once there is a mix of the 2, going past the equator becomes a mess.
The video shows just top hemisphere rotation, I found it somewhat difficult to film so the effect is lost somewhat.
I got an idea for a bit of a cheat that may make it look like its working fully, but for now I have the info I need for future projects.
Second portion of video shows the numbers.
Though I only sampled at 12.5 Hz I found I could perform all the maths for Pitch, Roll, Absolute Angle & Total G's in 8.7ms @ 1Mhz. (Useing CORDIC for Atan).
So that leaves plenty of scope to up the sample rate.
As requested here's the code.
This code was used for experimentation and not really of a quality for distribution, anyhow here it is with all its faults.
[ Ссылка ]
I plan to revisit the project at some stage. Then I may get a chance to tidy up the code and make it more sensible.
IXIBA (Craig Webster)
![](https://s2.save4k.ru/pic/Q8tQN6Q5LSY/maxresdefault.jpg)