spindle servo runs away over time/position

Moderators: TomKerekes, dynomotion

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

Re: spindle servo runs away over time/position

Post by TomKerekes » Tue Aug 20, 2019 1:57 am

Hi turbothis,
i changed the follow error down on the CH2 spindle and commented out the DAC to set zero thinking that might be what to do so the encoder position never changes.
Whatever is written to the DACs is unlikely to effect the measured encoder position.

ch2->MaxFollowingError=100000;
still seems large > 12 revs of error.

this kept the C program from enabling the channels
leaving garbage written to the DAC when they are disabled might cause problems.

so i just un commented the 3 lines from above
now with the same working code that cut this morning kmotioncnc will still not enable the channels?
Maybe you had the bad program running in multiple Threads? Were you aware of what Threads you were using?

i have done this a couple times and it does look accurate for the close to zero on the decimal
What were the numbers?

maybe the encoder just skips a beat at times?
I don't like those encoders they tend to have jitter on the position, are based on magnetics with interpolation rather than optics, and I believe only have single ended outputs. Where have you connected them?
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: spindle servo runs away over time/position

Post by turbothis » Tue Aug 20, 2019 4:41 pm

do you have an encoder to recommend on the back of the servo? it is 6mm thru hole
can i change my main C program to never change the cnc position?

i let the spindle run for maybe 30 minutes and it finally acted out
i hit OFF and checked the AXIS page and it is blank on the destination?
yesterday when hitting OFF it would leave the destination so i could compare like you where talking about

Image

Moray
Posts: 288
Joined: Thu Apr 26, 2018 10:16 pm

Re: spindle servo runs away over time/position

Post by Moray » Tue Aug 20, 2019 5:10 pm

turbothis wrote:
Tue Aug 20, 2019 4:41 pm
do you have an encoder to recommend on the back of the servo? it is 6mm thru hole
https://www.usdigital.com/products/enco ... tal/rotary (I'm assuming your in the US?)
Take your pick from any of the Optical encoders, although I'd probably suggest E5 to get differential output.
(Quick edit - you'll probably want to buy the relevant cable assembly at the same time, as I think all their common encoders don't come with cables attached)

If you're not in the US, and buying from the UK makes more sense, British Encoder (www.encoder.co.uk) are very helpful.

Other option is one of the plethora of encoders from China/eBay, although getting high CPR/PPR with differential output limits choice there.

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

Re: spindle servo runs away over time/position

Post by TomKerekes » Tue Aug 20, 2019 5:42 pm

Hi turbothis,
i let the spindle run for maybe 30 minutes and it finally acted out
i hit OFF and checked the AXIS page and it is blank on the destination?
yesterday when hitting OFF it would leave the destination so i could compare like you where talking about
Oops - that's a bug - huge numbers don't fit in the space on the screen. That's 3 bugs you found.

But no we don't care about the Destination, we want to check the encoder Position to see if it is at zero degrees (a multiple of 8192). Please follow the instructions and manually position the motor to zero degrees and tell us the encoder Position reading after a failure:

#4 - position the motor shaft to the same angle
#5 - record the encoder Position and tell us what it is
#6 - divide the position by 8192 and check if the fractional part is very close to zero

I believe your encoder only have single ended outputs. Do they?

Where have you connected the encoder? If you connect it properly it may work.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: spindle servo runs away over time/position

Post by turbothis » Tue Aug 20, 2019 5:56 pm

i forgot i have a couple of these
https://www.cui.com/product/resource/amt11.pdf
Image
i can wire one up real quick
i think the one i have on there now is single ended with there convertor cable
this new one is true differential i believe

so on these encoders, i can digitally set the Z index at zero so i would like to have the main enable code just set the
ch2->CommutationOffset = 0;
and not do the initial phase find for the index?
so this would just set DAC4=2000
wait 1 second for servo to settle and then ch2->CommutationOffset = 0;?
or something like that

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: spindle servo runs away over time/position

Post by turbothis » Wed Aug 21, 2019 2:37 am

