SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Moderators: TomKerekes, dynomotion

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

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by TomKerekes » Sat Mar 12, 2022 1:36 am

The first step would be to see if you can read the carousel's position. See the function below.

The example below should print it. The function goes through the inputs one by one until it finds it (or not).

Your program is all messed up regarding the Carousel function. It is defined to take 2 parameters, but you call it with one parameter, and then it doesn't use any parameters but just sets a bit. I would remove all that and just set the bit.

This statement is incorrect. ClearBit doesn't return anything to be tested by an 'if' statement. ClearBit and SetBit are assumed to never fail and unlike ReadBit which returns the state of the input.
if (ClearBit(DC_Carousel_Motor)) //return 1;


After the function is working just turn the carousel on, use a while loop to wait until the CarouselPostion returns the tool you want, then turn off the carousel.

Code: Select all

#include "KMotionDef.h"
    
////   THIS ARE THE INPUT BITS READING EACH TOOL
#define TOOL_1 1161   
#define TOOL_2 1162    
#define TOOL_3 1163   
#define TOOL_4 1164  
#define TOOL_5 1165   
#define TOOL_6 1166   
#define TOOL_7 1167  
#define TOOL_8 1168   

int CarouselPosition(void);  // define the function with no parameters and returns an integer


void main()
{
	int Pos;
	for (;;)  // loop forever
	{
		Pos = CarouselPosition();  // call the function
		printf("Carousel Position = %d\n",Pos);  // print what the function returned
		Delay_sec(1); // don't print too fast
	}  // end of loop
}


// returns current carousel position based on switches
int CarouselPosition(void)
{
	int i;
	
	for (i=0; i<8; i++)  // check all 8 inputs
	{
		if (ReadBit(TOOL_1 + i) == 1)   // found it?
			return i+1;					// yes, return it (add 1 to make first 1 not 0)
	} // end of for loop
	
	return -1;  // not found return -1
}
Regards,

Tom Kerekes
Dynomotion, Inc.

NOELNOG
Posts: 177
Joined: Wed Nov 10, 2021 3:54 pm

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by NOELNOG » Mon Mar 14, 2022 4:23 pm

Thank you Tom
TomKerekes wrote:
Sat Mar 12, 2022 1:36 am
The example below should print it. The function goes through the inputs one by one until it finds it (or not).
yes that program reads each input ok, it prints each tool number as carousel rotates
TomKerekes wrote:
Sat Mar 12, 2022 1:36 am
After the function is working just turn the carousel on, use a while loop to wait until the CarouselPostion returns the tool you want, then turn off the carousel.
now i am trying to add this to the main program, but i don't know where to paste it and how to do while loop, need little more help thanks

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

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by TomKerekes » Mon Mar 14, 2022 6:14 pm

See here.
Regards,

Tom Kerekes
Dynomotion, Inc.

NOELNOG
Posts: 177
Joined: Wed Nov 10, 2021 3:54 pm

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by NOELNOG » Fri Mar 18, 2022 7:28 pm

Hi Tom
TomKerekes wrote:
Sat Mar 12, 2022 1:36 am
The first step would be to see if you can read the carousel's position. See the function below.

The example below should print it. The function goes through the inputs one by one until it finds it (or not).

Your program is all messed up regarding the Carousel function. It is defined to take 2 parameters, but you call it with one parameter, and then it doesn't use any parameters but just sets a bit. I would remove all that and just set the bit.

This statement is incorrect. ClearBit doesn't return anything to be tested by an 'if' statement. ClearBit and SetBit are assumed to never fail and unlike ReadBit which returns the state of the input.
if (ClearBit(DC_Carousel_Motor)) //return 1;


After the function is working just turn the carousel on, use a while loop to wait until the CarouselPostion returns the tool you want, then turn off the carousel.

Code: Select all

#include "KMotionDef.h"
    
////   THIS ARE THE INPUT BITS READING EACH TOOL
#define TOOL_1 1161   
#define TOOL_2 1162    
#define TOOL_3 1163   
#define TOOL_4 1164  
#define TOOL_5 1165   
#define TOOL_6 1166   
#define TOOL_7 1167  
#define TOOL_8 1168   

