585,967 active members*
4,454 visitors online*
Register for free
Login
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2006
    Posts
    62

    Add external button

    Hi Tom
    Please help me add "cyclestart and estop" external button to this init, I tried to copy from
    "external botton" file to this init without any success, Thanks

  2. #2
    Join Date
    May 2006
    Posts
    4045
    Hi Itran2000,

    Looks like you are expecting an External FeedHold button wired to KSTEP Opto input #0 which maps to Virtual IO 48. Does that work? Does the IO 48 change on the digital IO Screen when you push the button? Where are the other buttons wired to?

    Regards
    TK
    http://dynomotion.com

  3. #3
    Join Date
    May 2006
    Posts
    62
    Hi Tom
    All wired to Kstep Jp33 , Feedhold to: pin9 (168), cyclestart to pin10(169), estop to pin11(170) they change state on the digital IO Screen
    when I press a button, I just need script(code) add to the init, that's all I need, sorry I don't know anything about C language,
    feed hold work ok when I change to 168.Thanks for your help.

  4. #4
    Join Date
    May 2006
    Posts
    4045
    Hi Itran2000,

    Try this (you will need to be using one of the later Test Versions V4.31o):

    Code:
    #include "KMotionDef.h"
    #define TMP 10 // which spare persist to use to transfer data
    #include "KflopToKMotionCNCFunctions.c"
    
    // Defines axis 0, 1, 2 as simple step dir TTL outputs for KSTEP
    // enables them
    // sets them as an xyz coordinate system for GCode
    // supports external buttons
    
    int flast=0,flastsolid=-1,fcount=0;  // for debouncing feedhold pushbutton
    int clast=0,clastsolid=-1,ccount=0;  // for debouncing cycle start pushbutton
    int elast=0,elastsolid=-1,ecount=0;  // for debouncing estop pushbutton
    
    int Debounce(int n, int *cnt, int *last, int *lastsolid);
    
    #define FEEDHOLDBIT 168  	// set to the external feedhold input bit
    #define CYCLESTARTBIT 169  	// set to the external cycle start input bit
    #define ESTOP 170  			// set to the external estop input bit
    
    
    int main() 
    {
    	double T0, LastX=0, LastY=0, LastZ=0, Tau;
    	int result;
    
    	KStepPresent=TRUE;      // enable KSTEP input multiplexing
    	FPGA(KAN_TRIG_REG)=4;  	// Mux PWM0 to JP7 Pin5 IO 44 for KSTEP 
    
    	FPGA(STEP_PULSE_LENGTH_ADD) = 63 + 0x80;  // set polarity and pulse length to 4us
    
    
    	SetBitDirection(0,1); //set as output
    
    	SetBit(0); // turn output on
    
    	ClearBit(0); // turn output off
    
    	Delay_sec(2);  // wait a while 
    
    
    	ch0->InputMode=NO_INPUT_MODE;
    	ch0->OutputMode=STEP_DIR_MODE;
    	ch0->Vel=20000;
    	ch0->Accel=60000;
    	ch0->Jerk=4e+006;
    	ch0->P=0;
    	ch0->I=0.01;
    	ch0->D=0;
    	ch0->FFAccel=0;
    	ch0->FFVel=0;
    	ch0->MaxI=200;
    	ch0->MaxErr=1e+006;
    	ch0->MaxOutput=200;
    	ch0->DeadBandGain=1;
    	ch0->DeadBandRange=0;
    	ch0->InputChan0=0;
    	ch0->InputChan1=0;
    	ch0->OutputChan0=8;
    	ch0->OutputChan1=0;
    	ch0->MasterAxis=-1;
    
    	ch0->LimitSwitchOptions=0xa8a80013;
    	ch0->InputGain0=1;
    	ch0->InputGain1=1;
    	ch0->InputOffset0=0;
    	ch0->InputOffset1=0;
    	ch0->OutputGain=1;
    	ch0->OutputOffset=0;
    	ch0->SlaveGain=-1;
    	ch0->BacklashMode=BACKLASH_OFF;
    	ch0->BacklashAmount=0;
    	ch0->BacklashRate=0;
    	ch0->invDistPerCycle=1;
    	ch0->Lead=0;
    	ch0->MaxFollowingError=1000000000;
    	ch0->StepperAmplitude=20;
    
    	ch0->iir[0].B0=1;
    	ch0->iir[0].B1=0;
    	ch0->iir[0].B2=0;
    	ch0->iir[0].A1=0;
    	ch0->iir[0].A2=0;
    
    	ch0->iir[1].B0=1;
    	ch0->iir[1].B1=0;
    	ch0->iir[1].B2=0;
    	ch0->iir[1].A1=0;
    	ch0->iir[1].A2=0;
    
    	ch0->iir[2].B0=0.000769;
    	ch0->iir[2].B1=0.001538;
    	ch0->iir[2].B2=0.000769;
    	ch0->iir[2].A1=1.92076;
    	ch0->iir[2].A2=-0.923833;
    	EnableAxisDest(0,0);
    
    	ch1->InputMode=NO_INPUT_MODE;
    	ch1->OutputMode=STEP_DIR_MODE;
    	ch1->Vel=20000;
    	ch1->Accel=60000;
    	ch1->Jerk=4e+006;
    	ch1->P=0;
    	ch1->I=0.01;
    	ch1->D=0;
    	ch1->FFAccel=0;
    	ch1->FFVel=0;
    	ch1->MaxI=200;
    	ch1->MaxErr=1e+006;
    	ch1->MaxOutput=200;
    	ch1->DeadBandGain=1;
    	ch1->DeadBandRange=0;
    	ch1->InputChan0=0;
    	ch1->InputChan1=0;
    	ch1->OutputChan0=9;
    	ch1->OutputChan1=0;
    	ch1->MasterAxis=-1;
    	ch1->LimitSwitchOptions=0xa9a90013;
    	ch1->InputGain0=1;
    	ch1->InputGain1=1;
    	ch1->InputOffset0=0;
    	ch1->InputOffset1=0;
    	ch1->OutputGain=-1;
    	ch1->OutputOffset=0;
    	ch1->SlaveGain=1;
    	ch1->BacklashMode=BACKLASH_OFF;
    	ch1->BacklashAmount=0;
    	ch1->BacklashRate=0;
    	ch1->invDistPerCycle=1;
    	ch1->Lead=0;
    	ch1->MaxFollowingError=1000000000;
    	ch1->StepperAmplitude=20;
    
    	ch1->iir[0].B0=1;
    	ch1->iir[0].B1=0;
    	ch1->iir[0].B2=0;
    	ch1->iir[0].A1=0;
    	ch1->iir[0].A2=0;
    
    	ch1->iir[1].B0=1;
    	ch1->iir[1].B1=0;
    	ch1->iir[1].B2=0;
    	ch1->iir[1].A1=0;
    	ch1->iir[1].A2=0;
    
    	ch1->iir[2].B0=0.000769;
    	ch1->iir[2].B1=0.001538;
    	ch1->iir[2].B2=0.000769;
    	ch1->iir[2].A1=1.92076;
    	ch1->iir[2].A2=-0.923833;
    	EnableAxisDest(1,0);
    
    	ch2->InputMode=NO_INPUT_MODE;
    	ch2->OutputMode=STEP_DIR_MODE;
    	ch2->Vel=20000;
    	ch2->Accel=10000;
    	ch2->Jerk=4e+006;
    	ch2->P=0;
    	ch2->I=0.01;
    	ch2->D=0;
    	ch2->FFAccel=0;
    	ch2->FFVel=0;
    	ch2->MaxI=200;
    	ch2->MaxErr=1e+006;
    	ch2->MaxOutput=200;
    	ch2->DeadBandGain=1;
    	ch2->DeadBandRange=0;
    	ch2->InputChan0=0;
    	ch2->InputChan1=0;
    	ch2->OutputChan0=10;
    	ch2->OutputChan1=0;
    	ch2->MasterAxis=-1;
    	ch2->LimitSwitchOptions=0xaaaa0013;
    
    	ch2->InputGain0=1;
    	ch2->InputGain1=1;
    	ch2->InputOffset0=0;
    	ch2->InputOffset1=0;
    	ch2->OutputGain=-1;
    	ch2->OutputOffset=0;
    	ch2->SlaveGain=1;
    	ch2->BacklashMode=BACKLASH_OFF;
    	ch2->BacklashAmount=0;
    	ch2->BacklashRate=0;
    	ch2->invDistPerCycle=1;
    	ch2->Lead=0;
    	ch2->MaxFollowingError=1000000000;
    	ch2->StepperAmplitude=20;
    
    	ch2->iir[0].B0=1;
    	ch2->iir[0].B1=0;
    	ch2->iir[0].B2=0;
    	ch2->iir[0].A1=0;
    	ch2->iir[0].A2=0;
    
    	ch2->iir[1].B0=1;
    	ch2->iir[1].B1=0;
    	ch2->iir[1].B2=0;
    	ch2->iir[1].A1=0;
    	ch2->iir[1].A2=0;
    
    	ch2->iir[2].B0=1;
    	ch2->iir[2].B1=0;
    	ch2->iir[2].B2=0;
    	ch2->iir[2].A1=0;
    	ch2->iir[2].A2=0;
    	EnableAxisDest(2,0);
    
    
    	ch3->InputMode=ENCODER_MODE;
    	ch3->OutputMode=STEP_DIR_MODE;
    	ch3->Vel=20000;
    	ch3->Accel=60000;
    	ch3->Jerk=4e+006;
    	ch3->P=0;
    	ch3->I=0.01;
    	ch3->D=0;
    	ch3->FFAccel=0;
    	ch3->FFVel=0;
    	ch3->MaxI=200;
    	ch3->MaxErr=1e+006;
    	ch3->MaxOutput=200;
    	ch3->DeadBandGain=1;
    	ch3->DeadBandRange=0;
    	ch3->InputChan0=3;
    	ch3->InputChan1=0;
    	ch3->OutputChan0=11;
    	ch3->OutputChan1=0;
    	ch3->MasterAxis=0;
    	ch3->LimitSwitchOptions=0xabab0010;
    	ch3->InputGain0=1;
    	ch3->InputGain1=1;
    	ch3->InputOffset0=0;
    	ch3->InputOffset1=0;
    	ch3->OutputGain=1;
    	ch3->OutputOffset=0;
    	ch3->SlaveGain=-1;
    	ch3->BacklashMode=BACKLASH_OFF;
    	ch3->BacklashAmount=0;
    	ch3->BacklashRate=0;
    	ch3->invDistPerCycle=1;
    	ch3->Lead=0;
    	ch3->MaxFollowingError=1000000000;
    	ch3->StepperAmplitude=20;
    
    	ch3->iir[0].B0=1;
    	ch3->iir[0].B1=0;
    	ch3->iir[0].B2=0;
    	ch3->iir[0].A1=0;
    	ch3->iir[0].A2=0;
    
    	ch3->iir[1].B0=1;
    	ch3->iir[1].B1=0;
    	ch3->iir[1].B2=0;
    	ch3->iir[1].A1=0;
    	ch3->iir[1].A2=0;
    
    	ch3->iir[2].B0=0.000769;
    	ch3->iir[2].B1=0.001538;
    	ch3->iir[2].B2=0.000769;
    	ch3->iir[2].A1=1.92081;
    	ch3->iir[2].A2=-0.923885;
    
    	EnableAxisDest(3,0);
    
    	DefineCoordSystem(0,1,2,-1);
    
    	SetBitDirection(45,1);  // set Enable Signal as Output
    	SetBit(45);				// Enable the amplifiers
    
    	//  Add a small amount of Coordinated Motion Path smoothing if desired
    	//	Tau = 0.001;  // seconds for Low Pass Filter Time Constant
    	//	KLP = exp(-TIMEBASE/Tau);
    	KLP=0; // force to 0 to disable
    	//	printf("Tau=%f KLP=%f\n",Tau,KLP);
    
    	for (;;) // loop forever
    	{
    		WaitNextTimeSlice();
    
    		if (Debounce(ReadBit(FEEDHOLDBIT),&fcount,&flast,&flastsolid) == 1)
    		{
    			// one push does feedhold, next will resume
    			if (CS0_StoppingState == 0)
    			{
    				StopCoordinatedMotion();
    				printf("Feed Hold on\n");
    			}
    			else
    			{
    				ResumeCoordinatedMotion();
    				printf("Feed Hold off\n");
    			}
    		}
    
    		// Handle Cycle Start
    		result = Debounce(ReadBit(CYCLESTARTBIT),&ccount,&clast,&clastsolid);
    		if  (result == 1)
    		{
    			DoPC(PC_COMM_EXECUTE);
    		}
    
    		// Handle ESTOP
    		result = Debounce(ReadBit(ESTOP),&ecount,&elast,&elastsolid);
    		if  (result == 1)
    		{
    			DoPC(PC_COMM_ESTOP);
    		}
    	}
    	return 0;
    }
    
    
    // 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
    TK
    http://dynomotion.com

  5. #5
    Join Date
    May 2006
    Posts
    62
    Hi Tom
    I get this error using new init " InitKStep3Axis_LT_V3.txt", I change it to " InitKStep3Axis_LT_V3.c", I am using 4.31o
    I don't get this error using the old initClick image for larger version. 

