mbed Datalogger for KOHZU SC-410 4Axis Controller and Micrometer which has RS232C output p30 TRG IN: TRG OUT(Linked to pulse motor Axis CW/CCW PULSE) of SC-410 *needs change opendrain mode, and pull up to +3.3 or +5V* p13 TRG OUT: 50Hz output of TRIGGER to Micrometer p10 Serial RX:Micrometer RS232C output, *CMOS LEVEL,Converter needed* mbed HDK Serial :Coupling Pulse count and RS232C data output

Dependencies:   mbed

mbed Datalogger Helper for KOHZU SC-410 4Axis Controller and Micrometer which has RS232C output.

Pin Assignment

  • p30 TRG IN: TRG OUT(Linked to pulse motor Axis CW/CCW PULSE) of SC-410 *needs change opendrain mode, and pull up to +3.3 or +5V*
  • p13 TRG OUT: 50Hz output of TRIGGER to Micrometer
  • p10 Serial RX:Micrometer RS232C output, *CMOS LEVEL,Converter needed*
  • mbed HDK Serial :Coupling Pulse count and RS232C data output

[SC-410 side]

                              +---vvvv------- VU (mbed +5V)
                              |
----|>o---------SC410TRG------+-------------- p13
                              |
----------------SC410GND------+-------------- GND (mbed GND)

[Micrometer Side]

        OC Driver(or PhotoCoupler)
p30 ----- |>o----- TRGIN (Micrometer)

GND -------------- GND (if needed)

p10 ------o<|----- RS232C TX
        LEVEL
      CONV(232C->CMOS)

Revision:
0:bfb59ebe2f4a
Child:
1:2ee96e43619f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 10 07:47:19 2014 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX) ;
+InterruptIn TRG(p30) ;
+DigitalOut TRG_OUT(p13) ;
+DigitalOut led1(LED1),led2(LED2),led3(LED3),led4(LED4);
+Ticker timer ;
+
+volatile int edgectr = 0;
+volatile int onctr = 0 ;
+volatile int state = 0 ;
+volatile int nowtrg = 0 ;
+
+void timer1ms()
+{
+    if (onctr > 0) {
+        onctr++;
+    }
+}
+
+void trgon()
+{
+    edgectr++ ;
+    if (onctr == 0) {
+        onctr++ ;
+    }
+}
+
+int main() {
+    pc.baud(115200) ;
+    TRG.mode(PullUp) ; 
+  TRG.fall(trgon);
+    timer.attach(timer1ms,0.001) ; // 1ms
+    while(1)
+    {
+        if (onctr > 0) {
+            if (onctr >= 20) {
+                onctr = 0 ;
+                led4 = !led4 ;
+                pc.printf(":%d\r\n",edgectr) ;
+            } else if (onctr >= 10) {
+                TRG_OUT = 0 ;   
+            }   else {
+                TRG_OUT = 1 ;
+            }
+        }
+        
+        if (pc.readable()) {
+            if (pc.getc() == '*') {
+                edgectr = 0 ;
+                pc.printf("+%d\r\n",edgectr) ;
+            }
+        }
+    }
+}