Vibration measurement in a wind turbine gearbox
Fork of ADXL345 by
Revision 1:d9496621bfb5, committed 2015-04-20
- Comitter:
- s1365797
- Date:
- Mon Apr 20 17:22:04 2015 +0000
- Parent:
- 0:745335502422
- Commit message:
- ADXL345
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 745335502422 -r d9496621bfb5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 20 17:22:04 2015 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" +#include "ADXL345.h" + +ADXL345 accelerometer(p5, p6, p7, p8); // MOSI, MISO, SCK, CS_bar +Serial pc(USBTX, USBRX); +// 11-bit extented values; 50 readings stored in an array. + int data[50][3]; + int reading = 0; +int main() { + + int readings[3] = {0, 0, 0}; + + pc.printf("\nStarting ADXL345 test...\n"); + pc.printf("Device ID is: 0x%02x\n\r", accelerometer.getDevId()); + //Go into standby mode to configure the device. + accelerometer.setPowerControl(0x00); + + //Full resolution, +/-4g, 4mg/LSB. + accelerometer.setDataFormatControl(0x09); + + //3.2kHz data rate. + accelerometer.setDataRate(ADXL345_3200HZ); + + //Measurement mode. + accelerometer.setPowerControl(0x08); + + // Create timers + Timer Write_time; + Write_time.start(); + + //Fill the data with values. + for (int i=0; i<50; i++){ + // Create timers for counting sampling time, and hence sampling rate. +// Timer Sample_time; +// Sample_time.start(); + accelerometer.getOutput(readings); +// Sample_time.stop(); +// pc.printf("\nTime taken to take one sample= %f seconds\n\r",Sample_time.read()); + + for (int j=0; j<3; j++){ + data[i][j] = readings[j]; + } + } + + Write_time.stop(); + + pc.printf("\nTime taken to write array= %f seconds\n\r",Write_time.read()); + + // Create timers + Timer Read_time; + Read_time.start(); +// Write to PC +for (int i=0; i<50; i++){ + reading++; + //11-bit, sign extended values. + pc.printf("\nAx=%i, Ay=%i, Az=%i\n", (int16_t)data[i][0], (int16_t)data[i][1], (int16_t)data[i][2]); + pc.printf ("reading %d\n\r", reading); + } + Read_time.stop(); + pc.printf("\nTime taken to read array= %f seconds\n\r",Read_time.read()); + +} +
diff -r 745335502422 -r d9496621bfb5 mbed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Mon Apr 20 17:22:04 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/gokmenascioglu/code/mbed/#a8fa94490a0a