a friend suggested that it is to be set in tool setup screen in KMotionCNC.exe..
as a variable... is this right?
it is not logical and i would not know this without help... :P
a friend suggested that it is to be set in tool setup screen in KMotionCNC.exe..
as a variable... is this right?
it is not logical and i would not know this without help... :P
Can you find the variable called "speed"?eem.. i am already stuck.. i don't know what i am looking at..
i can't see anything in the Spindle_S_Kstep.c file that has anything to do with my spinle speed... am i on the wrong file?
Can you see how it is set from persist Variable #1 passed from the KMotionCNC program?
Can you see how it is divided by RPM_FACTOR to be a value from 0 to 1 (no voltage to full voltage) and passed to the function to be corrected and output?
Yes the whole idea of what we are trying to do is to setup KMotionCNC so that it can pass the S RPM word to KFLOP so KFLOP can set that RPM. So we want to configure KMotionCNC "S" to set the desired RPM in some unused persist Variable in KFLOP and execute this program in some unused Thread.a friend suggested that it is to be set in tool setup screen in KMotionCNC.exe..
as a variable... is this right?
HTH
Regards
TK
http://dynomotion.com
what exactly does it say? and in what? in the "Spindle_S_Kstep.c" file there is 2 direct refferences to speed, and 1 to RPM..Can you find the variable called "speed"?
you need to remember that i need to be spoon fed this in a step by step manor, it is not something normal for me to program this..
..Can you see how it is set from persist Variable #1 passed from the KMotionCNC program?
Can you see how it is divided by RPM_FACTOR to be a value from 0 to 1 (no voltage to full voltage) and passed to the function to be corrected and output?
yes i know that, and i want nothing else then that.... but i still don't have any idea on how to do it.. and what a "unused persist Variable" and a "unused Thread" is..Yes the whole idea of what we are trying to do is to setup KMotionCNC so that it can pass the S RPM word to KFLOP so KFLOP can set that RPM. So we want to configure KMotionCNC "S" to set the desired RPM in some unused persist Variable in KFLOP and execute this program in some unused Thread.
ok.. my friend found something new..
i missed it when you said
in the Tool setup page i am to set the last line named "S" to "exec prog" and refer to Spindle_S_Kstep.cFor KMotionCNC there is an example C Program that can be used. Configure KmotionCNC | Tool Setup | S | Exec Prog for this program using Thread #2 and to pass the Speed in Var #1.
C:\KMotion433f\C Programs\KStep\KMotionCNC\Spindle_S_Kstep.c
How good is your math? See if you can change the calculations for your 400 RPM offset from zero.
Regards
are we setting the S-slider in the KMotionCNC interface to adjust the value / variable that we pass to the speed-variable in Spindle_S_Kstep.c, which again calculates the correct analog output according to the given speed / RPM_FACTOR, and then pass that to the controller?
(this is my friend that found it out, not me!)
but i still don't understand the calculation and math problem...
float speed = *(float *)&persist.UserData[1]; // value stored is actually a floatwhat exactly does it say? and in what? in the "Spindle_S_Kstep.c" file there is 2 direct refferences to speed, and 1 to RPM..
you need to remember that i need to be spoon fed this in a step by step manor, it is not something normal for me to program this..
This line of code creates a floating point variable called "speed" and loads it with the RPM value passed from KMotionCNC in UserData Variable #1. The variable "speed" can then be used in formulas as the desired speed in RPM.
Correct. And also set Var=1 (so the speed is passed down to UserData Variable #1) and Thread=2 (to execute the program in Thread #2)in the Tool setup page i am to set the last line named "S" to "exec prog" and refer to Spindle_S_Kstep.c
Sort of. But the C Program resides in the Controller (KFLOP). So the speed / RPM_FACTOR is a calculation that converts the speed in RPM passed down to KFLOP into a fraction of full speed (a number from 0 to 1).are we setting the S-slider in the KMotionCNC interface to adjust the value / variable that we pass to the speed-variable in Spindle_S_Kstep.c, which again calculates the correct analog output according to the given speed / RPM_FACTOR, and then pass that to the controller?
More than just the Slider whenever the Speed in GCode (or the Slider) is changed this is how it configured to make the change occur. The Slider changes the SRO (Spindle Rate Override). So say the GCode S Speed is set at 1000RPM and the Slider is moved to 1.1. Then KMotionCNC sends a new speed of 1100RPM to KFLOP.
Your system is special because 0V drives 282.52 RPM instead of 0 RPM like most systems. As you stated:but i still don't understand the calculation and math problem...
0V = 400RPM on motor = 282.52 RPM on spindle
5V = 3600RPM on motor = 2542.70 RPM on spindle
so instead of a single divide like this:
speed/RPM_FACTOR
you would need a subtract and divide by the RPM Range like:
(speed - 282.52)/(2542.70 - 282.52)
If you plug in speed values between 282.52 and 2542.70 and do the math the result should be between 0 and 1.
HTH
Regards
TK
http://dynomotion.com
we have tried to do as you say, by using the following code:
Code:#include "KMotionDef.h" #include "..\CorrectAnalogFunction.c" #define RPM_FACTOR 500 // RPM for full duty cycle (max analog out) // desired speed is passed in variable 1 main() { float speed = *(float *)&persist.UserData[1]; // value stored is actually a float speed = (speed - 282.52) /(2542.70 - 282.52); //here is what we tried FPGA(KAN_TRIG_REG)=4; // Mux PWM0 to JP7 Pin5 IO 44 for KSTEP SetBitDirection(44,1); // define bit as an output FPGA(IO_PWMS_PRESCALE) = 46; // divide clock by 46 (1.4 KHz) FPGA(IO_PWMS+1) = 1; // Enable FPGA(IO_PWMS) = CorrectAnalog(speed/RPM_FACTOR); // Set PWM }
and here is what what we connected up to test with:
Attachment 260672
the voltage on JP33 pin 7 and 5 is measured to 4.98V DC
and the result was that when we had the S slider in KMotionCNC to 0,1 the output was 0,0024V and at setting 2 (highest the slider can go) the maximum output we achieved was 0,789V
then we tried the example file KStepPWMCorrected.c and tried to test the output that way, but all we got was the same result...
so what is wrong here? is it in the way it is connected?
Hi Jossa,
Since you are doing a new formula then you don't want also do the old formula (division by RPM_FACTOR). Remove the old RPM_FACTOR definition and do not divide by it. So do this:
Also it all depends on the RPM setting in KMotionCNC. The slider only adjusts the RPM by a percentage. You must set the Base RPM with an S command. Type S2542 in the MDI and send it.Code:#include "KMotionDef.h" #include "..\CorrectAnalogFunction.c" // desired speed is passed in variable 1 main() { float speed = *(float *)&persist.UserData[1]; // value stored is actually a float speed = (speed - 282.52) /(2542.70 - 282.52); //here is what we tried FPGA(KAN_TRIG_REG)=4; // Mux PWM0 to JP7 Pin5 IO 44 for KSTEP SetBitDirection(44,1); // define bit as an output FPGA(IO_PWMS_PRESCALE) = 46; // divide clock by 46 (1.4 KHz) FPGA(IO_PWMS+1) = 1; // Enable FPGA(IO_PWMS) = CorrectAnalog(speed); // Set PWM }
But I suspect there is some other hardware problem as well. To test if the hardware is working test with the diagnostic program from the previous posts where you were able to output voltages. Does that output higher voltages like 4V?
Regards
TK
http://dynomotion.com
update:
tried connecting it to a external 5V PSU (the one that runs KFLOP) and now it works.. low is 0.016V and max is 5V...
the code used is:
#include "KMotionDef.h"
#include "..\CorrectAnalogFunction.c"
#define RPM_FACTOR 500 // RPM for full duty cycle (max analog out)
// desired speed is passed in variable 1
main()
{
float speed = *(float *)&persist.UserData[1]; // value stored is actually a float
speed -= 282.52;
FPGA(KAN_TRIG_REG)=4; // Mux PWM0 to JP7 Pin5 IO 44 for KSTEP
SetBitDirection(44,1); // define bit as an output
FPGA(IO_PWMS_PRESCALE) = 46; // divide clock by 46 (1.4 KHz)
FPGA(IO_PWMS+1) = 1; // Enable
FPGA(IO_PWMS) = CorrectAnalog(speed/RPM_FACTOR); // Set PWM
}
what is wrong, and how do we take into account the offset in this?
disregard last post.. did not see it..
your code works.
slider control's it from 0 to 5v#include "KMotionDef.h"
#include "..\CorrectAnalogFunction.c"
// desired speed is passed in variable 1
main()
{
float speed = *(float *)&persist.UserData[1]; // value stored is actually a float
speed = (speed - 282.52) /(2542.70 - 282.52); //here is what we tried
FPGA(KAN_TRIG_REG)=4; // Mux PWM0 to JP7 Pin5 IO 44 for KSTEP
SetBitDirection(44,1); // define bit as an output
FPGA(IO_PWMS_PRESCALE) = 46; // divide clock by 46 (1.4 KHz)
FPGA(IO_PWMS+1) = 1; // Enable
FPGA(IO_PWMS) = CorrectAnalog(speed); // Set PWM
}
diagnostics program also works.. 0 to 5V
so using external PSU works. But from the BLDC controller's 5V output it don't work
the problem is when getting power from the BLDC controller.. it is 5 volts, but maximum output i can set is 0,79V
hmmm..
any ideas on why it wont work?
the next problems is:
- Setting up the 4 relay card, CNC4PC C36
product page
product manual]404 Not Found
my plan is to have one canal for flood cooling and one for a solenoid to a future power draw bar.. the rest is spare for later
Hi Jossa,
You would need to debug things like that yourself. Measure voltages to find the issue. Is there +5V across KSTEP JP33 pins 5 and 7? What is the output voltage (pin6) relative to pin 7 (GND)? What is the output voltage when unloaded?hmmm..
any ideas on why it wont work?
Regarding C36. Looks like that should connect to any of KFLOP IO pins.
Regards
TK
http://dynomotion.com
I know that it is not your job to debug that.. i was just asking if you could see a connection..
The voltage is 4.98V without load and 4,98V connected to pin 7 and 5.. voltage on 6 and 7 is 0,79V...
How do i adress a spesific funtion to a adress (output)
I asume that it is done in KMotionCNC-tool setup?
Hi jossa
You aren't being very detailed or specific in your replies. It doesn't seem logical that the circuit would behave differently when supplied with a one +5V supply or another +5V supply. So we must be miss communicating somewhere. You might describe step-by-step what you are doing when using KFLOP +5V and then when using the Motor Control's +5V. When I asked about loaded and unloaded I meant to say the output (JP33 Pin6 connection). Not whether the supply was loaded or not. Testing unloaded would be with only the meter and noting else connected to pin 6 (referenced to pin7). I suspect it may have something to do with grounding. For example if you are using the Motor Control's +5V supply which has no Gnd connection to KFLOP but still referencing your measurement to KFLOP or earth GND.The voltage is 4.98V without load and 4,98V connected to pin 7 and 5.. voltage on 6 and 7 is 0,79V...
It depends what the function is and how it needs to be used. The simplest thing is to assign an M Code in KMotionCNC Tool Setup to turn on or off a bit. This can be any bit number. The first step would be to wire up the relay driver to an IO and toggle the bit on the Digital IO Screen to see if it functions correctly.How do i adress a spesific funtion to a adress (output)
I asume that it is done in KMotionCNC-tool setup?
Regards
TK
http://dynomotion.com
i am sorry about that, and yes we might have a communication problem, you see English is not my first language and i live in Europe.. so that might account for any weird phrasing and strange sentences i make..You aren't being very detailed or specific in your replies. It doesn't seem logical that the circuit would behave differently when supplied with a one +5V supply or another +5V supply. So we must be miss communicating somewhere. You might describe step-by-step what you are doing when using KFLOP +5V and then when using the Motor Control's +5V. When I asked about loaded and unloaded I meant to say the output (JP33 Pin6 connection). Not whether the supply was loaded or not. Testing unloaded would be with only the meter and noting else connected to pin 6 (referenced to pin7). I suspect it may have something to do with grounding. For example if you are using the Motor Control's +5V supply which has no Gnd connection to KFLOP but still referencing your measurement to KFLOP or earth GND.
i have tried many different ways, and i cant get the on board 5V on the BLDC controller to control through the Kflop, but if i use a external 5V it works (the PWM output on kflop, so the issue is with the crappy Chinese controller)..
an i have just spoken to a guy on the forums that is also using a BLDC controller like mine, and he was indicating that you can supply the controller with external 5V if you solder off a connection..
so i will try that.
i see.. and the way to understand this is:It depends what the function is and how it needs to be used. The simplest thing is to assign an M Code in KMotionCNC Tool Setup to turn on or off a bit. This can be any bit number. The first step would be to wire up the relay driver to an IO and toggle the bit on the Digital IO Screen to see if it functions correctly.
IE.
to connect a home switch to the kflop/kstep the way i would find out the bit number is by looking at the pin out for JP33 and find the physical pin:
JP33, pin 14 / Opto IN 5 / 173 Input ...
from that i would read that the bit number is 173 and it is named Opto IN 5...
it could be seen in the Digital I/O in Kmotion.exe if the input is high/low
Am i right so far?
where would the programming of homing switches be done? is that also in KMotionCNC / Tool setup / I/O bit ? or is it in C programming direct?
on a side note, the sensors i had laying around is a Pepperl+Fuchs NBN4-12GM40-Z0-V1
i include a datasheet for it below, do you think this sensor would work with kflop?
Attachment 261142
.......
i also have one more thing, when i have all the functions i want in software, how do i consolidate it into the Kmotion controller?
it might be a silly question but how is everything tied together in the final "version" of my program?
We tried what you suggested; toggling the bit on the Digital IO screen, and it works.
We also assigned the M3 button to toggle that bit, and it works after setting the bit as Output in the Digital IO screen in KMotion.
What I need to know is how to "permanently" set the bit as an Output, so I don't need to do it everytime the program is restarted.
Is there a way to do this in the graphical interface?
Or could this be done in code, by setting a button as:
(Button): Execute Prog: Thread: 2 (or some other unused thread), VAR: 0 (since we pass no var), C File: custom C-file with the following code:
#include "KMotionDef.h"
main()
{
// In this example I want to use bit 29
setBitDirection(29, 1); // Set bit 29 to be an output <-- Is it OK to call setBitDirection() for every execution? This should probably be set "globally" first?
setBit(29); // Set bit 29 state to 1 (on)
}
... and then use clearBit(29) for another button to clear it.
Am I completely off here?
I ran into the same issue with setting to output. I will post the c program I use when I get by the shop. It is really simple but will need to be added to your init program or run each time you power up.
Ben
Hi jossa,
You are correct. You can set the bit as an output in your Initialization C program then it will only execute once. Note that SetBitDirection starts with a capital 'S' C programs are case sensitive.
SetBitDirection(29, 1); // Set bit 29 to be an output
Regards
TK
http://dynomotion.com
Is this done in InitStepDir3Axis.C since i use StepDir controlled steppers.?
and how is everything tied together when i am finished?
is the KMotionDef.h also uploaded since it is included? and how about the stepper info and Mcode assignments...
i have seen the flash presentation in the help section, but i am not sure about it even after watching it..
one more thing, after i have assigned an input as a home switch, what is required to make it work as a X axis home switch? is the assignment and definition done in C also?
Hi Jossa,
Yes you would add the SetBitDirection() it to whatever initialization C program you have created. If using KSTEP that would usually be InitKStep3Axis.c not the one you specified.Is this done in InitStepDir3Axis.C since i use StepDir controlled steppers.?
It would help if you understood the conceptual difference between KFLOP and the PC. Nothing is really uploaded to the PC. The C Programs and (Header files) reside on the PC. They don't need to be tied together or sent anywhere. Pushing buttons and running M Codes will be configured to run these programs and do things to KFLOP. The KMotionCNC configuration is automatically saved in the Data directory. There is nothing you really need to do other than back up all the files in case something happens to your PC (like it crashes or is stolen).and how is everything tied together when i am finished?
is the KMotionDef.h also uploaded since it is included? and how about the stepper info and Mcode assignments...
i have seen the flash presentation in the help section, but i am not sure about it even after watching it..
Yes Homing is handled in KFLOP as a C Program so any method or input can be used. For standard Homing you don't need to write any C Code and just specify the Homing parameters for your system and call a standared function to Home. Seeone more thing, after i have assigned an input as a home switch, what is required to make it work as a X axis home switch? is the assignment and definition done in C also?
SimpleHomeIndexFunctionTest.c
Regards
TK
http://dynomotion.com
it is now done, and all 4 pins is set as outputs when i push INIT in KMotionCNC.exe and i can enable the relays via buttons.. IE, i have M3 assigned to set pin 29 high and and M5 assigned to set it to 0.. so i can basically control a spindle with it now..Yes you would add the SetBitDirection() it to whatever initialization C program you have created. If using KSTEP that would usually be InitKStep3Axis.c not the one you specified.
is this thinking right? or is it done differently normaly?
yes it would, ... i guess what i am struggling with understanding is how programs are put into Kmotion? (how does Kflop know what i program and what i want it to do)It would help if you understood the conceptual difference between KFLOP and the PC. Nothing is really uploaded to the PC. The C Programs and (Header files) reside on the PC. They don't need to be tied together or sent anywhere. Pushing buttons and running M Codes will be configured to run these programs and do things to KFLOP. The KMotionCNC configuration is automatically saved in the Data directory. There is nothing you really need to do other than back up all the files in case something happens to your PC (like it crashes or is stolen).
when i edit something in KMotion.exe and download it, or make a reference to a C program in KMotionCNC.exe.. how is that program enterd into the Kflop?
Yes Homing is handled in KFLOP as a C Program so any method or input can be used. For standard Homing you don't need to write any C Code and just specify the Homing parameters for your system and call a standared function to Home. See
SimpleHomeIndexFunctionTest.c
could SimpleHomeIndexFunctionTest.c be used in normal operation?
also, do you think this would work with KmotionCNC?
https://littlemachineshop.com/produc...ory=1963256893