A project similar to http://mbed.org/users/lhiggs/code/UM6_IMU_AHRS_2012/, where I'm trying to log data from a UM6 (CH Robotics orientation sensor) and a GPS transceiver to an sd card. I've adapted LHiggs code to include ModGPS. For sum reason a soon as I pick up a gps signal the UM6 data freezes i.e. the time and gps signals continue to print out but the UM6 signals fixes on a single value.
Dependencies: MODGPS MODSERIAL SDFileSystem mbed
Diff: main.cpp
- Revision:
- 1:9fe40d9ac0f5
- Parent:
- 0:52295643d083
- Child:
- 2:4a6e89c2d82a
--- a/main.cpp Thu May 23 13:29:26 2013 +0000 +++ b/main.cpp Thu May 23 14:08:06 2013 +0000 @@ -1,18 +1,38 @@ #include "mbed.h" +//------------ system and interface setup ----------------------------// LocalFileSystem local("local"); // sets up local file on mbed Serial pc(USBTX, USBRX); // sets up serial connection to pc terminal +//------------ Hardware setup ----------------------------------------// DigitalOut myled(LED1); // debug LED DigitalIn enable(p10); // enable signal for logging data to file +//------------ interrupt and variable setup --------------------------// +Ticker tick; +int counter=0; +int flag=0; + +//------------ LogData interrupt function ----------------------------// +void LogData() { + counter++; + flag=1; +} + +//============= Main Program =========================================// int main() { - while(1) { - if(enable==1) { - myled=1; - wait(0.2); - myled=0; - wait(0.2); - } - } -} + pc.baud(115200); // baud rate to pc interface + tick.attach(&LogData, 0.001); // attaches LogData function to 'tick' ticker interrupt every 0.5s + + while(1) { + while(enable) { + if(flag==1) { // prints counter value every interrupt raises flag + myled=1; + pc.printf("%2d \n",counter); + flag=0; + } // end if(flag=1) loop + } // end while(enable) loop + myled=0; // turns off LED when enable switch off + counter=0; // resets counter + } // end while(1) loop +} // end main() loop