Sunday 19 May 2019

Automatic gear selection macro M3 for The Shiz (Centroid Acorn)

The problem:
When I updated to 4.12, I posted on the Acorn forum about an issue with my M3 macro. Before the update it appeared to work fine but after the update, trying to force the machine to change gear ratio caused the CNC12 software to crash and dump me on the desktop. Not something you want to see in the middle of a machining operation. The explanation was going to be fairly obvious, namely The Fat Stupid Bloke up to his tricks again.

This is what I had. The initial bit is what ships with CNC12. The stuff below "My stuff" is my addition:
;M3 macro - Spindle CW
; Displays message to select auto spindle mode if it is not set
; See 13-8 M94/M95 Output On/Off etc
;-------
IF #4202 || #4201 THEN GOTO 200
M95 /2  ;variable SV_M94_M95_2 off - M04 spindle CCW OFF
M94 /1  ;variable SV_M94_M95_1 on - M03 spindle CW ON
IF #61058 THEN GOTO 200 ;skip the check if AutoSpindle is on - Output1058 is VCP "Autospindle" button LED.
G4 P.1; Dwell 100ms
#140 = 1.5 
N100
IF !#61058 THEN M225 #140 "Please Select Auto Spindle To Continue!" ;61058 = JPO2/SpindleAutoManualLED
G4 P.5; Dwell 500ms
IF !#61058 THEN GOTO 100
N200
;
; My stuff
;
IF #4119 >= 1000 THEN GOTO 1000     ; HIGH range required...
GOTO 2000                           ; ...otherwise LOW range required

N1000                               ; HIGH range selection
IF #50002 THEN GOTO 5000            ; Engaged in HIGH correctly, so finished
M05                                 ; check spindle stopped!
G04 P3                              ; spindle slow down - was in LOW
M94 /62                             ; energise HIGH solenoid - OUTPUT #2
M03                                 ; START SPINDLE - CW
G04 P0.2                            ; PAUSE to engage gears
M05                                 ; STOP SPINDLE
M95 /62                             ; de-energise HIGH solenoid
GOTO 1000                           ; recheck HIGH gears correctly engaged

N2000                               ; LOW range selection
IF #50001 THEN GOTO 5000            ; Engaged in LOW correctly, so finished
M05                                 ; check spindle stopped!
G04 P1.5                            ; spindle slow down - was in HIGH
M94 /61                             ; energise LOW solenoid - OUTPUT #1
M03                                 ; START SPINDLE - CW
G04 P0.2                            ; PAUSE to engage gears
M05                                 ; STOP SPINDLE
M95 /61                             ; de-energise LOW solenoid
GOTO 2000                           ; recheck LOW gears correctly engaged

N5000                               ; In correct range and gears engaged now
M95 /62                             ; check de-energise HIGH solenoid
M95 /61                             ; check de-energise LOW solenoid
M03                                 ; spindle enable CW

As ever, Blogger has screwed up the character spacings. The logic is fairly simple - if a gear change is required, energise the appropriate gear solenoid and then tickle the spindle motor just enough to allow the gears to engage, then check the gear position inputs. These tell the controller if the correct gear is actually meshed - without this test, the gears could grind if the motor is set off full chat before the gears have managed to engage fully.

The issue was the M03 commands (in bold above). Seems this command caused a recursive(?) loop which in turn would crash the CNC12 program.

There's another problem, namely that somewhere along the line, I managed to accidentally change the LOW gear selection input from #50001 to #50006. Fuck nose how that happened - TFSB again, undoubtedly.

And finally, there was a (now) redundant M95 /2 and M94 /1 at the start, which was in the original macro but is now superseded by my content.

M94 / M95 output control:
At this point I got rather confused about the commands for enabling and disabling the spindle, selecting FWD / REV etc. This is somewhat relevant:



So, M94 is used to turn an output ON and M95 is used to turn it OFF. At this point it's rather helpful to know which output is controlled by which variable. The first 16 are allocated already. I'm guessing that the wiring of these system outputs to physical outputs is mapped somewhere, such as the spindle CW and CCW, which are mapped to Acorn's real outputs 4 (purple wire, Yaskawa S1 input, FWD) & 5 (blue wire, Yaskawa S2 input, REV) respectively.


