RIT (Repetitive Interrupt Timer) Demo.

Dependencies:   mbed RIT FastAnalogIn

Revision:
0:faa449765bcc
Child:
1:508cd706654a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rit_demo.cpp	Fri Mar 11 10:30:32 2011 +0000
@@ -0,0 +1,68 @@
+/* mbed Repetitive Interrupt Timer Library
+ * Copyright (c) 2011 wvd_vegt
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "RIT.h"
+
+//We'll be using the Usb Serial port
+Serial serial(USBTX, USBRX); //tx, rx
+
+DigitalOut rit_led(LED3);
+
+volatile uint32_t rithits = 0;       //timer1 stops when timer1hits==imer1loop
+
+Timer rit_timing;
+
+void RIT_IRQHandler(void) {
+    //Flash Led.
+    rit_led=!rit_led;
+
+    //Count Hits.
+    rithits++;
+}
+
+RIT rit(1000);
+
+int main() {
+    // Set the Baudrate.
+    serial.baud(115200);
+
+    //rit.setup_ms(100);
+
+    rit.append(RIT_IRQHandler);
+
+    rit_timing.start();
+    rit.enable();
+    for (int i=0;i<20;i++) {
+        printf("COUNTER=%d\r\n", LPC_RIT->RICOUNTER);
+        wait(0.2);
+    }
+    rit.disable();
+    rit_timing.stop();
+
+    printf("COMPVAL=%d\r\n", LPC_RIT->RICOMPVAL);
+    printf("COUNTER=%d\r\n", LPC_RIT->RICOUNTER);
+    printf("HITS=%d\r\n", rithits);
+    printf("ELAPSED=%d ms\r\n", rit_timing.read_ms());
+
+    rit.unappend();
+}
\ No newline at end of file