Greetings all,
Well I have built myself a very capable CNC lathe, complete with two hand wheels each with homemade 200 PPR lasercut encoders. I have also salvaged an old table calculator with a nice keypad to use as a controller (data input, Digital Positional Readout, feedrate, Powerfeed, spindle control etc).
I had it all set up using Mach3. The hand wheels were directly wired to the breakout board and the keypad would, through an arduino Mega, interface with Mach3 via Modbus. This allowed me to display the DRO data on the 7 segment display but... It was painfully slow.
I would get a good 1 second latency on the display and keys would need to be held down for the same time before Mach3 picked them up. It was really annoying. Maybe it had something to do with my modbus code but it was so clumsy and Mach3 was just way too overkill for my project. (I have a Router that uses Mach3 thats why I tried it at first).
Then I thought why not just leave it all in the Mega! Read the two hand wheels via interupts, it was already powering the displays, all it needed to do was send step and direction pulses to the two stepper drivers.
So I added AccelStepper to the mix, ditched the modbus and added a simple turn the handle- move the carriage code. Worked super smooth.
Now just need to update the display and were away laughing.. Added the code and what do you know, accelStepper would bog down to almost 2 steps per second.!!
I did a bit of research and fluffing around it seems for loops are out, which is what I was using to update the individual characters of the display. So I broke down the for loop and just left it linear. That works better but still super slow. Just one function led.setChar() was enough to bog the whole system down and reduce the steps per second to unusable.
I haven't worked out exactly how many steps per second I need but 500mm/min should be enough. That would mean 1/8th microstep, 1600p/5mm 320p/1mm 2666p/second = 500mm/min
Question time;
Am I just asking too much from the Mega.? I have found one similar post here and the advise was to go to a faster board.
The requirements are to send steps as fast as possible (for two steppers that's around 6000 pulses/second) and update the display as smooth as possible (no less than 20fps).
Is seems like I need to prioritise the stepping and let the display update when there a gap in sending pulses? Seems reasonable. Not sure if its possible?
I had also thought to let a Nano do the display and free up the Mega to just do the stepping. But then the Mega would need to send the Nano the positional info for X and Z(via serial) which also bogs the system down. I tried just as a proof of concept Serial.write() in the main stepping loop and it reduced the loop speed to unusable like led.setChar().
Am I destined to buy a faster board? Or is this solvable with some optimised code?
I'll attach my current version of code, maybe something else is killing the speed? I've commented out the Display Update section. And as is it works fast enough.