Tool change using 8bit binary switch

Moderators: TomKerekes, dynomotion

Post Reply
AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Tool change using 8bit binary switch

Post by AmitKumar171 » Sat Feb 19, 2022 10:36 am

Hi tom,

I am using Kflop+kmotion for my machine.

I am using generic m6 txx command for tool change using automatic tool changer.

I want to use 8 bit binary switch to have tool change from tool 1 to tool 200.

How to go with that ?, as I can see there is no option of tool change using 8 bit binary switches. I have made a program that reads binary switch and gives tool number in console of kmotion but how do i pass it in M6 Txx command. ? I am attaching binary code program.
atc-8bit.txt
(653 Bytes) Downloaded 65 times
Waiting for kind reply.
Thank You

AMIT KUMAR

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Tool change using 8bit binary switch

Post by TomKerekes » Sun Feb 20, 2022 2:50 am

Hi Amit,

It isn't clear what exactly you are trying to do. You might just have the Tool Change Program read the binary switches.

Does the Operator need to set the switches in binary? Or is this some sort of dial?

You might write a C Program which reads the switches and sets a GCode Variable with the value. Such as:

Code: Select all

#include "KMotionDef.h"

#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"


main()
{
	int Switch = 2;  // read switch 
	
	// Save as double #5 (Persists 10 and 11)
	SetUserDataDouble(5,Switch);
	
	// transfer up to the GCode Vars
	SetVars(1,1,5);  // Upload 1 value to GCode 1 from persists double #5   
}
Then assign an MCode Action to the Program for the GCode Variable to be updated. Then use it as the T word.

Code: Select all

M110 (Read Switch to GCode Var 1)
M6T#1 (Use it as Tool number)
HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Re: Tool change using 8bit binary switch

Post by AmitKumar171 » Mon Feb 21, 2022 11:16 am

TomKerekes wrote:
Sun Feb 20, 2022 2:50 am
Hi Amit,

It isn't clear what exactly you are trying to do. You might just have the Tool Change Program read the binary switches.

Does the Operator need to set the switches in binary? Or is this some sort of dial?

You might write a C Program which reads the switches and sets a GCode Variable with the value. Such as:

Code: Select all

#include "KMotionDef.h"

#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"


main()
{
	int Switch = 2;  // read switch 
	
	// Save as double #5 (Persists 10 and 11)
	SetUserDataDouble(5,Switch);
	
	// transfer up to the GCode Vars
	SetVars(1,1,5);  // Upload 1 value to GCode 1 from persists double #5   
}
Then assign an MCode Action to the Program for the GCode Variable to be updated. Then use it as the T word.

Code: Select all

M110 (Read Switch to GCode Var 1)
M6T#1 (Use it as Tool number)
HTH
Hi tom,

Thanks for your reply.

I understood now, how to read tool number from 8 bit switch.

I want to use a NC switch to trigger M6 command and tool number from another NC switch. How can i do that ?
How to use M6 using a NC switch, considering tool number is already saved persist variable.

waiting for kind reply.
Thank You

AMIT KUMAR

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Tool change using 8bit binary switch

Post by TomKerekes » Tue Feb 22, 2022 12:19 am

Hi Amit,
tool number from another NC switch
I don't understand what you mean by that.

But maybe something like:

Code: Select all

#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

#define TOOLCHANGE 46
#define TOOL_PERSIST_VAR 10

int Debounce(int n, int *cnt, int *last, int *lastsolid);

// state variables for switch debouncing
int tlast=0,tlastsolid=-1,tcount=0;

main()
{
	char s[80];
	int result;

	persist.UserData[TOOL_PERSIST_VAR] = 7;  // set dummy tool number

	for (;;) // loop forever
	{
		WaitNextTimeSlice();

		// Check for Tool  Change
		result = Debounce(ReadBit(TOOLCHANGE),&tcount,&tlast,&tlastsolid);
		if  (result == 1)
		{
			sprintf(s,"M6T%d", persist.UserData[TOOL_PERSIST_VAR]);
			MDI(s);
		}
	}
}


