(x) > (max) ? (max) : (x))\r
\r
#define MMA8451_I2C_ADDRESS (0x1d<<1) // acc sensor address\r
-#define TIME_ACCURACY 0.001\r
+#define TIME_ACCURACY 0.0005\r
\r
#define ACC_SNS_DEFAULT 0.01 // default collecting interval in seconds\r
#define MAG_SNS_DEFAULT 0.1\r
// Interruption Declarations\r
//clock1.attach(&clock1_interrupt, TIME_ACCURACY); // maximun accuracy be 0.1s\r
serial.attach(&serialRx_interrupt, Serial::RxIrq); // receive interrupt for serialS\r
- serial.baud(115200);\r
+ //serial.baud(115200);\r
+ serial.baud(230400);\r
magSensor.begin();\r
\r
sdma_setup(UART0, 0);\r
\r
int ticks = 0, tocks = 0;\r
while(1){\r
- ticks = us_ticker_read() * TIME_ACCURACY;\r
+ ticks = (us_ticker_read()*1E-6) / TIME_ACCURACY;\r
if (tocks < ticks) {\r
clock1_interrupt();\r
tocks++;\r
static int a2dCnt;\r
static int ledCnt;\r
\r
- accCnt++;\r
- magCnt++;\r
- lgtCnt++;\r
- tchCnt++;\r
- a2dCnt++;\r
- ledCnt++;\r
-\r
// Write A2D output sine wave\r
a2dOutput.write(sin(a2dCnt * TIME_ACCURACY * (2*PI) * 0.1));\r
\r
// Send data through Serial\r
- if (accEnable && (accCnt<0 || accCnt>=accTmr/TIME_ACCURACY)){\r
+ if (accEnable && accCnt >= (int)(accTmr/TIME_ACCURACY+0.5)){\r
sendAccInfo();\r
accCnt = 0;\r
}\r
- if (magEnable && (magCnt<0 || magCnt>=magTmr/TIME_ACCURACY)){\r
+ if (magEnable && magCnt >= (int)(magTmr/TIME_ACCURACY+0.5)){\r
sendMagInfo();\r
magCnt = 0;\r
}\r
- if (lgtEnable && (lgtCnt<0 || lgtCnt>=lgtTmr/TIME_ACCURACY)){\r
+ if (lgtEnable && lgtCnt >= (int)(lgtTmr/TIME_ACCURACY+0.5)){\r
sendLgtInfo();\r
lgtCnt = 0;\r
}\r
- if (tchEnable && (tchCnt<0 || tchCnt>=tchTmr/TIME_ACCURACY)){\r
+ if (tchEnable && tchCnt >= (int)(tchTmr/TIME_ACCURACY+0.5)){\r
sendTchInfo();\r
tchCnt = 0;\r
}\r
- if (a2dEnable && (a2dCnt<0 || a2dCnt>=a2dTmr/TIME_ACCURACY)){\r
+ if (a2dEnable && a2dCnt >= (int)(a2dTmr/TIME_ACCURACY+0.5)){\r
sendA2dInfo();\r
a2dCnt = 0;\r
}\r
\r
// Toggel LED for debugging\r
- if (ledEnable && (ledCnt<0 || ledCnt>=ledTmr/TIME_ACCURACY)){\r
+ if (ledEnable && ledCnt>=ledTmr/TIME_ACCURACY){\r
led1 = !led1;\r
ledCnt = 0;\r
}\r
\r
+ accCnt++;\r
+ magCnt++;\r
+ lgtCnt++;\r
+ tchCnt++;\r
+ a2dCnt++;\r
+ ledCnt++;\r
+\r
sdma_flush();\r
}\r
\r