Problem with K-flop after shpindle starting


Results 1 to 3 of 3

Thread: Problem with K-flop after shpindle starting

  1. #1
    Dobro's Avatar
    Join Date
    Jul 2017
    Location
    ??????
    Posts
    2
    Downloads
    0
    Uploads
    0

    Default Problem with K-flop after shpindle starting

    Hi all!
    I have a problem with K-flop.
    My configuration is K-Flop+Konnect+24K Shpindle+Danfoss VLT Micro FC 51
    Spindle Speed Control by PWM to Analog on 62 and 63 pin of Konnect

    When I start Spindle and try to change speed, Kmotion CNC freeze and disconnect from Kflop until fully power off.

    For speed control I use this C file:
    HTML Code:
    #include "KMotionDef.h"
    #include "CorrectAnalogFunction.c"
    
    #define C 0.00029f // 1000uF
    #define R 100.0f // 100 ohms
    #define Vcc 11.230f // supply voltage
    #define HIGH_BIT 62 // This output drives Cap high
    #define LOW_BIT  63 // This output drives Cap low 
    #define RPM_FACTOR 24000.0 // RPM for full duty cycle (max analog out)
    
    // desired speed is passed in variable 1
    void ServiceKonnectPWM(void);
    int CorrectAnalog(float v);
    double T,T0 = 0;
    float Vout = 0.0; // desired voltage
    float V240=0.970;
    int correct;
    float V[]={
    0.001,  // count = 0
    0.031,  // count = 1
    0.044,  // count = 2
    0.054,  // count = 3
    0.062,  // count = 4
    0.069,  // count = 5
    0.074,  // count = 6
    0.079   // count = 7
    };
    float SpSet = 0;
    
    main()
    {
    
    
    
      SpSet = *(float *)&persist.UserData[1];
      //correct = CorrectAnalog(SpSet/RPM_FACTOR);     			// Set PWM
      //printf("Spindle Set V %f, Cor: %d \n",SpSet, correct);
      //Vout = SpSet / 195.5;
      Vout = SpSet / 3910;
    printf("Spindle Set %f Vout:%5.2f\n",SpSet, Vout);
      
    for(;;){
       T=WaitNextTimeSlice();
       ServiceKonnectPWM();
       //Vout = *(float *)&persist.UserData[1];  		// value stored is actually a float 
       
     //	
     }
    	
    }
    void ServiceKonnectPWM(void) {
    
        static int FirstTime = TRUE;
        static float Vc = 0.0f;
        static double T0;
        static int State;
        double T = Time_sec(); 
    
        if (FirstTime) {
            FirstTime = FALSE;
            T0 = T;
            State = 0;
        }
       else {
          float V,I;
          
          // Compute Voltage applied to Cap
          V = Vcc*State;
          
          // Compute current
          I = (V-Vc)/R;
          
          // Compute new Cap Voltage
          Vc += I/C*(T-T0);
          
          // determine next state
          
          if (Vc > Vout) {
             ClearBit(HIGH_BIT);
             SetBit(LOW_BIT);
             State=0;
            }
          else {
             ClearBit(LOW_BIT);
             SetBit(HIGH_BIT);
             State = 1;
            }
          
          T0 = T; // save time when applied
        }
    }
    
    
    int CorrectAnalog(float v)
    {
    	int r;
    	float v2=2.0f*v;
    	// compare with half way points to determine closest count
    	if (v2 < V[1]+V[0]) return 0;
    	if (v2 < V[2]+V[1]) return 1;
    	if (v2 < V[3]+V[2]) return 2;
    	if (v2 < V[4]+V[3]) return 3;
    	if (v2 < V[5]+V[4]) return 4;
    	if (v2 < V[6]+V[5]) return 5;
    	if (v2 < V[7]+V[6]) return 6;
    	
    	// must be 7 or higher do linear interpolation
    	
    	r = (int)(7.5 + (v-V[7])/(V240-V[7])*(240.0f-7.0f));
    	if (r>255) r=255;
    	return r;
    }
    P.S. English isn’t my first language, so please excuse any mistakes.



  2. #2
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4045
    Downloads
    0
    Uploads
    0

    Default Re: Problem with K-flop after shpindle starting

    Hi Dobro,

    I think the issue is this program contains a forever loop so the program never finishes. If the S action is configured to wait for the action to complete, then whenever KMotionCNC invokes the action it results in a hang. Our later Test Versions should timeout in such a case. You forgot to tell us how you configured KMotionCNC or what Version you are running.

    The Konnect PWM needs to be serviced continuously by software. So the best solution would be to call the ServiceKonnectPWM function from a forever loop in your Initialization User Program and not here in your Speed Change Program. If you do so then the Speed Change Program shouldn't need to do anything (change it to an empty main) program. Whenever the Speed is changed KMotionCNC will set the KFLOP Persist variable to the new speed which will be picked up and used immediately. To have the new value picked up you will need to move the 2 lines below inside the body of ServiceKonnectPWM function

    SpSet = *(float *)&persist.UserData[1];
    Vout = SpSet / 3910;

    Note all the CorrectAnalog stuff can be removed as you aren't using it. You have it both included and copied in.

    Regards

    Regards
    TK http://dynomotion.com


  3. #3
    Dobro's Avatar
    Join Date
    Jul 2017
    Location
    ??????
    Posts
    2
    Downloads
    0
    Uploads
    0

    Default

    Tom, thank you so much for reply!

    This configuration was working properly about two month ago. But now something wrong.

    I use Kmotion CNC 4.34j, my configuration file:
    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 outputs
    // enables them
    // sets them as an xyz coordinate system for GCode
    
    int main() 
    {
    	
    	InitAux();
    	AddKonnect_Aux0(0,&VirtualBits,VirtualBitsEx);
    
    	ch0->InputMode=NO_INPUT_MODE;
    	ch0->OutputMode=STEP_DIR_MODE;
    	ch0->Vel=60000;
    	ch0->Accel=60000;
    	ch0->Jerk=60000;
    	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=0;
    	ch0->OutputChan1=0;
    	ch0->MasterAxis=-1;
    	ch0->LimitSwitchOptions=0x101;
    	ch0->LimitSwitchNegBit=1024;
    	ch0->LimitSwitchPosBit=0;
    	ch0->SoftLimitPos=277700;
    	ch0->SoftLimitNeg=-277700;
    	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.92081;
    	ch0->iir[2].A2=-0.923885;
        EnableAxisDest(0,0);
    
    	ch1->InputMode=NO_INPUT_MODE;
    	ch1->OutputMode=STEP_DIR_MODE;
    	ch1->Vel=160000;
    	ch1->Accel=160000;
    	ch1->Jerk=160000;
    	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=1;
    	ch1->InputChan1=0;
    	ch1->OutputChan0=1;
    	ch1->OutputChan1=0;
    	ch1->MasterAxis=-1;
    	ch1->LimitSwitchOptions=0x101;
    	ch1->LimitSwitchNegBit=1025;
    	ch1->LimitSwitchPosBit=0;
    	ch1->SoftLimitPos=198890;
    	ch1->SoftLimitNeg=-198890;
    	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.92081;
    	ch1->iir[2].A2=-0.923885;
        EnableAxisDest(1,0);
    
    	ch2->InputMode=NO_INPUT_MODE;
    	ch2->OutputMode=STEP_DIR_MODE;
    	ch2->Vel=60000;
    	ch2->Accel=60000;
    	ch2->Jerk=60000;
    	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=2;
    	ch2->InputChan1=0;
    	ch2->OutputChan0=2;
    	ch2->OutputChan1=0;
    	ch2->MasterAxis=-1;
    	ch2->LimitSwitchOptions=0x101;
    	ch2->LimitSwitchNegBit=1026;
    	ch2->LimitSwitchPosBit=0;
    	ch2->SoftLimitPos=55290;
    	ch2->SoftLimitNeg=-55290;
    	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=0.000769;
    	ch2->iir[2].B1=0.001538;
    	ch2->iir[2].B2=0.000769;
    	ch2->iir[2].A1=1.92081;
    	ch2->iir[2].A2=-0.923885;
    	EnableAxisDest(2,0);
    
    	DefineCoordSystem(0,1,2,-1);
    
       // return 0;
    
     int Answer;
          for (;;) // loop forever
       {
          WaitNextTimeSlice();
          
    if (ReadBit(1027)||ReadBit(1028)||ReadBit(1029))  // Watch an external input switch
          {
             StopCoordinatedMotion();  //feedhold
             ClearBit(48); //stop shpindle and pump
             Answer = MsgBox("ALARM_AXIS",MB_OK|MB_ICONEXCLAMATION); //message ALARM_AXIS
                if (Answer == IDOK)
                ClearBit(4);
                ClearBit(5);
                ClearBit(6);
                Delay_sec(3);
                SetBit(4);
                SetBit(5);
                SetBit(6);
             Answer = MsgBox("AXIS_RESTART",MB_OK|MB_ICONEXCLAMATION); //message AXIS_RESTART
          }           
    }
        return 0;
    }
    When I turned off my frequency converter all working fine, until I try to turn on, after that I have Kflop disconnecting.



  4. #4
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4045
    Downloads
    0
    Uploads
    0

    Default Re: Problem with K-flop after shpindle starting

    Hi Dobro,

    So I assume you have the S Action configured without wait otherwise it would never work.

    If you have KFLOP disconnecting only with Spindle Power on and never otherwise then it is likely noise from the Spindle.

    Anything change? Is the Spindle body Earth Grounded? Do you have a reasonably short USB cable? Does the USB Cable have a good shield (shell to shell resistance less than 1 ohm)? Does the USB cable have ferrite rings? Is Spindle wiring close to the USB cable?

    You might also want to determine if KFLOP is re-booting (LEDs flash) due to power glitch or other. That would also cause a USB Disconnect.

    Regards

    Regards
    TK http://dynomotion.com


Posting Permissions

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


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

Problem with K-flop after shpindle starting

Problem with K-flop after shpindle starting