int CarouselPosition(void);  // define the function with no parameters and returns an integer


void main()
{
	int Pos;
	for (;;)  // loop forever
	{
		Pos = CarouselPosition();  // call the function
		printf("Carousel Position = %d\n",Pos);  // print what the function returned
		Delay_sec(1); // don't print too fast
	}  // end of loop
}


// returns current carousel position based on switches
int CarouselPosition(void)
{
	int i;
	
	for (i=0; i<8; i++)  // check all 8 inputs
	{
		if (ReadBit(TOOL_1 + i) == 1)   // found it?
			return i+1;					// yes, return it (add 1 to make first 1 not 0)
	} // end of for loop
	
	return -1;  // not found return -1
}
I added this program to my ATC main program, it works to the point where it waits for bit input based on switches to return the tool whaterver number is in the Gcode M6Txx, but it don't know wich tool is in the Gcode it reads all

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

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by TomKerekes » Fri Mar 18, 2022 11:41 pm

Sorry I don't understand what you are saying.
Regards,

Tom Kerekes
Dynomotion, Inc.

NOELNOG
Posts: 177
Joined: Wed Nov 10, 2021 3:54 pm

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by NOELNOG » Sat Mar 19, 2022 1:29 am

when the M06Txx call the c. program to do ATC, the program execute the action, it goes to carousel position, the carousel start rotating but it stop at the next tool not at the tool it supost to get, lets say in the Gcode are M06T 2 the carousel rotates and stops right away in the first tool it find not in the number 2,
ROTARY ATC DC MOTOR.c
(15.43 KiB) Downloaded 46 times
Thanks

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

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by TomKerekes » Sat Mar 19, 2022 5:29 pm

Tooltopickup() returns the current position of the carousel 1 through 8. Why did you change the name from 'CarouselPosition' to 'Tooltopockup'? It doesn't make sense to the carousel position to the ReadBit function as a bit number to read. If the Carousel is currently at position 5 why read bit 5?

Instead wait until Tooltopickup() (or properly named CarouselPosition) equals the requested tool number which has been passed in variable 'Tool'

You might have noted that the requested tool number 'Tool' was not being used so it couldn't possibly stop at the requested tool.

I'm not sure how the tool position switches work but I would expect that halfway between positions no switch will be activated. I had CarouselPosition() returning -1 in that case. You removed that. In that case with nothing specified to return the value might be anything and the results unpredictable. I would put that back in.

I also see CurrentTool is used but never determined. See below:

Validate.png
Regards,

Tom Kerekes
Dynomotion, Inc.

NOELNOG
Posts: 177
Joined: Wed Nov 10, 2021 3:54 pm

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by NOELNOG » Thu Mar 24, 2022 10:30 pm

Hi Tom

i am trying to make this function work, below is the program i am using to test but i couldn't make it print the numbers 1 to 8.
the last program you helped me regarding to reading input tool bits is working now, thank you very much.
TomKerekes wrote:
Tue Mar 01, 2022 5:48 pm
Yes you can decode the tool with a C Program. Read each sensor, multiply A by 4, B by 2, and add them up.

For example:

Code: Select all

int Tool = ReadBit(BITA) * 4 + ReadBit(BITB) * 2 + ReadBit(BITC);
BINARY CODE SENSORS.c
(1.1 KiB) Downloaded 46 times

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

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by TomKerekes » Fri Mar 25, 2022 5:17 pm

Are those bits working on the Digital IO Screen?
Regards,

Tom Kerekes
Dynomotion, Inc.

NOELNOG
Posts: 177
Joined: Wed Nov 10, 2021 3:54 pm

Re: SETTING UP KFLOP, KANALOG FOR NEW CNC ROUTER RETROFIT

Post by NOELNOG » Fri Mar 25, 2022 5:50 pm

yes they are working, actually when i put signal in the BITC 1171the console prints 1, with the other two bits doesn't do anything just print keep printing 0


thanks

Post Reply