Code to drive a CNC machine via a PC LPT port lookalike 25 pin 'D', experiment in 'PC/Mach3' replacement. Designed to compile and run on mbed LPC1768, Freescale KL25Z and Freescale KL46Z. Proved on LPC1768 and KL25Z, problem with serial port on KL46Z. Reads subset of 'G Codes' through usb/serial port and drives 3 stepper/servo drives for X, Y and Z, also similar Step/Dir outputs for spindle motor control. Emulates PC LPT, outputs 'charge pump', proved driving Seig KX3 CNC mill

Dependencies:   MODSERIAL mbed

Committer:
JonFreeman
Date:
Fri Jan 31 11:16:21 2014 +0000
Revision:
0:5d0f270bfc87
Child:
1:66ee619f206b
First wip, tested on KL25 and KL46

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 0:5d0f270bfc87 1 #include "mbed.h"
JonFreeman 0:5d0f270bfc87 2 #include "cnc.h"
JonFreeman 0:5d0f270bfc87 3 using namespace std;
JonFreeman 0:5d0f270bfc87 4 extern void lissajous (void) ;
JonFreeman 0:5d0f270bfc87 5 extern void command_line_interpreter (void) ;
JonFreeman 0:5d0f270bfc87 6 extern void init_last_position () ;
JonFreeman 0:5d0f270bfc87 7 extern char * readout (char * txt, int p) ; // p has running subtotal of all pulses issued to stepper driver
JonFreeman 0:5d0f270bfc87 8
JonFreeman 0:5d0f270bfc87 9 Serial pc(USBTX, USBRX); // tx, rx to pc
JonFreeman 0:5d0f270bfc87 10 const int BAUD = 9600;
JonFreeman 0:5d0f270bfc87 11 Ticker NCO_gen; // Ticker generating interrupts at NCO updating frequency
JonFreeman 0:5d0f270bfc87 12 struct axis_speeds_element axis_speeds[axis_speeds_buffsize + 1]; // buffer space for list of future moves
JonFreeman 0:5d0f270bfc87 13 struct digital_readouts dro; //some signed int
JonFreeman 0:5d0f270bfc87 14
JonFreeman 0:5d0f270bfc87 15 bool running = false;
JonFreeman 0:5d0f270bfc87 16 volatile unsigned long ticks = 0L;
JonFreeman 0:5d0f270bfc87 17 unsigned long
JonFreeman 0:5d0f270bfc87 18 pir_a = 0L,
JonFreeman 0:5d0f270bfc87 19 pir_x = 0L,
JonFreeman 0:5d0f270bfc87 20 pir_y = 0L,
JonFreeman 0:5d0f270bfc87 21 pir_z = 0L,
JonFreeman 0:5d0f270bfc87 22 pir_s = 0L, // Referenced only in command_interpreter as spindle speed setting
JonFreeman 0:5d0f270bfc87 23 tickrun = 0L;
JonFreeman 0:5d0f270bfc87 24
JonFreeman 0:5d0f270bfc87 25 int spindlefwdrev = 0; // Takes values of 0 or 4 only
JonFreeman 0:5d0f270bfc87 26
JonFreeman 0:5d0f270bfc87 27 #if defined (TARGET_KL25Z)
JonFreeman 0:5d0f270bfc87 28 DigitalOut intled(PTE1); //J2p20
JonFreeman 0:5d0f270bfc87 29 //SPISlave spidevice(PTD3, PTD2, PTD1, PTD0); // mosi, miso, sclk THIS TURNS LED ON BLUE ! (uses p11, p12, p13 on mbed LPC)
JonFreeman 0:5d0f270bfc87 30 SPISlave spidevice(PTD2, PTD3, PTD1, PTD0); // mosi, miso, sclk THIS TURNS LED ON BLUE ! (uses p11, p12, p13 on mbed LPC)
JonFreeman 0:5d0f270bfc87 31 // J2p08,J2p10,J2p12, J2p06
JonFreeman 0:5d0f270bfc87 32 //SPI spidevice(PTD2, PTD3, PTD1); // mosi, miso, sclk THIS TURNS LED ON BLUE ! (uses p11, p12, p13 on mbed LPC)
JonFreeman 0:5d0f270bfc87 33 //SPI spidevice(PTD3, PTD2, PTD1); // mosi, miso, sclk THIS TURNS LED ON BLUE ! (uses p11, p12, p13 on mbed LPC)
JonFreeman 0:5d0f270bfc87 34 //NOTE doubt possibly miso mosi in wrong order here, PTD3 and PTD2
JonFreeman 0:5d0f270bfc87 35 #define STEPPER_PORT PortC
JonFreeman 0:5d0f270bfc87 36 const int PortBitXSt = 3, // Port bit num X Step J1P05
JonFreeman 0:5d0f270bfc87 37 PortBitXDi = 4, // Port bit num X Dir J1P07
JonFreeman 0:5d0f270bfc87 38 PortBitYSt = 5, // Port bit num Y Step J1P09
JonFreeman 0:5d0f270bfc87 39 PortBitYDi = 6, // Port bit num Y Dir J1P11
JonFreeman 0:5d0f270bfc87 40 PortBitZSt = 10, // Port bit num Z Step J1P13
JonFreeman 0:5d0f270bfc87 41 PortBitZDi = 11, // Port bit num Z Dir J1P15
JonFreeman 0:5d0f270bfc87 42 PortBitASt = 12, // Port bit num A Step J2P01
JonFreeman 0:5d0f270bfc87 43 PortBitADi = 13; // Port bit num A Dir J2P03
JonFreeman 0:5d0f270bfc87 44 #endif
JonFreeman 0:5d0f270bfc87 45 #if defined (TARGET_KL46Z)
JonFreeman 0:5d0f270bfc87 46 DigitalOut intled(PTE1); //J2p20
JonFreeman 0:5d0f270bfc87 47 SPISlave spidevice(PTA16, PTA17, PTA15, PTA14); // mosi, miso, sclk, ssel (uses p11, p12, p13, p? on mbed LPC)
JonFreeman 0:5d0f270bfc87 48 // J2p13, J2p15, J2p11, J2p09
JonFreeman 0:5d0f270bfc87 49 // Easy way to allocate port bits for *** N O T CHECKED for 46Z ***
JonFreeman 0:5d0f270bfc87 50 // output of stepper motor Step and DIR sigs
JonFreeman 0:5d0f270bfc87 51 #define STEPPER_PORT PortC
JonFreeman 0:5d0f270bfc87 52 const int PortBitXSt = 0, // Port bit num X Step J1P05
JonFreeman 0:5d0f270bfc87 53 PortBitXDi = 4, // Port bit num X Dir J1P07
JonFreeman 0:5d0f270bfc87 54 PortBitYSt = 6, // Port bit num Y Step J1P09
JonFreeman 0:5d0f270bfc87 55 PortBitYDi = 7, // Port bit num Y Dir J1P11
JonFreeman 0:5d0f270bfc87 56 PortBitZSt = 10, // Port bit num Z Step J1P13
JonFreeman 0:5d0f270bfc87 57 PortBitZDi = 11, // Port bit num Z Dir J1P15
JonFreeman 0:5d0f270bfc87 58 PortBitASt = 13, // Port bit num A Step J2P01
JonFreeman 0:5d0f270bfc87 59 PortBitADi = 16; // Port bit num A Dir J2P03
JonFreeman 0:5d0f270bfc87 60 #endif
JonFreeman 0:5d0f270bfc87 61 #if defined (TARGET_MBED_LPC1768)
JonFreeman 0:5d0f270bfc87 62 DigitalOut intled(LED2);
JonFreeman 0:5d0f270bfc87 63 SPISlave spidevice(p5, p6, p7, p8);
JonFreeman 0:5d0f270bfc87 64 // Easy way to allocate port bits for *** N O T CHECKED for MBED_LPC1768 ***
JonFreeman 0:5d0f270bfc87 65 // output of stepper motor Step and DIR sigs
JonFreeman 0:5d0f270bfc87 66 #define STEPPER_PORT Port0
JonFreeman 0:5d0f270bfc87 67 /* Port 0 bits routed to DIP pins as follows:-
JonFreeman 0:5d0f270bfc87 68 P0.00 p09 Reserve SDA
JonFreeman 0:5d0f270bfc87 69 P0.01 p10 Reserve SCL
JonFreeman 0:5d0f270bfc87 70 P0.04 p30 CAN rd - USE X Step
JonFreeman 0:5d0f270bfc87 71 P0.05 p29 CAN td - USE X Dir
JonFreeman 0:5d0f270bfc87 72 P0.10 p28 SDA - USE Y Step
JonFreeman 0:5d0f270bfc87 73 P0.11 p27 SCL - USE Y Dir
JonFreeman 0:5d0f270bfc87 74 P0.15 p13 Tx - USE Z Step
JonFreeman 0:5d0f270bfc87 75 P0.16 p14 Rx - USE Z Dir
JonFreeman 0:5d0f270bfc87 76 P0.17 p12 miso - USE A Step
JonFreeman 0:5d0f270bfc87 77 P0.18 p11 mosi - Use A Dir
JonFreeman 0:5d0f270bfc87 78 P0.23 p15 A In
JonFreeman 0:5d0f270bfc87 79 P0.24 p16 A In
JonFreeman 0:5d0f270bfc87 80 P0.25 p17 A In
JonFreeman 0:5d0f270bfc87 81 P0.26 p18 Reserve A Out
JonFreeman 0:5d0f270bfc87 82 */
JonFreeman 0:5d0f270bfc87 83 const int PortBitXSt = 4, // Port bit num X Step
JonFreeman 0:5d0f270bfc87 84 PortBitXDi = 5, // Port bit num X Dir
JonFreeman 0:5d0f270bfc87 85 PortBitYSt = 10, // Port bit num Y Step
JonFreeman 0:5d0f270bfc87 86 PortBitYDi = 11, // Port bit num Y Dir
JonFreeman 0:5d0f270bfc87 87 PortBitZSt = 15, // Port bit num Z Step
JonFreeman 0:5d0f270bfc87 88 PortBitZDi = 16, // Port bit num Z Dir
JonFreeman 0:5d0f270bfc87 89 PortBitASt = 17, // Port bit num A Step
JonFreeman 0:5d0f270bfc87 90 PortBitADi = 18; // Port bit num A Dir
JonFreeman 0:5d0f270bfc87 91 #endif
JonFreeman 0:5d0f270bfc87 92
JonFreeman 0:5d0f270bfc87 93 static const long
JonFreeman 0:5d0f270bfc87 94 XSt1 = 1 << PortBitXSt, XSt0 = 0,
JonFreeman 0:5d0f270bfc87 95 XDi1 = 1 << PortBitXDi, XDi0 = 0,
JonFreeman 0:5d0f270bfc87 96 YSt1 = 1 << PortBitYSt, YSt0 = 0,
JonFreeman 0:5d0f270bfc87 97 YDi1 = 1 << PortBitYDi, YDi0 = 0,
JonFreeman 0:5d0f270bfc87 98 ZSt1 = 1 << PortBitZSt, ZSt0 = 0,
JonFreeman 0:5d0f270bfc87 99 ZDi1 = 1 << PortBitZDi, ZDi0 = 0,
JonFreeman 0:5d0f270bfc87 100 ASt1 = 1 << PortBitASt, ASt0 = 0,
JonFreeman 0:5d0f270bfc87 101 ADi1 = 1 << PortBitADi, ADi0 = 0,
JonFreeman 0:5d0f270bfc87 102
JonFreeman 0:5d0f270bfc87 103 SM_MASK = (XSt1 | XDi1 | YSt1 | YDi1 | ZSt1 | ZDi1 | ASt1 | ADi1);
JonFreeman 0:5d0f270bfc87 104
JonFreeman 0:5d0f270bfc87 105 PortOut mysteppers(STEPPER_PORT, SM_MASK);
JonFreeman 0:5d0f270bfc87 106
JonFreeman 0:5d0f270bfc87 107 /*
JonFreeman 0:5d0f270bfc87 108 * Interrupt Service Routine
JonFreeman 0:5d0f270bfc87 109 */
JonFreeman 0:5d0f270bfc87 110 //void Numerically_Controlled_Oscillators_ISR () { // services Ticker 'NCO_gen' generated interrupts ***ISR***
JonFreeman 0:5d0f270bfc87 111 // intled = 1;
JonFreeman 0:5d0f270bfc87 112 // ticks++;
JonFreeman 0:5d0f270bfc87 113 // intled = 0;
JonFreeman 0:5d0f270bfc87 114 //}
JonFreeman 0:5d0f270bfc87 115 void Numerically_Controlled_Oscillators_ISR () { // services Ticker 'NCO_gen' generated interrupts ***ISR***
JonFreeman 0:5d0f270bfc87 116 const long bit_lutx[4] = {XSt0 | XDi0, XSt0 | XDi1, XSt1 | XDi1, XSt1 | XDi0}, // Used to look-up 'clk' and 'dir' signals from accum MSBs
JonFreeman 0:5d0f270bfc87 117 bit_luty[4] = {YSt0 | YDi0, YSt0 | YDi1, YSt1 | YDi1, YSt1 | YDi0}, // Used to look-up 'clk' and 'dir' signals from accum MSBs
JonFreeman 0:5d0f270bfc87 118 bit_lutz[4] = {ZSt0 | ZDi0, ZSt0 | ZDi1, ZSt1 | ZDi1, ZSt1 | ZDi0}, // Used to look-up 'clk' and 'dir' signals from accum MSBs
JonFreeman 0:5d0f270bfc87 119 bit_luta[4] = {ASt0 | ADi0, ASt0 | ADi1, ASt1 | ADi1, ASt1 | ADi0}, // Used to look-up 'clk' and 'dir' signals from accum MSBs
JonFreeman 0:5d0f270bfc87 120 bits2shift = (sizeof (long) << 3) - 2;
JonFreeman 0:5d0f270bfc87 121 static unsigned long
JonFreeman 0:5d0f270bfc87 122 // acc_s = 0L, // For Spindle motor, probably not needed as may be pwm
JonFreeman 0:5d0f270bfc87 123 acc_a = 0L,
JonFreeman 0:5d0f270bfc87 124 acc_x = 0L,
JonFreeman 0:5d0f270bfc87 125 acc_y = 0L,
JonFreeman 0:5d0f270bfc87 126 acc_z = 0L;
JonFreeman 0:5d0f270bfc87 127 static int obitz = 0;
JonFreeman 0:5d0f270bfc87 128 int oldbitz, acts;
JonFreeman 0:5d0f270bfc87 129
JonFreeman 0:5d0f270bfc87 130 intled = 1; // LED on for duration of interrupt service - point for scope probing
JonFreeman 0:5d0f270bfc87 131 ticks++; // count of interrupts serviced
JonFreeman 0:5d0f270bfc87 132 // int response = spidevice.write(0x55); // Only if SPI Master -- TAKES 2.5 us --
JonFreeman 0:5d0f270bfc87 133 // The rest of the whole int handler takes only about 3.0 us
JonFreeman 0:5d0f270bfc87 134 acc_x += pir_x; // Update phase of signals in accumulators
JonFreeman 0:5d0f270bfc87 135 acc_y += pir_y;
JonFreeman 0:5d0f270bfc87 136 acc_z += pir_z;
JonFreeman 0:5d0f270bfc87 137 acc_a += pir_a;
JonFreeman 0:5d0f270bfc87 138 // acc_s += pir_s; // pir_s used for spindle speed
JonFreeman 0:5d0f270bfc87 139 oldbitz = obitz; // pin output levels as determined during previous interrut
JonFreeman 0:5d0f270bfc87 140 obitz = bit_lutx[acc_x >> bits2shift] | bit_luty[acc_y >> bits2shift] | bit_lutz[acc_z >> bits2shift] | bit_luta[acc_a >> bits2shift];
JonFreeman 0:5d0f270bfc87 141
JonFreeman 0:5d0f270bfc87 142 mysteppers = obitz; // Output signals to stepper motor drivers, next look for _- pos clk events on bits 0, 2 and 4
JonFreeman 0:5d0f270bfc87 143
JonFreeman 0:5d0f270bfc87 144 acts = (~oldbitz & obitz); // get pos clk edge triggers in bits 0, 2 and 4 (1, 4, 16)
JonFreeman 0:5d0f270bfc87 145 acts |= (obitz & (XDi1 | YDi1 | ZDi1)); // get directions
JonFreeman 0:5d0f270bfc87 146 if(acts & XSt1) { // got pos clk edge for axis X
JonFreeman 0:5d0f270bfc87 147 if (acts & XDi1)
JonFreeman 0:5d0f270bfc87 148 dro.x++;
JonFreeman 0:5d0f270bfc87 149 else dro.x--;
JonFreeman 0:5d0f270bfc87 150 }
JonFreeman 0:5d0f270bfc87 151 if(acts & YSt1) { // got pos clk edge for axis Y
JonFreeman 0:5d0f270bfc87 152 if (acts & YDi1)
JonFreeman 0:5d0f270bfc87 153 dro.y++;
JonFreeman 0:5d0f270bfc87 154 else dro.y--;
JonFreeman 0:5d0f270bfc87 155 }
JonFreeman 0:5d0f270bfc87 156 if(acts & ZSt1) { // got pos clk edge for axis Z
JonFreeman 0:5d0f270bfc87 157 if (acts & ZDi1)
JonFreeman 0:5d0f270bfc87 158 dro.z++;
JonFreeman 0:5d0f270bfc87 159 else dro.z--;
JonFreeman 0:5d0f270bfc87 160 }
JonFreeman 0:5d0f270bfc87 161 if (running && tickrun <= ticks) { // End of a machine movement detected, start next move here if possible
JonFreeman 0:5d0f270bfc87 162 running = false;
JonFreeman 0:5d0f270bfc87 163 pir_x = 0L; // stop all stepper motors
JonFreeman 0:5d0f270bfc87 164 pir_y = 0L;
JonFreeman 0:5d0f270bfc87 165 pir_z = 0L;
JonFreeman 0:5d0f270bfc87 166 pir_a = 0L;
JonFreeman 0:5d0f270bfc87 167 }
JonFreeman 0:5d0f270bfc87 168 intled = 0; // LED off
JonFreeman 0:5d0f270bfc87 169 } // end of interrupt handler
JonFreeman 0:5d0f270bfc87 170
JonFreeman 0:5d0f270bfc87 171 /*
JonFreeman 0:5d0f270bfc87 172 * End of Interrupt Service Routine
JonFreeman 0:5d0f270bfc87 173 */
JonFreeman 0:5d0f270bfc87 174
JonFreeman 0:5d0f270bfc87 175
JonFreeman 0:5d0f270bfc87 176 void pir_updater (struct axis_speeds_element * p) { // To arrive here with wanted 'mm per min' values in x, y and z
JonFreeman 0:5d0f270bfc87 177 //void pir_updater (struct pirs * p) { // To arrive here with wanted 'mm per min' values in x, y and z
JonFreeman 0:5d0f270bfc87 178 // pc.printf(p.x ? "true":"false"); // Uses pointer as we may wish to rapid update from circular buffer
JonFreeman 0:5d0f270bfc87 179 tickrun = p->duration_ticks;
JonFreeman 0:5d0f270bfc87 180 unsigned long tc = ticks, after;
JonFreeman 0:5d0f270bfc87 181 while (tc == ticks) {} // wait until just after an interrupt - note requires 'volatile' ticks
JonFreeman 0:5d0f270bfc87 182 tickrun += ticks;
JonFreeman 0:5d0f270bfc87 183 pir_x = p->x; // Update NCO phase inc registers
JonFreeman 0:5d0f270bfc87 184 pir_y = p->y;
JonFreeman 0:5d0f270bfc87 185 pir_z = p->z;
JonFreeman 0:5d0f270bfc87 186 pir_a = p->a;
JonFreeman 0:5d0f270bfc87 187 after = ticks - tc;
JonFreeman 0:5d0f270bfc87 188 running = true;
JonFreeman 0:5d0f270bfc87 189 if (after == 1)
JonFreeman 0:5d0f270bfc87 190 pc.printf("pir_update was good !, ticks %d\r\n", p->duration_ticks);
JonFreeman 0:5d0f270bfc87 191 else
JonFreeman 0:5d0f270bfc87 192 pc.printf("Oops! Looks like pir_update got run-over, code = %d\r\n", after);
JonFreeman 0:5d0f270bfc87 193 }
JonFreeman 0:5d0f270bfc87 194
JonFreeman 0:5d0f270bfc87 195 int main() {
JonFreeman 0:5d0f270bfc87 196 char txt[10]; // few chars used for dro output
JonFreeman 0:5d0f270bfc87 197 pc.baud(BAUD); // comms to 'PuTTY' serial terminal via mbed usb
JonFreeman 0:5d0f270bfc87 198 dro.x = dro.y = dro.z = 0; // These dro registers count pulses delivered to stepper motor driver
JonFreeman 0:5d0f270bfc87 199 dro.dro_output = true;
JonFreeman 0:5d0f270bfc87 200 init_last_position () ; // Zeros one 'pirs' structure
JonFreeman 0:5d0f270bfc87 201 spidevice.format(8, 0); // 8 bits mode 0, // p11 mosi, p12 miso, p13 sclk ** ONLY 8 BIT **
JonFreeman 0:5d0f270bfc87 202 spidevice.frequency(12000000); // 12MHz bit rate
JonFreeman 0:5d0f270bfc87 203 // int response = spidevice.write(0xFFFF); // Only if SPI Master
JonFreeman 0:5d0f270bfc87 204 // spidevice.reply(0x00); // Prime SPI with first reply
JonFreeman 0:5d0f270bfc87 205 /*
JonFreeman 0:5d0f270bfc87 206 // Reply to a SPI master as slave
JonFreeman 0:5d0f270bfc87 207
JonFreeman 0:5d0f270bfc87 208 #include "mbed.h"
JonFreeman 0:5d0f270bfc87 209
JonFreeman 0:5d0f270bfc87 210 SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
JonFreeman 0:5d0f270bfc87 211
JonFreeman 0:5d0f270bfc87 212 int main() {
JonFreeman 0:5d0f270bfc87 213 device.reply(0x00); // Prime SPI with first reply
JonFreeman 0:5d0f270bfc87 214 while(1) {
JonFreeman 0:5d0f270bfc87 215 if(device.receive()) {
JonFreeman 0:5d0f270bfc87 216 int v = device.read(); // Read byte from master
JonFreeman 0:5d0f270bfc87 217 v = (v + 1) % 0x100; // Add one to it, modulo 256
JonFreeman 0:5d0f270bfc87 218 device.reply(v); // Make this the next reply
JonFreeman 0:5d0f270bfc87 219 }
JonFreeman 0:5d0f270bfc87 220 }
JonFreeman 0:5d0f270bfc87 221 } */
JonFreeman 0:5d0f270bfc87 222
JonFreeman 0:5d0f270bfc87 223 struct axis_speeds_element * asepp = axis_speeds; // Address of axis_speeds[0]
JonFreeman 0:5d0f270bfc87 224 for (int i = 0; i < axis_speeds_buffsize; i++) {
JonFreeman 0:5d0f270bfc87 225 axis_speeds[i].x =
JonFreeman 0:5d0f270bfc87 226 axis_speeds[i].y =
JonFreeman 0:5d0f270bfc87 227 axis_speeds[i].z =
JonFreeman 0:5d0f270bfc87 228 axis_speeds[i].a =
JonFreeman 0:5d0f270bfc87 229 axis_speeds[i].duration_ticks = 0L;
JonFreeman 0:5d0f270bfc87 230 axis_speeds[i].ready = false;
JonFreeman 0:5d0f270bfc87 231 }
JonFreeman 0:5d0f270bfc87 232 // pc.printf("SPI Setup returned 0x%x\r\n", response);
JonFreeman 0:5d0f270bfc87 233 /* int ch;
JonFreeman 0:5d0f270bfc87 234 while (true) {
JonFreeman 0:5d0f270bfc87 235 while (pc.readable()) {
JonFreeman 0:5d0f270bfc87 236 ch = pc.getc();
JonFreeman 0:5d0f270bfc87 237 pc.printf("**%c**", ch);
JonFreeman 0:5d0f270bfc87 238 }
JonFreeman 0:5d0f270bfc87 239 pc.printf("No more\r\n");
JonFreeman 0:5d0f270bfc87 240 wait(0.5);
JonFreeman 0:5d0f270bfc87 241 }
JonFreeman 0:5d0f270bfc87 242 */
JonFreeman 0:5d0f270bfc87 243 lissajous ();
JonFreeman 0:5d0f270bfc87 244 #if defined (TARGET_KL25Z)
JonFreeman 0:5d0f270bfc87 245 pc.printf ("Found device Freescale KL25Z\r\n");
JonFreeman 0:5d0f270bfc87 246 // DigitalOut intled(PTA1); ** THIS KILLS SERIAL Rx **
JonFreeman 0:5d0f270bfc87 247 #endif
JonFreeman 0:5d0f270bfc87 248 #if defined (TARGET_KL46Z)
JonFreeman 0:5d0f270bfc87 249 pc.printf ("Found device Freescale KL46Z\r\n");
JonFreeman 0:5d0f270bfc87 250 #endif
JonFreeman 0:5d0f270bfc87 251 #if defined (TARGET_MBED_LPC1768)
JonFreeman 0:5d0f270bfc87 252 pc.printf ("Found device MBED_LPC1768\r\n");
JonFreeman 0:5d0f270bfc87 253 #endif
JonFreeman 0:5d0f270bfc87 254 pc.printf("Three NCOs have been setup, they will move when given values by the G0 x? y? z? command\r\n");
JonFreeman 0:5d0f270bfc87 255 pc.printf("sizeof long long is %d bytes, pulsecnt at 1mm per min = %f, top speed = %d mm per min\r\n", sizeof(long long), n_for_onemmpermin, max_mm_per_min);
JonFreeman 0:5d0f270bfc87 256 NCO_gen.attach_us(&Numerically_Controlled_Oscillators_ISR, interrupt_period_us);// Have setup timed interrupts, let other code deal
JonFreeman 0:5d0f270bfc87 257 while(1) {
JonFreeman 0:5d0f270bfc87 258 // if(!(ticks & 0x00000ff)) {
JonFreeman 0:5d0f270bfc87 259 // mybigmotor = arr[step++];
JonFreeman 0:5d0f270bfc87 260 // step &= 0x03;
JonFreeman 0:5d0f270bfc87 261 // pc.printf("^");
JonFreeman 0:5d0f270bfc87 262 // }
JonFreeman 0:5d0f270bfc87 263 command_line_interpreter ();
JonFreeman 0:5d0f270bfc87 264 // myled = 1; //wait(0.4);// myled = 0; //wait(0.4);
JonFreeman 0:5d0f270bfc87 265 // if(running && dro_output && !(ticks & 0x00007ffc)) { // including 'running' causes display to freeze at almost there !
JonFreeman 0:5d0f270bfc87 266 if(dro.dro_output && !(ticks & 0x00007ffc)) {
JonFreeman 0:5d0f270bfc87 267 pc.printf("dros X %s, Y ", readout(txt, dro.x)); // dro.n has running subtotal of all pulses issued to stepper driver.n
JonFreeman 0:5d0f270bfc87 268 pc.printf("%s, Z ", readout(txt, dro.y));
JonFreeman 0:5d0f270bfc87 269 pc.printf("%s", readout(txt, dro.z));
JonFreeman 0:5d0f270bfc87 270 pc.printf(", ticks %d\r\n", ticks);
JonFreeman 0:5d0f270bfc87 271 asepp++;
JonFreeman 0:5d0f270bfc87 272 if (asepp >= axis_speeds + axis_speeds_buffsize) {
JonFreeman 0:5d0f270bfc87 273 asepp = axis_speeds;
JonFreeman 0:5d0f270bfc87 274 }
JonFreeman 0:5d0f270bfc87 275 // pc.printf ("axis_speed %d, %lx\r\n", asepp - axis_speeds, (long)asep);
JonFreeman 0:5d0f270bfc87 276 }
JonFreeman 0:5d0f270bfc87 277 }
JonFreeman 0:5d0f270bfc87 278 }