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

Revision:
2:b3c668ec43ac
Parent:
1:66ee619f206b
--- a/arith.cpp	Thu Feb 06 08:45:02 2014 +0000
+++ b/arith.cpp	Thu Feb 20 09:27:18 2014 +0000
@@ -4,18 +4,21 @@
 
 const   double  ball_screw_pitch_mm   =   4.0,    //  KX3 has 4mm ball screws
                 motor_step_per_rev  =   200.0,    //  KX3 has 200 step per rev steppers
-                micro_steps         =   20.0,      //  Arc Eurotrade choice 2,4,5,8,10,16,20,25,32,40,50,64,100,125,128
+                micro_steps         =   10.0,      //  Arc Eurotrade choice 2,4,5,8,10,16,20,25,32,40,50,64,100,125,128
                 pulses_per_mm       =   micro_steps * motor_step_per_rev / ball_screw_pitch_mm,
 
-                interrupt_period_us =   24.0, //16 is possible with Mbed LPC1768
+                interrupt_period_us =   32.0,//24.0, //16 is possible with Mbed LPC1768
                 interrupt_freq_Hz   =   1000000.0 / interrupt_period_us,  //  Serious limit when doing all in software, no real limit with FPGA
-                max_pulse_freq_Hz   =   interrupt_freq_Hz / 4.5,  //  strictly 4, but allow a good margin
+                max_pulse_freq_Hz   =   interrupt_freq_Hz / 3.25,  //  strictly 2.0, but allow a good margin
                 max_mm_per_min      =   60.0 * max_pulse_freq_Hz / pulses_per_mm,
-                n_for_onemmpermin   = pulses_per_mm * interrupt_period_us * pow(2.0,32) / 60000000.0, //  n pir to produce 1mm/min travel
+//                n_for_onemmpermin   = pulses_per_mm * interrupt_period_us * pow(2.0,32) / 60000000.0, //  n pir to produce 1mm/min travel
+                n_for_onemmpermin   = pulses_per_mm * interrupt_period_us * pow(2.0,31) / 60000000.0, //  n pir to produce 1mm/min travel
+                //  note power reduced from 32to 31 as interrupt handler now issued step pulse on both edges
                 feed_rate_max       = max_mm_per_min,
+                spindle_factor      = interrupt_period_us * 4280,
                 spindle_max         = 5000.0;
 //The output frequency F<sub>out</sub> = 'Kernel Speed (Hz)' * n / (2 to the power of 32)
-
+    
 struct  Gparams    last_position;
 void    grain_clr   (struct singleGparam & g)  {
     g.dbl = 0.0;