Friday, 16 August 2024

Updating the Centroid Lathe PLC code with ATC turret mods

Previously, I edited the Centroid Lathe PLC code to make it work with my ATC turret. The reason for this is that the generic turret options that come with the wizard expect some form of 3 line Graycode signal (similar to BCD) from the turret to tell the controller what tool position is currently in play. However, my turret (supplier unknown) actually uses 8 individual lines, one per position. I have enough spare digital inputs on the ETHER1616 expansion board to handle those extra signals, so the challenge was to modify the logic code to recognise these inputs rather than the Graycode that is expected by default.

All has been working fine since those mods were made - except from the tool touch-off functions that are required for automatically measuring the tool offsets. Previously I tore out large clumps of my hair trying to make head or tail of the behaviour before concluding that I wasn't going to be able to fix it myself. It would clearly require the Centroid engineers to dig into the code and fix what were evidently some logical errors in the offset calculation. As the lathe users appear to be fairly thin on the ground relative to the number of mill, router and plasma users, this wasn't going to happen any time soon.

That time seems to have come finally. There's a beta release that sounds as if it may have fixed some of these issues, so let's have a go at installing it and trying it out.

The update process for my system is as follows:

  • Open CNC12, run the settings wizard and take screenshots of all the settings screens. NB: For subsequent versions, hitting Ctl-P will automatically save the as PDFs.
  • Save the current (4.80) installation by renaming the C:\cnct folder to something like C:\cnct_4.80. You can easily revert back to this working version at any time by simply renaming it back to c:\cnct
  • Create a fresh install from the downloaded link (5.19 beta in this case)
  • Run the wizard and copy the settings across from the PDF screenshots.
  • Update the ATC-related parameters in the config > parameters screen:
    • P160 >> 1 [enhanced ATC:1 = Nonrandom]
    • P264 >> 7 [rapid rate override display - actually non-ATC]
    • P830 >> 4 [ATC type: 4 = Graycode 1 output]
    • P849 >> 10 [toolchange timeout TimerDefault = 10]
    • P851 >> 0.1 [ATC time before reversing]
  • Using Visual Studio Code or Notepad++, open the acorn_lathe_plc.src source file from the c:\cnct folder and comment out or delete the following content...
=========================================================================
                               ATCGrayCodeStage
;=========================================================================
; Check input based on parameter bits to determine tool location
IF !(ToolTurretPosBit1 ^ P831Bit0) && !(ToolTurretPosBit2 ^ P831Bit1) 
 && !(ToolTurretPosBit3 ^ P831Bit2) && !(ToolTurretPosBit4 ^ P831Bit3)
 && SV_MACHINE_PARAMETER_161 >= 1 THEN CurrentTurretPosition_W = 1
IF !(ToolTurretPosBit1 ^ P832Bit0) && !(ToolTurretPosBit2 ^ P832Bit1) 
 && !(ToolTurretPosBit3 ^ P832Bit2) && !(ToolTurretPosBit4 ^ P832Bit3)
 && SV_MACHINE_PARAMETER_161 >= 2 THEN CurrentTurretPosition_W = 2
IF !(ToolTurretPosBit1 ^ P833Bit0) && !(ToolTurretPosBit2 ^ P833Bit1) 
 && !(ToolTurretPosBit3 ^ P833Bit2) && !(ToolTurretPosBit4 ^ P833Bit3)
 && SV_MACHINE_PARAMETER_161 >= 3 THEN CurrentTurretPosition_W = 3
IF !(ToolTurretPosBit1 ^ P834Bit0) && !(ToolTurretPosBit2 ^ P834Bit1) 
 && !(ToolTurretPosBit3 ^ P834Bit2) && !(ToolTurretPosBit4 ^ P834Bit3)
 && SV_MACHINE_PARAMETER_161 >= 4 THEN CurrentTurretPosition_W = 4
IF !(ToolTurretPosBit1 ^ P835Bit0) && !(ToolTurretPosBit2 ^ P835Bit1)
 && !(ToolTurretPosBit3 ^ P835Bit2) && !(ToolTurretPosBit4 ^ P835Bit3)
 && SV_MACHINE_PARAMETER_161 >= 6 THEN CurrentTurretPosition_W = 5
IF !(ToolTurretPosBit1 ^ P836Bit0) && !(ToolTurretPosBit2 ^ P836Bit1)
 && !(ToolTurretPosBit3 ^ P836Bit2) && !(ToolTurretPosBit4 ^ P836Bit3)
 && SV_MACHINE_PARAMETER_161 >= 6 THEN CurrentTurretPosition_W = 6
IF !(ToolTurretPosBit1 ^ P837Bit0) && !(ToolTurretPosBit2 ^ P837Bit1)
 && !(ToolTurretPosBit3 ^ P837Bit2) && !(ToolTurretPosBit4 ^ P837Bit3)
 && SV_MACHINE_PARAMETER_161 >= 7 THEN CurrentTurretPosition_W = 7