i got the newer edition of the CUI encoder mounted and working. ran it for about a half hour with no issues.
maybe these runs better? i have no fxxxing clue.
making chips tomorrow for as long as it will go!
thanks for the help

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: spindle servo runs away over time/position

Post by turbothis » Wed Aug 21, 2019 8:38 pm

well i spent about 2 hours cutting now stop with zero issues. maybe this thing is ready to work!
thanks a ton
i will have some more general questions soon i am sure

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: spindle servo runs away over time/position

Post by turbothis » Tue Aug 27, 2019 5:33 pm

lathe acted strange with a very weak spindle position yesterday
tried a bunch of stuff and ended up using the phase find again in the -1 direction to get a

ch2->CommutationOffset = -1850; // from auto phase find

just did a ton of work with

ch2->CommutationOffset = 800; // from auto phase find

really not sure how or why this changed
encoder might be just as dum as the last one but in a different way?!
would it be nice to get an absolute encoder or something on this?
Last edited by turbothis on Tue Aug 27, 2019 6:16 pm, edited 1 time in total.

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

Re: spindle servo runs away over time/position

Post by TomKerekes » Tue Aug 27, 2019 6:13 pm

Hi turbothis,

You might have posted your AutoPhaseFind Program.

It seems the index pulse is being detected twice sometimes. The AutoPhaseFind program is supposed to rotate multiple revs forward and reverse so the reported positions should be +/- 8192 counts apart. Once an index pulse is found the motor field is advanced some amount while the index pulse is ignored to allow the previously detected pulse to go away before looking for the next pulse. If the motor has a lot of friction it may get stuck right at the index pulse and not move even though the motor field has moved some amount. It is then falsely detected a 2nd time at the same position. You might increase the amount that the index pulse is ignored after being found.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: spindle servo runs away over time/position

Post by turbothis » Tue Aug 27, 2019 6:18 pm

Code: Select all

#include "KMotionDef.h"

// Drive a 3 Phase motor that has a Z index by
// 3 phase driving the coils (like a stepping motor)
// two revs each direction (two z pulses)
// monitor how many counts/cycle and counts/rev 
// (including direction)and also determine the commutation
// offset by recording the phase angle at the index 
// (which will be where zero is set) and offsetting by 1/4 of a cycle 
//
// Set the following parameters according to your situation
// See the report generated on the Console Screen

#define DAC_CHAN 4      // which pair of PWM channels used
#define ENCODER_CHAN 2  // which encoder we are connected to
#define ENCODER_GAIN -1  // Set to -1 if desired to reverse axis direction
#define AMPLITUDE 200   // Set how hard to drive the coils pwm counts
#define Z_BIT_NUMBER 38  // What bit the Z index is connected to
#define AXIS_CHAN 2     // Axis channel to be used and configured
#define Ncycles 4       // don't change this

// x must be in the range 0->1 returns sin(x) and sin(x+120 degrees)
float Sine3PH (float x, float *sin2);

// put a voltage v on a 3 Phase motor at specified commutation angle
void Write3PH_DACs(CHAN *ch0, float v, double angle_in_cycles); 

// return fractional part of a huge number accurately
float fractionf(double v);


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/1000.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]/1000.0);

	printf("Counts per rev = %6.0f\n",p0[1]-p0[0]);
	cnts_per_cycle = (p0[1]-p0[0])/(kpos[1]-kpos[0])*1000.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])/2000.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);
}


// put a voltage v on a 3 Phase motor at specified commutation angle
void Write3PH_DACs(CHAN *ch, float v, double angle_in_cycles)
{
	float theta,sin1f;

	if (angle_in_cycles<0)
		theta = 1.0f-fractionf(-angle_in_cycles);
	else
		theta = fractionf(angle_in_cycles);

	DAC(ch->OutputChan0, (int)(v * Sine3PH(theta,&sin1f)));
	DAC(ch->OutputChan1, (int)(v * sin1f));
}

Post Reply