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.