// Debounce a bit
//
// return 1 one time when first debounced high 
// return 0 one time when first debounced low 
// return -1 otherwise 
#define DBTIME 300

int Debounce(int n, int *cnt, int *last, int *lastsolid)
{
	int v = -1;
	
	if (n == *last)  // same as last time?
	{
		if (*cnt == DBTIME-1)
		{
			if (n != *lastsolid)
			{
				v = *lastsolid = n;  // return debounced value
			}
		}
		if (*cnt < DBTIME)	(*cnt)++;
	}
	else
	{
		*cnt = 0;  // reset count
	}
	*last = n;
	return v;
}
Regards,

Tom Kerekes
Dynomotion, Inc.

AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Re: Tool change using 8bit binary switch

Post by AmitKumar171 » Tue Feb 22, 2022 2:05 pm

Hi tom,

Thank you for reply.

Those program that you have shared are working as expected.

I have one problem in Linear4ToolHolders Rev 2.c program (default program in setup).

It does not have preload tool option. How to add preload tool option in Linear4ToolHolders Rev 2.c .

for tool preload just tool number Txxx is enough. as there is no need to put M6 in that.

example
(
T12
M06
T14
(Machining with T12 in spindle, but T14 is ready for next M06)
M06
(Now T14 is loaded)
T02 (Setting up T02 for later)
(Machining with T14)
M06
(Now T02 is in spindle)
( etc. )

How to implement same in tool changer.c default program.

Waiting for your kind reply.
Thank You

AMIT KUMAR

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Tool change using 8bit binary switch

Post by TomKerekes » Tue Feb 22, 2022 3:51 pm

You didn't explain how your tool changer works, but you might use an MCode to preload a tool. ie.

M6T12 (Load tool 12)
M106P14 (Preload tool 14)

M106 would be configured not to wait (otherwise there would be no point in preloading). So some mechanism might be required to have M6 be sure M106 has entirely completed. ie using a Virtual Bit.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Re: Tool change using 8bit binary switch

Post by AmitKumar171 » Wed Feb 23, 2022 3:26 am

TomKerekes wrote:
Tue Feb 22, 2022 3:51 pm
You didn't explain how your tool changer works, but you might use an MCode to preload a tool. ie.

M6T12 (Load tool 12)
M106P14 (Preload tool 14)

M106 would be configured not to wait (otherwise there would be no point in preloading). So some mechanism might be required to have M6 be sure M106 has entirely completed. ie using a Virtual Bit.

HTH
Hi tom,

Thanks for the reply.

we have a linear tool changer that works as per Linear4ToolHolders Rev 2.c.

In above example you shared M106P14 (Preload tool 14) which .c program to use in M106 ? or we can use same Linear4ToolHolders Rev 2.c.

Waiting for your kind reply.
Thank You

AMIT KUMAR

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Tool change using 8bit binary switch

Post by TomKerekes » Wed Feb 23, 2022 5:51 pm

Hi Amit,

With that that type of tool changer I don't see how it is possible or necessary to preload a tool.
Regards,

Tom Kerekes
Dynomotion, Inc.

AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Re: Tool change using 8bit binary switch

Post by AmitKumar171 » Thu Feb 24, 2022 12:37 am

Hi tom,

Thanks for the reply. But we have a provision to load 2 tools in atc arm, and we have plans of extending those 4 tools ( 4tool atc default program) to 100 tools. So for this many tools we need preload option so tool Changer time get reduced.

So in your previous post which m106 tool preload program i have to use with p number.????

Waiting for kind reply.
Thank You

AMIT KUMAR

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: Tool change using 8bit binary switch

Post by TomKerekes » Thu Feb 24, 2022 4:26 pm

Hi Amit,

You would need to create your own Program to perform the Preload operation however your preloader works.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply