So the solenoid somehow causes the crank to rotate?
TK
http://dynomotion.com
Yes
So how do you expect that would work?
TK
http://dynomotion.com
I'm thinking that currently there is a 2 solenoid controlled pneumatic valve attached to this pneumatic thing (see Pic), it turns what used to be the hand wheel on my mill, It was working with the system I replaced and if air is activated one way it will increase the speed, if activated the other way it decreases the speed. If I can get help writing the C-code for it, I believe that when the g-code calls for an "S"whatever it will speed up or down.
I also have a pneumatic breaking system on this mill which activates an air cylinder to break the spindle when mill spindle is stopped.It will released when you run a program and spindle is activated. Would be kinda nice to have both working.
I do have an encoder attached to the spindle but it's not displaying RPM yet.
Are there 2 solenoids? Do you have the specifications for the solenoids with regard to the current?
TK
http://dynomotion.com
10.5 Watts @ 24V is less than 1 Amp so it should work with Kanalogs SWx outputs. A reverse diode across the coil is required otherwise switching off could cause a spark and damage. Connect like this:
Attachment 456320
TK
http://dynomotion.com
Can I connect it to JP13 without a reverse diode (don't have any).
No. Do not use JP13 it can't handle the current and would also need a reverse diode. Kanalog Opto Outputs are limited to 0.025 Amps. Your solenoid requires about 0.4A. Also connecting A supply directly to the opto output, as you show, without any load to limit the current would cause damage. That would be like wiring AC power directly to a light switch without any light bulb in the circuit. If you turned on the switch it would blow the fuse or worse. The load needs to be in series not parallel.
TK
http://dynomotion.com
Ok, I think It may already have a diode in the selenoid switch so I should be good.
I tried to make a C-program to run the spindle break which is operated by an air cylinder. I was able to get a c-code program to validate and compile, but it will not command the air valve. Here is my program, do you see anything I need to correct. I need the air cylinder to expand when the spindle turns off and contract when on. The picture is how I have the air solenoid connected per our earlier conversation.
All the information/lessons I find about C-code is making programs with math equations, is there somewhere you know of that shows how to make programs needed for Kflop?
#include "KMotionDef.h"
#define SPINDLEAXIS_7
#define SPINDLECW_BIT 156
#define SPINDLECCW_BIT 153
#define SOLENOID_BIT 159
main()
{
if
SPINDLEAXIS_7 (1) // spindle on
ClearBit(159);
else
SetBit(159);
}
I havent had a chance to try this out but, would this fix it?
#include "KMotionDef.h"
#define SPINDLEAXIS_7
#define SPINDLECW_BIT 156
#define SPINDLECCW_BIT 153
#define SOLENOID_BIT 159
main()
if
{
(SPINDLEAXIS_7 = Active) // spindle on
ClearBit(159);
}
else
{
SetBit(159);
}
You need to explain what you mean by:
Enabled?I need the air cylinder to expand when the spindle turns off and contract when on.
#define statements basically do text substitution allowing you to give a symbolic name to something. Sort of like Find and Replace. It has 2 parts. The first is the name you choose to use. The second is the thing to substitute when that name is found. So for example:
#define SOLENOID_BIT 159
Defines 159 to be substituted for SOLENOID_BIT. So now you could code:
ClearBit(SOLENOID_BIT);
The advantage is that instead of using magic numbers (159) you can then use names to make the code more understandable. Furthermore if the thing is used in more than one place, for example in your SetBit and ClearBit, if you ever were to change where the Solenoid was connected to say 158 all you would need to do is change the #define one place and everything would be updated.
If you make defines and don't use them anywhere you are just adding confusion.
#define SPINDLEAXIS_7
Tells the compiler to replace SPINDLEAXIS_7 with nothing. So your program becomes:
(Notice I posted the code using the # code tag so the code is properly indented and readable unlike how you just posted it as text making it difficult to read)Code:main() { if (1) // spindle on ClearBit(159); else SetBit(159); }
In the C Language zero is FALSE and non-zero (ie 1) is TRUE. Since the 'if' condition is always TRUE then your program will always Clear Bit 159. So your program boils down to:
Code:main() { ClearBit(159); }
I assume you need to Set the bit to release the brake? Did you test it using the Digital IO Screen?
Anyways it isn't clear you need any Spindle testing. Another approach is that you already have an Init program to enable the axes and the Spindle. Why not just release the Brake at the same time enabling the Spindle? Do you ever need to re-apply the Brake?
You might also read our wiki and look at some of the many C examples.
TK
http://dynomotion.com
Ok, maybe Enabled wasn't the best term. Spindle on and turning CW or CCW is what I meant.
So if I have multiple Solenoids how does the computer/kflop tell them apart? Do I just use something like Sol159 and no define?
I assume false = off and true = on?
Yes, I believe so, It appears that this solenoid is normally open so when the G-code sees an M5 or M30 the spindle stops and at the same time the solenoid activates the air to the extend side of the air cylinder and applys the spindle break. When the spindle encounters a start rotating command the solenoid should be energized and close/or route the air to the other side of the cylinder which retracts the cylinder rod and stops applying pressure to the spindle break. I tested it with KmotionCNC by running the spindle CW and CCW.
I need the brake on to change tools, anytime the spindle is not rotating, and off anytime the spindle rotates.
I have but not finding anything which suits my specific need which I understand. I have also watched a few Youtube videos but they mostly talk about making mathematical equations, which I don't really understand how to convert it from 123456789 to a name or thing and how the computer/control board knows what I'm saying to it.
I'm sure the control/computer, you are saying WTF is this guy saying. You don't know of a way to translate this to Redneck dumbass do you? Anyway thanks for the help I am tracking somewhat.
I have tested the solenoid and air cylinder using the Digital IO Screen, and it works. What i need to happen is when the spindle is not rotating the solenoid is not energized (like it is now), but when the spindle rotates the solenoid needs to be energized. How/where do I insert the code to make it work this way; at the end of my Init program?
Test
[#Code:]
main()
if (SPINDLEAXIS_7==1)
{SetBit(159);
}
else()
{ClearBit(159);
}[#Code:]
Each IO has a different Bit number. If you define a name to represent the number it should be unique and not contain the number itself in case the IO ever changes.So if I have multiple Solenoids how does the computer/kflop tell them apart? Do I just use something like Sol159 and no define?
Sort of but true and false is somewhat different than on and off. 5 > 4 is true, 4 > 5 is false. Its referred to as a condition. Note in C to check for equality the == operator is used and the check of inequality != is used. The = operator is reserved as an assignment. For example x=5; sets the variable x to 5 it does not compare x to 5. To compare x to 5 you would code if (x==5) ...I assume false = off and true = on?
This is confusing to me. You describe it as already working properly so what is the point of all this? But yes, since you have C Programs to start the Spindle CW and start the Spindle CCW and to stop the Spindle I would add code to those to release and set the brake appropriately. If you look at them by default they set and clear bits normally used to enable/disable and set the direction of the spindle that your system probably doesn't need.Yes, I believe so, It appears that this solenoid is normally open so when the G-code sees an M5 or M30 the spindle stops and at the same time the solenoid activates the air to the extend side of the air cylinder and applys the spindle break. When the spindle encounters a start rotating command the solenoid should be energized and close/or route the air to the other side of the cylinder which retracts the cylinder rod and stops applying pressure to the spindle break. I tested it with KmotionCNC by running the spindle CW and CCW
A side issue is that most systems don't like to be enabled with a brake on. If the spindle can't move and there is a small error the servo may try really hard to correct the error and apply maximum torque. This might make the motor hot and so forth. Also when the brake is released there might be a violent jump. So whenever the brake is applied you might want to disable the servo and then re-enable it when re-started.
TK
http://dynomotion.com
Code:Test main() if (SPINDLEAXIS_7==1) {SetBit(159); } else() {ClearBit(159); }