X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=yue%2Fmain.cpp;h=218b27a9bbf8e96336ff8667e510d8c93f493063;hb=fc3721b2f7f7acd9dae5340615b434f68b811b28;hp=ce909d4eeff3eb9d95e69f8d6825b7c1f76209ea;hpb=9aac27c40443111e0de8ae11d241678cb9e04334;p=~andy%2Fcsm213a-hw diff --git a/yue/main.cpp b/yue/main.cpp index ce909d4..218b27a 100644 --- a/yue/main.cpp +++ b/yue/main.cpp @@ -15,7 +15,7 @@ (x) > (max) ? (max) : (x)) #define MMA8451_I2C_ADDRESS (0x1d<<1) // acc sensor address -#define TIME_ACCURACY 0.001 +#define TIME_ACCURACY 0.0005 #define ACC_SNS_DEFAULT 0.01 // default collecting interval in seconds #define MAG_SNS_DEFAULT 0.1 @@ -148,7 +148,8 @@ int main(void) { // Interruption Declarations //clock1.attach(&clock1_interrupt, TIME_ACCURACY); // maximun accuracy be 0.1s serial.attach(&serialRx_interrupt, Serial::RxIrq); // receive interrupt for serialS - serial.baud(115200); + //serial.baud(115200); + serial.baud(230400); magSensor.begin(); sdma_setup(UART0, 0); @@ -157,7 +158,7 @@ int main(void) { int ticks = 0, tocks = 0; while(1){ - ticks = us_ticker_read() * TIME_ACCURACY; + ticks = (us_ticker_read()*1E-6) / TIME_ACCURACY; if (tocks < ticks) { clock1_interrupt(); tocks++; @@ -218,44 +219,44 @@ void clock1_interrupt(void){ static int a2dCnt; static int ledCnt; - accCnt++; - magCnt++; - lgtCnt++; - tchCnt++; - a2dCnt++; - ledCnt++; - // Write A2D output sine wave a2dOutput.write(sin(a2dCnt * TIME_ACCURACY * (2*PI) * 0.1)); // Send data through Serial - if (accEnable && (accCnt<0 || accCnt>=accTmr/TIME_ACCURACY)){ + if (accEnable && accCnt >= (int)(accTmr/TIME_ACCURACY+0.5)){ sendAccInfo(); accCnt = 0; } - if (magEnable && (magCnt<0 || magCnt>=magTmr/TIME_ACCURACY)){ + if (magEnable && magCnt >= (int)(magTmr/TIME_ACCURACY+0.5)){ sendMagInfo(); magCnt = 0; } - if (lgtEnable && (lgtCnt<0 || lgtCnt>=lgtTmr/TIME_ACCURACY)){ + if (lgtEnable && lgtCnt >= (int)(lgtTmr/TIME_ACCURACY+0.5)){ sendLgtInfo(); lgtCnt = 0; } - if (tchEnable && (tchCnt<0 || tchCnt>=tchTmr/TIME_ACCURACY)){ + if (tchEnable && tchCnt >= (int)(tchTmr/TIME_ACCURACY+0.5)){ sendTchInfo(); tchCnt = 0; } - if (a2dEnable && (a2dCnt<0 || a2dCnt>=a2dTmr/TIME_ACCURACY)){ + if (a2dEnable && a2dCnt >= (int)(a2dTmr/TIME_ACCURACY+0.5)){ sendA2dInfo(); a2dCnt = 0; } // Toggel LED for debugging - if (ledEnable && (ledCnt<0 || ledCnt>=ledTmr/TIME_ACCURACY)){ + if (ledEnable && ledCnt>=ledTmr/TIME_ACCURACY){ led1 = !led1; ledCnt = 0; } + accCnt++; + magCnt++; + lgtCnt++; + tchCnt++; + a2dCnt++; + ledCnt++; + sdma_flush(); }