And it seems that outputs 1 (low solenoid) & 2 (high solenoid) are variables 61 & 62 respectively. 
  • So, to turn on the spindle in a FWD (CW) direction using M3, you'd issue a command such as M94 /1 inside the M3 macro and to stop the spindle, you'd issue M95 /1.
  • To turn on the spindle in a REV (CCW) direction using M4, you'd issue a command such as M94 /2 inside the M4 macro and to stop the spindle, you'd issue M95 /2. 
  • To energise the low ratio solenoid (output 1), you'd issue a command such as M94 /61 inside a macro and to de-energise it, you'd issue M95 /61. 
  • To energise the high ratio solenoid (output 2), you'd issue a command such as M94 /62 inside a macro and to de-energise it, you'd issue M95 /62. 
Got that? Good.

The solution:

;-------
; M3 macro - Spindle CW 4.14
; Murray's mods to automatically select high or low ratio.
; Displays message to select auto spindle mode if it is not set
; See 13-8 M94/M95 Output On/Off etc
; See CNC12 manual 13-8 M94/M95 Output On/Off etc - M94 = On, M95 = Off
; M94 /1 turns spindle CW ON
; M95 /1 turns spindle CW OFF
; M94 /2 turns spindle CCW ON
; M95 /2 turns spindle CCW OFF
; M94 /61 turns O/P 1 (Low ratio solenoid) ON
; M95 /61 turns O/P 1 (Low ratio solenoid) OFF
; M94 /62 turns O/P 2 (High ratio solenoid) ON
; M95 /62 turns O/P 2 (High ratio solenoid) OFF
; etc
;-------
IF #4202 || #4201 THEN GOTO 6000 ; skip to end if graphing or searching
IF #61058 THEN GOTO 200         ;skip check if AutoSpindle on - Output1058 is VCP "Autospindle" button LED.
G4 P.1; Dwell 100ms
#140 = 1.5 
N100
IF !#61058 THEN M225 #140 "Please Select Auto Spindle To Continue!" ;61058 = JPO2/SpindleAutoManualLED
G4 P.5; Dwell 500ms
IF !#61058 THEN GOTO 100
N200
;
; Murray's stuff
;
IF #4119 >= 1000 THEN GOTO 1000     ; HIGH range required...
GOTO 2000                       ; ...otherwise LOW range required

N1000                               ; HIGH range selection

IF #50002 THEN GOTO 5000            ; Engaged in HIGH correctly, so finished
M05                                  ; check spindle stopped!
G04 P3                              ; spindle slow down - was in LOW
M94 /62                            ; energise HIGH solenoid - OUTPUT #2
M94 /1                              ; START SPINDLE - CW
G04 P0.2                           ; PAUSE to engage gears
M05                                  ; STOP SPINDLE
M95 /62                            ; de-energise HIGH solenoid
GOTO 1000                       ; recheck HIGH gears correctly engaged

N2000                               ; LOW range selection

IF #50001 THEN GOTO 5000            ; Engaged in LOW correctly, so finished
M05                                  ; check spindle stopped!
G04 P1.5                           ; spindle slow down - was in HIGH
M94 /61                            ; energise LOW solenoid - OUTPUT #1
M94 /1                              ; START SPINDLE - CW
G04 P0.2                           ; PAUSE to engage gears
M05                                  ; STOP SPINDLE
M95 /61                            ; de-energise LOW solenoid
GOTO 2000                       ; recheck LOW gears correctly engaged

N5000                               ; In correct range and gears engaged now
M95 /62                            ; check de-energise HIGH solenoid
M95 /61                            ; check de-energise LOW solenoid
M94 /1                              ; spindle enable CW

N6000 ; jumping out point if graphing or searching

Note also the suggestion from "swissi" (on the Acorn forum) to branch directly to the end of the program if #4201 or #4202 are true, in which case the macro is being called in graphical or searching mode ie the machine is not actually moving. That seemed like a good idea, so I've implemented it (jump to N6000), even if I haven't bothered to test it exhaustively.

