....
....
Can I get some help with my, what should be simply, C-Code?
I am trying to write some C-code to change the << DAC(7,speed); >> value "speed" from Positive to Negative and/or Negative to Positive for the M03/M04.
At least what I thought should be simple is not working so well. It would seem the I cannot get the correct sign on the this "speed" value when it is needed base on the M03 and/or the M04.
What I thought should happen is the M03/M04 code would be read first in the "Tool Setup Screen" and then the "S" code from the Spindle.C which I though should setting the "speed" value sign correctly.
But this is not the case.
The NC code I am testing is:
M05
M03S200
M05
M04S200
M05
M30
My Spindle.C is this:
Code:
#include "KMotionDef.h"
#define FACTOR 0.2228 // Factor 0.2228 * Speed from NC code for DAC7
#define SPEEDVAR 99 // global persistant variable to store latest speed
#define STATEVAR 98 // global persistant variable to store latest state (-1=CCW,0=off,1=CW)
main()
{
int speed;
float spd = *(float *)&persist.UserData[9]; // s value from g code
speed = spd * FACTOR; // set dac counts
printf("Spindle Speed = "); //single line comment
printf("%4.4f\n",spd);
printf("Factor Used Spindle Speed = "); //single line comment
printf("%4.4f\n",FACTOR);
// limit min speed
if (speed < 60)
{
speed = 60;
}
// limit max speed
if (speed > 1000)
{
speed = 1000;
}
if (persist.UserData[STATEVAR] == -1) // should be M04
{
DAC(7,-speed);
persist.UserData[SPEEDVAR] = spd;
printf("Spindle Speed = "); //single line comment
printf("%d\n",persist.UserData[SPEEDVAR]);
printf("Print the value for STATEVAR for M4 in Spindle.C = "); //single line comment
printf("%d\n",persist.UserData[STATEVAR]);
printf("\n");
printf("\n");
printf("\n");
}
if (persist.UserData[STATEVAR] == 1) // should be M03
{
DAC(7,speed);
persist.UserData[SPEEDVAR] = spd;
printf("Spindle Speed = "); //single line comment
printf("%d\n",persist.UserData[SPEEDVAR]);
printf("Print the value for STATEVAR for M3 in Spindle.C = "); //single line comment
printf("%d\n",persist.UserData[STATEVAR]);
}
}
My m3.c code is this:
Code:
#include "KMotionDef.h"
// M03 C-Code for Spindle Direction
// Spindle CW Jog function with +/- voltage used for direction
#define SPEEDVAR 99 // global persistant variable to store latest speed
#define STATEVAR 98 // global persistant variable to store latest state (-1=CCW,0=off,1=CW)
// M03 command passes no arguments
// desired speed is read from user variable SPEEDVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed
main()
{
persist.UserData[STATEVAR] = 1;
// SetBit(151); // spindle on; when OPTO Out #7 is used to signal spindle direction
SetBit(152); // FET Driver 0 on (Relay), Spindle will go on thru Interlock
printf("Print the value for STATEVAR from M3.C = "); //single line comment
printf("%d\n",persist.UserData[STATEVAR]);
printf("\n");
printf("\n");
printf("\n");
}
My m4.c is this:
Code:
#include "KMotionDef.h"
// M03 C-Code for Spindle Direction
// Spindle CW Jog function with +/- voltage used for direction
#define SPEEDVAR 99 // global persistant variable to store latest speed
#define STATEVAR 98 // global persistant variable to store latest state (-1=CCW,0=off,1=CW)
// M03 command passes no arguments
// desired speed is read from user variable SPEEDVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed
main()
{
persist.UserData[STATEVAR] = -1;
// SetBit(151); // spindle on; when OPTO Out #7 is used to signal spindle direction
SetBit(152); // FET Driver 0 on (Relay), Spindle will go on thru Interlock
printf("Print the value for STATEVAR from M4.C = "); //single line comment
printf("%d\n",persist.UserData[STATEVAR]);
printf("\n");
printf("\n");
printf("\n");
}
Also, I was trying to use other C programming syntax I see on online however, it would seem I do not have the correct default C Standard Input and Output Library like "stdio.h" and "stdlib.h".
However, if I try to add these at the beginning of the Spindle.C program as #include "stdio.h" the compiler does not like it and/or there are other libraries within the library that also are not available.
Is there a way to get more of these default C Standard Input and Output Library included in the C-code I am trying to write for KMotion?
.....
.....
J325 Quick Links:
Machine
Existing Machine Schematics
Electronic Cabinet-Right Side
Electronic Cabinet-Back SIde
Existing Drive Board SD1525-10
J325 Servo Drive-SD1525 Manual
3-Phase Rotary Convert Used
RickB's J325 Retrofit Wiring
KFLOP 5VDC/15Watt/3A Power Supply
KANALOG Mounted & Connected
Kmotion - Axis Encoder Manual Test of Position via Manual Movement
Kanalog-Encoder Voltage High/Low Checks & 1KOhm Resister
Kmotion Configuration Screens "RUN-AWAY"
Tree Journeyman 325 Designed Specs.
Tree Journeyman 325 Axis-Tension Frequency Settings
Final Axis Tuned Error Parameters
VFD Wiring to Existing Tree325 Old Controller
DAC Values to RPM / Voltage Checks
.....
.....