IF !(ToolTurretPosBit1 ^ P838Bit0) && !(ToolTurretPosBit2 ^ P838Bit1)
 && !(ToolTurretPosBit3 ^ P838Bit2) && !(ToolTurretPosBit4 ^ P838Bit3)
 && SV_MACHINE_PARAMETER_161 >= 8 THEN CurrentTurretPosition_W = 8
IF !(ToolTurretPosBit1 ^ P839Bit0) && !(ToolTurretPosBit2 ^ P839Bit1)
 && !(ToolTurretPosBit3 ^ P839Bit2) && !(ToolTurretPosBit4 ^ P839Bit3)
 && SV_MACHINE_PARAMETER_161 >= 9 THEN CurrentTurretPosition_W = 9
IF !(ToolTurretPosBit1 ^ P840Bit0) && !(ToolTurretPosBit2 ^ P840Bit1)
 && !(ToolTurretPosBit3 ^ P840Bit2) && !(ToolTurretPosBit4 ^ P840Bit3)
 && SV_MACHINE_PARAMETER_161 >= 10 THEN CurrentTurretPosition_W = 10
IF !(ToolTurretPosBit1 ^ P841Bit0) && !(ToolTurretPosBit2 ^ P841Bit1)
 && !(ToolTurretPosBit3 ^ P841Bit2) && !(ToolTurretPosBit4 ^ P841Bit3)
 && SV_MACHINE_PARAMETER_161 >= 11 THEN CurrentTurretPosition_W = 11
IF !(ToolTurretPosBit1 ^ P842Bit0) && !(ToolTurretPosBit2 ^ P842Bit1)
 && !(ToolTurretPosBit3 ^ P842Bit2) && !(ToolTurretPosBit4 ^ P842Bit3)
 && SV_MACHINE_PARAMETER_161 >= 12 THEN CurrentTurretPosition_W = 12
IF !(ToolTurretPosBit1 ^ P843Bit0) && !(ToolTurretPosBit2 ^ P843Bit1)
 && !(ToolTurretPosBit3 ^ P843Bit2) && !(ToolTurretPosBit4 ^ P843Bit3)
 && SV_MACHINE_PARAMETER_161 >= 13 THEN CurrentTurretPosition_W = 13
IF !(ToolTurretPosBit1 ^ P844Bit0) && !(ToolTurretPosBit2 ^ P844Bit1)
 && !(ToolTurretPosBit3 ^ P844Bit2) && !(ToolTurretPosBit4 ^ P844Bit3)
 && SV_MACHINE_PARAMETER_161 >= 14 THEN CurrentTurretPosition_W = 14
IF !(ToolTurretPosBit1 ^ P845Bit0) && !(ToolTurretPosBit2 ^ P845Bit1)
 && !(ToolTurretPosBit3 ^ P845Bit2) && !(ToolTurretPosBit4 ^ P845Bit3)
 && SV_MACHINE_PARAMETER_161 >= 15 THEN CurrentTurretPosition_W = 15
IF !(ToolTurretPosBit1 ^ P846Bit0) && !(ToolTurretPosBit2 ^ P846Bit1)
 && !(ToolTurretPosBit3 ^ P846Bit2) && !(ToolTurretPosBit4 ^ P846Bit3)
 && SV_MACHINE_PARAMETER_161 >= 16 THEN CurrentTurretPosition_W = 16

IF TRUE THEN SV_PLC_CAROUSEL_POSITION = CurrentTurretPosition_W
  • ...then paste the following section to replace the content you just commented out or deleted:
;===========================================================
                               ATCGrayCodeStage
;===========================================================
; EME 2024-08-09 ATC control trials
; Input 1 on Ether1616 with A0 address = CNC12 input 33 etc
; IF Tool1Input THEN CurrentTurretPosition_W = 1
; IF Tool2Input THEN CurrentTurretPosition_W = 2
; etc...
IF TRUE THEN CurrentTurretPosition_W = 0
IF INP33 THEN CurrentTurretPosition_W = 1
IF INP34 THEN CurrentTurretPosition_W = 2
IF INP35 THEN CurrentTurretPosition_W = 3
IF INP36 THEN CurrentTurretPosition_W = 4
IF INP37 THEN CurrentTurretPosition_W = 5
IF INP38 THEN CurrentTurretPosition_W = 6
IF INP39 THEN CurrentTurretPosition_W = 7
IF INP40 THEN CurrentTurretPosition_W = 8
IF TRUE THEN SV_PLC_CAROUSEL_POSITION = CurrentTurretPosition_W
; EME end of substitution
  • Change to the cnct folder and compile the modified acorn_lathe_plc.src file to create the mpu.plc file using the following commands in a CMD window:
    • cd c:\cnct
    • mpucomp acorn_lathe_plc.src mpu.plc
  • Run CNC12 and follow the instructions - you will need to let it reflash the Beaglebone and cycle the Acorn before you can expect it to work consistently.
That should do the trick. And sure enough it works - once you remember to update the parameters that is. So: install new CNC12, update parameters and modify the plc code.

No comments:

Post a Comment

TIG welder up and running - after some fault diagnostics and repair

Finally got some time to connect up the flow meter and argon hose. Plugged in the torch and ground cables and the torch hose etc. Powered it...