Next steps:
I need to finish what I started, namely replicate the same macro for CCW operation. I thought I'd bottom it out for CW rotation firstly (M3), then modify it for CCW (M4). 

So now to modify the M4 macro, like this:
;-------
; M4 macro - Spindle CCW 4.14
; Murray's mods to automatically select high or low ratio.
; Displays message to select auto spindle mode if it is not set
; See 13-8 M94/M95 Output On/Off etc
; See CNC12 manual 13-8 M94/M95 Output On/Off etc - M94 = On, M95 = Off
; M94 /1 turns spindle CW ON
; M95 /1 turns spindle CW OFF
; M94 /2 turns spindle CCW ON
; M95 /2 turns spindle CCW OFF
; M94 /61 turns O/P 1 (Low ratio solenoid) ON
; M95 /61 turns O/P 1 (Low ratio solenoid) OFF
; M94 /62 turns O/P 2 (High ratio solenoid) ON
; M95 /62 turns O/P 2 (High ratio solenoid) OFF
; etc
;-------
IF #4202 || #4201 THEN GOTO 6000 ; skip to end if graphing or searching
IF #61058 THEN GOTO 200 ;skip the check if AutoSpindle is on - Output1058 is VCP "Autospindle" button LED.
G4 P.1; Dwell 100ms
#140 = 1.5 
N100
IF !#61058 THEN M225 #140 "Please Select Auto Spindle To Continue!" ;61058 = JPO2/SpindleAutoManualLED
G4 P.5; Dwell 500ms
IF !#61058 THEN GOTO 100
N200
;
; Murray's stuff
;
IF #4119 >= 1000 THEN GOTO 1000     ; HIGH range required...
GOTO 2000                           ; ...otherwise LOW range required

N1000                                  ; HIGH range selection
IF #50002 THEN GOTO 5000            ; Engaged in HIGH correctly, so finished
M05                                     ; check spindle stopped!
G04 P3                                 ; spindle slow down - was in LOW
M94 /62                               ; energise HIGH solenoid - OUTPUT #2
M94 /2                                 ; START SPINDLE - CCW
G04 P0.2                              ; PAUSE to engage gears
M05                                     ; STOP SPINDLE
M95 /62                               ; de-energise HIGH solenoid
GOTO 1000                          ; recheck HIGH gears correctly engaged

N2000                                 ; LOW range selection
IF #50001 THEN GOTO 5000 ; Engaged in LOW correctly, so finished
M05                                    ; check spindle stopped!
G04 P1.5                             ; spindle slow down - was in HIGH
M94 /61                              ; energise LOW solenoid - OUTPUT #1
M94 /2                               ; START SPINDLE - CCW
G04 P0.2                            ; PAUSE to engage gears
M05                                   ; STOP SPINDLE
M95 /61                             ; de-energise LOW solenoid
GOTO 2000                        ; recheck LOW gears correctly engaged

N5000                               ; In correct range and gears engaged now
M95 /62                             ; check de-energise HIGH solenoid
M95 /61                             ; check de-energise LOW solenoid
M94 /2                              ; spindle enable CCW


N6000 ; jumping out point if graphing or searching

Good stuff - that tested out OK. It automatically selects the right gear range in either direction (M3 or M4), depending on whether the required spindle speed is above or below the threshold speed - which I have arbitrarily set to 1000rpm. The spindle motor is capable of decent torque down to around that speed but a low ratio makes sense below that for operations such as tapping and large drilling.

Next issue:
The VFD is being set to the commanded speed, ignoring the low gear ratio. So if I ask for 100rpm, the motor itself spins at 100rpm and the spindle then turns at something dumb like 20rpm. I'll need to dig into the manual a bit further to see how to take account of the gear ratio. Clearly the motor would need to be spinning at around 500rpm(?) or so in this example. It may be because fitted an encoder to the motor for rigid tapping perhaps?

No comments:

Post a Comment

Final assembly and test of the spindle nose adaptor - RESULT!!

After the recent distraction caused by the 3D scanner, resurrecting the 3D printer and buggering about with the throttle bodies for my Honda...