Electronic spindle gearbox
09 Mar 2015 21:52 #56567
by andypugh
Only of the loop is guaranteed to exit in a known time much less than the thread period.
Bear in mind that the code gets called every thread period. If it hasn't finished when it is called again then very bad things happen....
So, to "wait" in a HAL component you set a flag or timer, then check whether the wait has finished the next time the component is run. You don't wait inside the code.
Replied by andypugh on topic Electronic spindle gearbox
I'm thinking a while loop is what I should use. Does that sound right?.
Only of the loop is guaranteed to exit in a known time much less than the thread period.
Bear in mind that the code gets called every thread period. If it hasn't finished when it is called again then very bad things happen....
So, to "wait" in a HAL component you set a flag or timer, then check whether the wait has finished the next time the component is run. You don't wait inside the code.
The following user(s) said Thank You: SOLD
Please Log in or Create an account to join the conversation.
- microsprintbuilder
- Offline
- Elite Member
Less
More
- Posts: 163
- Thank you received: 4
09 Mar 2015 22:20 #56570
by microsprintbuilder
Replied by microsprintbuilder on topic Electronic spindle gearbox
gotcha, so how do you determine the waited time amount?
Please Log in or Create an account to join the conversation.
09 Mar 2015 22:24 #56571
by andypugh
"fperiod" is a variable that is supplied in a .comp that tells you the period of the thread that the function is running in. You can therefore add or subtract "fperiod" from a static variable (or HAL pin) to track how long the wait has been.
Replied by andypugh on topic Electronic spindle gearbox
gotcha, so how do you determine the waited time amount?
"fperiod" is a variable that is supplied in a .comp that tells you the period of the thread that the function is running in. You can therefore add or subtract "fperiod" from a static variable (or HAL pin) to track how long the wait has been.
Please Log in or Create an account to join the conversation.
- microsprintbuilder
- Offline
- Elite Member
Less
More
- Posts: 163
- Thank you received: 4
09 Mar 2015 22:29 #56572
by microsprintbuilder
Replied by microsprintbuilder on topic Electronic spindle gearbox
is the timeout = 10 ten seconds? or ten of something else?
Please Log in or Create an account to join the conversation.
09 Mar 2015 22:39 #56573
by andypugh
"fperiod" is (floating point) seconds. "period" is nanoseconds.
www.linuxcnc.org/docs/html/hal/comp.html#_implicit_parameters
Replied by andypugh on topic Electronic spindle gearbox
is the timeout = 10 ten seconds? or ten of something else?
"fperiod" is (floating point) seconds. "period" is nanoseconds.
www.linuxcnc.org/docs/html/hal/comp.html#_implicit_parameters
Please Log in or Create an account to join the conversation.
- microsprintbuilder
- Offline
- Elite Member
Less
More
- Posts: 163
- Thank you received: 4
12 Mar 2015 01:51 #56709
by microsprintbuilder
Replied by microsprintbuilder on topic Electronic spindle gearbox
does this look right?
component ebox "electronic gearbox component";
licence "GPL";
pin in bit spindle-slow
pin in bit spindle-on-in;
pin out bit spindle-on-out;
pin in float spindle-speed;
pin out bit relay1;
pin out bit relay2;
pin out bit relay3;
pin out s32 spindle-gearbox-output-scale
pin out s32 spindle-gearbox-out-min-limit
pin out s32 spindle-gearbox-out-max-limit
pin in s33 spindle-gearbox-low-output-scale
pin in s32 spindle-gearbox-low-min-limit
pin in s32 spindle-gearbox-low-max-limit
pin in s32 spindle-gearbox-mid-output-scale
pin in s32 spindle-gearbox-mid-min-limit
pin in s32 spindle-gearbox-mid-max-limit
pin in s32 spindle-gearbox-hi-output-scale
pin in s32 spindle-gearbox-hi-min-limit
pin in s32 spindle-gearbox-hi-max-limit
int gear-called
int gear-set
function _;
;;
FUNCTION(_){
static int timer;
if (timer > 0){
timer -= 1;
spindle_on_out = 0;
} else {
spindle_on_out = spindle_on_in;
}
// determine gear required
if (spindle_speed >= 2500){
gear-called = 3
} else if (spindle-speed <= 1200)
{
gear-called = 1
} else
{
gear-called = 2
}
// determine if gear change required
while (gear-called <> gear-set)
{
spindle_on_out=0
if (spindle-slow=0){
wait
} else {
if (spindle_speed >= 2500)
{
relay 1 = 0;
relay 2 = 0;
relay 3 = 1;
spindle-gearbox-output-scale = spindle-gearbox-hi-output-scale
spindle-gearbox-out-min-limit = spindle-gearbox-hi-min-limit
spindle-gearbox-out-max-limit = spindle-gearbox-hi-max-limit
gear-set = 3
timer = 2000
} else if (spindle-speed <= 1200)
{
relay 1 = 1;
relay 2 = 0;
relay 3 = 0;
spindle-gearbox-output-scale = spindle-gearbox-low-output-scale
spindle-gearbox-out-min-limit = spindle-gearbox-low-min-limit
spindle-gearbox-out-max-limit = spindle-gearbox-low-max-limit
gear-set = 1
timer = 2000
} else {
relay 1 = 0;
relay 2 = 1;
relay 3 = 0;
spindle-gearbox-output-scale = spindle-gearbox-mid-output-scale
spindle-gearbox-out-min-limit = spindle-gearbox-mid-min-limit
spindle-gearbox-out-max-limit = spindle-gearbox-mid-max-limit
gear-set = 2
timer = 2000
}}}}
component ebox "electronic gearbox component";
licence "GPL";
pin in bit spindle-slow
pin in bit spindle-on-in;
pin out bit spindle-on-out;
pin in float spindle-speed;
pin out bit relay1;
pin out bit relay2;
pin out bit relay3;
pin out s32 spindle-gearbox-output-scale
pin out s32 spindle-gearbox-out-min-limit
pin out s32 spindle-gearbox-out-max-limit
pin in s33 spindle-gearbox-low-output-scale
pin in s32 spindle-gearbox-low-min-limit
pin in s32 spindle-gearbox-low-max-limit
pin in s32 spindle-gearbox-mid-output-scale
pin in s32 spindle-gearbox-mid-min-limit
pin in s32 spindle-gearbox-mid-max-limit
pin in s32 spindle-gearbox-hi-output-scale
pin in s32 spindle-gearbox-hi-min-limit
pin in s32 spindle-gearbox-hi-max-limit
int gear-called
int gear-set
function _;
;;
FUNCTION(_){
static int timer;
if (timer > 0){
timer -= 1;
spindle_on_out = 0;
} else {
spindle_on_out = spindle_on_in;
}
// determine gear required
if (spindle_speed >= 2500){
gear-called = 3
} else if (spindle-speed <= 1200)
{
gear-called = 1
} else
{
gear-called = 2
}
// determine if gear change required
while (gear-called <> gear-set)
{
spindle_on_out=0
if (spindle-slow=0){
wait
} else {
if (spindle_speed >= 2500)
{
relay 1 = 0;
relay 2 = 0;
relay 3 = 1;
spindle-gearbox-output-scale = spindle-gearbox-hi-output-scale
spindle-gearbox-out-min-limit = spindle-gearbox-hi-min-limit
spindle-gearbox-out-max-limit = spindle-gearbox-hi-max-limit
gear-set = 3
timer = 2000
} else if (spindle-speed <= 1200)
{
relay 1 = 1;
relay 2 = 0;
relay 3 = 0;
spindle-gearbox-output-scale = spindle-gearbox-low-output-scale
spindle-gearbox-out-min-limit = spindle-gearbox-low-min-limit
spindle-gearbox-out-max-limit = spindle-gearbox-low-max-limit
gear-set = 1
timer = 2000
} else {
relay 1 = 0;
relay 2 = 1;
relay 3 = 0;
spindle-gearbox-output-scale = spindle-gearbox-mid-output-scale
spindle-gearbox-out-min-limit = spindle-gearbox-mid-min-limit
spindle-gearbox-out-max-limit = spindle-gearbox-mid-max-limit
gear-set = 2
timer = 2000
}}}}
Please Log in or Create an account to join the conversation.
12 Mar 2015 05:16 #56715
by andypugh
Replied by andypugh on topic Electronic spindle gearbox
Rather than ask if it looks right, does it compile, and does it work?
Please Log in or Create an account to join the conversation.
- microsprintbuilder
- Offline
- Elite Member
Less
More
- Posts: 163
- Thank you received: 4
12 Mar 2015 05:39 #56716
by microsprintbuilder
Replied by microsprintbuilder on topic Electronic spindle gearbox
Haven't done that yet. I thought I'd ask to see if it's plausible. Instead I get my question answered with a question. Thanks for you help.
Please Log in or Create an account to join the conversation.
12 Mar 2015 05:48 #56717
by andypugh
Replied by andypugh on topic Electronic spindle gearbox
It looks like it ought to work, except that you have relay 1 instead of relay1 (etc) in a few places. The pin names and variable names need to match exactly, and can't have spaces.
Please Log in or Create an account to join the conversation.
07 Oct 2023 20:37 #282515
by Trav328
Replied by Trav328 on topic Electronic spindle gearbox
Resurrected with mod approvalĀ
Microsprintbuilder , did you ever get this working right ? , I am doing a retrofit on a milltronics partner lathe with the identical spindle winding "gear" setup , probably even the same parts , im going to try compiling the last bit you posted and see what can be done with that , this board has no pm's so this is the only way to reach out.
Microsprintbuilder , did you ever get this working right ? , I am doing a retrofit on a milltronics partner lathe with the identical spindle winding "gear" setup , probably even the same parts , im going to try compiling the last bit you posted and see what can be done with that , this board has no pm's so this is the only way to reach out.
Please Log in or Create an account to join the conversation.
Time to create page: 0.086 seconds