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)

main.cpp

Committer:
mio
Date:
2014-02-11
Revision:
2:b3703b128b14
Parent:
1:2ee96e43619f

File content as of revision 2:b3703b128b14:

// p30 : TRG IN (Interrupt In)
// p13 : TRG OUT (Digital Out)
#include "mbed.h"

Serial pc(USBTX,USBRX) ;
Serial zw(p9,p10) ;
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++ ;
    }
}

char zwrxbuf[1024] = "---------------------------" ;
int zwrxctr = 0;

char sendbuf[] = "************" ;

int main() {
    pc.baud(115200) ;
    zw.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,%s\r\n",edgectr,sendbuf) ;
            } else if (onctr >= 10) {
                TRG_OUT = 0 ;   
            }   else {
                TRG_OUT = 1 ;
            }
        }
        
        if (pc.readable()) {
            if (pc.getc() == '*') {
                edgectr = 0 ;
                for(int i=0;i<sizeof(sendbuf)-1;i++) {
                    sendbuf[i] = '*' ;
                }
                pc.printf("%d,%s\r\n",edgectr,sendbuf) ;
            }
        }
        
        // read zw
        if (zw.readable()) {
            int c = zw.getc() ;
            if (c != 0x0D) {
                zwrxbuf[zwrxctr] = c ;
                zwrxctr = (zwrxctr + 1) & 0xFF ;
                led3 = !led3 ;
            } else {
                // copy
                for(int i=0;i<sizeof(sendbuf)-1;i++) {
                    sendbuf[i] = zwrxbuf[i] ;
                }
                // reset
                zwrxctr = 0 ;
                led2 = !led2 ;
            }
        }
    }
}