HURCO KMB-1 Control Update
- PCW
-
- Online
- Moderator
-
Less
More
- Posts: 17955
- Thank you received: 5262
18 Feb 2026 22:31 #343181
by PCW
Replied by PCW on topic HURCO KMB-1 Control Update
Ok Peter, so that is resetting my original understanding. But I have been unable to get the index pulse, which is clearly present in halscope to trigger the position reset.
The way index works on LinuxCNC with quadrature encoders is that when LinuxCNC (or some hal component)
wants a encoder reset at the next index occurrence, it sets the index-enable pin. This arms the encoder counter
hardware so at the next index, two things happen, the encoder position is reset to 0, and the index enable pin
is set false, so LinuxCNC or the controlling hal component knows that the index has been detected (and position zeroed)
The way index works on LinuxCNC with quadrature encoders is that when LinuxCNC (or some hal component)
wants a encoder reset at the next index occurrence, it sets the index-enable pin. This arms the encoder counter
hardware so at the next index, two things happen, the encoder position is reset to 0, and the index enable pin
is set false, so LinuxCNC or the controlling hal component knows that the index has been detected (and position zeroed)
The following user(s) said Thank You: NT4Boy
Please Log in or Create an account to join the conversation.
- NT4Boy
- Offline
- Premium Member
-
Less
More
- Posts: 147
- Thank you received: 13
19 Feb 2026 17:22 #343196
by NT4Boy
Replied by NT4Boy on topic HURCO KMB-1 Control Update
I've ended up fighting the hal loader.
#
# M19 ORIENT – single driver / multi‑sink form
#
loadrt orient count=1
addf orient.0 servo-thread
loadrt pid names=pid.o
addf pid.o.do-pid-calcs servo-thread
loadrt mux2 count=1
addf mux2.0 servo-thread
loadrt or2 count=1
addf or2.0 servo-thread
# --- Orient PID tuning ---
setp pid.o.Pgain 0.05
setp pid.o.Igain 0.0005
setp pid.o.Dgain 0.0002
setp pid.o.maxoutput 60
setp pid.o.error-previous-target true
setp orient.0.tolerance 0.05
setp orient.0.angle 0
# --- One signal name, declared once and fanned out ---
net orient-bit spindle.0.orient => orient.0.enable
net orient-bit => or2.0.in1
net orient-bit => mux2.0.sel
# separate signal drives the encoder’s index enable input
net orient-arm-index orient-bit => hm2_7i92.0.encoder.05.index-enable
# --- Run enable OR gate ---
net run-enable or2.0.out => hm2_7i92.0.7i77.0.1.spinena
net spindle-enable => or2.0.in0
# --- Orient angle / feedback wiring ---
net orient-angle spindle.0.orient-angle => orient.0.angle
net spindle-revs hm2_7i92.0.encoder.05.position => orient.0.position
# --- Orient PID loop ---
net orient-cmd orient.0.command => pid.o.command
net orient-fb hm2_7i92.0.encoder.05.velocity-rpm => pid.o.feedback
net orient-out pid.o.output => mux2.0.in1
# --- Normal spindle path and output switch ---
net spindle-output pid.s.output => mux2.0.in0
net spindle-vfd-out mux2.0.out => hm2_7i92.0.7i77.0.1.analogout5
# --- Completion flag back to controller ---
net orient-done orient.0.is-oriented => spindle.0.is-oriented
#Error in file ./spindlecontrol.hal:
# Pin 'orient-bit' does not exist
#Shutting down and cleaning up LinuxCNC…
#
# M19 ORIENT – single driver / multi‑sink form
#
loadrt orient count=1
addf orient.0 servo-thread
loadrt pid names=pid.o
addf pid.o.do-pid-calcs servo-thread
loadrt mux2 count=1
addf mux2.0 servo-thread
loadrt or2 count=1
addf or2.0 servo-thread
# --- Orient PID tuning ---
setp pid.o.Pgain 0.05
setp pid.o.Igain 0.0005
setp pid.o.Dgain 0.0002
setp pid.o.maxoutput 60
setp pid.o.error-previous-target true
setp orient.0.tolerance 0.05
setp orient.0.angle 0
# --- One signal name, declared once and fanned out ---
net orient-bit spindle.0.orient => orient.0.enable
net orient-bit => or2.0.in1
net orient-bit => mux2.0.sel
# separate signal drives the encoder’s index enable input
net orient-arm-index orient-bit => hm2_7i92.0.encoder.05.index-enable
# --- Run enable OR gate ---
net run-enable or2.0.out => hm2_7i92.0.7i77.0.1.spinena
net spindle-enable => or2.0.in0
# --- Orient angle / feedback wiring ---
net orient-angle spindle.0.orient-angle => orient.0.angle
net spindle-revs hm2_7i92.0.encoder.05.position => orient.0.position
# --- Orient PID loop ---
net orient-cmd orient.0.command => pid.o.command
net orient-fb hm2_7i92.0.encoder.05.velocity-rpm => pid.o.feedback
net orient-out pid.o.output => mux2.0.in1
# --- Normal spindle path and output switch ---
net spindle-output pid.s.output => mux2.0.in0
net spindle-vfd-out mux2.0.out => hm2_7i92.0.7i77.0.1.analogout5
# --- Completion flag back to controller ---
net orient-done orient.0.is-oriented => spindle.0.is-oriented
#Error in file ./spindlecontrol.hal:
# Pin 'orient-bit' does not exist
#Shutting down and cleaning up LinuxCNC…
Please Log in or Create an account to join the conversation.
- NT4Boy
- Offline
- Premium Member
-
Less
More
- Posts: 147
- Thank you received: 13
20 Feb 2026 13:52 - 20 Feb 2026 13:53 #343224
by NT4Boy
Replied by NT4Boy on topic HURCO KMB-1 Control Update
If it's open loop, the question becomes what is changing the analog out command?
(bottom trace second plot)
Fixed the varying speed.. The source was the analog speed override pots, which are 5volt, being scaled to 3.3 and lastly 8 bit converted.
I inserted a low pass filter with gain at 0.01 after the analogin pin, and its magically stable.
You suggested this some time back, and as ever it was a good call. Thanks
Last edit: 20 Feb 2026 13:53 by NT4Boy.
Please Log in or Create an account to join the conversation.
- NT4Boy
- Offline
- Premium Member
-
Less
More
- Posts: 147
- Thank you received: 13
23 Feb 2026 19:49 - 23 Feb 2026 19:51 #343359
by NT4Boy
Replied by NT4Boy on topic HURCO KMB-1 Control Update
I fought the non existent pin in my spindle control hal until I found out that
hm2_7i92.0.encoder.N.index‑enable isn’t just a plain input pin. Not realy sure what I mean by that, but I cannot use 'normal' signal and pin logic, but I can set it with a setp halcmd which for now is a start.
The top trace shows the index enable being set, then encountering the index pulse, which unsets it, meanwhile the orient.0.poserr also gets reset and increases until the next manual reset, but the poserr values are not making much sense to me. The bottom of the sawtooth is -5398 and as time passes this figure increases towards zero and in fact eventually into positive, Can anyone explain these values please? [attachment=74653]poserr.png[/attachment]Attachments:
Last edit: 23 Feb 2026 19:51 by NT4Boy.
Please Log in or Create an account to join the conversation.
- NT4Boy
- Offline
- Premium Member
-
Less
More
- Posts: 147
- Thank you received: 13
23 Feb 2026 19:53 #343361
by NT4Boy
Replied by NT4Boy on topic HURCO KMB-1 Control Update
Attachments:
Please Log in or Create an account to join the conversation.
- NT4Boy
- Offline
- Premium Member
-
Less
More
- Posts: 147
- Thank you received: 13
16 Jun 2026 15:21 #347115
by NT4Boy
Replied by NT4Boy on topic HURCO KMB-1 Control Update
Its been some months since I started this quest, and only a week or so ago, I managed to get a reliable spindle orientation system working.
This was only achieved by working with that bright but sometimes impossibly childlike system, Co-Pilot.
Just about the same time I started looking at this, the 1983 parajust spindle vfd became unmendable, so I adopted a Yakagawa vfd and although it ran to me normally, I hadn't appreciated a few finer points, like what is the minimum rpm figure and what happens if the input stage receives a negative voltage indicating reverse, when the machine is setup to have a reversing relay.
So the basic premis is that the spindle, which is to all intentes direct driven as the motor is connected by a 1:1 HPD belt, has on it a 48 tooth wheel passing two hall effects sensors suitably spaced to output a quadrature signal. There is a separate single tooth index on the other edge of the pulley. The version of Linuxcnc is 2.9.3 and on a Raspberry PI (5) platform. The latter fact caused a lot of confusion as there are some subtle timing issues wrt to index pulses. Once overcome, the trying to use the Orient command failed as the orient window ends up being 22° wide, and maybe because the motion controller expects an encoder with over a thousand counts per rev, not 192. Anyway, means I cannot use Orient.
Neither could I use M19, and I could not find any pin that would light up when M19 called, so have adopted M119 as a custom command. (There is also an M109 to cancel M119, but not used as the M119 contains the shut down itself down after a wait.) M19 cannot be remapped as its too deep in the motion control, I believe.
The vfd can be set to run right down to less than 20rpm and the machine's spindle brake is hard wired into the vfd enable signal, so the only viable method I have found is to set the index enable, run the spindle until the index enable pin goes low, and disable the vfd and apply the brake.
You'll see from the attached hal file that this simple statement led to a complex solution.
The Normal spindle commands M3 and M4 on this machine do not require a spindle PID. The vfd on its own without any feedback runs the spindle stably and consistently, so is not implemented. Because I have a reversing relay, the vfd speed signal needs to be abs, so not to go negative. Also before I set out on this orientation quest, rigid tapping via M33.1 worked, so that encoder feedback requires being maintained.
This may not be elegant, but it does work for me, where none of the other methods, and I try try too many of them, didn't suit my hardware.
The actual code here was written by Co-Pilot and my relationship with 'him' has been interesting Just because he gets the syntax right once, don't be surprised when some iterations later, 'he' 'forgets' and has to be reminded. At times it has been extraordinarily frustating, but the way I see it is that he has read the whole forum, github releases and a lot more, so can guess at solutions, but won't know if something that was put forward actually worked, so if you engage in this kind of torture, you have to go back with facts, and he will rewrite, over and over..
One thing left over to solve is that when running at 3000 rpm say, and calling for a tool change, the spindle enable signal disappears and the spindle brake applies instantly, and to my mind its uneccessarily violent. I asked Co-Pilot to write me a soft stop that instead of simply cutting the enable signal, reduces the speed to 450 rpm speed, so the spindle is braked internally via the vfd and braking resisitor to a much slower speed before applying the brake. This is written, but not yet tested.
This was only achieved by working with that bright but sometimes impossibly childlike system, Co-Pilot.
Just about the same time I started looking at this, the 1983 parajust spindle vfd became unmendable, so I adopted a Yakagawa vfd and although it ran to me normally, I hadn't appreciated a few finer points, like what is the minimum rpm figure and what happens if the input stage receives a negative voltage indicating reverse, when the machine is setup to have a reversing relay.
So the basic premis is that the spindle, which is to all intentes direct driven as the motor is connected by a 1:1 HPD belt, has on it a 48 tooth wheel passing two hall effects sensors suitably spaced to output a quadrature signal. There is a separate single tooth index on the other edge of the pulley. The version of Linuxcnc is 2.9.3 and on a Raspberry PI (5) platform. The latter fact caused a lot of confusion as there are some subtle timing issues wrt to index pulses. Once overcome, the trying to use the Orient command failed as the orient window ends up being 22° wide, and maybe because the motion controller expects an encoder with over a thousand counts per rev, not 192. Anyway, means I cannot use Orient.
Neither could I use M19, and I could not find any pin that would light up when M19 called, so have adopted M119 as a custom command. (There is also an M109 to cancel M119, but not used as the M119 contains the shut down itself down after a wait.) M19 cannot be remapped as its too deep in the motion control, I believe.
The vfd can be set to run right down to less than 20rpm and the machine's spindle brake is hard wired into the vfd enable signal, so the only viable method I have found is to set the index enable, run the spindle until the index enable pin goes low, and disable the vfd and apply the brake.
You'll see from the attached hal file that this simple statement led to a complex solution.
The Normal spindle commands M3 and M4 on this machine do not require a spindle PID. The vfd on its own without any feedback runs the spindle stably and consistently, so is not implemented. Because I have a reversing relay, the vfd speed signal needs to be abs, so not to go negative. Also before I set out on this orientation quest, rigid tapping via M33.1 worked, so that encoder feedback requires being maintained.
This may not be elegant, but it does work for me, where none of the other methods, and I try try too many of them, didn't suit my hardware.
The actual code here was written by Co-Pilot and my relationship with 'him' has been interesting Just because he gets the syntax right once, don't be surprised when some iterations later, 'he' 'forgets' and has to be reminded. At times it has been extraordinarily frustating, but the way I see it is that he has read the whole forum, github releases and a lot more, so can guess at solutions, but won't know if something that was put forward actually worked, so if you engage in this kind of torture, you have to go back with facts, and he will rewrite, over and over..
One thing left over to solve is that when running at 3000 rpm say, and calling for a tool change, the spindle enable signal disappears and the spindle brake applies instantly, and to my mind its uneccessarily violent. I asked Co-Pilot to write me a soft stop that instead of simply cutting the enable signal, reduces the speed to 450 rpm speed, so the spindle is braked internally via the vfd and braking resisitor to a much slower speed before applying the brake. This is written, but not yet tested.
Please Log in or Create an account to join the conversation.
Moderators: piasdom
Time to create page: 0.211 seconds