Hal encoder bug?
- garymcrobertpdx
- Offline
- Premium Member
- Posts: 101
- Thank you received: 1
The encoder.N.reset fails to reliably reset the encoder counts
and position. A encoder reset occurs about every third or fourth
reset pulse regardless of the pulse width or period.
I have spent several hours attempting to get reliable behavior with
no success, all I can conclude that this is a genuine bug.
Is this a known bug, is there a work around?
Please Log in or Create an account to join the conversation.
John
Please Log in or Create an account to join the conversation.
Can you pastebin your HAL file?
Please Log in or Create an account to join the conversation.
- garymcrobertpdx
- Offline
- Premium Member
- Posts: 101
- Thank you received: 1
A bit of a hack but it works well enough for experimenting.
I have a 2500 count / rev encoder from my junk box. I know
this is way more counts / rev than desired so I run things slow.
The encoder is attached to the output shaft of the step motor.
The index output is attached to parport pin 10, pins 11 & 12 are
attached to outputs A & B. With my Tek scope and I see a very
nice 4.5 volt 250 micro second index pulse.
My Hal code snippet
Net parport_10_in <= parport.0.pin-10-in => encoder.0.phase-z
Net parport_10_in => encoder.0.reset
Net parport_11_in <= parport.0.pin-11-in => encoder.0.phase-A
Net parport_12_in <= parport.0.pin-12-in => encoder.0.phase-B
Using Hal scope and Hal meter I observe encoder.0.position
and encoder.0.counts. These appear not to be reliably reset to
0 when encoder.0.reset = true.
Please Log in or Create an account to join the conversation.
and the capture part in a servo thread.
If you want to clear the encoder count on index, you should probably use the normal homing method (set index enable, wait for index enable clear)
Please Log in or Create an account to join the conversation.
And what is the timing of each thread?
Please Log in or Create an account to join the conversation.
- garymcrobertpdx
- Offline
- Premium Member
- Posts: 101
- Thank you received: 1
for encoder use so I get thread assignments
addf Parport.0.read base-thread
addf encoder.update-counters base-thread
addf encoder.capture-postion servo-thread
From the ini file Base_period 50000 servo_period 1000000
I then put my few lines of code into the custom hal folder
My first attempted was to use the encoder.N.index-enable pin
but it is already linked to the motion.spindle-enable pin and
it is a bidirectional pin also.
Being a newbie I had was not sure how to work this out so
the other pin was an attractive option. unfortunately it works
differently than expected.
So is it that the servo period is to slow to capture the index
250 microsecond pulse and would work properly when I
run the code on my faster computer rather than the junker
that I have at my work bench
I have devised a not so elegant work around using G33 M5
to turn the spindle one rev and stop. Seems to work OK but
I rather not do it this way.
Please Log in or Create an account to join the conversation.
So is it that the servo period is to slow to capture the index
250 microsecond pulse and would work properly when I
run the code on my faster computer rather than the junker
that I have at my work bench
No, you would generally always keep the servo period at 1mS, and the base thread period should be fine for capturing the reset pulse.
I was wondering if the update-counters function was running in the servo thread, which would explain the effect.
Out of interest, why are you wanting to reset the encoder?
You might find that the latch-enable etc pins do what you want. The actual source code is here, if you want to ponder in detail what the pins do.
git.linuxcnc.org/gitweb?p=emc2.git;a=blo...04eb0d55015e;hb=HEAD
It seems that the latch functions run in the base thread, but the reset only runs in the servo thread. This is probably reasonable, as the typical source of a reset pulse will run in the servo thread too.
Please Log in or Create an account to join the conversation.
- garymcrobertpdx
- Offline
- Premium Member
- Posts: 101
- Thank you received: 1
I think it was you that suggested using a mux and a pid
and the tool change bit to accomplish this.
So I thought if I zeroed the encoder position on the index
Pulse, with the encoder position linked to the pid feedback
and set the pid command input to zero. With the pid output
linked to the stepgen which drives my spindle motor.
Hopefully this would cause the spindle to rotate to a repeatable
position for tool change. It seemed to work but then completely
miss the mark, that is when i discovered the reset problem.
Please Log in or Create an account to join the conversation.
I expect to find out some time next year, I have the same puzzle to solve.
Please Log in or Create an account to join the conversation.