/** comparatorin_demo * Simple program to demonstrate the basic functions * of the analog comparator of the FRDM-KL25Z board. * * Used library: * - ComparatorIn //https://developer.mbed.org/users/frankvnk/code/ComparatorIn/ * written by Frank Vannieuwkerke * * Hardware requirements: * - FRDM-KL25 board * - CdS photoresistor pulled up by 10 k * - Connecect the midpoint of the divider to PTE29 * * 10k CdS photoresistor * +3.3V --/\/\/\---+---/\/\/\---- GND * | * PTE29 * */

Dependencies:   ComparatorIn mbed

Fork of 05_comparator_demo by Istvan Cserny

Revision:
0:e5deffde916d
Child:
1:fb35e688f9f4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 05 18:07:02 2013 +0000
@@ -0,0 +1,51 @@
+#include "ComparatorIn.h"
+#include "mbed.h"
+
+DigitalOut myled(LED1); // Blue
+DigitalOut cmpled(LED2); // Green
+DigitalOut cmp_en (PTD5);
+AnalogIn cmp_lvl (PTB0);
+ComparatorIn compi(PTC8, NC); // light sensor comparator input
+
+// Comparator callback function
+void cmp_ISR(unsigned int cmp_ret)
+{
+    printf("\n%02X - Light sensor : %7.5f Volt - ",cmp_ret,cmp_lvl*3.3);
+    if ((cmp_ret & CMP_SCR_CFR_MASK)==CMP_SCR_CFR_MASK)
+    {
+        printf("<INT=Rising edge on HSCMP0>\n");
+    }
+    if ((cmp_ret & CMP_SCR_CFF_MASK)==CMP_SCR_CFF_MASK)
+    {
+        printf("<INT=Falling edge on HSCMP0>\n ");
+    }
+}
+
+
+
+int main()
+{
+    cmp_en = 1;
+
+    compi._callbackISR(&cmp_ISR);               // Set comparator callback to cmp_ISR
+    compi.treshold(0x20);                       // Set copmarator threshold to 1.03V = 20 * 3.3V / 64
+
+    while(1)
+    {
+//        printf("InP : %02X - InM : %02X - DACCR : %02X\n",(CMP0->MUXCR & 0x38)>>3,(CMP0->MUXCR & 0x07),(CMP0->DACCR & 0x3f));
+        printf("Light sensor : %7.5f Volt\n",cmp_lvl*3.3);
+        myled = 1;
+        wait(1);
+        myled = 0;
+        wait(0.2);
+        if (compi.status() == 0x01)
+        {
+            cmpled = 0;
+        }
+        else
+        {
+            cmpled = 1;
+        }
+    }
+}
+