===KMotionDef.h===
The KMotionDef.h, is a C header file which lists all variables and functions available to [[KFLOP C Programs]]. The KMotionDef.h file can be located in the <KMotion Installation Dir >\DSP_KFLOP\ directory.
The KMotionDef.h, is a C header file which lists all variables and functions available to [[KFLOP C Programs]]. The KMotionDef.h file can be found at <KMotion Installation Directory>\DSP_KFLOP\
====The Big List====
<span style="color: #ff0000;">Please Note - at the moment this is a direct copy and paste of the KMotionDef.h file. As time allows, it will gradually link to other pages containing further details and examples of related variables and functions. If you wish to contribute to this task, please register.</span>
<span style="color: #0000ff;">To make already linked variables/functions stand out, the original unedited text has been coloured Blue. As the page is edited and linked, it will revert to normal wiki text colours.</span>
//<br />// KMotionDef.h - MAIN HEADER FILE FOR USER C PROGRAMS<br />//<br />// Copyright Dynomotion 2/20/2004<br />//<br />// Include this header file in User C programs that execute<br />// in the DSP to define all User accessible KMotion functions,<br />// constants, and data structures
<span style="color: #ifndef KMotionDef_h0000ff;">//</span><br /><span style="color: #0000ff;">// KMotionDef.h - MAIN HEADER FILE FOR USER C PROGRAMS</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// Copyright Dynomotion 2/20/2004</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// Include this header file in User C programs that execute</span><br /><span style="color: #0000ff;">// in the DSP to define KMotionDef_hall User accessible KMotion functions,</span><br /><span style="color: #0000ff;">// constants, and data structures</span>
#define KFLOP<span style="color: #0000ff;">ifndef KMotionDef_h</span><br /><span style="color: #0000ff;">#define C6722KMotionDef_h</span>
#define BOARD <span style="color: #0000ff;">define KFLOP</span><br /><span style="color: #0000ff;">#define C6722</span>
extern const char VersionAndBuildTime[]# <span style="color: #0000ff; ">define BOARD "KFLOP"<// string with version and build timespan>
<span style="color: #define CLOCKFREQ 50.0e6 0000ff;">extern const char VersionAndBuildTime[]; // 200 MHzstring with version and build time</4 span>
typedef int BOOL# <span style="color: #0000ff;">define CLOCKFREQ 50.0e6 // 200 MHz/4 </span>
#ifndef _SIZE_T<br />span style="color: #define _SIZE_T<br /0000ff;">typedef unsigned int size_tBOOL;<br /span>#endif
#<span style="color: #0000ff;">ifndef NULL_SIZE_T</span><br /><span style="color: #0000ff;">#define NULL 0_SIZE_T</span><br /><span style="color: #0000ff;">typedef unsigned int size_t;</span><br /><span style="color: #0000ff;">#endif</span>
#ifndef FALSE<br />span style="color: #define FALSE 0<br /0000ff;">#endif<br />#ifndef TRUENULL<br /span>#define TRUE 1<br />#endif <br />span style="color: #ifndef PI<br /0000ff;">#define PI 3.14159265358979323846264NULL 0<br /span>#endif <br />#ifndef PI_F<br />span style="color: #define PI_F 3.1415926535f<br /0000ff;">#endif endif<br /span>#ifndef TWO_PI_F<br />#define TWO_PI_F (2.0f * 3.1415926535f)<br />#endif <br />#ifndef PI_2F<br />#define PI_2F (3.1415926535f * 0.5f) <br />#endif <br />#ifndef TWO_PI<br />#define TWO_PI (2.0 * 3.14159265358979323846264)<br />#endif
# <span style="color: #0000ff;">ifndef FALSE</span><br /><span style="color: #include 0000ff;"PC-DSP>#define FALSE 0</span><br /><span style="color: #0000ff;">#endif</span><br /><span style="color: #0000ff;">#ifndef TRUE</span><br /><span style="color: #0000ff;">#define TRUE 1</span><br /><span style="color: #0000ff;">#endif </span><br /><span style="color: #0000ff;">#ifndef PI</span><br /><span style="color: #0000ff;">#define PI 3.h14159265358979323846264</span><br /><span style=" color: #0000ff;">#endif </span><br / contains common structures shared by PC and DSP><span style="color: #0000ff;">#ifndef PI_F</span><br /><span style="color: #0000ff;">#define PI_F 3.1415926535f</span><br /><span style="color: #0000ff;">#endif </span><br /><span style="color: #0000ff;">#ifndef TWO_PI_F</span><br /><span style="color: #0000ff;">#define TWO_PI_F (2.0f * 3.1415926535f)</span><br /><span style="color: #0000ff;">#endif </span><br /><span style="color: #0000ff;">#ifndef PI_2F</span><br /><span style="color: #0000ff;">#define PI_2F (3.1415926535f * 0.5f) </span><br /><span style="color: #0000ff;">#endif </span><br /><span style="color: #0000ff;">#ifndef TWO_PI</span><br /><span style="color: #0000ff;">#define TWO_PI (2.0 * 3.14159265358979323846264)</span><br /><span style="color: #0000ff;">#endif </span>
// Global Host Status that the PC Application can specify as it Requests Global Status<br />// to inform KFLOP User threads of its current state. ie Job Actively running<br /span style="color: #0000ff;">// up to 32 bits of status can be specified. See #include "PC-DSP.h for normal bit defines" // contains common structures shared by PC and DSP<br /span>extern int volatile HostStatus;
<span style="color: #define JOB_ACTIVE (0000ff;">// Global Host Status that the PC Application can specify as it Requests Global Status</span><br /><span style="color: #0000ff;">// to inform KFLOP User threads of its current state. ie Job Actively running</span><br /><span style="color: #0000ff;">// up to 32 bits of status can be specified. See PC-DSP.h for normal bit defines</span><br /><span style="color: #0000ff;">extern int volatile HostStatus & HOST_JOB_ACTIVE_BIT);</span>
# <span style="color: #0000ff;">define JOB_ACTIVE (HostStatus & HOST_JOB_ACTIVE_BIT)</span>
// standard math funtions
extern float sqrtf (float x);<br />extern float expf (float x)span style="color: #0000ff;<br /">extern float logf (float x);<br />extern float log10f(float x);<br />extern float powf (float x, float y);standard math funtions<br /span>extern float sinf (float x);<br />extern float cosf (float x);<br />extern float tanf (float x);<br />extern float asinf (float x);<br />extern float acosf (float x);<br />extern float atanf (float x);<br />extern float atan2f(float y, float x); <br />extern float fast_fabsf (float y);
<span style="color: #0000ff;">extern double sqrt float sqrtf (double float x);</span><br /><span style="color: #0000ff;">extern double exp float expf (double float x);</span><br /><span style="color: #0000ff;">extern double log float logf (double float x);</span><br /><span style="color: #0000ff;">extern double log10float log10f(double float x);</span><br /><span style="color: #0000ff;">extern double pow float powf (double float x, double float y);</span><br /><span style="color: #0000ff;">extern double sin float sinf (double float x);</span><br /><span style="color: #0000ff;">extern double cos float cosf (double float x);</span><br /><span style="color: #0000ff;">extern double tan float tanf (double float x);</span><br /><span style="color: #0000ff;">extern double asin float asinf (double float x);</span><br /><span style="color: #0000ff;">extern double acos float acosf (double float x);</span><br /><span style="color: #0000ff;">extern double atan float atanf (double float x);</span><br /><span style="color: #0000ff;">extern double atan2float atan2f(double float y, double float x); </span><br /><span style="color: #0000ff;">extern double fast_fabs float fast_fabsf (double float y);</span>
<span style="color: #0000ff;">extern double sqrt (double x);</span><br /><span style="color: #define FPGA_ADDR 0000ff;">extern double exp ((volatile unsigned char *double x)0x91000000) ;<// Base of FPGA addressesspan><br /><span style="color: #define FPGA0000ff;">extern double log (Xdouble x) ;</span><br /><span style="color: #0000ff;">extern double log10(FPGA_ADDR[(X)*4+2]double x);</span><br /><span style="color: #define FPGA_ADDRW 0000ff;">extern double pow ((volatile unsigned short int *double x, double y)0x91000000) ;<// Base of FPGA addressesspan><br /><span style="color: #define FPGAW0000ff;">extern double sin (Xdouble x) ;</span><br /><span style="color: #0000ff;">extern double cos (FPGA_ADDRW[(X)*2+1]double x);<br /span> <br /><span style="color: #0000ff;">extern double tan (double x);<// This structure is set to default every time the program runs UNTILspan><br /><span style="color: #0000ff;">extern double asin (double x);</span><br / the program image has been FLASHED using the FLASH command><span style="color: #0000ff;">extern double acos (double x);</span><br /><span style="color: #0000ff;">extern double atan (double x);</span><br / from then on it will not be cleared><span style="color: #0000ff;">extern double atan2(double y, so data that was present at thedouble x); </span><br /><span style="color: #0000ff;">extern double fast_fabs (double y);<// time it was flashed will persist span>
<br /><span style="color: #0000ff;">#define N_USER_DATA_VARS 200FPGA_ADDR ((volatile unsigned char *)0x91000000) // Base of FPGA addresses</span><br /> <span style="color: #0000ff;">#define FPGA(X) (FPGA_ADDR[(X)*4+2])</span><br />typedef struct<span style="color: #0000ff;">#define FPGA_ADDRW ((volatile unsigned short int *)0x91000000) // Base of FPGA addresses</span><br />{<span style="color: #0000ff;">#define FPGAW(X) (FPGA_ADDRW[(X)*2+1])</span><br /><span style="color: #0000ff;"> int RunOnStartUp</span><br /><span style="color: #0000ff; ">// word Bits 1-7 selects which threads This structure is set to execute on startup default every time the program runs UNTIL</span><br /> unsigned int EntryPoints[N_USER_THREADS]<span style="color: #0000ff; ">// each downloaded the program's entry pointimage has been FLASHED using the FLASH command</span><br /> int UserData[N_USER_DATA_VARS]<span style="color: #0000ff; ">// General purpose way to share and or save user program from then on it will not be cleared, so datathat was present at the</span><br />} PERSIST<span style="color: #0000ff;">// time it was flashed will persist </span>
extern PERSIST persist# <span style="color: #0000ff;">define N_USER_DATA_VARS 200</span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">typedef struct</span><br /><span style="color: #0000ff;">{</span><br /><span style="color: #0000ff;"> int RunOnStartUp; // word Bits 1-7 selects which threads to execute on startup </span><br /><span style="color: #0000ff;"> unsigned int EntryPoints[N_USER_THREADS]; // each downloaded program's entry point</span><br /><span style="color: #0000ff;"> int UserData[N_USER_DATA_VARS]; // General purpose way to share and or save user program data</span><br /><span style="color: #0000ff;">} PERSIST;</span>
<span style="color: #0000ff;">extern int StatusRequestCounterPERSIST persist; / </ increments each time host requests statusspan>
<span style="color: #0000ff;">extern int StatusRequestCounter; // data gathering variablesincrements each time host requests status</span>
<span style="color: #define MAX_GATHER_VALUES 320000ff;">// data gathering variables</span>
#define GATHER_NULL_TYPE 7<br />span style="color: #define GATHER_ADC_TYPE 6<br /0000ff;">#define GATHER_DOUBLE_TYPE 5MAX_GATHER_VALUES 32<br /span>#define GATHER_FLOAT_TYPE 4<br />#define GATHER_LASTPWMC_TYPE 3<br />#define GATHER_LASTPWM_TYPE 2<br />#define GATHER_INT_TYPE 1<br />#define GATHER_END_TYPE 0
typedef struct // # <span style="color: #0000ff;">define a size and address to storeGATHER_NULL_TYPE 7<br /span>{ <br /> int type; // GATHER_XXXXX_TYPE, 0<span style=end of list"color: #0000ff;">#define GATHER_ADC_TYPE 6<br /span> void *addr;<br />} GATHER_VALUE_DEF<span style="color: #0000ff;">#define GATHER_DOUBLE_TYPE 5<br /span> <br />typedef struct<br /span style="color: #0000ff;">{#define GATHER_FLOAT_TYPE 4<br /span> double *bufptr; // data gathering buffer pointer<br /> double *endptr; // done if bufptr <span style= endptr "color: #0000ff;">#define GATHER_LASTPWMC_TYPE 3<br /span> <br /> double Dest<span style="color: #0000ff; // Save where the injection will be relative to">#define GATHER_LASTPWM_TYPE 2<br /span> <br /> int Inject<span style="color: #0000ff; // if set, 1st address is to be copied from buffer to the address ">#define GATHER_INT_TYPE 1<br /span> <br /> GATHER_VALUE_DEF list[MAX_GATHER_VALUES]<span style="color: #0000ff; // list of addresses to gather (null after last value)">#define GATHER_END_TYPE 0<br /span>} GATHER;
extern GATHER gather<span style="color: #0000ff;">typedef struct // define a size and address to store</span><br /><span style="color: #0000ff;">{ </span><br /><span style="color: #0000ff;"> int type; // GATHER_XXXXX_TYPE, 0=end of list</span><br /> <span style="color: #0000ff;"> void *addr;</span><br /><span style="color: #0000ff;">} GATHER_VALUE_DEF;</span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">typedef struct</span><br /><span style="color: #0000ff;">{</span><br /><span style="color: #0000ff;"> double *bufptr; // data gathering buffer pointer</span><br /><span style="color: #0000ff;"> double *endptr; // done if bufptr = endptr </span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;"> double Dest; // Save where the injection will be relative to</span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;"> int Inject; // if set, 1st address is to be copied from buffer to the address </span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;"> GATHER_VALUE_DEF list[MAX_GATHER_VALUES]; // list of addresses to gather (null after last value)</span><br /><span style="color: #0000ff;">} GATHER;</span>
<span style="color: #define MAX_GATHER_DATA 1000000 // Size of 0000ff;">extern GATHER gather buffer (number of doubles, 8 bytes each). ; </span><br />extern double *gather_buffer<span style="color: #0000ff; "> <// Large buffer for data gathering, Bode plots, or User usespan>
#<span style="color: #0000ff;">define N_CPLX 2048MAX_GATHER_DATA 1000000 // Size of gather buffer (number of doubles, 8 bytes each). </span><br /><span style="color: #0000ff;">extern double *gather_buffer; // Large buffer for data gathering, Bode plots, or User use</span>
extern float *input# <span style="color: #0000ff;">define N_CPLX 2048</span>
void SetupGatherAllOnAxis(int c, int n_Samples)<span style="color: #0000ff;">extern float *input; // Prepares to gather info for an axis<br /span>void TriggerGather(); // starts gathering defined items into gather buffer
<span style="color: #0000ff;">void SetupGatherAllOnAxis(int c, int n_Samples); // Prepares to gather info for an axis</span><br /><span style="color: #0000ff;">void TriggerGather(); // starts gathering defined items into gather buffer</span>
<br />#define TRAJECTORY_OFF 0 // no trajectory generation<br />#define TRAJECTORY_INDEPENDENT 1 // simple independent axis (3rd order funtion of time)<br />#define TRAJECTORY_LINEAR 2 // linear interpolated from coord system 0 (x = c*p+d)<br />#define TRAJECTORY_CIRCULAR 3 // circular interpolated from coord system 0 (x = c*sin(p*a+b)+d)<br />#define TRAJECTORY_SPECIAL 4 // Special Command to clear/set IO bit<br /> // do the operation<br /> // 0 = clearbit<br /> // 1 = setbit<br /> // 2 = wait for bit low<br /> // 3 = wait for bit high<br /> // 4 = beginning of Rapid<br /> // 5 = end of Rapid<br /> <br /> // param 0 = bit number
<br /><span style="color: #0000ff;">#define TRAJECTORY_OFF 0 // no trajectory generation</span><br /><span style="color: #0000ff;">#define TRAJECTORY_INDEPENDENT 1 // simple independent axis (3rd order funtion of time)</span><br /><span style="color: #0000ff;">#define TRAJECTORY_LINEAR 2 // linear interpolated from coord system 0 (x = c*p+d)</span><br /><span style="color: #0000ff;">#define TRAJECTORY_CIRCULAR 3 // circular interpolated from coord system 0 (x = c*sin(p*a+b)+d)</span><br /><span style="color: #0000ff;">#define TRAJECTORY_SPECIAL 4 // Special Command to clear/set IO bit</span><br /><span style="color: #0000ff;"> // do the operation</span><br /><span style="color: #0000ff;"> // 0 = clearbit</span><br /><span style="color: #0000ff;"> // 1 = setbit</span><br /><span style="color: #0000ff;"> // 2 = wait for bit low</span><br /><span style="color: #0000ff;"> // 3 = wait for bit high</span><br /><span style="color: #0000ff;"> // 4 = beginning of Rapid</span><br /><span style="color: #0000ff;"> // 5 = end of Rapid</span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;"> // param 0 = bit number</span>
<br />#define TRAJECTORY_EXPONENTIAL 5 // independent axis (exponentially approach Dest a=Ratio per tick, b=Dest)
#define LAST_MOTION_JOG 0 // type of last independent motion was a jog<br /><span style="color: #define LAST_MOTION_MOVE 1 // type of last independent motion was a move<br /0000ff;">#define LAST_MOTION_MULTI 2 TRAJECTORY_EXPONENTIAL 5 // type of last independent motion was a multi axis move (G0 typeexponentially approach Dest a=Ratio per tick, b=Dest)<br /span>#define LAST_MOTION_EXP 3 // type of last independent motion was an exponential
# <br /span style="color: #0000ff;">typedef struct define LAST_MOTION_JOG 0 // linear (only c and d are used),or sine equationtype of last independent motion was a jog<br /span>{ <br /> double a; <br /> double bspan style="color: #0000ff; ">#define LAST_MOTION_MOVE 1 // type of last independent motion was a move<br /span> double c; <br /> double d<span style="color: #0000ff; ">#define LAST_MOTION_MULTI 2 // always t^0 constant coefficient type of last independent motion was a multi axis move (starting positionG0 type)</span><br />} TRIP_CIRCLE_LINEAR<span style="color: #0000ff;">#define LAST_MOTION_EXP 3 // type of last independent motion was an exponential</span>
<br /><span style="color: #0000ff;">typedef struct // linear (only c and d are used),or sine equation</span><br /><span style="color: #0000ff;">{ </span><br /><span style="color: #0000ff;"> double a; </span><br /><span style="color: #0000ff;"> double b; </span><br /><span style="color: #0000ff;"> double c; </span><br /><span style="color: #0000ff;"> double d; // always t^0 constant coefficient (starting position)</span><br /><span style="color: #0000ff;">} TRIP_LINEARTRIP_CIRCLE_LINEAR;</span>
//<br /span style="color: #0000ff;">typedef struct // Motion structure for a coordinate systemlinear (only c and d are used)<br /span>//<br />// 3rd order polynomial for the parametric parameter <br span style="color: #0000ff;">{ </span>//<br />// defines a parametric parameter p that varies from 0-<span style="color: #0000ff;">1 over the double c; <br /span>// segment of motion as a function of time. All the associated axes <br /><span style="color: #0000ff;"> double d; // derive their always t^0 constant coefficient (starting position from this (either circular or linear) </span><br /><span style="color: #0000ff;">} TRIP_LINEAR;<// using either a circular formula or linear formulaspan>
typedef struct <br span style="color: #0000ff;">//>{ <br /span> char trajectory_mode; // Off, circular, or linear<br /> unsigned char x_axis<span style="color: #0000ff; ">// associated x axis / or special command Motion structure for a coordinate system<br /span> unsigned char y_axis; // associated y axis<br /> unsigned char z_axis<span style="color: #0000ff; ">// associated z axis<br /span> unsigned char a_axis; // associated a axis<br /> unsigned char b_axis<span style="color: #0000ff; ">// associated b axis3rd order polynomial for the parametric parameter <br /span> unsigned char c_axis; // associated c axis<br /> unsigned char u_axis<span style="color: #0000ff; ">// associated u axis<br /span> unsigned char v_axis; // associated v axis<br /> short int special_param<span style="color: #0000ff; ">// special param defines a parametric parameter p that varies from 0->1 over the<br /span> double t; // time duration (in sec) of trip state<br /> double a<span style="color: #0000ff; ">// t^3 coefficient (Jerk)segment of motion as a function of time. All the associated axes <br /span> double b; // t^2 coefficient (initial acceleration)<br /> double c<span style="color: #0000ff; ">// t^1 coefficient derive their position from this (initial velocityeither circular or linear)<br /span> double d; // t^0 constant coefficient (starting position) <br /> TRIP_CIRCLE_LINEAR X,Y;<br /> TRIP_LINEAR Z,A,B,C,U,Vspan style="color: #0000ff;">// using either a circular formula or linear formula<br /span>} PARAMETRIC_COEFF;
<span style="color: #0000ff;">typedef struct </span><br /><span style="color: #0000ff;">{ </span><br /><span style="color: #0000ff;"> char trajectory_mode; // Off, circular, or linear</span><br /><span style="color: #0000ff;"> unsigned char x_axis; // associated x axis / or special command </span><br /><span style="color: #0000ff;"> unsigned char y_axis; // associated y axis</span><br /><span style="color: #0000ff;"> unsigned char z_axis; // associated z axis</span><br /><span style="color: #0000ff;"> unsigned char a_axis; // associated a axis</span><br /><span style="color: #0000ff;"> unsigned char b_axis; // associated b axis</span><br /><span style="color: #0000ff;"> unsigned char c_axis; // associated c axis</span><br /><span style="color: #0000ff;"> unsigned char u_axis; // associated u axis</span><br /><span style="color: #0000ff;"> unsigned char v_axis; // associated v axis</span><br /><span style="color: #0000ff;"> short int special_param; // special param 0</span><br /><span style="color: #0000ff;"> double t; // time duration (in sec) of trip state</span><br /><span style="color: #0000ff;"> double a; // t^3 coefficient (Jerk)</span><br /><span style="color: #0000ff;"> double b; // t^2 coefficient (initial acceleration)</span><br /><span style="color: #0000ff;"> double c; // t^1 coefficient (initial velocity)</span><br /><span style="color: #0000ff;"> double d; // t^0 constant coefficient (starting position) </span><br /><span style="color: #0000ff;"> TRIP_CIRCLE_LINEAR X,Y;</span><br /><span style="color: #0000ff;"> TRIP_LINEAR Z,A,B,C,U,V;</span><br /><span style="color: #0000ff;">} PARAMETRIC_COEFF;</span>
<br />typedef struct // 3rd order polynomial for a single trip state<br />{ <br /> int trajectory_mode;<br /> double t; // time duration (in sec) of trip state<br /> double a; // t^3 coefficient (Jerk)<br /> double b; // t^2 coefficient (initial acceleration)<br /> double c; // t^1 coefficient (initial velocity)<br /> double d; // t^0 constant coefficient (starting position)<br />} TRIP_COEFF;<br /> <br />typedef struct // 2nd order IIR Filter<br />{<br /> float A1; // output coefficient Z-1<br /> float A2; // output coefficient Z-2<br /> float B0; // input coefficient Z-0 <br /> float B1; // input coefficient Z-1<br /> float B2; // input coefficient Z-2<br /> float d0,d1; // delay values<br />} IIR;
<br /><span style="color: #0000ff;">typedef struct / MOTION TRAJECTORY STRUCTURES/ 3rd order polynomial for a single trip state</span><br /><span style="color: #0000ff;">{ </span><br /><span style="color: #0000ff;"> int trajectory_mode;</span><br />extern <span style="color: #0000ff;"> double CS0_tt; // Current Coordinated Motion Segment Timestime duration (in sec) of trip state</span><br />extern <span style="color: #0000ff;"> double CS0_TimeExecuteda; // Sum of all previous Coordinated Motion Segments Executedt^3 coefficient (Jerk)</span><br />extern <span style="color: #0000ff;"> double CS0_TimeDownloadedb; // Sum of all Coord Motion Segments downloaded from Hostt^2 coefficient (initial acceleration)</span><br />extern double CS0_TimeLost<span style="color: #0000ff;"> double c; // Sum of all Coord Motion Segments downloaded from Host that have been discarded t^1 coefficient (buffer wrapinitial velocity)</span><br />extern <span style="color: #0000ff;"> double CS0_TimeBased; // how much coordinated motion is advanced each tickt^0 constant coefficient (starting position)</span><br />extern double CS0_TimeBaseDelta<span style="color: #0000ff; ">} TRIP_COEFF;</span><br / max amount coordinated motion time base is changed per tick><span style="color: #0000ff;"> </span><br />extern <span style="color: #0000ff;">typedef struct // 2nd order IIR Filter</span><br /><span style="color: #0000ff;">{</span><br /><span style="color: #0000ff;"> float CS0_DecelTimeA1; // output coefficient Z-1</span><br /><span style="color: #0000ff;"> float A2; // how long to take to stop the coordinated motion (computed by StopMotion)output coefficient Z-2</span><br />extern double CS0_TimeBaseDesired<span style="color: #0000ff; "> float B0; // Last Desired rateinput coefficient Z-of0 </span><br /><span style="color: #0000ff;"> float B1; // input coefficient Z-time (TIMEBASE 1</span><br /><span style= real time)"color: #0000ff;"> float B2; // input coefficient Z-2</span><br /><span style="color: #0000ff;"> float d0,d1; // delay values</span><br /><span style="color: #0000ff;">} IIR;</span>
<span style="color: #0000ff;">// MOTION TRAJECTORY STRUCTURES</span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">extern BOOL CS0_DoingRapiddouble CS0_t; // Flag indicating Rapid in Progress so use normal Time Base ignoring FRO Current Coordinated Motion Segment Times</span><br /><span style="color: #0000ff;">extern double CS0_TimeExecuted; // Sum of all previous Coordinated Motion Segments Executed</span><br /><span style="color: #0000ff;">extern double CS0_TimeDownloaded; // Sum of all Coord Motion Segments downloaded from Host</span><br /><span style="color: #0000ff;">extern double CS0_TimeLost; // Sum of all Coord Motion Segments downloaded from Host that have been discarded (except for FeedHoldbuffer wrap) </span><br /><span style="color: #0000ff;">extern BOOL CS0_Flusheddouble CS0_TimeBase; // Coordinated how much coordinated motion Terminated so no longer necessary to worry about starvation is advanced each tick</span><br /><span style="color: #0000ff;">extern BOOL CS0_HoldAtEnddouble CS0_TimeBaseDelta; // Coordinated max amount coordinated motion time base is changed per tick</span><br /><span style="color: #0000ff;">extern float CS0_DecelTime; // how long to not Terminate but rather Hold when reaching end take to stop the coordinated motion (computed by StopMotion)</span><br /><span style="color: #0000ff;">extern double CS0_TimeBaseDesired; // Last Desired rate-of buffer -time (TIMEBASE = real time)</span>
<span style="color: #0000ff;">extern float CS0_NomDecel2TB2BOOL CS0_DoingRapid; // Nominal Decel Flag indicating Rapid in Progress so use normal Time/Base ignoring FRO (2 TIMEBASE^2except for FeedHold) </span><br /><span style= Factor "color: #0000ff;">extern BOOL CS0_Flushed; // Coordinated motion Terminated so no longer necessary to relate buffer time to TimeBase worry about starvation </span><br /><span style="color: #0000ff;">extern BOOL CS0_HoldAtEnd; // Coordinated motion to be able to stopnot Terminate but rather Hold when reaching end of buffer </span>
extern int CS0_StoppingState; // emergency stop in progress, 0 <span style= not stopping, 1=stopping coord motion, 2=stopping indep, 3=fully stopped, 4=ind stopped<br />extern PARAMETRIC_COEFF *CoordSystem0"color: #0000ff; // current pointer into Coordinated Motion<br /">extern PARAMETRIC_COEFF *LastCoordSystem0float CS0_NomDecel2TB2;<br />extern int ParametricIndex; /Nominal Decel Time/ Index of where (2 TIMEBASE^2) = Factor to put next downloaded Coord Motion Segment or command<br />extern BOOL ParametricIndexWrapped; // Indicates that Coord Motion Buffer has wrapped and additional segments will cause segments relate buffer time to TimeBase to be lost<br />extern PARAMETRIC_COEFF *ParametricCoeffs; // Points able to beginning of Coord Motion Bufferstop<br /span>extern PARAMETRIC_COEFF *ParametricCoeffsEnd; // Points to End+1 of Allocated Coord Motion Buffer (MAX_SEGMENTS)<br />extern PARAMETRIC_COEFF *LastCoordSystem0; // Pointer to last Segment executed when finished<br />extern PARAMETRIC_COEFF *LastValidTrajSegment; // Last Segment actually Executed
void StopCoordinatedMotion(void)<span style="color: #0000ff; ">extern int CS0_StoppingState; // bring any coordinated motion to a emergency stop ASAPin progress, 0 = not stopping, 1=stopping coord motion, 2=stopping indep, 3=fully stopped, 4=ind stopped<br /span>void ResumeCoordinatedMotion(void); // resume coordinated/Indep motion after an emergency stop<br />void ClearStopImmediately(void)<span style="color: #0000ff;">extern PARAMETRIC_COEFF *CoordSystem0; // Clear Stop Condition without resumingcurrent pointer into Coordinated Motion<br /span>void UpdateStoppingState(void); // Update Stopping Status (only required for indep stopping)<br />float GetNominalFROChangeTime(void)<span style="color: #0000ff;">extern PARAMETRIC_COEFF *LastCoordSystem0;<// computed time to change from FRO 1.0 to 0.0 for all defined CoordSystem Axes and their specified Vel, Accel, jerkspan><br />void SetFRO(float FRO)<span style="color: #0000ff; ">extern int ParametricIndex; // change from current Index of where to the specified FRO (FRO=1.0=Realtime)using a nominal rate based on computed time to change from 1.0 to 0.0put next downloaded Coord Motion Segment or command<br /span>void SetRapidFRO(float FRO); // change from current to the specified Rapid FRO (FRO=1.0=Realtime)using a nominal rate based on computed time to change from 1.0 to 0.0<br />void SetFROTemp(float FRO)<span style="color: #0000ff; ">extern BOOL ParametricIndexWrapped; // Temporarily change from current Indicates that Coord Motion Buffer has wrapped and additional segments will cause segments to the specified FRO using a nominal rate, override FeedHold, don't save as LastFRO be lost</span><br />void SetFROwRate(float FRO, float DecelTime)<span style="color: #0000ff; ">extern PARAMETRIC_COEFF *ParametricCoeffs; // change from current Points to the specified FRO (FRO=1.0=Realtime)using a rate based on caller specified time to change from 1.0 to 0.0beginning of Coord Motion Buffer</span><br />void SetRapidFROwRate(float FRO, float DecelTime)<span style="color: #0000ff; ">extern PARAMETRIC_COEFF *ParametricCoeffsEnd; // change from current Points to the specified Rapid FRO End+1 of Allocated Coord Motion Buffer (FRO=1.0=RealtimeMAX_SEGMENTS)using a rate based on caller specified time to change from 1.0 to 0.0</span><br />void SetFROwRateTemp(float FRO, float DecelTime)<span style="color: #0000ff; ">extern PARAMETRIC_COEFF *LastCoordSystem0; // Temporarily change from current Pointer to the specified FRO using a rate based on caller specified time, override FeedHold, don't save as LastFROlast Segment executed when finished</span><br /><span style="color: #0000ff;">extern float CS0_LastFROPARAMETRIC_COEFF *LastValidTrajSegment; // Last Desired FRO (used for Resume after FeedHold or for changes in FRO while in FeedHold) Segment actually Executed<br /span>extern float CS0_LastRapidFRO; // Last Desired FRO (used for Resume after FeedHold during Rapid)
<span style="color: #0000ff;">void StopCoordinatedMotion(void); // Called after adding something bring any coordinated motion to the Cood Motion Buffer.a emergency stop ASAP</span><br /><span style="color: #0000ff;">void ResumeCoordinatedMotion(void); Increments the Coord Motion Buffer pointer // resume coordinated/Indep motion after an emergency stop</span><br /><span style="color: #0000ff;">void ClearStopImmediately(void); // while keeping track of how much time is currently in the buffer Clear Stop Condition without resuming</span><br /><span style="color: #0000ff;">void UpdateStoppingState(CS0_TimeDownloadedvoid); // Update Stopping Status (only required for indep stopping)</span><br /><span style="color: #0000ff;">float GetNominalFROChangeTime(void);// computed time to change from FRO 1.0 to 0.0 for all defined CoordSystem Axes and their specified Vel, also how much Accel, jerk</span><br /><span style="color: #0000ff;">void SetFRO(float FRO); // was over written due change from current to buffer wrapping the specified FRO (CS0_TimeLostFRO=1.0=Realtime) using a nominal rate based on computed time to be able change from 1.0 to 0.0</span><br /><span style="color: #0000ff;">void SetRapidFRO(float FRO); // change from current to determine the extent that it is specified Rapid FRO (FRO=1.0=Realtime)using a nominal rate based on computed time to change from 1.0 to 0.0</span><br /><span style="color: #0000ff;">void SetFROTemp(float FRO); // possible Temporarily change from current to reversethe specified FRO using a nominal rate, and keep override FeedHold, don't save as LastFRO </span><br /><span style="color: #0000ff;">void SetFROwRate(float FRO, float DecelTime); // change from current to the buffer terminated with TRAJECTORY_OFFspecified FRO (FRO=1.0=Realtime)using a rate based on caller specified time to change from 1.0 to 0.0</span><br /><span style="color: #0000ff;">void IncParametricIndexSetRapidFROwRate(float FRO, float DecelTime); // change from current to the specified Rapid FRO (FRO=1.0=Realtime)using a rate based on caller specified time to change from 1.0 to 0.0</span><br /><span style="color: #0000ff;">voidSetFROwRateTemp(float FRO, float DecelTime);// Temporarily change from current to the specified FRO using a rate based on caller specified time, override FeedHold, don't save as LastFRO</span><br /><span style="color: #0000ff;">extern float CS0_LastFRO; // Last Desired FRO (used for Resume after FeedHold or for changes in FRO while in FeedHold) </span><br /><span style="color: #0000ff;">extern float CS0_LastRapidFRO; // Last Desired FRO (used for Resume after FeedHold during Rapid)</span>
<span style="color: #0000ff;">// Called after adding something to the Cood Motion Buffer. Increments the Coord Motion Buffer pointer </span><br /><span style="color: #define MAX_TRIP 20 0000ff;">// max trip states for individual axis moveswhile keeping track of how much time is currently in the buffer (CS0_TimeDownloaded), also how much </span><br />extern TRIP_COEFF TripCoeffs[N_CHANNELS][MAX_TRIP]<span style="color: #0000ff; ">// Trip Coeff lists for each channelwas over written due to buffer wrapping (CS0_TimeLost) to be able to determine the extent that it is </span><br /><span style="color: #0000ff;">// possible to reverse, and keep the buffer terminated with TRAJECTORY_OFF</span><br /><span style="color: #0000ff;">void IncParametricIndex(void);</span>
<br /><span style="color: #0000ff;">#define MAX_TRIP 20 / Limit Switch Options/ max trip states for individual axis moves</span><br /><span style="color: #0000ff;">extern TRIP_COEFF TripCoeffs[N_CHANNELS][MAX_TRIP]; // Trip Coeff lists for each channel</span>
// Bit 0 1=Stop Motor on Neg Limit, 0=Ignore Neg limit<br />// Bit 1 1span style=Stop Motor on Pos Limit, 0=Ignore Pos limit<br /"color: #0000ff;">// Bit 2 Neg Limit Polarity 0=stop on high, 1=stop on lowSwitch Options<br /span>// Bit 3 Pos Limit Polarity 0=stop on high, 1=stop on low<br />//<br />// Bits 4-7 Action - 0 Kill Motor Drive<br />// 1 Disallow drive in direction of limit<br />// 2 Stop movement<br />//<br />// Bit 8=use Extended Limit Bit Numbers (LimitNegSwitchBit,LimitPosSwitchBit)<br />//<br />// (for legacy support allow packed 8-bit numbers)<br />// Bits 16-23 Neg Limit I/O Bit number<br />// Bits 24-31 Pos Limit I/O Bit number
<span style="color: #0000ff;">// Bit 0 1=Stop Motor on Neg Limit, 0=Ignore Neg limit</span><br /><span style="color: #0000ff;">// Bit 1 1=Stop Motor on Pos Limit, 0=Ignore Pos limit</span><br /><span style="color: #0000ff;">// Bit 2 Neg Limit Polarity 0=stop on high, 1=stop on low</span><br /><span style="color: #0000ff;">// Bit 3 Pos Limit Polarity 0=stop on high, 1=stop on low</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// Bits 4-7 Action - 0 Kill Motor Drive</span><br /><span style="color: #0000ff;">// 1 Disallow drive in direction of limit</span><br /><span style="color: #0000ff;">// 2 Stop movement</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// Bit 8=use Extended Limit Bit Numbers (LimitNegSwitchBit,LimitPosSwitchBit)</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// (for legacy support allow packed 8-bit numbers)</span><br /><span style="color: #0000ff;">// Bits 16-23 Neg Limit I/O Bit number</span><br /><span style="color: #0000ff;">// Bits 24-31 Pos Limit I/O Bit number</span>
<br />// M A I N S T R U C T U R E T H A T D E F I N E S A N A X I S
typedef struct<br />{ <br /> int ChanNumber; // channel number 0-3<br /> int Enable; // enables feedback<br /> int InputMode; // sets position input mode (See Axis Input Modes)<br /> int OutputMode; // sets servo/motor mode (See Axis Output Modes)<br /> int LimitSwitchOptions; // see above for description<br /> int LimitSwitchNegBit; // Neg Limit I/O Bit number<br /> int LimitSwitchPosBit; // Pos Limit I/O Bit number<br /> int MasterAxis; // -1 if none, else master axis channel to slave to<br /> double SlaveGain; // Multiplicative Factor for slave motion <br /> double MaxFollowingError; // Kill motor if error exceeds this value<br /> double LastFollowingError; // Last Measured Following Error<br /> double t; // current time in secs within the trip state<br /> double Dest; // current dest position for servo<br /> double UnfilteredDest; // unfiltered current dest position for servo (before CM smoothing)<br /> double DestOffset; // Additional offset to position (used by Injection)<br /> float Vel; // max velocity for the move trajectory<br /> float Accel; // max Acceleration for the move trajectory<br /> float Jerk; // max Jerk (rate of change of Accel) for the move<br /> float FFAccel; // Acceleration feed forward<br /> float FFVel; // Velocity feed forward<br /> double Position; // encoder, ADC, Resolver, reading<br /> double invDistPerCycle; // for stepper distance for one complete cycle (4 full steps)<br /> // for brushless 3-4 phase encoder counts for one complete cycle<br /> // (saved as reciprical for speed) <br /> float StepperAmplitude; // Microstepper Amplitude in PWM counts to apply (moving slow, without lead comp)<br /> float Output; // Value output to PWM or DAC or CL Stepper offset <br /> float prev_output; // previous Output so Slave can track Master when in CL Stepper <br /> float Lead; // Lead compensation to correct for step motor inductance<br /> TRIP_COEFF *pcoeff; // pointer to coeff that interrupt routine uses, NULL if done <br /> double last_position; // last measured error<br /> double last_dest; // last destination from beginning of prev servo interrupt<br /> double prev_dest; // prev destination from end of prev servo interrupt (will incl User changes to Dest)<br /> int LastNonZeroDir; // Last direction we actually moved some amount(+1span style=Positive, 0=undefined, -1=negative)<br /> int DirectionOfMotion"color: #0000ff; // Dest change was in this direction (+1=Positive, 0=none, -1=negative)<br /"> float last_vel; // last destination velocity<br /> float x1last,x2last; // used with lead compensation <br /> int OutputChan0,OutputChan1; // pwm or DAC channels to use <br /> int InputChan0,InputChan1; // Encoder or ADC channels to use <br /> float InputOffset0,InputGain0; // offsets and gains for Resolver Input 0,1 (x'=ax+b)<br /> float InputOffset1,InputGain1; // or for ADC, or (InputGain0=-1 reverses encoder)<br /> float OutputGain; // Scale or Reverse Output Magnitude or Direction<br /> float OutputOffset; // Offset the output<br /> float CommutationOffset; // 3 or 4 phase commutation offset, PhaseA = sin((Position+CommutationOffset)*invDistPerCycle)<br /> float last_theta; // last resolver theta reading<br /> float theta_correction; // resolver correction offset to correct for nonlinearities<br /> signed char last_enc; // last fpga encoder reading<br /> float P,M A I,N S T R U C T U R E T H A T D; // pid gain valuesE F I N E S A N A X I S<br /span> float MaxI; // max integrator windup<br /> float MaxErr; // error saturates at this value<br /> float integrator; // current integrator vlue<br /> float MaxOutput; // max allowed servo output<br /> float DeadBandRange; // Range about zero where gain change occurs<br /> float DeadBandGain; // Additional gain within DeadBand Range<br /> int LastMotionType; // Type of last move - used in Immediate Stop/Resume<br /> double LastMotionDest; // Where last move was to go - used in Immediate Stop/Resume<br /> float ExpMotionVc; // Velocity point on exp curve where Max Accel is obtained<br /> float ExpMotionXc; // Distance point on exponential curve where Max Accel is obtained<br /> float SoftLimitNeg; // Negative Soft Limit (counts)<br /> float SoftLimitPos; // Positive Soft Limit (counts)<br /> int BacklashMode; // Type of correction: Currently only BACKLASH_OFF, BACKLASH_LINEAR<br /> float BacklashAmount; // Amount of Backlash to be applied<br /> float BacklashRate; // Rate Backlash shoule be applied, counts/sec<br /> int BacklashDirection; // Last non zero direction moved<br /> float PrevBacklashDest; // Prev Destination where backlash was determined to allow small hysteresis<br /> float Backlash; // current amount of compensation being applied
<span style="color: #0000ff;">typedef struct</span><br /><span style="color: #0000ff;">{ </span><br /><span style="color: #0000ff;"> int ChanNumber; // channel number 0-3</span><br /><span style="color: #0000ff;"> int Enable; // enables feedback</span><br /><span style="color: #0000ff;"> int InputMode; // sets position input mode (See Axis Input Modes)</span><br /><span style="color: #0000ff;"> int OutputMode; // sets servo/motor mode (See Axis Output Modes)</span><br /><span style="color: #0000ff;"> int LimitSwitchOptions; // see above for description</span><br /><span style="color: #0000ff;"> int LimitSwitchNegBit; // Neg Limit I/O Bit number</span><br /><span style="color: #0000ff;"> int LimitSwitchPosBit; // Pos Limit I/O Bit number</span><br /><span style="color: #0000ff;"> int MasterAxis; // -1 if none, else master axis channel to slave to</span><br /><span style="color: #0000ff;"> double SlaveGain; // Multiplicative Factor for slave motion </span><br /><span style="color: #0000ff;"> double MaxFollowingError; // Kill motor if error exceeds this value</span><br /><span style="color: #0000ff;"> double LastFollowingError; // Last Measured Following Error</span><br /><span style="color: #0000ff;"> double t; // current time in secs within the trip state</span><br /><span style="color: #0000ff;"> double Dest; // current dest position for servo</span><br /><span style="color: #0000ff;"> double UnfilteredDest; // unfiltered current dest position for servo (before CM smoothing)</span><br /><span style="color: #0000ff;"> double DestOffset; // Additional offset to position (used by Injection)</span><br /><span style="color: #0000ff;"> float Vel; // max velocity for the move trajectory</span><br /><span style="color: #0000ff;"> float Accel; // max Acceleration for the move trajectory</span><br /><span style="color: #0000ff;"> float Jerk; // max Jerk (rate of change of Accel) for the move</span><br /><span style="color: #0000ff;"> float FFAccel; // Acceleration feed forward</span><br /><span style="color: #0000ff;"> float FFVel; // Velocity feed forward</span><br /><span style="color: #0000ff;"> double Position; // encoder, ADC, Resolver, reading</span><br /><span style="color: #0000ff;"> double invDistPerCycle; // for stepper distance for one complete cycle (4 full steps)</span><br /><span style="color: #0000ff;"> // for brushless 3-4 phase encoder counts for one complete cycle</span><br /><span style="color: #0000ff;"> // (saved as reciprical for speed) </span><br /><span style="color: #0000ff;"> float StepperAmplitude; // Microstepper Amplitude in PWM counts to apply (moving slow, without lead comp)</span><br /><span style="color: #0000ff;"> float Output; // Value output to PWM or DAC or CL Stepper offset </span><br /><span style="color: #0000ff;"> float prev_output; // previous Output so Slave can track Master when in CL Stepper </span><br /><span style="color: #0000ff;"> float Lead; // Lead compensation to correct for step motor inductance</span><br /><span style="color: #0000ff;"> TRIP_COEFF *cpcoeff; // pointer to coeff that interrupt routine uses, NULL if done </span><br /><span style="color: #0000ff;"> double last_position; // last measured error</span><br /><span style="color: #0000ff;"> double last_dest; // last destination from beginning of prev servo interrupt</span><br /><span style="color: #0000ff;"> double prev_dest; // prev destination from end of prev servo interrupt (will incl User changes to Dest)</span><br /><span style="color: #0000ff;"> int LastNonZeroDir; // Last direction we actually moved some amount(+1=Positive, 0=undefined, -1=negative)</span><br /><span style="color: #0000ff;"> int DirectionOfMotion; // Dest change was in this direction (+1=Positive, 0=none, -1=negative)</span><br /><span style="color: #0000ff;"> float last_vel; // last destination velocity</span><br /><span style="color: #0000ff;"> float x1last,x2last; // used with lead compensation </span><br /><span style="color: #0000ff;"> int OutputChan0,OutputChan1; // move profile polynomial coefficients list pwm or DAC channels to use </span><br /><span style="color: #0000ff;"> int InputChan0,InputChan1; // Encoder or ADC channels to use </span><br /><span style="color: #0000ff;"> float InputOffset0,InputGain0; // offsets and gains for Resolver Input 0,1 (up tp MAX_TRIPx'=ax+b)</span><br /><span style="color: #0000ff;"> IIR iir[N_IIR_FILTERS]float InputOffset1,InputGain1; // or for ADC, or (InputGain0=-1 reverses encoder)</span><br /><span style="color: #0000ff;"> float OutputGain; // Scale or Reverse Output Magnitude or Direction</span><br /><span style="color: #0000ff;"> float OutputOffset; // Offset the output</span><br /><span style="color: #0000ff;"> float CommutationOffset; // 3 or 4 phase commutation offset, PhaseA = sin((Position+CommutationOffset)*invDistPerCycle)</span><br /><span style="color: #0000ff;"> float last_theta; // last resolver theta reading</span><br /><span style="color: #0000ff;"> float theta_correction; // several IIR filtersresolver correction offset to correct for nonlinearities</span><br />}CHAN<span style="color: #0000ff;"> signed char last_enc; // last fpga encoder reading</span><br /><span style="color: #0000ff;"> float P,I,D; // pid gain values</span><br /><span style="color: #0000ff;"> float MaxI; // max integrator windup</span><br /><span style="color: #0000ff;"> float MaxErr; // error saturates at this value</span><br /><span style="color: #0000ff;"> float integrator; // current integrator vlue</span><br /><span style="color: #0000ff;"> float MaxOutput; // max allowed servo output</span><br /><span style="color: #0000ff;"> float DeadBandRange; // Range about zero where gain change occurs</span><br /><span style="color: #0000ff;"> float DeadBandGain; // Additional gain within DeadBand Range</span><br /><span style="color: #0000ff;"> int LastMotionType; // Type of last move - used in Immediate Stop/Resume</span><br /><span style="color: #0000ff;"> double LastMotionDest; // Where last move was to go - used in Immediate Stop/Resume</span><br /><span style="color: #0000ff;"> float ExpMotionVc; // Velocity point on exp curve where Max Accel is obtained</span><br /><span style="color: #0000ff;"> float ExpMotionXc; // Distance point on exponential curve where Max Accel is obtained</span><br /><span style="color: #0000ff;"> float SoftLimitNeg; // Negative Soft Limit (counts)</span><br /><span style="color: #0000ff;"> float SoftLimitPos; // Positive Soft Limit (counts)</span><br /><span style="color: #0000ff;"> int BacklashMode; // Type of correction: Currently only BACKLASH_OFF, BACKLASH_LINEAR</span><br /><span style="color: #0000ff;"> float BacklashAmount; // Amount of Backlash to be applied</span><br /><span style="color: #0000ff;"> float BacklashRate; // Rate Backlash shoule be applied, counts/sec</span><br /><span style="color: #0000ff;"> int BacklashDirection; // Last non zero direction moved</span><br /><span style="color: #0000ff;"> float PrevBacklashDest; // Prev Destination where backlash was determined to allow small hysteresis</span><br /><span style="color: #0000ff;"> float Backlash; // current amount of compensation being applied</span>
<span style="color: #0000ff;"> TRIP_COEFF *c; // continuously sent by DMA to DACsmove profile polynomial coefficients list (up tp MAX_TRIP)</span><br />extern short int DAC_Buffer<span style="color: #0000ff;"> IIR iir[N_DACSN_IIR_FILTERS]; // format 12 bits data several IIR filters</span><br />#define DAC(ch, v) DAC_Buffer[ch]<span style=((v-2048)&0xfff) "color: #0000ff;">}CHAN;<// set DAC channel to value (range -2048/+2047)span>
<span style="color: #0000ff;">// continuously sent by DMA to DACs</span><br /><span style="color: #0000ff;">extern short int ADC_BufferInDAC_Buffer[N_ADCSN_DACS]; // format format 12 bits data </span><br /><span style="color: #0000ff;">#define ADCDAC(ch, v) (ADC_BufferInDAC_Buffer[ch]=((v-2048) &0xfff) // return ADC reading of specified set DAC channel to value (range -2048/+2047)extern int ADC_BufferIn[N_ADCS]; /</ format 4-dummy bits 12 bits data 16 dummyspan>
<span style="color: #0000ff;">extern int ADC_BufferInSnapADC_BufferIn[2*N_ADCS_SNAPN_ADCS]; // Snap Amp Current format 12 bits data </span><br /><span style="color: #0000ff;">#define ADC format 16(ch) (ADC_BufferIn[ch]-2048) // return ADC reading of specified channel (range -2048/2047)extern int ADC_BufferIn[N_ADCS]; // format 4-dummy bits 12 bits data16 dummy</span>
#define FULL_RANGE_CURRENT 4.85f<br />span style="color: #define MeasuredAxisAmps(axis) ((ADC(axis+4)+2048)0000ff;">extern int ADC_BufferInSnap[2*(FULL_RANGE_CURRENTN_ADCS_SNAP]; //4096.0f)) Snap Amp Current ADC format 16-bits data<// returns measured current in an axis (Amperes)span>
# <span style="color: #0000ff;">define FULL_RANGE_CURRENT 4.85f</span><br / On board Power Amp PWM control><span style="color: #0000ff;">#define MeasuredAxisAmps(axis) ((ADC(axis+4)+2048)*(FULL_RANGE_CURRENT/4096.0f)) // returns measured current in an axis (Amperes)</span>
<span style="color: #define MAX_PWMR_VALUE 400 // Max value for PWMs in Recirculate mode<br /0000ff;">void WritePWMR(int ch, int v); // Write to On board Power Amp PWM - Recirculate mode (+ or - power then shorted)control<br /span>#define MAX_PWM_VALUE 230 // Max value for PWMs in antiphase mode<br />void WritePWM(int ch, int v); // Write to PWM - locked anti-phase mode (+ power then - power)
#<span style="color: #0000ff;">define MAX_PWMC_VALUE 1000 MAX_PWMR_VALUE 400 // Max value for PWMs in Current Mode Recirculate mode</span><br /><span style="color: #0000ff;">void WritePWMR(SnapAmps onlyint ch, int v); // Write to PWM - Recirculate mode (+ or - power then shorted)</span><br /><span style="color: #0000ff;">#define MAX_PWM_VALUE 230 // Max value for PWMs in antiphase mode</span><br /><span style="color: #0000ff;">void WritePWMCWritePWM(int ch, int v); // Write to PWM - Current Loop locked anti-phase mode (+ power then - Always optimal decaypower)</span>
extern int SnapAmpPresent# <span style="color: #0000ff; ">define MAX_PWMC_VALUE 1000 // 1 = SnapAmp Present 0= Not PresentMax value for PWMs in Current Mode (SnapAmps only)<br /span>extern int DisableSnapAmpDetectOnBoot; // disables using Bits 12,13, and 15 on JP7 detect AutoDetect SnapAmps<br /><span style="color: #0000ff;">void WriteSnapAmpWritePWMC(int addch, int datav); // write a 16Write to PWM -bit word directly to SnapAmp FPGA Current Loop mode - Always optimal decay<br /span>int ReadSnapAmp(int add); // read a 16-bit word directly from SnapAmp FPGA
<span style="color: #0000ff;">extern int SnapAmpPresent; // 1 = SnapAmp Present 0= Not Present</span><br /><span style="color: #0000ff;">extern int DisableSnapAmpDetectOnBoot; // Digital Idisables using Bits 12,13, and 15 on JP7 detect AutoDetect SnapAmps</O bit PWM control span><br /><span style="color: #0000ff;">void WriteSnapAmp(8 Iint add, int data); /O bits on KFlop JP6 may be pulsed/ write a 16-bit word directly to SnapAmp FPGA </span><br /><span style="color: #0000ff;">int ReadSnapAmp(int add); // read a 16-bit word directly from SnapAmp FPGA</span>
#define N_IO_PWMS 8 // Number of pwms that may be assigned to GPIO bits <br /><span style="color: #define IO_PWMS 0xD0 0000ff;">// FPGA offset to IO Digital I/O bit PWM registers control (2 bytes each - value, enable(bit0)8 I/O bits on KFlop JP6 may be pulsed)<br /span>#define IO_PWMS_PRESCALE 0x2f // FPGA offset to IO PWM Pre-Scale clock divider 0-255, 0 = 16.6MHz, 1=8.33MHz, ...<br />#define IO_PWM_MAX_VALUE 255 // 0 = 0%, 255 = 100 % duty cycle
# <span style="color: #0000ff;">define N_IO_PWMS 8 // addr Number of pwms that may be assigned to rGPIO bits </w encoder noise rejection filter value (0..255), span><br /><span style="color: #0000ff;">#define IO_PWMS 0xD0 // Bit8 switches Encoders Ch4-7 from JP5 FPGA offset to JP6IO PWM registers (2 bytes each - value, enable(bit0))<br /span>// Bit9 switches Encoders Ch0-3 from JP7 to JP4<br /><span style="color: #define ENC_NOISE_FILTER_ADD 0x05 <br /0000ff;">#define ENC_0_3_JP4 0x200IO_PWMS_PRESCALE 0x2f // FPGA offset to IO PWM Pre-Scale clock divider 0-255, 0 = 16.6MHz, 1=8.33MHz, ...<br /span>#define ENC_4_7_JP6 0x100<br /><span style="color: #0000ff;">#define ENC_NOISE_FILTER_DEFAULT_VAL 7 IO_PWM_MAX_VALUE 255 // noise rejection filter default value (100MHz/3/7/2 0 = 2MHz)0%, 255 = 100 % duty cycle</span>
<span style="color: #0000ff;">// addr to r/w encoder noise rejection filter value (0..255), </span><br /><span style="color: #define ENC_NOISE_ERR_ADD 0x08 0000ff;">// encoder sudden change by 2 error addressBit8 switches Encoders Ch4-7 from JP5 to JP6, </span><br /><span style="color: #define ENC_NOISE_ERR_BIT0 4 0000ff;">// encoder sudden change by 2 error bit for encoder 0Bit9 switches Encoders Ch0-3 from JP7 to JP4</span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT1 5 /ENC_NOISE_FILTER_ADD 0x05 </ encoder sudden change by 2 error bit for encoder 1span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT2 6 ENC_0_3_JP4 0x200</span><br / encoder sudden change by 2 error bit for encoder 2><span style="color: #0000ff;">#define ENC_4_7_JP6 0x100</span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT3 ENC_NOISE_FILTER_DEFAULT_VAL 7 // encoder sudden change by 2 error bit for encoder noise rejection filter default value (100MHz/3/7/2 = 2MHz)</span>
<br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_ADD 0x08 // encoder sudden change by 2 error address</span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT0 4 // encoder sudden change by 2 error bit for encoder 0</span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT1 5 // encoder sudden change by 2 error bit for encoder 1</span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT2 6 // encoder sudden change by 2 error bit for encoder 2</span><br /><span style="color: #0000ff;">#define ENC_NOISE_ERR_BIT3 7 // encoder sudden change by 2 error bit for encoder 3</span>
// FPGA Step and Direction Frequency Generators (8) are available<br />//<br />// <br />#define NSTEPDIR 8
// address of 6 bit pulse length 0-63<span style= "color: # 16.666MHz clocks, 0000ff;">// FPGA Step and Direction Frequency Generators (8) are available</span><br /><span style="color: #0000ff;">// bit6 muxes generators 0-3 from JP7 to JP4 and JP6, </span><br /><span style="color: #0000ff;">// bit7 reverses polarity (0=pulses low & Pos Dir high, 1=pulses high & Pos Dir Low)</span><br /><span style="color: #0000ff;">#define STEP_PULSE_LENGTH_ADD 0x06NSTEPDIR 8</span>
<span style="color: #define STEP_PULSE_LENGTH_DEFAULT 32 0000ff;">// default address of 6 bit pulse length of ~ 2us0-63= # 16.666MHz clocks, </span><br /><span style="color: #0000ff;">// bit6 muxes generators 0-3 from JP7 to JP4 and JP6, </span><br /><span style="color: #0000ff;">// bit7 reverses polarity (0=pulses low & Pos Dir high, 1=pulses high & Pos Dir Low)</span><br /><span style="color: #0000ff;">#define STEP_PULSE_LENGTH_ADD 0x06</span>
#define STEP_RATE_ADD 0x3c // write a 32 bit word - Bit31<span style=enable, Bit27=Drive, Bits24-26=chan, 0-23= signed fraction of 16.666MHz<br />"color: #define STEP_POSITION_ADD0 0x40 // read a 16 bit word - step count0 - 9 bits signed position and 7 bits of fraction<br /0000ff;">#define STEP_POSITION_ADD1 0x42 STEP_PULSE_LENGTH_DEFAULT 32 // read a 16 bit word - step count1 - 9 bits signed position and 7 bits default pulse length of fraction~ 2us<br /span>#define STEP_POSITION_ADD2 0x44 // read a 16 bit word - step count2 - 9 bits signed position and 7 bits of fraction<br />#define STEP_POSITION_ADD3 0x46 // read a 16 bit word - step count3 - 9 bits signed position and 7 bits of fraction<br />#define STEP_POSITION_ADD4 0x48 // read a 16 bit word - step count4 - 9 bits signed position and 7 bits of fraction<br />#define STEP_POSITION_ADD5 0x4a // read a 16 bit word - step count5 - 9 bits signed position and 7 bits of fraction<br />#define STEP_POSITION_ADD6 0x4c // read a 16 bit word - step count6 - 9 bits signed position and 7 bits of fraction<br />#define STEP_POSITION_ADD7 0x4e // read a 16 bit word - step count7 - 9 bits signed position and 7 bits of fraction
# <span style="color: #0000ff;">define STEP_RATE_ADD 0x3c // write a 32 bit word - Bit31=enable, Bit27=Drive, Bits24-26=chan, 0-23= signed fraction of 16.666MHz</span><br />extern int KanalogPresent<span style="color: #0000ff; ">#define STEP_POSITION_ADD0 0x40 // 1read a 16 bit word - step count0 - 9 bits signed position and 7 bits of fraction</span><br /><span style=Kanalog Present"color: #0000ff;">#define STEP_POSITION_ADD1 0x42 // read a 16 bit word - step count1 - 9 bits signed position and 7 bits of fraction</span><br />extern int DisableKanalogDetectOnBoot<span style="color: #0000ff; ">#define STEP_POSITION_ADD2 0x44 // disables using Bits read a 16bit word -20 step count2 - 9 bits signed position and 23 on JP4 to detect AutoDetect Kanalog7 bits of fraction</span><br /><span style="color: #0000ff;">#define STEP_POSITION_ADD3 0x46 // read a 16 bit word - step count3 - 9 bits signed position and 7 bits of fraction</span><br /><span style="color: #0000ff;">#define STEP_POSITION_ADD4 0x48 // read a 16 bit word - step count4 - 9 bits signed position and 7 bits of fraction</span><br /><span style="color: #0000ff;">#define STEP_POSITION_ADD5 0x4a // read a 16 bit word - step count5 - 9 bits signed position and 7 bits of fraction</span><br /><span style="color: #0000ff;">#define STEP_POSITION_ADD6 0x4c // read a 16 bit word - step count6 - 9 bits signed position and 7 bits of fraction</span><br /><span style="color: #0000ff;">#define STEP_POSITION_ADD7 0x4e // read a 16 bit word - step count7 - 9 bits signed position and 7 bits of fraction</span>
<br /><span style="color: #0000ff;">extern int KStepPresentKanalogPresent; // 1=KStep Kanalog Present </span><br /><span style="color: #0000ff;">extern int DisableKanalogDetectOnBoot; // disables using Bits 16- set this 20 and 23 on JP4 to mux inputs into virtual bits 48-63detect AutoDetect Kanalog</span>
// Kanalog FPGA Registers for internal use only<br />span style="color: #define KAN_TRIG_REG 0xA0 // triggers a transfer to/from Kanalog, 1-enables Kanalog, 2-enables RS232, 3-both<br /0000ff;">#define KAN_DAC_REGS 0x80 // 8 - 12 bit r/w regs<br />#define KAN_FET_OPTO 0x88 extern int KStepPresent; // 1 =KStep Present - 16 bit 15set this to mux inputs into virtual bits 48-8 FET drivers, 7-0 Opto Outputs63<br /span>#define KAN_GPOUT 0x89 // 1 - 8 bit 7-0 GP 3.3V OUTPUTS<br />#define KAN_ADC_REGS 0x90 // 8 - 12 bit r/w regs<br />#define KAN_OPTOIN_GPIN 0x98 // 1 - 16 bit 15-8 OptoInputs, 7-0 GP 3.3V inputs
<span style="color: #0000ff;">// Kanalog IO Bit numbersFPGA Registers for internal use only</span><br /><span style="color: #0000ff;">#define KAN_INPUTS 128 KAN_TRIG_REG 0xA0 // 16 Bits 128triggers a transfer to/from Kanalog, 1-143 (128enables Kanalog, 2-135 GPINenables RS232, 1363-143 Opto in)both</span><br /><span style="color: #0000ff;">#define KAN_NINPUTS 16 KAN_DAC_REGS 0x80 // 16 Input Bits8 - 12 bit r/w regs</span><br /><span style="color: #0000ff;">#define KAN_OUTPUTS 144 KAN_FET_OPTO 0x88 // 24 Bits 1441 -167 (14416 bit 15-151 Opto out8 FET drivers, 1527-159 FET0 Opto Outputs</Relay Drivers, 160span><br /><span style="color: #0000ff;">#define KAN_GPOUT 0x89 // 1 -167 GPOUT)8 bit 7-0 GP 3.3V OUTPUTS</span><br /><span style="color: #0000ff;">#define KAN_NOUTPUTS 24 KAN_ADC_REGS 0x90 // 24 output Bits8 - 12 bit r/w regs</span><br /><span style="color: #0000ff;">#define KAN_OPTOIN_GPIN 0x98 // 1 - 16 bit 15-8 OptoInputs, 7-0 GP 3.3V inputs</span>
<span style="color: #0000ff;">// Kanalog IO Bit numbers</span><br /><span style="color: #0000ff;">#define KAN_INPUTS 128 // 16 Bits 128-143 (128-135 GPIN, 136-143 Opto in)</span><br /><span style="color: #0000ff;">#define KAN_NINPUTS 16 // 16 Input Bits</span><br /><span style="color: #0000ff;">#define KAN_OUTPUTS 144 // 24 Bits 144-167 (144-151 Opto out, 152-159 FET/Relay Drivers, 160-167 GPOUT)</span><br /><span style="color: #0000ff;">#define KAN_NOUTPUTS 24 // 24 output Bits</span>
// 3 Phase manual control. Angle is specified in cycles.<br />// cycles is a double precision value an may be a very<br />// large number. Only the fractional part will be used. <br />#define MAXV 230.0f // Max allowed 3 phase vector (512/2/sin(60) - EOFF*4)<br />void Write3PH(CHAN *ch0, float v, double angle_in_cycles); // put a voltage v on a 3 Phase motor at specified commutation angle<br />void Write4PH(CHAN *ch0, float v, double angle_in_cycles); // put a voltage v on a 4 Phase motor at specified commutation angle
<span style="color: #0000ff;">// 3 Phase manual control. Angle is specified in cycles.</span><br />extern int LastPWM[N_PWMS+<span style="color: #0000ff;">// cycles is a double precision value an may be a very</span><br /><span style="color: #0000ff;">// large number. Only the fractional part will be used. </span><br /><span style="color: #0000ff;">#define MAXV 230.0f // Max allowed 3 phase vector (512/2/sin(60) - EOFF*N_PWMS_SNAP]4)</span><br /><span style="color: #0000ff;">void Write3PH(CHAN *ch0, float v, double angle_in_cycles); // +put a voltage v on a 3 Phase motor at specified commutation angle</- 255 countsspan><br /><span style="color: #0000ff;">void Write4PH(CHAN *ch0, float v, double angle_in_cycles); // put a voltage v on a 4 Phase motor at specified commutation angle</span>
int ReadADC(int ch); // User Programs should use ADC() command instead<br />void WriteDAC(int ch, <span style="color: #0000ff;">extern int v)LastPWM[N_PWMS+2*N_PWMS_SNAP]; // User Programs should use DAC() command instead+/- 255 counts</span>
<span style="color: #0000ff;">int ReadADC(int ch); // User Programs should use ADC() command instead</span><br /><span style="color: #0000ff;">void WriteDAC(int ch, int v); // User Programs should use DAC() command instead</span>
// S P I N D L E A N D T H R E A D I N G S U P P O R T
<span style="color: #0000ff;">// main Spindle data structure which maintains Spindle S P I N D L E A N D T H R E A D I N G S U P P O R T<br /span>// Position Info and threading control
typedef struct <br />{<br /> double Position; // position in revs<br /> double StartPosition; // position in revs to begin threading<br /> double LastUpdatePosition; // last position in revs where speed was computed<br /> double RevsPerCount; // inverse of counts/rev<br /> double UpdateTick; // which servo tic we should calc RPM<br /> double DeltaTicks; // span style="color: # Servo tics between speed measurement<br /> double AdjTimeFilt0000ff; // Lead Adjusted, filtered, time<br /"> double LastCSTime; // Previous Coordinate System Time<br /> double *pEncoderPos; // pointer to main Spindle Position <br /> double K; // Tau low pass filter coefficient<br /> float TrueSpeedRPS; // last measured speed<br /> float InvBaseSpeedRPS; // Reciprocal of Base speed of data structure which trajectory was plannedmaintains Spindle <br /span> double InvBaseSpeedRPSK1; // InvBaseSpeedRPS * (1-K)<br /> float InvUpdateTime; // Reciprocal of update time to avoid division<br /> float Tauspan style="color: #0000ff; // Time constant for spindle filtering<br /"> int Type; // Type=0 None, Type=1 uses encoder to measure spindle positionPosition Info and threading control<br /span> int ThreadingActive; // True when threading is in progress
} SPINDLE<span style="color: #0000ff;">typedef struct </span><br /><span style="color: #0000ff;">{</span><br /><span style="color: #0000ff;"> double Position; // position in revs</span><br /><span style="color: #0000ff;"> double StartPosition; // position in revs to begin threading</span><br /><span style="color: #0000ff;"> double LastUpdatePosition; // last position in revs where speed was computed</span><br /><span style="color: #0000ff;"> double RevsPerCount; // inverse of counts/rev</span><br /><span style="color: #0000ff;"> double UpdateTick; // which servo tic we should calc RPM</span><br /><span style="color: #0000ff;"> double DeltaTicks; // # Servo tics between speed measurement</span><br /><span style="color: #0000ff;"> double AdjTimeFilt; // Lead Adjusted, filtered, time</span><br /><span style="color: #0000ff;"> double LastCSTime; // Previous Coordinate System Time</span><br /><span style="color: #0000ff;"> double *pEncoderPos; // pointer to Spindle Position </span><br /><span style="color: #0000ff;"> double K; // Tau low pass filter coefficient</span><br /><span style="color: #0000ff;"> float TrueSpeedRPS; // last measured speed</span><br /><span style="color: #0000ff;"> float InvBaseSpeedRPS; // Reciprocal of Base speed of which trajectory was planned</span><br /><span style="color: #0000ff;"> double InvBaseSpeedRPSK1; // InvBaseSpeedRPS * (1-K)</span><br /><span style="color: #0000ff;"> float InvUpdateTime; // Reciprocal of update time to avoid division</span><br /><span style="color: #0000ff;"> float Tau; // Time constant for spindle filtering</span><br /><span style="color: #0000ff;"> int Type; // Type=0 None, Type=1 uses encoder to measure spindle position</span><br /><span style="color: #0000ff;"> int ThreadingActive; // True when threading is in progress</span>
extern <span style="color: #0000ff;">} SPINDLE Spindle;</span>
void ConfigureSpindle(int Type, int Axis, float UpdateTimeSecs, float Tau, float CountsPerRev)<span style="color: #0000ff; // configures for type of ">extern SPINDLE Spindle feedback;<br /span>void TrigThreading(float BaseSpeedRPS); // triggers threading coordinated motion, BaseSpeed is the ideal Spindle speed thatthe motion was planned for
<span style="color: #0000ff;">void ConfigureSpindle(int Type, int Axis, float UpdateTimeSecs, float Tau, float CountsPerRev); // configures for type of Spindle feedback</span><br /><span style="color: #0000ff;">void TrigThreading(float BaseSpeedRPS); // triggers threading coordinated motion, BaseSpeed is the ideal Spindle speed thatthe motion was planned for</span>
// T I M E F U N C T I O N S
double Time_sec()<span style="color: #0000ff;">// returns total time since power up in seconds T I M E F U N C T I O N S</span>
void WaitUntil(<span style="color: #0000ff;">double time_secTime_sec();// wait until a specified returns total timesince power up in seconds</span>
<span style="color: #0000ff;">void Delay_secWaitUntil(double sectime_sec);// Delay wait until a specified time in seconds</span>
// (returns current time)<br /span style="color: #0000ff;">void Delay_sec(double WaitNextTimeSlice(voidsec);// wait until a thread's new Delay time slice beginsin seconds</span>
<span style="color: #0000ff;">// (returns current time)</span><br /><span style="color: #0000ff;">double WaitNextTimeSlice(void);// wait until a thread's new time slice begins</span>
#define TIMER0 (*(volatile int *)0x42000010) // 32 bit raw hardware timer counts at CLOCKFREQ (see PC_DSP.h)
extern volatile double ServoTick; // increments each servo interrupt<br />extern volatile unsigned int LastTimer0; // Last timer value when the ServoTick was incremented
# <span style="color: #0000ff;">define TIMER0 (*(volatile int *)0x42000010) // 32 bit raw hardware timer counts at CLOCKFREQ (see PC_DSP.h) </span>
<br />extern CHAN chan[N_CHANNELS]span style="color: #0000ff; // the axes channel related structures<br /">extern CHAN *ch0volatile double ServoTick; // global pointer to axis 0 increments each servo interrupt<br /span>extern CHAN *ch1; // global pointer to axis 1 <br />extern CHAN *ch2; // global pointer to axis 2 <br />extern CHAN *ch3span style="color: #0000ff; // global pointer to axis 3 <br /">extern CHAN *ch4volatile unsigned int LastTimer0; // global pointer to axis 4 Last timer value when the ServoTick was incremented<br /span>extern CHAN *ch5; // global pointer to axis 5 <br />extern CHAN *ch6; // global pointer to axis 6 <br />extern CHAN *ch7; // global pointer to axis 7
<br />// This status contains the majority of all status<br />// so that it can be uploaded as a bulk transfer<br />extern MAIN_STATUS MainStatus;
<span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">extern CHAN chan[N_CHANNELS]; // the axes channel related structures</span><br /><span style="color: #0000ff;">extern CHAN *ch0; // global pointer to axis 0 </span><br /><span style="color: #0000ff;">extern CHAN *ch1; // global pointer to axis 1 </span><br /><span style="color: #0000ff;">extern CHAN *ch2; // global pointer to axis 2 </span><br /><span style="color: #0000ff;">extern CHAN *ch3; // global pointer to axis 3 </span><br /><span style="color: #0000ff;">extern CHAN *ch4; // global pointer to axis 4 </span><br /><span style="color: #0000ff;">extern CHAN *ch5; // global pointer to axis 5 </span><br /><span style="color: #0000ff;">extern CHAN *ch6; // global pointer to axis 6 </span><br /><span style="color: #0000ff;">extern CHAN *ch7; // global pointer to axis 7</span>
void DisableAxis(int ch)<br /><span style="color: #0000ff; ">// Disable This status contains the Axis, Servo output is set to zeromajority of all status</span><br /><span style="color: #0000ff;">// so that it can be uploaded as a bulk transfer</span><br /><span style="color: #0000ff;">extern MAIN_STATUS MainStatus;</span>
<br />void EnableAxisDest(int ch, double Dest); // enable the Axis and set the destination
<br /span style="color: #0000ff;">void EnableAxisDisableAxis(int ch); // enable Disable the Axis at the current encoder position, Servo output is set to zero</span>
<br />// do this before enabling servo or when<br />// filter coefficients change<br /span style="color: #0000ff;">void ResetFiltersEnableAxisDest(int ch, double Dest); // Resets Filter history to known stateenable the Axis and set the destination</span>
<br /><span style="color: #0000ff;">void ZeroEnableAxis(int ch); // Zero enable the Encoder Position and Current Commanded PositionAxis at the current encoder position</span>
// Basic motion commands to move one axis<br />void Move(int ch, double x)<span style="color: #0000ff; ">// move using absolute coordinatesdo this before enabling servo or when<br /span>void MoveAtVel(int chno, double x, float MaxVel); // move using absolute coordinates and specify the velocity<br />void MoveRel(int ch, double dx)<span style="color: #0000ff; ">// move relative to current destinationfilter coefficients change<br /span>void MoveRelAtVel(int chno, double x, float MaxVel); // move relative to current destinatio and specify the velocity<br /><span style="color: #0000ff;">void JogResetFilters(int ch, double vel); // move continiously at specified velocityResets Filter history to known state<br /span>void MoveExp(int chno, double x, double Tau); // exponentially approach a target at time constant Tau
int CheckDone<br /><span style="color: #0000ff;">void Zero(int ch); // returns 1 if axis is Done, 0 if not, -1 if axis is disabledZero the Encoder Position and Current Commanded Position</span>
<br /span style="color: #0000ff;">// Basic motion commands to move 3 axes one axis</span><br /><span style="color: #0000ff;">void Move(int ch, double x); // move using absolute coordinates</span><br /><span style="color: #0000ff;">void MoveXYZABCMoveAtVel(int chno, double x, double yfloat MaxVel); // move using absolute coordinates and specify the velocity</span><br /><span style="color: #0000ff;">void MoveRel(int ch, double zdx); // move relative to current destination</span><br /><span style="color: #0000ff;">void MoveRelAtVel(int chno, double ax, double b, double cfloat MaxVel); // Moves 6 axes (each axis moves independently) move relative to current destinatio and specify the velocity</span><br />int CheckDoneXYZABC<span style="color: #0000ff;">void Jog(int ch, double vel); // Check if all CS axis have completed move continiously at specified velocity</span><br /><span style="color: #0000ff;">void MoveExp(int chno, returns 1 if all completedouble x, -1 if any is disabled, otherwise 0double Tau); // exponentially approach a target at time constant Tau</span>
<br /span style="color: #0000ff;">int CheckDoneBufCheckDone(int ch); // returns 1 if axis is Done, 0 if not, -1 if any axis in CS is disabled<br /span>int CheckDoneGather();<br />void StartMove(int ch);
void SetupForMove(double From, double To, float MaxVel, CHAN *ch, int CoeffOffset,<br /> int NoJerkControlAtStart, <br /span style="color: #0000ff;"> int NoJerkControlAtEnd,// Basic motion commands to move 3 axes <br /span> int Start,<br /> int *Nstates)<span style="color: #0000ff;">// <br /span> <br /><span style="color: #0000ff;">void SetupForMotionPauseMoveXYZABC(double x,CHAN *chdouble y,int CoeffOffsetdouble z, double timea, double b, double c); // stay still Moves 6 axes (each axis moves independently)</span><br /><span style="color: #0000ff;">int CheckDoneXYZABC(); // Check if all CS axis have completed , returns 1 if all complete, -1 if any is disabled, otherwise 0</span>
// coordinate systems #0 - axis definitions<br />extern int CS0_axis_x<span style="color: #0000ff; // Axis channel number to use as x<br /">extern int CS0_axis_yCheckDoneBuf(); // Axis channel number to use as y returns 1 if Done, 0 if not, -1 if any axis in CS disabled<br /span>extern int CS0_axis_z; // Axis channel number to use as z <br />extern int CS0_axis_a<span style="color: #0000ff; // Axis channel number to use as a <br /">extern int CS0_axis_bCheckDoneGather(); // Axis channel number to use as b <br /span>extern int CS0_axis_c; // Axis channel number to use as c <br />extern <span style="color: #0000ff;">void StartMove(int CS0_axis_uch); // Axis channel number to use as u <br /span>extern int CS0_axis_v; // Axis channel number to use as v
<span style="color: #0000ff;">void DefineCoordSystemSetupForMove(int axisxdouble From, int axisydouble To, int axiszfloat MaxVel, CHAN *ch, int axisa); CoeffOffset,</span><br / define axis chan numbers to use as x><span style="color: #0000ff;"> int NoJerkControlAtStart,y,z,a (set -1 to disable)</span><br />void DefineCoordSystem6(<span style="color: #0000ff;"> int axisxNoJerkControlAtEnd, </span><br /><span style="color: #0000ff;"> int axisy, int axiszStart, </span><br /><span style="color: #0000ff;"> int axisa, int axisb, int axisc*Nstates); </span><br / define axis chan numbers to use as x,y,z,a,b,c (set -1 to disable)><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">void DefineCoordSystem8SetupForMotionPause(int axisxdouble x, int axisyCHAN *ch, int axiszCoeffOffset, int axisa, int axisb, int axisc, int axisu, int axisvdouble time); // define axis chan numbers to use as x,y,z,a,b,c,u,v (set -1 to disable)stay still </span>
<span style="color: #0000ff;">// coordinate systems #0 - axis definitions</span><br /><span style="color: #0000ff;">extern int CS0_axis_x; // A Low Pass filter can be applied Axis channel number to all 8 axes of coordinated motionuse as x</span><br /><span style="color: #0000ff;">extern int CS0_axis_y; // by setting the KLP coefficient. To compute an appropriate coefficientAxis channel number to use as y </span><br /><span style="color: #0000ff;">extern int CS0_axis_z; // from a time constant Tau in seconds Axis channel number to use KLP as z </span><br /><span style= exp(-TIMEBASE"color: #0000ff;">extern int CS0_axis_a; /Tau)/ Axis channel number to use as a </span><br /><span style="color: #0000ff;">extern int CS0_axis_b; // Axis channel number to use as b </span><br /> <span style="color: #0000ff;">extern int CS0_axis_c; // Axis channel number to use as c </span><br /><span style="color: #0000ff;">extern double KLPint CS0_axis_u; // coordinated motion low pass filter coefficientAxis channel number to use as u </span><br /><span style="color: #0000ff;">extern int CS0_axis_v; // Axis channel number to use as v </span>
<span style="color: #0000ff;">void DefineCoordSystem(int axisx, int axisy, int axisz, int axisa); // TauKLP = define axis chan numbers to use as x,y,z,a (set -TIMEBASE1 to disable)</logspan><br /><span style="color: #0000ff;">void DefineCoordSystem6(KLPint axisx, int axisy, int axisz, int axisa, int axisb, int axisc); automatically computed by ExecBuf command// define axis chan numbers to use as x,y,z,a,b,c (set -1 to disable)</span><br />extern float TauKLP<span style="color: #0000ff;">void DefineCoordSystem8(int axisx, int axisy, int axisz, int axisa, int axisb, int axisc, int axisu, int axisv); // "smoothing" related time constant used for End Motiondefine axis chan numbers to use as x,y,z,a,b,c,u,v (set -1 to disable)</span>
extern float SplineTauFactor<br /><span style="color: #0000ff; ">// Final Spline motion A Low Pass filter can be applied to target will have all 8 axes of coordinated motion</span><br /><span style="color: #0000ff;">// by setting the KLP coefficient. To compute an appropriate coefficient</span><br /><span style="color: #0000ff;">// from a time duration of this number of TauKLP constant Tau in seconds use KLP = exp(defaults to 2-TIMEBASE/Tau);</span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">extern double KLP; // coordinated motion low pass filter coefficient</span>
<br /span style="color: #0000ff;">// Stop profile generation<br TauKLP = -TIMEBASE/>// which will stop updating log(freezeKLP) the destination ; automatically computed by ExecBuf command</span><br /><span style="color: #0000ff;">extern float TauKLP; // new commands can then be placed into the queue"smoothing" related time constant used for End Motion</span>
void StopMotion<span style="color: #0000ff;">extern float SplineTauFactor; // Final Spline motion to target will have a time duration of this number of TauKLP (CHAN *chdefaults to 2);</span>
<br /><span style="color: #0000ff;">/ put a trajectory off into the queue / Stop profile generation<br /span> <br />void SetupForMotionEnd<span style="color: #0000ff;">// which will stop updating (CHAN *ch, int CoeffOffsetfreeze) the destination </span><br /><span style="color: #0000ff;">// new commands can then be placed into the queue</span>
<br />// Digital I/O Functions <br /> <br />span style="color: #define BIT_SET 0x100 // rel address in FPGA where bit set ports reside<br /0000ff;">#define BIT_CLR 0x110 // rel address in FPGA where bit clear ports residevoid StopMotion(CHAN *ch);<br /span>#define BIT_DIR 0x120 // rel address in FPGA where bit Direction ports reside<br />#define BIT_READ 0x130 // rel address in FPGA where bit read ports reside
<span style="color: #0000ff;">// Fixed Iput a trajectory off into the queue </O bit definitionsspan><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">void SetupForMotionEnd(CHAN *ch, int CoeffOffset) ;</span>
<br /><span style="color: #0000ff;">// Digital I/O Functions </span><br /><span style="color: #0000ff;"> </span><br /><span style="color: #0000ff;">#define LED0 46 BIT_SET 0x100 // KFLOP LED rel address in FPGA where bit set ports reside</span><br /><span style="color: #0 0000ff;">#define BIT_CLR 0x110 // rel address in FPGA where bit numberclear ports reside</span><br /><span style="color: #0000ff;">#define LED1 47 BIT_DIR 0x120 // KFLOP LED rel address in FPGA where bit Direction ports reside</span><br /><span style="color: #1 0000ff;">#define BIT_READ 0x130 // rel address in FPGA where bit numberread ports reside</span>
<br /span style="color: #0000ff;">// Virtual Fixed I/O bitsbit definitions<br /span>extern int VirtualBits; // Virtual I/O bits simulated in memory, use SetBit/ClearBit/SetStateBit(32-63 to reference)
# <span style="color: #0000ff;">define LED0 46 // Virtual IKFLOP LED #0 bit number</O bits Extended 1024-2047span><br />extern int VirtualBitsEx[N_VIRTUAL_BITS_EX/32]<span style="color: #0000ff; ">#define LED1 47 // 1024 Expanded Virtual Bits (1024-2047)KFLOP LED #1 bit number</span>
extern int BitDirShadow[2]; // direction of all 64 I/O bits<br />extern int BitDirShadowSnap0<span style="color: #0000ff; ">// direction of 14 Snap Amp, 1st board, Virtual I/O bits</span><br /><span style="color: #0000ff;">extern int BitDirShadowSnap1VirtualBits; // direction of 14 Snap Amp, 2nd board, Virtual I/O bitssimulated in memory, use SetBit/ClearBit/SetStateBit(32-63 to reference)</span>
void SetBitDirection(int bit, int dir)<span style="color: #0000ff; ">// define bit as input (0) or output (1) Virtual I/O bits Extended 1024-2047<br /span>int GetBitDirection(int bit); // returns whether bit is defined as input (0) or output (1)<br />void SetBit(int bit)<span style="color: #0000ff; // set a bit high (bit must be defined as an output, see SetBitDirection)<br /">void ClearBit(extern int bit); VirtualBitsEx[N_VIRTUAL_BITS_EX// set a bit low (bit must be defined as an output, see SetBitDirection)<br />void SetStateBit(int bit, int state)32]; // set a bit high or low 1024 Expanded Virtual Bits (bit must be defined as an output, see SetBitDirection1024-2047)<br /span>int ReadBit(int bit); // read the state of an I/O bit
<span style="color: #0000ff;">extern int BitDirShadow[2]; // direction of all 64 I/O bits</span><br /><span style="color: #0000ff;">extern int BitDirShadowSnap0; // Non volatile Flash functionsdirection of 14 Snap Amp, 1st board, I/O bits</span><br /><span style="color: #0000ff;">extern int BitDirShadowSnap1; // direction of 14 Snap Amp, 2nd board, I/O bits</span>
<span style="color: #0000ff;">void SetBitDirection(int bit, int dir); // define FLASH bit as input (0) or output (volatile char *1)0x90000000) <// beginning of FLASH - first 1MByte is for System Usespan><br /><span style="color: #define FLASH_USER 0000ff;">int GetBitDirection((volatile char *int bit)0x90100000) ; // 2nd MegByte returns whether bit is for User usedefined as input (0) or output (1)</span><br /><span style="color: #define FLASH_BLOCK_SIZE 0000ff;">void SetBit(0x10000int bit) ; // FLASH erases in 64KByte Blocks set a bit high (bit must be defined as an output, see SetBitDirection)<br /span>#define IRAM ((volatile char *)0x10000000)<br /><span style="color: #define SDRAM 0000ff;">void ClearBit(int bit); // set a bit low (volatile char *)0x80000000bit must be defined as an output, see SetBitDirection)</span><br />int ProgramFlash<span style="color: #0000ff;">void SetStateBit(volatile char *src, int Lengthbit, volatile char *dest, char *messageint state); //Programs Flash source address of data, length in 16-set a bit high or low (bit words, dest add must be on 64KByte blockdefined as an output, optional \n terminated messagesee SetBitDirection)</span><br />void SetFlashBank<span style="color: #0000ff;">int ReadBit(volatile unsigned short *addint bit); // sets read the currently addressable flash bank (address bits 14-19)state of an I/O bit</span>
<br /><span style="color: #0000ff;">// Non volatile Flash functions</span>
# <span style="color: #0000ff;">define FLASH ((volatile char *)0x90000000) // KONNECT AUX PORT FUNCTIONSbeginning of FLASH - first 1MByte is for System Use<br /span>// <br /><span style="color: #0000ff;">#define FLASH_USER ((volatile char *)0x90100000) // Example:2nd MegByte is for User use<br /span>//<br /><span style="color: #0000ff;">#define FLASH_BLOCK_SIZE (0x10000) // Configure KFLOP to service Konnect 32 Input 16 output IO boardFLASH erases in 64KByte Blocks <br /span>// Board address is 0, <br />// 16 Outputs are mapped to Virtual IO 48-63 <span style="color: #0000ff;">#define IRAM (VirtualBits(volatile char *)0x10000000)<br /span><br // 32 Inputs are mapped to Virtual IO 1024-1055 ><span style="color: #0000ff;">#define SDRAM (VirtualBits[0](volatile char *)0x80000000)<br /span>//<br />// InitAux<span style="color: #0000ff;">int ProgramFlash(volatile char *src, int Length, volatile char *dest, char *message); //Programs Flash source address of data, length in 16-bit words, dest add must be on 64KByte block, optional \n terminated message</span><br /><span style="color: #0000ff;">void SetFlashBank(volatile unsigned short *add); // AddKonnectsets the currently addressable flash bank (0,&VirtualBits,VirtualBitsExaddress bits 14-19);<br /span>//
void InitAux(void); // Initialize the AUX Port KFLOP JP4 or JP6 and clear list of board to be serviced (only one Aux Port may be used at a time)
<span style="color: #0000ff;">// KONNECT AUX PORT FUNCTIONS</span><br /><span style="color: #0000ff;">// </span><br /><span style="color: #0000ff;">// Example:</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// Configure KFLOP to service Konnect 32 Input 16 output IO board</span><br /><span style="color: #0000ff;">// Board addressis 0, address of 32-bit into </span><br /><span style="color: #0000ff;">// 16 Outputs are mapped to get the Output Bits Virtual IO 48-63 (in low 16 bitsVirtualBits), address of where to put </span><br /><span style="color: #0000ff;">// 32 Inputsare mapped to Virtual IO 1024-1055 (VirtualBits[0])</span><br />void AddKonnect<span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// InitAux();</span><br /><span style="color: #0000ff;">// AddKonnect(int BoardAddress0, int *OutputAddress&VirtualBits, int *InputAddressVirtualBitsEx); </span><br / add a Konnect Board to list of AUX1 Port Boards to be serviced><span style="color: #0000ff;">//</span>
// Board address, address of 32-bit into to get the Output Bits (in low 16 bits), address of where to put 32 Inputs<br /span style="color: #0000ff;">void AddKonnect_Aux0InitAux(int BoardAddress, int *OutputAddress, int *InputAddressvoid); // add a Konnect Board to Initialize the AUX Port KFLOP JP4 or JP6 and clear list of AUX0 Port Boards board to be serviced(only one Aux Port may be used at a time)</span>
<br /span style="color: #0000ff;"> <br />// User Print Routines<br />//<br />// sends a string Board address, address of 32-bit into to get the user console Output Bits (in low 16 bits), address of the KMotionwhere to put 32 Inputs<br /span>// application. Because other threads may be sending<br />// characters, the strings are buffered in a queue<br /span style="color: #0000ff;">// and sent by the primary thread as soon as there<br />// is no PC input to process.void AddKonnect(int BoardAddress, int *OutputAddress, int *InputAddress); The string prepends <br />// an escape so the PC application knows for sure<br />// add a Konnect Board to send this list of AUX1 Port Boards to the Console window and not to <br />// process it as a response to a command that may<br />// be in the pipeline.serviced<br /span>//<br />//<br />// normally the routine exits to the caller quickly<br />// unless the queue is full, then it must wait
<span style="color: #define MAX_STRING 128 0000ff;">// Board address, address of 32-bit into to get the Output Bits (in low 16 bits), address of where to put 32 Inputs</span><br /><span style="color: #define MAX_NSTRINGS 256 0000ff;">void AddKonnect_Aux0(int BoardAddress, int *OutputAddress, int *InputAddress); // must add a Konnect Board to list of AUX0 Port Boards to be binary serviced</span>
<br /><span style="color: #0000ff;"> </ Notespan><br /><span style="color: standard C language printf#0000ff;">// User Print Routines</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// sends a string to the user console of the KMotion</span><br /><span style="color: #0000ff;">// application. Because other threads may be sending</span><br /><span style="color: #0000ff;">// characters, the strings are buffered in a queue</span><br /><span style="color: #0000ff;">// and sent by the primary thread as soon as there</span><br /><span style="color: #0000ff;">// is no PC input to process. The string prepends </span><br /><span style="color: #0000ff;">// an escape so the PC application knows for sure</span><br /><span style="color: #0000ff;">// to send this to the Console window and not to </span><br /><span style="color: #0000ff;">// process it as a response to a command that may</span><br /><span style="color: #0000ff;">// be in the pipeline.</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">//</span><br /><span style="color: #0000ff;">// normally the routine exits to the caller quickly</span><br /><span style="color: #0000ff;">// unless the queue is full, then it must wait</span>
int printf(const char *format, ...)# <span style="color: #0000ff; ">define MAX_STRING 128 <// Print formatted string to consolespan><br />int sprintf(char *s, const char *format, ...)<span style="color: #0000ff; ">#define MAX_NSTRINGS 256 // Print formatted string to stringmust be binary </span>
typedef int FILE;<br />FILE *fopen(const char*, const char*); // Open a text file for writing on the PC (2nd param span style= "rtcolor: #0000ff;" or "wt") <br />int fprintf(FILE *f, const char * format, ...); // Print formatted string to the PC's Disk FileNote: standard C language printf<br /span>int fclose(FILE *f); // Close the disk file on the PC
<span style="color: #0000ff;">int Printprintf(const char *sformat, ...); // Print a formatted string to the console window<br /span>int PrintFloat(char *Format, double v); // Print a double using printf format, ex "%8.3f\n"<br />int PrintInt(char *Format, int v)<span style="color: #0000ff; // Print an integer using printf format, ex "result=%4d\n"<br /> <br />int sscanfsprintf(const char *_strs, const char *_fmtformat, ...); //scan Print formatted string and convert to valuesstring</span>
<span style="color: #define MAX_READ_DISK_LENGTH 1024 // max allowed length of disk file line length<br /0000ff;">extern volatile typedef int read_disk_buffer_statusFILE; //status of read disk buffer 1=line available, 2=error, 3=eof <br /span>extern char read_disk_buffer[MAX_READ_DISK_LENGTH+1];<br />char <span style="color: #0000ff;">FILE *fgetsfopen(const char *str, int n, FILE const char*file); //read string from PC disk Open a text file, str=buffer, n=buffer length, f=FILE pointer, returns NULL for writing on errorthe PC (2nd param = "rt" or "wt") </span><br /><span style="color: #0000ff;">int fscanffprintf(FILE *f, const char *format, ...); //read sting from Print formatted string to the PC 's Disk file, convert values, returns number of items convertedFile</span><br /><span style="color: #0000ff;">int feoffclose(FILE *f); // End of file status for Close the disk readingfile on the PC</span>
/*<br /span style="color: #0000ff;"> int Print(char * MessageBox(s) Flags thes can be passed ; // Print a string to the PC to invoke MessageBoxesconsole window<br /span> * for some applications such as KMotionCNC which monitor upload<br /> * status and present message boxes when requested. See the pc-dsp.h<br /span style="color: #0000ff;"> int PrintFloat(char * header for more information<br />Format, double v); * /<br />#define MB_OK 0x00000000LPrint a double using printf format, ex "%8.3f\n"<br /span>#define MB_OKCANCEL 0x00000001L<br />#define MB_ABORTRETRYIGNORE 0x00000002L<br />span style="color: #define MB_YESNOCANCEL 0x00000003L<br /0000ff;">#define MB_YESNO 0x00000004L<br int PrintInt(char *Format, int v); />#define MB_RETRYCANCEL 0x00000005L<br />#define MB_CANCELTRYCONTINUE 0x00000006LPrint an integer using printf format, ex "result=%4d\n"<br /span>#define MB_ICONHAND 0x00000010L<br />#define MB_ICONQUESTION 0x00000020L<br />span style="color: #define MB_ICONEXCLAMATION 0x00000030L<br /0000ff;">#define MB_ICONASTERISK 0x00000040L <br /span>#define MB_APPLMODAL 0x00000000L<br />#define MB_SYSTEMMODAL 0x00001000L<br />span style="color: #define MB_TASKMODAL 0x00002000L<br /0000ff;">#define MB_NOFOCUS 0x00008000L<br int sscanf(const char *_str, const char *_fmt, ...); />#define MB_SETFOREGROUND 0x00010000L<br />#define MB_DEFAULT_DESKTOP_ONLY 0x00020000Lscan string and convert to values<br /span>#define MB_TOPMOST 0x00040000L<br />#define MB_RIGHT 0x00080000L
# <span style="color: #0000ff;">define MAX_READ_DISK_LENGTH 1024 /*/ max allowed length of disk file line length<br /span> * Dialog Box Command IDs<br /> *<span style="color: #0000ff;">extern volatile int read_disk_buffer_status; //status of read disk buffer 1=line available, 2=error, 3=eof </span><br /><span style="color: #define IDOK 0000ff;">extern char read_disk_buffer[MAX_READ_DISK_LENGTH+1];<br /span>#define IDCANCEL 2<br /><span style="color: #define IDABORT 30000ff;">char *fgets(char *str, int n, FILE *file); //read string from PC disk file, str=buffer, n=buffer length, f=FILE pointer, returns NULL on error<br /span>#define IDRETRY 4<br /><span style="color: #define IDIGNORE 50000ff;">int fscanf(FILE *f, const char *format, ...); //read sting from PC Disk file, convert values, returns number of items converted<br /span>#define IDYES 6<br /><span style="color: #define IDNO 70000ff;">int feof(FILE *f); // End of file status for disk reading</span>
<span style="color: #0000ff;">/*</span><br /><span style="color: #0000ff;"> * MessageBox() Flags thes can be passed to the PC to invoke MessageBoxes</span><br /><span style="color: #0000ff;"> * for some applications such as KMotionCNC which monitor upload</span><br /><span style="color: #0000ff;"> * status and present message boxes when requested. See the pc-dsp.h</span><br /><span style="color: #0000ff;"> * header for more information</span><br /><span style="color: #0000ff;"> */</span><br /><span style="color: #0000ff;">#define MB_OK 0x00000000L</span><br /><span style="color: #0000ff;">#define MB_OKCANCEL 0x00000001L</span><br /><span style="color: #0000ff;">#define MB_ABORTRETRYIGNORE 0x00000002L</span><br /><span style="color: #0000ff;">#define MB_YESNOCANCEL 0x00000003L</span><br /><span style="color: #0000ff;">#define MB_YESNO 0x00000004L</span><br /><span style="color: #0000ff;">#define MB_RETRYCANCEL 0x00000005L</span><br /><span style="color: #0000ff;">#define MB_CANCELTRYCONTINUE 0x00000006L</span><br /><span style="color: #0000ff;">#define MB_ICONHAND 0x00000010L</span><br /><span style="color: #0000ff;">#define MB_ICONQUESTION 0x00000020L</span><br /><span style="color: #0000ff;">#define MB_ICONEXCLAMATION 0x00000030L</span><br /><span style="color: #0000ff;">#define MB_ICONASTERISK 0x00000040L</span><br /><span style="color: #0000ff;">#define MB_APPLMODAL 0x00000000L</span><br /><span style="color: #0000ff;">#define MB_SYSTEMMODAL 0x00001000L</span><br /><span style="color: #0000ff;">#define MB_TASKMODAL 0x00002000L</span><br /><span style="color: #0000ff;">#define MB_NOFOCUS 0x00008000L</span><br /><span style="color: #0000ff;">#define MB_SETFOREGROUND 0x00010000L</span><br /><span style="color: #0000ff;">#define MB_DEFAULT_DESKTOP_ONLY 0x00020000L</span><br /><span style="color: #0000ff;">#define MB_TOPMOST 0x00040000L</span><br /><span style="color: #0000ff;">#define MB_RIGHT 0x00080000L</span>
<span style="color: #0000ff;">/*</ Misc routinesspan><br /><span style="color: #0000ff;"> * Dialog Box Command IDs</span><br /><span style="color: #0000ff;"> */</span><br /><span style="color: #0000ff;">#define IDOK 1</span><br /><span style="color: #0000ff;">#define IDCANCEL 2</span><br /><span style="color: #0000ff;">#define IDABORT 3</span><br /><span style="color: #0000ff;">#define IDRETRY 4</span><br /><span style="color: #0000ff;">#define IDIGNORE 5</span><br /><span style="color: #0000ff;">#define IDYES 6</span><br /><span style="color: #0000ff;">#define IDNO 7</span>
void DoResolverInput2(CHAN *chx, float x, float y); // optimized routine to handle sin/cosine resolver input
extern double ResolverFactor<span style="color: #0000ff; ">// defaults to 1000.0Misc routines</TWO_PI converts sine/cosine angle to reported Positionspan>
<br /span style="color: #0000ff;">void DoResolverInput2(CHAN *chx, float x, float y); // M U L T I - T H R E A D S U P P O R Toptimized routine to handle sin/cosine resolver input</span>
<span style="color: #0000ff;">extern double ResolverFactor; // user threads are numbered 1 defaults to 1000.. n0/TWO_PI converts sine/cosine angle to reported Position</span>
void StartThread(int thread); // starts a downloaded program at it's entry point<br />void PauseThread(int thread); // stops a thread from executing<br />int ResumeThread(int thread)span style="color: #0000ff; // resumes a tread after a pause <br /">void ThreadDone(void); // call to terminate current threadM U L T I - T H R E A D S U P P O R T<br /span>extern int CurrentThread; // current thread that is/was executing 0 = Pri 1-7 = User Threads
<span style="color: #0000ff;">// user threads are numbered 1 .. n</span>
<span style="color: #0000ff;">void StartThread(int thread); // A User Program Call Back can be defined to be called every Servo Samplestarts a downloaded program at it's entry point</span><br /><span style="color: #0000ff;">void PauseThread(int thread); // Set to Non-NULL for the the Callback to be made. The Callback Routinestops a thread from executing</span><br /><span style="color: #0000ff;">int ResumeThread(int thread); // must return with resumes a few micro seconds or the system may become unstabletread after a pause </span><br />typedef <span style="color: #0000ff;">void USERCALLBACKThreadDone(void); // call to terminate current thread</span><br /><span style="color: #0000ff;">extern USERCALLBACK *UserCallBackint CurrentThread; // current thread that is/was executing 0 = Pri 1-7 = User Threads</span>
<br />// used to allow mutual exclusive access to a resource<br />// (waits until resource is available, then locks it)<br />// if the thread that locked it is no longer active,<br />// release the lock
<span style="color: #0000ff;">// A User Program Call Back can be defined to be called every Servo Sample</span><br /><span style="color: #0000ff;">// Set to Non-NULL for the the Callback to be made. The Callback Routine</span><br /><span style="color: #0000ff;">// must return with a few micro seconds or the system may become unstable</span><br /><span style="color: #0000ff;">typedef void MutexLockUSERCALLBACK(int *mutexvoid);</span><br />void MutexUnlock(int <span style="color: #0000ff;">extern USERCALLBACK *mutex)UserCallBack;</span>
<br /><span style="color: #0000ff;">/ These routines are written in assembly such that/ used to allow mutual exclusive access to a resource</span><br /><span style="color: #0000ff;">// they are atomic and are un-interruptible by using(waits until resource is available, then locks it)</span><br /><span style="color: #0000ff;">// instructions in delayed branchingif the thread that locked it is no longer active,</span><br /><span style="color: #0000ff;">// release the lock</span>
<span style="color: #0000ff;">void AtomicSetMutexLock(int *p, int maskmutex);<br /span>//{<br />// *p <span style= "color: #0000ff;">void MutexUnlock(int *p | maskmutex);<br /span>//}
void AtomicClear(int *p, int mask);<br /span style="color: #0000ff;">//{These routines are written in assembly such that<br /span><br // *p ><span style= *p & mask"color: #0000ff;">// they are atomic and are un-interruptible by using</span><br /><span style="color: #0000ff;">//}instructions in delayed branching</span>
<span style="color: #0000ff;">void AtomicSet(int *p, int mask);</span><br / test a location and if zero, set><span style="color: #0000ff;">//{</span><br /><span style="color: #0000ff;">// to value. returns the original*p = *p | mask;</span><br /><span style="color: #0000ff;">// value. routine is atomic}</span>
int TestAndSet<span style="color: #0000ff;">void AtomicClear(int *mutexp, int valuemask);</span><br /><span style="color: #0000ff;">//{<br /span>// register result = *mutex;<br /><span style="color: #0000ff;">// if (result= *p =0) *mutex=valuep & mask;<br /span>// return result;<br /><span style="color: #0000ff;">//}</span>
<span style="color: #0000ff;">// test a location and if zero, set</span><br /><span style="color: #0000ff;">// S N A P A M P D E F I N I T I O N Sto value. returns the original</span><br /><span style="color: #0000ff;">// value. routine is atomic</span>
<span style="color: #define KM_SNAP_READ_LOW 0xc0000ff;">int TestAndSet(int *mutex, int value);<br /span>#define KM_SNAP_READ_HI 0xd<br /><span style="color: #define KM_SNAP_READ_EXCEPTION 0x100000ff;">//{<br /span>#define KM_SNAP_CLK_ENA 0x09<br /><span style="color: #define KM_SNAP_SHIFT_BYTE 0x0a0000ff;">// register result = *mutex;<br /span>#define KM_SNAP_WRITE_HIGH_TRIG 0x0b<br /><span style="color: #define KM_SNAP_READ_ADD_TRIG 0x0c0000ff;">// if (result==0) *mutex=value;</span><br /><span style="color: #define KM_SNAP_READ_ADD_BITMAP 0x280000ff;">// return result;</span><br /><span style="color: #0000ff;">// FPGA Registers}</span>
#define SNAP0 0x40 // Base Addresse SNAP AMP #0 <br /><span style="color: #define SNAP1 0x60 0000ff;">// Base Addresse SNAP AMP #1 S N A P A M P D E F I N I T I O N S</span>
# <span style="color: #0000ff;">define KM_SNAP_READ_LOW 0xc</span><br / write addresses><span style="color: #0000ff;">#define KM_SNAP_READ_HI 0xd</span><br /><span style="color: #0000ff;">#define KM_SNAP_READ_EXCEPTION 0x10</span><br /><span style="color: #0000ff;">#define KM_SNAP_CLK_ENA 0x09</span><br /><span style="color: #0000ff;">#define KM_SNAP_SHIFT_BYTE 0x0a</span><br /><span style="color: #0000ff;">#define KM_SNAP_WRITE_HIGH_TRIG 0x0b</span><br /><span style="color: #0000ff;">#define KM_SNAP_READ_ADD_TRIG 0x0c</span><br /><span style="color: #0000ff;">#define KM_SNAP_READ_ADD_BITMAP 0x28</span><br /><span style="color: #0000ff;">// FPGA Registers</span>
#define SNAP_PWMS 0 // (4) 16 bit PWMs <br />#define SNAP_CLR_ENC_ERRS 8 // any write clears all encoder errors<br />#define SNAP_CUR_LOOP_GAINS 9 // (4) 8 bit Current Loop Gains Defaultspan style=16<br />"color: #define SNAP_SET_BIT 17 // (14) GPIO bits<br /0000ff;">#define SNAP_CLR_BIT 18 SNAP0 0x40 // (14) GPIO bits<br />Base Addresse SNAP AMP #define SNAP_DIR_BIT 19 // (14) GPIO bits0 <br /span>#define SNAP_SUPPLY_CLAMP0 20 // 16 bit power supply clamp setting side A<br />#define SNAP_SUPPLY_CLAMP_ENA0 21 // 1 bit power supply clamp enable side A<br />span style="color: #define SNAP_SUPPLY_CLAMP1 22 // 16 bit power supply clamp setting side B<br /0000ff;">#define SNAP_SUPPLY_CLAMP_ENA1 23 SNAP1 0x60 // 1 bit power supply clamp enable side B<br />Base Addresse SNAP AMP #define SNAP_PEAK_CUR_LIMIT0 24 // 4 bits peak current limit side A1 <br /span>#define SNAP_PEAK_CUR_LIMIT1 25 // 4 bits peak current limit side B
<span style="color: #0000ff;">// read write addresses</span>
#<span style="color: #0000ff;">define SNAP_PWMS 0 // (4) 16 bit PWMs </span><br /><span style="color: #0000ff;">#define SNAP_ENC 8 SNAP_CLR_ENC_ERRS 8 // (4) 16 bit Encoders (bit15=error 7-0=data) any write clears all encoder errors</span><br /><span style="color: #0000ff;">#define SNAP_CURRENT_A0 12 SNAP_CUR_LOOP_GAINS 9 // Measured Current Side A Lead A (14bits4)8 bit Current Loop Gains Default=16<br /span>#define SNAP_CURRENT_C0 13 // Measured Current Side A Lead C<br /><span style="color: #0000ff;">#define SNAP_CURRENT_A1 14 SNAP_SET_BIT 17 // Measured Current Side B Lead A(14) GPIO bits<br /span>#define SNAP_CURRENT_C1 15 // Measured Current Side B Lead C<br /><span style="color: #0000ff;">#define SNAP_DIFF_IN 16 SNAP_CLR_BIT 18 // 16 bits (15-8= Diff inputs 7-0=encoder inputs14) GPIO bits</span><br /><span style="color: #0000ff;">#define SNAP_IN_BIT 17 SNAP_DIR_BIT 19 // (14) GPIO bits</span><br /><span style="color: #0000ff;">#define SNAP_SUPPLY_VOLT0 22 SNAP_SUPPLY_CLAMP0 20 // Measured Supply Voltage Side 16 bit power supply clamp setting side A</span><br /><span style="color: #0000ff;">#define SNAP_SUPPLY_VOLT1 23 SNAP_SUPPLY_CLAMP_ENA0 21 // Measured Supply Voltage Side B1 bit power supply clamp enable side A</span><br /><span style="color: #0000ff;">#define SNAP_TEMP0 24 SNAP_SUPPLY_CLAMP1 22 // Measured Temperature Side A16 bit power supply clamp setting side B</span><br /><span style="color: #0000ff;">#define SNAP_TEMP1 25 SNAP_SUPPLY_CLAMP_ENA1 23 // Measured Temperature Side 1 bit power supply clamp enable side B</span><br /><span style="color: #0000ff;">#define SNAP_STATUS 30 SNAP_PEAK_CUR_LIMIT0 24 // Status (FAN,OverTemp1,OverTemp0,OVER_CUR1,OVER_CUR0,Fault)4 bits peak current limit side A</span><br /><span style="color: #0000ff;">#define SNAP_RESET 31 SNAP_PEAK_CUR_LIMIT1 25 // Reset4 bits peak current limit side B</span>
<span style="color: #0000ff;">//RS232 FPGA Register Definitionsread addresses</span>
#<span style="color: #0000ff;">define RS232_STATUS 0xc1 SNAP_PWMS 0 // Status Reg Address(4) 16 bit PWMs </span><br /><span style="color: #0000ff;">#define RS232_DATA 0xc0 SNAP_ENC 8 // 8 (4) 16 bit Encoders (bit15=error 7-0=data read) </write reg addressspan><br /><span style="color: #0000ff;">#define RS232_DATA_READY 0x01 SNAP_CURRENT_A0 12 // Data ready to read status maskMeasured Current Side A Lead A (14bits)</span><br /><span style="color: #0000ff;">#define RS232_TRANSMIT_FULL 0x02SNAP_CURRENT_C0 13 // Transmit buffer full status maskMeasured Current Side A Lead C</span><br /><span style="color: #0000ff;">#define SNAP_CURRENT_A1 14 // Measured Current Side B Lead A</span><br /><span style="color: #0000ff;">#define SNAP_CURRENT_C1 15 // Measured Current Side B Lead C</span><br /><span style="color: #0000ff;">#define SNAP_DIFF_IN 16 // 16 bits (15-8= Diff inputs 7-0=encoder inputs) </span><br /><span style="color: #0000ff;">#define SNAP_IN_BIT 17 // (14) GPIO bits</span><br /><span style="color: #0000ff;">#define SNAP_SUPPLY_VOLT0 22 // Measured Supply Voltage Side A</span><br /><span style="color: #0000ff;">#define SNAP_SUPPLY_VOLT1 23 // Measured Supply Voltage Side B</span><br /><span style="color: #0000ff;">#define SNAP_TEMP0 24 // Measured Temperature Side A</span><br /><span style="color: #0000ff;">#define SNAP_TEMP1 25 // Measured Temperature Side B</span><br /><span style="color: #0000ff;">#define SNAP_STATUS 30 // Status (FAN,OverTemp1,OverTemp0,OVER_CUR1,OVER_CUR0,Fault)</span><br /><span style="color: #0000ff;">#define SNAP_RESET 31 // Reset</span>
#define RS232_BAUD_REG 0xc1 // Set Baud rate 8-bit divisor Reg Address <br />span style="color: #define RS232_BAUD_115200 ((16666666/115200/16)-1)// 8-bit divisor value to set 115200 baud<br /0000ff;">#define RS232_BAUD_57600 ((16666666/57600/16)-1) // 8-bit divisor value to set 57600 baudRS232 FPGA Register Definitions<br /span>#define RS232_BAUD_38400 ((16666666/38400/16)-1) // 8-bit divisor value to set 38400 baud<br />#define RS232_BAUD_19200 ((16666666/19200/16)-1) // 8-bit divisor value to set 19200 baud<br />#define RS232_BAUD_9600 ((16666666/9600/16)-1) // 8-bit divisor value to set 9600 baud<br />#define RS232_BAUD_4800 ((16666666/4800/16)-1) // 8-bit divisor value to set 4800 baud
void InitRS232(int baud)# <span style="color: #0000ff;">define RS232_STATUS 0xc1 // Status Reg Address</span><br />void EnableRS232Cmds(int baud)<span style="color: #0000ff;">#define RS232_DATA 0xc0 // 8 bit data read/write reg address</span><br /><span style="color: #0000ff;">#define RS232_DATA_READY 0x01 // Data ready to read status mask</span><br /><span style="color: #0000ff;">#define RS232_TRANSMIT_FULL 0x02// Transmit buffer full status mask</span>
extern char * volatile pRS232RecIn# <span style="color: #0000ff;">define RS232_BAUD_REG 0xc1 // Set Baud rate 8-bit divisor Reg Address </span><br /><span style="color: #0000ff;">#define RS232_BAUD_115200 ((16666666/115200/ Buffered Receive Pointer Head16)-1)// 8-bit divisor value to set 115200 baud</span><br />extern char *pRS232RecOut<span style="color: #0000ff; ">#define RS232_BAUD_57600 ((16666666/57600/ Buffered Receive Pointer Tail16)-1) // 8-bit divisor value to set 57600 baud</span><br />extern char *pRS232TxIn<span style="color: #0000ff; ">#define RS232_BAUD_38400 ((16666666/38400/ Buffered Transmit Pointer Head16)-1) // 8-bit divisor value to set 38400 baud</span><br />extern char * volatile pRS232TxOut<span style="color: #0000ff;">#define RS232_BAUD_19200 ((16666666/19200/ Buffered Transmit Pointer Tail16)-1) // 8-bit divisor value to set 19200 baud</span><br />extern int DoRS232Cmds<span style="color: #0000ff; ">#define RS232_BAUD_9600 ((16666666/9600/ Enables16)-1) /disables KFLOP Command processor / 8-bit divisor value toset 9600 baud</from RS232span><br /><span style="color: #0000ff;">#define RS232_BAUD_4800 ((16666666/4800/16)-1) // 8-bit divisor value to set 4800 baud</span>
char RS232_GetChar(<span style="color: #0000ff;">voidInitRS232(int baud); <// Get Internally Buffered (1000 chars) RS232 received Data span><br /><span style="color: #0000ff;">void RS232_PutCharEnableRS232Cmds(char cint baud); <// Put Internally Buffered (1000 chars) RS232 transmit Dataspan>
<span style="color: #0000ff;">extern char * volatile pRS232RecIn; // Buffered Receive Pointer Head</span><br /><span style="color: #0000ff;">extern char *pRS232RecOut; // Buffered Receive Pointer Tail</span><br /><span style="color: #0000ff;">extern char *pRS232TxIn; // Buffered Transmit Pointer Head</span><br /><span style="color: #0000ff;">extern char * volatile pRS232TxOut; // Buffered Transmit Pointer Tail</span><br /><span style="color: #0000ff;">extern int DoRS232Cmds; // Enables/disables KFLOP Command processor to/from RS232</span>
<span style="color: #0000ff;">char RS232_GetChar(void); // Get Internally Buffered (1000 chars) RS232 received Data </span><br /><span style="color: #0000ff;">void RS232_PutChar(char c); // Put Internally Buffered (1000 chars) RS232 transmit Data</span> # <span style="color: #0000ff;">endif</span>