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
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@0:bfb59ebe2f4a, 2014-02-10 (annotated)
- Committer:
- mio
- Date:
- Mon Feb 10 07:47:19 2014 +0000
- Revision:
- 0:bfb59ebe2f4a
- Child:
- 1:2ee96e43619f
version1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mio | 0:bfb59ebe2f4a | 1 | #include "mbed.h" |
mio | 0:bfb59ebe2f4a | 2 | |
mio | 0:bfb59ebe2f4a | 3 | Serial pc(USBTX,USBRX) ; |
mio | 0:bfb59ebe2f4a | 4 | InterruptIn TRG(p30) ; |
mio | 0:bfb59ebe2f4a | 5 | DigitalOut TRG_OUT(p13) ; |
mio | 0:bfb59ebe2f4a | 6 | DigitalOut led1(LED1),led2(LED2),led3(LED3),led4(LED4); |
mio | 0:bfb59ebe2f4a | 7 | Ticker timer ; |
mio | 0:bfb59ebe2f4a | 8 | |
mio | 0:bfb59ebe2f4a | 9 | volatile int edgectr = 0; |
mio | 0:bfb59ebe2f4a | 10 | volatile int onctr = 0 ; |
mio | 0:bfb59ebe2f4a | 11 | volatile int state = 0 ; |
mio | 0:bfb59ebe2f4a | 12 | volatile int nowtrg = 0 ; |
mio | 0:bfb59ebe2f4a | 13 | |
mio | 0:bfb59ebe2f4a | 14 | void timer1ms() |
mio | 0:bfb59ebe2f4a | 15 | { |
mio | 0:bfb59ebe2f4a | 16 | if (onctr > 0) { |
mio | 0:bfb59ebe2f4a | 17 | onctr++; |
mio | 0:bfb59ebe2f4a | 18 | } |
mio | 0:bfb59ebe2f4a | 19 | } |
mio | 0:bfb59ebe2f4a | 20 | |
mio | 0:bfb59ebe2f4a | 21 | void trgon() |
mio | 0:bfb59ebe2f4a | 22 | { |
mio | 0:bfb59ebe2f4a | 23 | edgectr++ ; |
mio | 0:bfb59ebe2f4a | 24 | if (onctr == 0) { |
mio | 0:bfb59ebe2f4a | 25 | onctr++ ; |
mio | 0:bfb59ebe2f4a | 26 | } |
mio | 0:bfb59ebe2f4a | 27 | } |
mio | 0:bfb59ebe2f4a | 28 | |
mio | 0:bfb59ebe2f4a | 29 | int main() { |
mio | 0:bfb59ebe2f4a | 30 | pc.baud(115200) ; |
mio | 0:bfb59ebe2f4a | 31 | TRG.mode(PullUp) ; |
mio | 0:bfb59ebe2f4a | 32 | TRG.fall(trgon); |
mio | 0:bfb59ebe2f4a | 33 | timer.attach(timer1ms,0.001) ; // 1ms |
mio | 0:bfb59ebe2f4a | 34 | while(1) |
mio | 0:bfb59ebe2f4a | 35 | { |
mio | 0:bfb59ebe2f4a | 36 | if (onctr > 0) { |
mio | 0:bfb59ebe2f4a | 37 | if (onctr >= 20) { |
mio | 0:bfb59ebe2f4a | 38 | onctr = 0 ; |
mio | 0:bfb59ebe2f4a | 39 | led4 = !led4 ; |
mio | 0:bfb59ebe2f4a | 40 | pc.printf(":%d\r\n",edgectr) ; |
mio | 0:bfb59ebe2f4a | 41 | } else if (onctr >= 10) { |
mio | 0:bfb59ebe2f4a | 42 | TRG_OUT = 0 ; |
mio | 0:bfb59ebe2f4a | 43 | } else { |
mio | 0:bfb59ebe2f4a | 44 | TRG_OUT = 1 ; |
mio | 0:bfb59ebe2f4a | 45 | } |
mio | 0:bfb59ebe2f4a | 46 | } |
mio | 0:bfb59ebe2f4a | 47 | |
mio | 0:bfb59ebe2f4a | 48 | if (pc.readable()) { |
mio | 0:bfb59ebe2f4a | 49 | if (pc.getc() == '*') { |
mio | 0:bfb59ebe2f4a | 50 | edgectr = 0 ; |
mio | 0:bfb59ebe2f4a | 51 | pc.printf("+%d\r\n",edgectr) ; |
mio | 0:bfb59ebe2f4a | 52 | } |
mio | 0:bfb59ebe2f4a | 53 | } |
mio | 0:bfb59ebe2f4a | 54 | } |
mio | 0:bfb59ebe2f4a | 55 | } |