Name:	Error.jpg 
Views:	0 
Size:	30.7 KB 
ID:	211762.

  6. #6
    Join Date
    May 2006
    Posts
    4045
    Hi Itran2000

    The c program is including another c file that was expected to be in the same directory. If your program is in the KSTEP subdirectory and the other file is in the parent directory you can tell the C Compiler to go up one directory to find it by changing:

    #include "KflopToKMotionCNCFunctions.c"

    to

    #include "..\KflopToKMotionCNCFunctions.c"

    Otherwise you can just copy the file to the same directory.

    Regards
    TK
    http://dynomotion.com

  7. #7
    Join Date
    May 2006
    Posts
    62
    Hi Tom,
    All work as expected, no more error, all button work, Thanks for all your help.
    Ltran2000

  8. #8
    Join Date
    May 2006
    Posts
    62
    Hi Tom
    I have a small problem with the Init above ( InitKStep3Axis_LT_V3.txt)
    -when I set kmotioncnc M3 to " I/O setbit o to 1" all button working ok.
    - when I set to "exec/wait Thread 1 var o" 2 out 3 button (estop & feedhold)no longer work, my exec/wait
    script is:
    #include "KMotionDef.h"

    int main()
    {
    SetBit(0); // turn output on
    Delay_sec(2.0);

    return 0;
    }
    This wait script work ok before adding new external buttons, Please help , Thanks
    Ltran2000

  9. #9
    Join Date
    May 2006
    Posts
    4045
    Hi Ltran2000,

    Use a different Thread (like #2) for your M3 program. The rule is that if two programs ever run at the same time they must run in different Threads. Your "Init" program runs in Thread #1 forever watching the button inputs. If you run a different program in Thread #1 it will kill your "Init" program. See here for more info.



    Regards
    TK
    http://dynomotion.com

  10. #10
    Join Date
    May 2006
    Posts
    62
    Thanks for your explanation, all buttons work now, thanks again

Similar Threads

  1. External Programing
    By Scrambled1 in forum HURCO
    Replies: 0
    Last Post: 03-07-2013, 11:48 PM
  2. Replies: 12
    Last Post: 09-17-2011, 05:25 AM
  3. External References do you use them?
    By Rich05 in forum Solidworks
    Replies: 3
    Last Post: 02-13-2011, 10:36 PM
  4. External Cycle Start button
    By Jerry Shorter in forum LinuxCNC (formerly EMC2)
    Replies: 2
    Last Post: 06-07-2010, 07:59 PM
  5. External Threading
    By skipper in forum MetalWork Discussion
    Replies: 4
    Last Post: 10-27-2007, 03:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •