main()
{
	int i,k;
	double T0,*p=gather_buffer;
	
	while (CS0_TimeExecuted==0.0) ;	// wait till we Start
	
	t0 = Time_sec();

	// Capture Data
	
	for (i=0; i<N; i++)
	{
		for (k=0; k<4; k++)	WaitNextTimeSlice();
		
		*p++ = Time_sec() - T0;
		*p++ = ch0->Dest;
		*p++ = ch0->Position;
		*p++ = ch1->Dest;
		*p++ = ch1->Position;
	}

	for (i=0; i<N; i++)
	{
		for (k=0; k<4; k++)	WaitNextTimeSlice();
		
		*p++ = Time_sec() - T0;
		*p++ = ch0->Dest;
		*p++ = ch0->Position;
		*p++ = ch1->Dest;
		*p++ = ch1->Position;
	}


}
Exemple #2
0
main()
{
	int i=0;
	double t0,t1,t2,t3;

	for (;;)
	{
		t0=WaitNextTimeSlice();
		t1=WaitNextTimeSlice();
	
		t3=Time_sec();
	
		do
		{
			t2=t3;
			t3=Time_sec();
		}
		while (t3-t2 < 10e-6) ;
		
		if (i==0)
		{
			printf("Time Slice = %8.2f us\n",(t1-t0)*0.5e6);
			printf("Thread Execution time = %8.2f us\n",(t2-t1)*1e6);
			i++;
		}
		printf("IRQ time = %8.2f us\n",((t1-t0)*0.5-(t2-t1))*1e6);
		Delay_sec(1);
	}
}
Exemple #3
0
main()
{
	double Pot,LastSpeed_X=0.0,LastSpeed_Y=0.0,LastSpeed_Z=0.0;
	
	printf("%f\n",KANALOG_CONVERT_ADC_TO_VOLTS(ADC(0)));
	
	for (;;)
	{
		T1=WaitNextTimeSlice();

		if (T1-T0 > 0.05)  // only change speed every so often
		{
			// convert 0-10V input to -1.0 to 1.0 range
			// Pot mid range of 5V will be zero
			Pot=KANALOG_CONVERT_ADC_TO_VOLTS(ADC(0)) * (1.0/5.0) - 1.0;
			
			// force small values to exactly zero (stopped)
			if (Pot < MIN_THRESHOLD && Pot > -MIN_THRESHOLD) Pot=0;

			DoSpeedAxis(XAXIS, XSELECT, &LastSpeed_X, Pot*MAX_SPEED_X);
			DoSpeedAxis(YAXIS, YSELECT, &LastSpeed_Y, Pot*MAX_SPEED_Y);
			DoSpeedAxis(ZAXIS, ZSELECT, &LastSpeed_Z, Pot*MAX_SPEED_Z);
		}
	}
}
main()
{
	InitAux();
	AddKonnect_Aux0(0,&VirtualBits,VirtualBitsEx);
	
	for(;;)
	{
		T=WaitNextTimeSlice();
		ServiceKonnectPWM();
		
		// Fixed
//		Vout = 0.1;
		
			
		//Generate a 5 Hz 3V Sine Wave
		Vout = 3.0f*sin(T * TWO_PI * 5.0) + 5.0;


		//Generate a Saw Tooth wave
//		Vout = 2 + 6.0* (5.0*T - ((int)(5.0*T)));
		
		//Generate a 5 Hz Square wave
//		Vout = (5.0*T - ((int)(5.0*T))) > 0.5 ? 8 : 2; 
	}
}
main()
{
	SetBitDirection(26,1);  		// Set bit 26 (PWM 0 as an output)
	SetBitDirection(29,1);  		// Set bit 29 (DIR 0 as an output)
	
	FPGA(IO_PWMS_PRESCALE) = 1;  	// set pwm period to 30 KHz
	FPGA(IO_PWMS+1) = 1;			// enable the PWM0

	for (;;)  //loop forever
	{
		WaitNextTimeSlice();
		if (ch0->Enable)
		{
			if (ch0->Output >= 0.0f)
			{			
				SetBit(29);						// Direction
				FPGA(IO_PWMS+0) = ch0->Output;  // Magnitude
			}
			else
			{
				ClearBit(29);					 // Direction
				FPGA(IO_PWMS+0) = -ch0->Output;  // Magnitude
			}
		}
		else
		{
			FPGA(IO_PWMS+0) = 0;  // whenever not enabled put 0% duty cycle
		}
	}
}
main()
{
	for(;;)
	{
		WaitNextTimeSlice();
		ServiceKonnectPWM();
	}
}
main()
{
	for (;;)
	{
		WaitNextTimeSlice();
		ServiceMaxOutput();
	}
}
Exemple #8
0
// Loop servicing things
main()
{
	for (;;)  // loop forever
	{
		WaitNextTimeSlice();
		ServiceToolChange();
		ServiceToolButtons();
	}
}
main()
{
	for (;;) // loop forever
	{
		WaitNextTimeSlice();
		
		if (ReadBit(46))  // Watch an external input switch
		{
			StopCoordinatedMotion();  //feedhold
		}
	}
}
Exemple #10
0
main()
{
	double vx,vy,speed;
	for (;;)
    {
        Delay_sec(0.5);
        WaitNextTimeSlice();  // ensure we don't get interrupted
		vx = (ch0->Dest - ch0->last_dest) * (1.0f/TIMEBASE);
        vy = (ch1->Dest - ch1->last_dest) * (1.0f/TIMEBASE);
        speed = sqrtf(vx*vx+vy*vy);
		printf("speed = %f steps/sec\n",speed);
    }
}
// Pass a command to the PC and wait for it to handshake
// that it was received by either clearing the command
// or changing it to a negative error code
int DoPC(int cmd)
{
	int result;
	
	persist.UserData[PC_COMM_PERSIST]=cmd;
	
	do
	{
		WaitNextTimeSlice();	
	}while (result=persist.UserData[PC_COMM_PERSIST]>0);
	
	printf("Result = %d\n",result);

	return result;
}
Exemple #12
0
main()
{
	double vx,vy,speed;
	for (;;)
    {
        Delay_sec(0.5);
        WaitNextTimeSlice();  // ensure we don't get interrupted
		vx = (ch0->Dest - ch0->last_dest) * (1.0f/TIMEBASE);
        vy = (ch1->Dest - ch1->last_dest) * (1.0f/TIMEBASE);
		printf("speed = %f %f cnts/sec Err = %12.0f %12.0f %12.0f cnts\n",
			vx,vy,
			ch0->LastFollowingError,
			ch1->LastFollowingError,
			ch2->LastFollowingError);
    }
}
main()
{
	int *ChangerState    = &persist.UserData[TOOL_STATE_VAR];
	int Tool = persist.UserData[TOOL_VAR];  // value stored is an integer 

	if (*ChangerState == T_IDLE)
	{
		*ChangerState = T_START;  // Go!
		printf("Tool %d Change Initiated\n",Tool);

		// wait till finished
		while (*ChangerState != T_IDLE)
			WaitNextTimeSlice();
	}
	else
	{
		printf("Error Tool Changer not idle");
	}					
}
main()
{
	int i,k;
	double T0,*p=gather_buffer;

	
	// I just have it go, launched by an M code.  It records roughly 4 seconds from launch and
	// doesn't appear to saturate the USB line.  This lets me really target where I want it to
	// log data such that I'm seeing the exact problem area.  It displays axis position and 
	// following error!
	
	T0 = Time_sec();

	// Capture Data
	
	for (i=0; i<N-1; i++)
	{
		for (k=0; k<4; k++)	WaitNextTimeSlice();
		
		*p++ = Time_sec() - T0;
		*p++ = ch0->Position;
		*p++ = ch1->Position;
		*p++ = ch2->Position;
		*p++ = ch0->Dest;
		*p++ = ch1->Dest;
		*p++ = ch2->Dest;
	}
	
	p=gather_buffer;

	for (i=0; i<N; i++)
	{
		printf("%12.6f,%12.3f,%12.3f,%12.3f,%12.3f,%12.3f,%12.3f\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6]);
		p += 7;
	}
}
void DoSlave(void)
{
	MoveExp(ZAXIS,(chan[SPINDLE_AXIS].Dest-S0)*SlaveGain+Z0, TAU);
	WaitNextTimeSlice();
}
void main() 
{
	float mid,k=0,dk=0.2,A=AMPLITUDE;   // set coil current amplitude
	int i,ignore=300,kpos[Ncycles],zmark,m=0;
	double cnts_per_cycle,p0[Ncycles];
	CHAN *ch = &chan[AXIS_CHAN];

	// rotate until we find the index mark

	ch->Enable=FALSE;
	ch->InputMode=ENCODER_MODE;
	ch->InputChan0=ENCODER_CHAN;
	ch->OutputChan0=DAC_CHAN;
	ch->OutputChan1=DAC_CHAN+1;
	ch->OutputMode=NO_OUTPUT_MODE;
	ch->InputGain0=ENCODER_GAIN;

	for (;;)
	{
		WaitNextTimeSlice();

		k+= dk;

		Write3PH_DACs(ch,A, k/10000.0);  // move the pole 

		zmark = ReadBit(Z_BIT_NUMBER);

		if (!zmark && ignore>0) ignore--;

		if (ignore==0 && zmark)  // check for index mark
		{
			p0[m]=ch->Position;  // save position
			kpos[m]=k;           // save phase angle

			if (++m == Ncycles) 
			{
				ch->Position=0;  // set current position to Zero
				break;
			}

			if (m==2) dk = -dk;
			ignore=300;
		}
	}

	Write3PH_DACs(ch,0,0);    // turn off the coil    

	printf("\nREPORT\n------\n");
	for (i=0; i<Ncycles; i++)
		printf("%d Position = %6.0f PhaseAngle = %f\n",i,p0[i],kpos[i]/10000.0);

	printf("Counts per rev = %6.0f\n",p0[1]-p0[0]);
	cnts_per_cycle = (p0[1]-p0[0])/(kpos[1]-kpos[0])*10000.0;
	printf("Counts per cycle = %6.0f\n",cnts_per_cycle);

	// round to 16
	if (cnts_per_cycle>0)
		cnts_per_cycle = ((int)(cnts_per_cycle/16.0 + 0.5))*16.0;
	else
		cnts_per_cycle = ((int)(cnts_per_cycle/16.0 - 0.5))*16.0;

	printf("Counts per cycle (rounded to 16)= %6.0f\n",cnts_per_cycle);

	ch->invDistPerCycle = 1.0/cnts_per_cycle;
	printf("invDistPerCycle (rounded)= %15.12f\n",ch->invDistPerCycle);

	mid = (kpos[2]+kpos[1])/20000.0;
	mid = mid - (int)mid;
	ch->CommutationOffset = mid*cnts_per_cycle + 0.25*fast_fabs(cnts_per_cycle);
	printf("Commutation offset = %6.0f\n",ch->CommutationOffset);
	printf("Input Gain Specified = %6.3f\n",ch->InputGain0);
}
Exemple #17
0
int main() 
{
	double T0, LastX=0, LastY=0, LastZ=0, Tau;
	
	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
	
	ch0->InputMode=NO_INPUT_MODE;
	ch0->OutputMode=STEP_DIR_MODE;
	ch0->Vel=40000;
	ch0->Accel=200000;
	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=0x0;
	ch0->SoftLimitPos=1e+030;
	ch0->SoftLimitNeg=-1e+030;
	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=40000;
	ch1->Accel=200000;
	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=0x0;
	ch1->SoftLimitPos=1e+030;
	ch1->SoftLimitNeg=-1e+030;
	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=40000;
	ch2->Accel=200000;
	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=0x0;
	ch2->SoftLimitPos=1e+009;
	ch2->SoftLimitNeg=-1e+009;
	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);

	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();
		
		// Service Amplifier disable after no activity for a while
		if (ch0->Dest != LastX || ch1->Dest != LastY || ch2->Dest != LastZ)
		{
			// we moved - enable KStep Amplifers
			SetBit(45);
			T0 = Time_sec();  // record the time and position of last motion
			LastX=ch0->Dest;
			LastY=ch1->Dest;
			LastZ=ch2->Dest; 
		}
		else
		{
			if (Time_sec() > T0 + 10.0) ClearBit(45);
		}
	}

    return 0;
}