Page 1 of 1

plc programming

Posted: Fri Feb 15, 2019 2:51 am
by acorn_automation
Usin the Acorn to drive a custom hardware configuration for a single axis horizontal deep drill. Use two hardware inputs as triggers: ProbeDetect (INP6) to RetractDrillBtn; and ProbeTrigger (INP7) to StartDrillCycleBtn.

Remarked out all the lines the have ProbeDetect & ProbeTrigger. The StartDrillCycleBtn acts as a Cycle Start. This operates ok.

However when the RetractDrillBtn (formerly ProbeDetect) executes the ... DoCycleCancel ... the following problems occure
1) loose some of the functionality of the virtual jog panel, specifically the red cycle stop button and the green cycle start. It does not mater where the code is inserted: mainstage, spindlestage, jog panel stage or mcode processing.
2) loose the output M3, it gets stuck on no matter what is done: E-Stop, even exiting the CNC12; the m3 output relay will not turn off. have to kill power to the Acorn.

I have tried each function, StartDrillCycleBtn & RetractDrillBtn, separately and both together. The RetractDrillBtn causes the same problem no matter what, no matter where it is inserted

Any suggestions.







Code fragment liner 155 thru 166

;------------------------------------------------------------------------------
; INPUT DEFINITIONS
; Closed = 1 (green) Open = 0 (red)
;------------------------------------------------------------------------------
FirstAxisHomeLimitOk IS INP1 ;&*;
SecondAxisHomeLimitOk IS INP2 ;&*;
ThirdAxisHomeLimitOk IS INP3 ;&*;
FourthAxisHomeLimitOk IS INP4 ;&*;
DriveOk IS INP5 ;&*;
RetractDrillBtn IS INP6 ;&*; ProbeDetect
StartDrillCycleBtn IS INP7 ;&*; ProbeTripped
EStopOk IS INP8 ;&*;
;------------------------------------------------------------------------------
Code fragment liner 2032 thru 2042

IF (CycleCancelKey || KbCycleCancel_M || SkinCycleCancel_M) && (SV_PROGRAM_RUNNING || SV_MDI_MODE)
|| ErrorFlag_M
THEN (DoCycleCancel)

IF (StartDrillCycleBtn || CycleStartKey || KbCycleStart_M || SkinCycleStart_M) THEN (DoCycleStart)

IF True THEN RST JogKeysNormalStage,
RST JogKeysInvert2Stage,
RST JogKeysSwappedStage,
RST JogKeysSwapAndInvert2Stage
;------------------------------------------------------------------------------
Code fragment line 2767 thru 2076
;--M-Codes
; Reset these M-codes if not in CNC Program Running mode
IF !(SV_PROGRAM_RUNNING || SV_MDI_MODE) || SV_STOP
THEN RST M3,
RST M4,
RST M8,
RST M7,
RST M10
;
IF RetractDrillBtn && SV_PROGRAM_RUNNING THEN (DoFeedHold),(DoCycleCancel), (DoSpindleStop)

Re: plc programming

Posted: Fri Feb 15, 2019 10:32 am
by acorn_automation
Is it possible to program the mpu.plc to call a external custom macro: M68 thru M79. there are no definitions for calls to M68-M79 in the mpu.src file.

Re: plc programming

Posted: Fri Feb 15, 2019 11:27 am
by tblough
acorn_automation wrote: Fri Feb 15, 2019 10:32 am Is it possible to program the mpu.plc to call a external custom macro: M68 thru M79. there are no definitions for calls to M68-M79 in the mpu.src file.
Check this thread viewtopic.php?f=20&t=2540 for macro calls from the PLC.

Re: plc programming

Posted: Fri Feb 15, 2019 1:07 pm
by Centroid_Tech
Please always post a current report from the system in order for us to be able to properly assist you. Personally, I believe that your issue is with the following line

IF RetractDrillBtn && SV_PROGRAM_RUNNING THEN (DoFeedHold),(DoCycleCancel), (DoSpindleStop)

I believe that the parenthesis on those system variables may be the culprit. The PLC logic uses the following logic

IF CONDITION THEN SET/RST OUTPUT

The OUTPUT can be a physical output, memory bit, timer, stage, etc. If you had logic in the PLC program that would have the following behavior

IF CONDITION THEN SET OUTPUT
IF !CONDITION THEN RST OUTPUT

then those 2 lines can be combined into 1 line as follows

IF CONDITION THEN (OUTPUT)

The parentheses on OUTPUT will set the state of OUTPUT to be "on" or "set" as long as the CONDITION is true and if the CONDITION is false then the state of OUTPUT will be "off" or "reset". When writing a PLC program, those parentheses should only be used if the state of that OUTPUT is ONLY controlled by that one CONDITION. If there are other CONDITIONs anywhere else is the PLC program, then you are going to have competing logic trying to control the state of the OUTPUT.

There are other locations in the PLC program that are setting DoFeedHold, DoCycleCancel, and DoSpindleStop so chances are that is what is causing your issue but without the current report, I can only speculate on that. Also, having the CONDITION set DoFeedHold and DoCycleCancel doesn't make any sense. There is no need to place the system into a FeedHold state if you are cancelling out of the job.

What I would recommend doing is adding your CONDITION, RetractDrillBtn && SV_PROGRAM_RUNNING, to the existing CONDITION that is already in the PLC program that handles the DoCycleCancel and DoSpindleStop.

