![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Production Test Program (PTP) for the LPC4088 Experiment Base Board
Dependencies: EALib I2S LM75B SDFileSystem mbed
TestAcc.cpp@9:eb6086159020, 2014-10-01 (annotated)
- Committer:
- embeddedartists
- Date:
- Wed Oct 01 11:16:38 2014 +0000
- Revision:
- 9:eb6086159020
- Parent:
- 2:2f4b7535ceb3
Updated used libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 2:2f4b7535ceb3 | 1 | /* |
embeddedartists | 2:2f4b7535ceb3 | 2 | * Copyright 2013 Embedded Artists AB |
embeddedartists | 2:2f4b7535ceb3 | 3 | * |
embeddedartists | 2:2f4b7535ceb3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 2:2f4b7535ceb3 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 2:2f4b7535ceb3 | 6 | * You may obtain a copy of the License at |
embeddedartists | 2:2f4b7535ceb3 | 7 | * |
embeddedartists | 2:2f4b7535ceb3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 2:2f4b7535ceb3 | 9 | * |
embeddedartists | 2:2f4b7535ceb3 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 2:2f4b7535ceb3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 2:2f4b7535ceb3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 2:2f4b7535ceb3 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 2:2f4b7535ceb3 | 14 | * limitations under the License. |
embeddedartists | 2:2f4b7535ceb3 | 15 | */ |
embeddedartists | 2:2f4b7535ceb3 | 16 | |
embeddedartists | 2:2f4b7535ceb3 | 17 | /****************************************************************************** |
embeddedartists | 2:2f4b7535ceb3 | 18 | * Includes |
embeddedartists | 2:2f4b7535ceb3 | 19 | *****************************************************************************/ |
embeddedartists | 2:2f4b7535ceb3 | 20 | |
embeddedartists | 2:2f4b7535ceb3 | 21 | #include "mbed.h" |
embeddedartists | 2:2f4b7535ceb3 | 22 | #include "TestAcc.h" |
embeddedartists | 2:2f4b7535ceb3 | 23 | #include "MMA7455.h" |
embeddedartists | 2:2f4b7535ceb3 | 24 | |
embeddedartists | 2:2f4b7535ceb3 | 25 | /****************************************************************************** |
embeddedartists | 2:2f4b7535ceb3 | 26 | * Defines and typedefs |
embeddedartists | 2:2f4b7535ceb3 | 27 | *****************************************************************************/ |
embeddedartists | 2:2f4b7535ceb3 | 28 | |
embeddedartists | 2:2f4b7535ceb3 | 29 | #define ACC_XMIN (1<<0) |
embeddedartists | 2:2f4b7535ceb3 | 30 | #define ACC_XMAX (1<<1) |
embeddedartists | 2:2f4b7535ceb3 | 31 | #define ACC_YMIN (1<<2) |
embeddedartists | 2:2f4b7535ceb3 | 32 | #define ACC_YMAX (1<<3) |
embeddedartists | 2:2f4b7535ceb3 | 33 | #define ACC_ZMIN (1<<4) |
embeddedartists | 2:2f4b7535ceb3 | 34 | #define ACC_ZMAX (1<<5) |
embeddedartists | 2:2f4b7535ceb3 | 35 | |
embeddedartists | 2:2f4b7535ceb3 | 36 | #define ACC_MIN_LIMIT (-50) |
embeddedartists | 2:2f4b7535ceb3 | 37 | #define ACC_MAX_LIMIT ( 50) |
embeddedartists | 2:2f4b7535ceb3 | 38 | |
embeddedartists | 2:2f4b7535ceb3 | 39 | #define ACC_THRESHOLD (2) |
embeddedartists | 2:2f4b7535ceb3 | 40 | |
embeddedartists | 2:2f4b7535ceb3 | 41 | /****************************************************************************** |
embeddedartists | 2:2f4b7535ceb3 | 42 | * Public Functions |
embeddedartists | 2:2f4b7535ceb3 | 43 | *****************************************************************************/ |
embeddedartists | 2:2f4b7535ceb3 | 44 | |
embeddedartists | 2:2f4b7535ceb3 | 45 | /* |
embeddedartists | 2:2f4b7535ceb3 | 46 | Prerequisites: |
embeddedartists | 2:2f4b7535ceb3 | 47 | |
embeddedartists | 2:2f4b7535ceb3 | 48 | - For this test to work jumpers JP8 and JP9 on the LPC4088 Experiment Base Board |
embeddedartists | 2:2f4b7535ceb3 | 49 | must both be in positions 1-2 |
embeddedartists | 2:2f4b7535ceb3 | 50 | */ |
embeddedartists | 2:2f4b7535ceb3 | 51 | |
embeddedartists | 2:2f4b7535ceb3 | 52 | bool TestAcc::runTest() { |
embeddedartists | 2:2f4b7535ceb3 | 53 | MMA7455 sensor(P0_27, P0_28); |
embeddedartists | 2:2f4b7535ceb3 | 54 | |
embeddedartists | 2:2f4b7535ceb3 | 55 | // Initialize the accelerometer |
embeddedartists | 2:2f4b7535ceb3 | 56 | if (!sensor.setMode(MMA7455::ModeMeasurement)) { |
embeddedartists | 2:2f4b7535ceb3 | 57 | printf("Unable to set mode for MMA7455!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 58 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 59 | } |
embeddedartists | 2:2f4b7535ceb3 | 60 | |
embeddedartists | 2:2f4b7535ceb3 | 61 | // Calibrate it. It does not matter if it is on a level surface |
embeddedartists | 2:2f4b7535ceb3 | 62 | // as this test is only interested in relative values. |
embeddedartists | 2:2f4b7535ceb3 | 63 | if (!sensor.calibrate()) { |
embeddedartists | 2:2f4b7535ceb3 | 64 | printf("Failed to calibrate MMA7455!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 65 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 66 | } |
embeddedartists | 2:2f4b7535ceb3 | 67 | |
embeddedartists | 2:2f4b7535ceb3 | 68 | int val[3] = { 0, 0, 0}; |
embeddedartists | 2:2f4b7535ceb3 | 69 | int max[3] = {-1000,-1000,-1000}; |
embeddedartists | 2:2f4b7535ceb3 | 70 | int min[3] = { 1000, 1000, 1000}; |
embeddedartists | 2:2f4b7535ceb3 | 71 | int i; |
embeddedartists | 2:2f4b7535ceb3 | 72 | Timer t; |
embeddedartists | 2:2f4b7535ceb3 | 73 | t.start(); |
embeddedartists | 2:2f4b7535ceb3 | 74 | |
embeddedartists | 2:2f4b7535ceb3 | 75 | // Read the x, y and z values every 100ms for up to five seconds. |
embeddedartists | 2:2f4b7535ceb3 | 76 | // When the accelerometer is working those values will sightly vary |
embeddedartists | 2:2f4b7535ceb3 | 77 | // even if the board is still. When a ACC_THRESHOLD difference has |
embeddedartists | 2:2f4b7535ceb3 | 78 | // been detected in each of the three axis the test is considered |
embeddedartists | 2:2f4b7535ceb3 | 79 | // successful. |
embeddedartists | 2:2f4b7535ceb3 | 80 | while (t.read() < 5) { |
embeddedartists | 2:2f4b7535ceb3 | 81 | if (!sensor.read(val[0], val[1], val[2])) { |
embeddedartists | 2:2f4b7535ceb3 | 82 | printf("Failed to read accelerometer data!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 83 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 84 | } |
embeddedartists | 2:2f4b7535ceb3 | 85 | printf("ACC: x,y,z = {%5d, %5d, %5d}\n", val[0], val[1], val[2]); |
embeddedartists | 2:2f4b7535ceb3 | 86 | for (i = 0; i < 3; i++) { |
embeddedartists | 2:2f4b7535ceb3 | 87 | if (val[i] < min[i]) { |
embeddedartists | 2:2f4b7535ceb3 | 88 | min[i] = val[i]; |
embeddedartists | 2:2f4b7535ceb3 | 89 | } |
embeddedartists | 2:2f4b7535ceb3 | 90 | if (val[i] > max[i]) { |
embeddedartists | 2:2f4b7535ceb3 | 91 | max[i] = val[i]; |
embeddedartists | 2:2f4b7535ceb3 | 92 | } |
embeddedartists | 2:2f4b7535ceb3 | 93 | } |
embeddedartists | 2:2f4b7535ceb3 | 94 | for (i = 0; i < 3; i++) { |
embeddedartists | 2:2f4b7535ceb3 | 95 | if ((max[i] - min[i]) < ACC_THRESHOLD) { |
embeddedartists | 2:2f4b7535ceb3 | 96 | break; |
embeddedartists | 2:2f4b7535ceb3 | 97 | } |
embeddedartists | 2:2f4b7535ceb3 | 98 | if (i == 2) { |
embeddedartists | 2:2f4b7535ceb3 | 99 | printf("All three axis work\n"); |
embeddedartists | 2:2f4b7535ceb3 | 100 | return true; |
embeddedartists | 2:2f4b7535ceb3 | 101 | } |
embeddedartists | 2:2f4b7535ceb3 | 102 | } |
embeddedartists | 2:2f4b7535ceb3 | 103 | wait(0.1); |
embeddedartists | 2:2f4b7535ceb3 | 104 | } |
embeddedartists | 2:2f4b7535ceb3 | 105 | printf("Accelerometer data invalid\n"); |
embeddedartists | 2:2f4b7535ceb3 | 106 | printf("Not enough variation X {%d..%d}, Y {%d..%d}, Z {%d..%d}!\n", |
embeddedartists | 2:2f4b7535ceb3 | 107 | min[0], max[0], min[1], max[1], min[2], max[2]); |
embeddedartists | 2:2f4b7535ceb3 | 108 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 109 | } |
embeddedartists | 2:2f4b7535ceb3 | 110 | |
embeddedartists | 2:2f4b7535ceb3 | 111 | bool TestAcc::alternativeTest() { |
embeddedartists | 2:2f4b7535ceb3 | 112 | MMA7455 sensor(P0_27, P0_28); |
embeddedartists | 2:2f4b7535ceb3 | 113 | |
embeddedartists | 2:2f4b7535ceb3 | 114 | // Initialize the accelerometer |
embeddedartists | 2:2f4b7535ceb3 | 115 | if (!sensor.setMode(MMA7455::ModeMeasurement)) { |
embeddedartists | 2:2f4b7535ceb3 | 116 | printf("Unable to set mode for MMA7455!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 117 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 118 | } |
embeddedartists | 2:2f4b7535ceb3 | 119 | |
embeddedartists | 2:2f4b7535ceb3 | 120 | // Calibrate it. The board must be on a flat surface |
embeddedartists | 2:2f4b7535ceb3 | 121 | // during calibration! |
embeddedartists | 2:2f4b7535ceb3 | 122 | if (!sensor.calibrate()) { |
embeddedartists | 2:2f4b7535ceb3 | 123 | printf("Failed to calibrate MMA7455!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 124 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 125 | } |
embeddedartists | 2:2f4b7535ceb3 | 126 | |
embeddedartists | 2:2f4b7535ceb3 | 127 | printf("Now tilt the board in all directions (max 10 seconds)...\n"); |
embeddedartists | 2:2f4b7535ceb3 | 128 | int x=0, y=0, z=0; |
embeddedartists | 2:2f4b7535ceb3 | 129 | uint8_t done = 0; |
embeddedartists | 2:2f4b7535ceb3 | 130 | char msg[30] = {0}; |
embeddedartists | 2:2f4b7535ceb3 | 131 | |
embeddedartists | 2:2f4b7535ceb3 | 132 | Timer t; |
embeddedartists | 2:2f4b7535ceb3 | 133 | t.start(); |
embeddedartists | 2:2f4b7535ceb3 | 134 | |
embeddedartists | 2:2f4b7535ceb3 | 135 | // Read the x, y and z values every 100ms for up to ten seconds. |
embeddedartists | 2:2f4b7535ceb3 | 136 | // Lift and tilt the board along all axis and look at the printed |
embeddedartists | 2:2f4b7535ceb3 | 137 | // output. There are ACC_MIN_LIMIT and ACC_MAX_LIMIT limits and |
embeddedartists | 2:2f4b7535ceb3 | 138 | // as the value of an axis passes that limit it is printed and |
embeddedartists | 2:2f4b7535ceb3 | 139 | // if all six limits (min/max for x,y and z) are passed within the |
embeddedartists | 2:2f4b7535ceb3 | 140 | // time limit the test is considered successful. |
embeddedartists | 2:2f4b7535ceb3 | 141 | while ((t.read() < 10) && (done != 0x3f)) { |
embeddedartists | 2:2f4b7535ceb3 | 142 | if (!sensor.read(x, y, z)) { |
embeddedartists | 2:2f4b7535ceb3 | 143 | printf("Failed to read accelerometer data!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 144 | return false; |
embeddedartists | 2:2f4b7535ceb3 | 145 | } |
embeddedartists | 2:2f4b7535ceb3 | 146 | printf("ACC: x,y,z = {%5d, %5d, %5d} %s\n", x, y, z, msg); |
embeddedartists | 2:2f4b7535ceb3 | 147 | if ((x < ACC_MIN_LIMIT) && !(done & ACC_XMIN)) { |
embeddedartists | 2:2f4b7535ceb3 | 148 | done |= ACC_XMIN; |
embeddedartists | 2:2f4b7535ceb3 | 149 | printf("Tilted XMIN\n"); |
embeddedartists | 2:2f4b7535ceb3 | 150 | } else if ((x > ACC_MAX_LIMIT) && !(done & ACC_XMAX)) { |
embeddedartists | 2:2f4b7535ceb3 | 151 | done |= ACC_XMAX; |
embeddedartists | 2:2f4b7535ceb3 | 152 | printf("Tilted XMAX\n"); |
embeddedartists | 2:2f4b7535ceb3 | 153 | } |
embeddedartists | 2:2f4b7535ceb3 | 154 | if ((y < ACC_MIN_LIMIT) && !(done & ACC_YMIN)) { |
embeddedartists | 2:2f4b7535ceb3 | 155 | done |= ACC_YMIN; |
embeddedartists | 2:2f4b7535ceb3 | 156 | printf("Tilted YMIN\n"); |
embeddedartists | 2:2f4b7535ceb3 | 157 | } else if ((y > ACC_MAX_LIMIT) && !(done & ACC_YMAX)) { |
embeddedartists | 2:2f4b7535ceb3 | 158 | done |= ACC_YMAX; |
embeddedartists | 2:2f4b7535ceb3 | 159 | printf("Tilted XMAX\n"); |
embeddedartists | 2:2f4b7535ceb3 | 160 | } |
embeddedartists | 2:2f4b7535ceb3 | 161 | if ((z < ACC_MIN_LIMIT) && !(done & ACC_ZMIN)) { |
embeddedartists | 2:2f4b7535ceb3 | 162 | done |= ACC_ZMIN; |
embeddedartists | 2:2f4b7535ceb3 | 163 | printf("Tilted ZMIN\n"); |
embeddedartists | 2:2f4b7535ceb3 | 164 | } else if ((z > ACC_MAX_LIMIT) && !(done & ACC_ZMAX)) { |
embeddedartists | 2:2f4b7535ceb3 | 165 | done |= ACC_ZMAX; |
embeddedartists | 2:2f4b7535ceb3 | 166 | printf("Tilted ZMAX\n"); |
embeddedartists | 2:2f4b7535ceb3 | 167 | } |
embeddedartists | 2:2f4b7535ceb3 | 168 | wait(0.1); |
embeddedartists | 2:2f4b7535ceb3 | 169 | } |
embeddedartists | 2:2f4b7535ceb3 | 170 | printf("Done with ACC tests!\n"); |
embeddedartists | 2:2f4b7535ceb3 | 171 | return (t.read() < 10); |
embeddedartists | 2:2f4b7535ceb3 | 172 | } |
embeddedartists | 2:2f4b7535ceb3 | 173 |