Smouk писал(а):Так Вы код то хотя бы покажите сразу - обоих функций
Код кнопки Zero
#include "KMotionDef.h"
main()
{
Zero(0);
Zero(1);
Zero(2);
Zero(3);
InitAux();
AddKonnect_Aux0(0,&VirtualBits,VirtualBitsEx);
Delay_sec(2);
SetBit(149);
Delay_sec(2);
SetBit(57);
}
Код кнопки Resolver
#include "KMotionDef.h"
// Two Axis Resolver Program 1/6/08
//
// outputs square

to both resolvers using Aux Switch Output
//
// then samples output coils near positive and negative peaks
// takes the difference to compute magnitudes
//
// these ratios are used to match the amplitudes of sine:cosine
#define RATIO0 (985.0f/936.0f) // size j/size k
#define RATIO1 (1060.0f/1056.0f) // size n/size m
#define RATIO2 (1046.0f/1065.0f) // size p/size q
main()
{
int i=0;
int k0,j0,k1,j1;
int m0,n0,m1,n1;
int q0,p0,q1,p1;
SetBit(167); //+/-15V on
SetBitDirection(152,1); // configure AUX switch as output
SetBitDirection(144,1);
SetBitDirection(145,1);
SetBitDirection(146,1);
SetBitDirection(148,1);
DefineCoordSystem(0,1,2,-1); // Define 2 axis system
Delay_sec(0.1); // wait for +/- 15V to be stable
for (;;) // repeat forever
{
WaitNextTimeSlice(); // wait a few servo cycles
WaitNextTimeSlice();
WaitNextTimeSlice();
Delay_sec(10e-6); // wait for ADC conversion to complete
k0=ADC(0); // Sample all the ADCs
j0=ADC(1);
m0=ADC(2);
n0=ADC(3);
q0=ADC(4);
p0=ADC(5);
SetBit(152); // Switch the resolver excitation
//compute & track position based on measured magnitudes
DoResolverInput2(ch0,(k1-k0)*RATIO0,j1-j0);
DoResolverInput2(ch1,(m1-m0)*RATIO1,n1-n0);
DoResolverInput2(ch2,(q1-q0)*RATIO2,p1-p0);
WaitNextTimeSlice();// wait a few servo cycles
WaitNextTimeSlice();
WaitNextTimeSlice();
Delay_sec(10e-6); // wait for ADC conversion to complete
k1=ADC(0); // Sample all the ADCs
j1=ADC(1);
m1=ADC(2);
n1=ADC(3);
q1=ADC(4);
p1=ADC(5);
ClearBit(152); // Switch the resolver excitation
//compute & track position based on measured magnitudes
DoResolverInput2(ch0,(k1-k0)*RATIO0,j1-j0);
DoResolverInput2(ch1,(m1-m0)*RATIO1,n1-n0);
DoResolverInput2(ch2,(q1-q0)*RATIO2,p1-p0);
if (ch0->Enable && ch1->Enable && ch2->Enable)
SetBit(144);
else
ClearBit(144);
if (ch0->Enable && ch1->Enable && ch2->Enable)
SetBit(145);
else
ClearBit(145);
if (ch0->Enable && ch1->Enable && ch2->Enable)
SetBit(146);
else
ClearBit(146);
if (!ReadBit(1054)) // если пропадет сигнал (знак !) на пине 137
{
StopCoordinatedMotion(); //встать на паузуDisableAxis(0);
DisableAxis(0);
DisableAxis(1);
DisableAxis(2);
DisableAxis(3);
ClearBit(148);
}
#if 0 // enable this to print the magnitudes occasionally
if (++i==1000)
{
i=0;
printf("%5d% 5d\n",p1-p0,q1-q0);
}
#endif
}
}
Объединил их скопировав в одну. Между ними Delay на 2 секунды.
Код всех файлов брал из этого же форума)) и init тоже