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:
Thu Feb 20 09:27:18 2014 +0000
Revision:
2:b3c668ec43ac
Parent:
1:66ee619f206b
As used to produce Lissajous patterns for EiM articles.  XYZ axis good, Axis A not implemented, spindle 'S' working.  Using MODSERIAL, therefore no longer compatible with KL46Z, good for KL25Z and Mbed LPC1768

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
JonFreeman 1:66ee619f206b 5 const double ball_screw_pitch_mm = 4.0, // KX3 has 4mm ball screws
JonFreeman 1:66ee619f206b 6 motor_step_per_rev = 200.0, // KX3 has 200 step per rev steppers
JonFreeman 2:b3c668ec43ac 7 micro_steps = 10.0, // Arc Eurotrade choice 2,4,5,8,10,16,20,25,32,40,50,64,100,125,128
JonFreeman 1:66ee619f206b 8 pulses_per_mm = micro_steps * motor_step_per_rev / ball_screw_pitch_mm,
JonFreeman 0:5d0f270bfc87 9
JonFreeman 2:b3c668ec43ac 10 interrupt_period_us = 32.0,//24.0, //16 is possible with Mbed LPC1768
JonFreeman 1:66ee619f206b 11 interrupt_freq_Hz = 1000000.0 / interrupt_period_us, // Serious limit when doing all in software, no real limit with FPGA
JonFreeman 2:b3c668ec43ac 12 max_pulse_freq_Hz = interrupt_freq_Hz / 3.25, // strictly 2.0, but allow a good margin
JonFreeman 1:66ee619f206b 13 max_mm_per_min = 60.0 * max_pulse_freq_Hz / pulses_per_mm,
JonFreeman 2:b3c668ec43ac 14 // n_for_onemmpermin = pulses_per_mm * interrupt_period_us * pow(2.0,32) / 60000000.0, // n pir to produce 1mm/min travel
JonFreeman 2:b3c668ec43ac 15 n_for_onemmpermin = pulses_per_mm * interrupt_period_us * pow(2.0,31) / 60000000.0, // n pir to produce 1mm/min travel
JonFreeman 2:b3c668ec43ac 16 // note power reduced from 32to 31 as interrupt handler now issued step pulse on both edges
JonFreeman 1:66ee619f206b 17 feed_rate_max = max_mm_per_min,
JonFreeman 2:b3c668ec43ac 18 spindle_factor = interrupt_period_us * 4280,
JonFreeman 1:66ee619f206b 19 spindle_max = 5000.0;
JonFreeman 0:5d0f270bfc87 20 //The output frequency F<sub>out</sub> = 'Kernel Speed (Hz)' * n / (2 to the power of 32)
JonFreeman 2:b3c668ec43ac 21
JonFreeman 0:5d0f270bfc87 22 struct Gparams last_position;
JonFreeman 0:5d0f270bfc87 23 void grain_clr (struct singleGparam & g) {
JonFreeman 0:5d0f270bfc87 24 g.dbl = 0.0;
JonFreeman 0:5d0f270bfc87 25 g.ul = 0L;
JonFreeman 0:5d0f270bfc87 26 g.i = g.c = 0;
JonFreeman 0:5d0f270bfc87 27 g.changed = false;
JonFreeman 0:5d0f270bfc87 28 }
JonFreeman 0:5d0f270bfc87 29 void pirs_clr2 (struct Gparams & p) {
JonFreeman 0:5d0f270bfc87 30 grain_clr (p.x); grain_clr (p.y); grain_clr (p.z); grain_clr (p.i); grain_clr (p.j);
JonFreeman 0:5d0f270bfc87 31 grain_clr (p.r); grain_clr (p.a); grain_clr (p.b); grain_clr (p.c); grain_clr (p.d);
JonFreeman 0:5d0f270bfc87 32 }
JonFreeman 1:66ee619f206b 33 void more_setup () {
JonFreeman 0:5d0f270bfc87 34 pirs_clr2 (last_position);
JonFreeman 0:5d0f270bfc87 35 }
JonFreeman 0:5d0f270bfc87 36
JonFreeman 0:5d0f270bfc87 37