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)

Committer:
mio
Date:
Tue Feb 11 23:35:01 2014 +0000
Revision:
2:b3703b128b14
Parent:
1:2ee96e43619f
publish version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mio 2:b3703b128b14 1 // p30 : TRG IN (Interrupt In)
mio 2:b3703b128b14 2 // p13 : TRG OUT (Digital Out)
mio 0:bfb59ebe2f4a 3 #include "mbed.h"
mio 0:bfb59ebe2f4a 4
mio 0:bfb59ebe2f4a 5 Serial pc(USBTX,USBRX) ;
mio 1:2ee96e43619f 6 Serial zw(p9,p10) ;
mio 0:bfb59ebe2f4a 7 InterruptIn TRG(p30) ;
mio 0:bfb59ebe2f4a 8 DigitalOut TRG_OUT(p13) ;
mio 0:bfb59ebe2f4a 9 DigitalOut led1(LED1),led2(LED2),led3(LED3),led4(LED4);
mio 0:bfb59ebe2f4a 10 Ticker timer ;
mio 0:bfb59ebe2f4a 11
mio 0:bfb59ebe2f4a 12 volatile int edgectr = 0;
mio 0:bfb59ebe2f4a 13 volatile int onctr = 0 ;
mio 0:bfb59ebe2f4a 14 volatile int state = 0 ;
mio 0:bfb59ebe2f4a 15 volatile int nowtrg = 0 ;
mio 0:bfb59ebe2f4a 16
mio 0:bfb59ebe2f4a 17 void timer1ms()
mio 0:bfb59ebe2f4a 18 {
mio 0:bfb59ebe2f4a 19 if (onctr > 0) {
mio 0:bfb59ebe2f4a 20 onctr++;
mio 0:bfb59ebe2f4a 21 }
mio 0:bfb59ebe2f4a 22 }
mio 0:bfb59ebe2f4a 23
mio 0:bfb59ebe2f4a 24 void trgon()
mio 0:bfb59ebe2f4a 25 {
mio 0:bfb59ebe2f4a 26 edgectr++ ;
mio 0:bfb59ebe2f4a 27 if (onctr == 0) {
mio 0:bfb59ebe2f4a 28 onctr++ ;
mio 0:bfb59ebe2f4a 29 }
mio 0:bfb59ebe2f4a 30 }
mio 0:bfb59ebe2f4a 31
mio 1:2ee96e43619f 32 char zwrxbuf[1024] = "---------------------------" ;
mio 1:2ee96e43619f 33 int zwrxctr = 0;
mio 1:2ee96e43619f 34
mio 1:2ee96e43619f 35 char sendbuf[] = "************" ;
mio 1:2ee96e43619f 36
mio 0:bfb59ebe2f4a 37 int main() {
mio 0:bfb59ebe2f4a 38 pc.baud(115200) ;
mio 1:2ee96e43619f 39 zw.baud(115200) ;
mio 0:bfb59ebe2f4a 40 TRG.mode(PullUp) ;
mio 0:bfb59ebe2f4a 41 TRG.fall(trgon);
mio 0:bfb59ebe2f4a 42 timer.attach(timer1ms,0.001) ; // 1ms
mio 0:bfb59ebe2f4a 43 while(1)
mio 0:bfb59ebe2f4a 44 {
mio 0:bfb59ebe2f4a 45 if (onctr > 0) {
mio 0:bfb59ebe2f4a 46 if (onctr >= 20) {
mio 0:bfb59ebe2f4a 47 onctr = 0 ;
mio 0:bfb59ebe2f4a 48 led4 = !led4 ;
mio 1:2ee96e43619f 49 pc.printf("%d,%s\r\n",edgectr,sendbuf) ;
mio 0:bfb59ebe2f4a 50 } else if (onctr >= 10) {
mio 0:bfb59ebe2f4a 51 TRG_OUT = 0 ;
mio 0:bfb59ebe2f4a 52 } else {
mio 0:bfb59ebe2f4a 53 TRG_OUT = 1 ;
mio 0:bfb59ebe2f4a 54 }
mio 0:bfb59ebe2f4a 55 }
mio 0:bfb59ebe2f4a 56
mio 0:bfb59ebe2f4a 57 if (pc.readable()) {
mio 0:bfb59ebe2f4a 58 if (pc.getc() == '*') {
mio 0:bfb59ebe2f4a 59 edgectr = 0 ;
mio 1:2ee96e43619f 60 for(int i=0;i<sizeof(sendbuf)-1;i++) {
mio 1:2ee96e43619f 61 sendbuf[i] = '*' ;
mio 1:2ee96e43619f 62 }
mio 1:2ee96e43619f 63 pc.printf("%d,%s\r\n",edgectr,sendbuf) ;
mio 1:2ee96e43619f 64 }
mio 1:2ee96e43619f 65 }
mio 1:2ee96e43619f 66
mio 1:2ee96e43619f 67 // read zw
mio 1:2ee96e43619f 68 if (zw.readable()) {
mio 1:2ee96e43619f 69 int c = zw.getc() ;
mio 1:2ee96e43619f 70 if (c != 0x0D) {
mio 1:2ee96e43619f 71 zwrxbuf[zwrxctr] = c ;
mio 1:2ee96e43619f 72 zwrxctr = (zwrxctr + 1) & 0xFF ;
mio 1:2ee96e43619f 73 led3 = !led3 ;
mio 1:2ee96e43619f 74 } else {
mio 1:2ee96e43619f 75 // copy
mio 1:2ee96e43619f 76 for(int i=0;i<sizeof(sendbuf)-1;i++) {
mio 1:2ee96e43619f 77 sendbuf[i] = zwrxbuf[i] ;
mio 1:2ee96e43619f 78 }
mio 1:2ee96e43619f 79 // reset
mio 1:2ee96e43619f 80 zwrxctr = 0 ;
mio 1:2ee96e43619f 81 led2 = !led2 ;
mio 0:bfb59ebe2f4a 82 }
mio 0:bfb59ebe2f4a 83 }
mio 0:bfb59ebe2f4a 84 }
mio 0:bfb59ebe2f4a 85 }