Let me know if what I stated above is confusing and what is confusing so that I can try to make it clearer.

Posted: Mon Feb 18, 2019 4:24 pm
by acorn_automation
Understood. FYI I am an experienced computer and PLC programmer. I have read thru the mpu.src code many times. I understand the syntax, and can distinguish between variables and functions. But any guidance you can provide is appreciated. In modifying the code, I make one change at a time and keep a history of changes so I can revert to a prior working version if things go to crap. When changes are made I try everything associated with the change to make sure nothing is 'broken'.

Have tried many variations on getting this to work but have been unsuccessful. Specifically, added code/logic that does what Is desired but 'breaks' : the virtual jog panel Cycle Start and or Hold; MDI M5, spindle does not stop; hard wired E-stop, not stop spindle.

Stepping back and starting over with an unmodified version of mpu.src.

1st step just compile and load to see no adverse affects; all ok.
2nd step rename ProbeDetect to StartDrillCycle
modified line as shown: <ProbeDetect IS INP6 ;&*;> to <StartDrillCycle IS INP6 ;&*;>.
And remark out where ProbeDetect appears, it causes a compiler error.

remarked out lines 2182 thru 2186
;IF (SpinStopKey || KbSpinStop_M || SkinSpinStop_M) ||
; (SpinAutoModeLED && !(M3 || M4)) ||
; (SV_PC_RIGID_TAP_SPINDLE_OFF && SpinAutoModeLED) ||
; ProbeDetect || SV_STOP || ErrorFlag_M || LimitTripped_M
; THEN (SpinStop_M

and line 2220
;IF ProbeDetect && SpinStart_M THEN SET ProbeFault_M

Nothing else. No processing or logic.
Loaded the new mpu.plc. Power off the acorn board. Powerup. Home the machine.
Run spindle via MDI M3. Spindle output comes on, contactor activates, spindle runs.
Try to stop spindle via MDI: M5. Nothing, spindle will not stop. "Press" Jog Panel Virtual Estop: nothing, spindle will not stop. Exit CNC12, spindle does not stop. The only way to stop the spindle is to remove power from the Acorn board.

No logic added only label and remark out code.

I do not see how to attach a report file.

Re: plc programming

Posted: Sat Mar 02, 2019 9:45 pm
by rruizvial
I am a senior programmer in C / C ++, but I do not understand much about PLC programming, there is only IF THEN and GOTO (is it like using BASIC language?? or they are macros for C, because they use the operators || (OR) and && (AND) ??), where there is a document that explains if there are more keywords or the structure of the program or the specificities of acorn board??

Re: plc programming

Posted: Sat Mar 02, 2019 11:58 pm
by rl49

Re: plc programming

Posted: Sun Mar 03, 2019 9:20 am
by martyscncgarage
You attach a report to your message by clicking on the attachments tab below the box you type your message in. (Under the Save Draft Preview Submit buttons)

Re: plc programming

Posted: Mon Mar 04, 2019 1:05 am
by DannyB
rruizvial wrote: Sat Mar 02, 2019 9:45 pm I am a senior programmer in C / C ++, but I do not understand much about PLC programming, there is only IF THEN and GOTO (is it like using BASIC language?? or they are macros for C, because they use the operators || (OR) and && (AND) ??), where there is a document that explains if there are more keywords or the structure of the program or the specificities of acorn board??
You can think of PLC programming as a while loop around some C code where everything is a shadow variable. All loads to shadow variables occur at the top of the loop, all stores from shadow variables occur at the end of the iteration.

IE
while (1)
{
reg1 = *realmem1
reg2 = *realmem2

<plc code that uses reg1, reg2, reg3>

*realmem1 = reg1
*realmem2 = reg2
}


Things like stages are just scoped blocks controlled by conditionals.
IE

if (stage1) { <code for stage> ...}

(PLC languages vary a *lot*. Though nowadays, there are standards for PLC programming languages like iec 61131-3 that are supported by a lot of vendors that make it fairly portable.)

Re: plc programming

Posted: Mon Mar 04, 2019 3:25 am
by rruizvial
DannyB wrote: Mon Mar 04, 2019 1:05 am
rruizvial wrote: Sat Mar 02, 2019 9:45 pm I am a senior programmer in C / C ++, but I do not understand much about PLC programming, there is only IF THEN and GOTO (is it like using BASIC language?? or they are macros for C, because they use the operators || (OR) and && (AND) ??), where there is a document that explains if there are more keywords or the structure of the program or the specificities of acorn board??
You can think of PLC programming as a while loop around some C code where everything is a shadow variable. All loads to shadow variables occur at the top of the loop, all stores from shadow variables occur at the end of the iteration.

IE
while (1)
{
reg1 = *realmem1
reg2 = *realmem2

<plc code that uses reg1, reg2, reg3>

*realmem1 = reg1
*realmem2 = reg2
}


Things like stages are just scoped blocks controlled by conditionals.
IE

if (stage1) { <code for stage> ...}

(PLC languages vary a *lot*. Though nowadays, there are standards for PLC programming languages like iec 61131-3 that are supported by a lot of vendors that make it fairly portable.)
"stages" it reminds me a little the arduino programming:

InitialStage -> setup()
MainStage -> loop()