Test index of rotary encoder with hal only

More
06 Oct 2019 15:49 - 06 Oct 2019 15:53 #147253 by JC10
Hello,

I am trying to test the index of a suspicious rotary encoder.

My idea is to use the pulse of the index as input of a HAL toggle and observe its output.

Any time the index pulses, the toggle output should change.

Underr halcmd, I load and start the following :
# components
loadrt hostmot2 
loadrt hm2_eth board_ip="10.10.10.10" config=" num_encoders=1 num_pwmgens=0 num_stepgens=0 sserial_port_0=0000xx" 
loadrt toggle 
loadrt threads name1=test-thread period1=1000000 
#loadrt __test-thread  (not loaded by loadrt, no args saved)
# pin aliases
# param aliases
# signals
# nets
net index_enable hm2_7i92.0.encoder.00.index-enable
net pulse hm2_7i92.0.encoder.00.input-index => toggle.0.in
net step toggle.0.out
# parameter values
setp hm2_7i92.0.7i76.0.0.output-00-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-01-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-02-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-03-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-04-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-05-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-06-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-07-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-08-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-09-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-10-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-11-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-12-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-13-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-14-invert        FALSE
setp hm2_7i92.0.7i76.0.0.output-15-invert        FALSE
setp hm2_7i92.0.7i76.0.0.spindir-invert        FALSE
setp hm2_7i92.0.7i76.0.0.spinena-invert        FALSE
setp hm2_7i92.0.7i76.0.0.spinout-maxlim          100
setp hm2_7i92.0.7i76.0.0.spinout-minlim            0
setp hm2_7i92.0.7i76.0.0.spinout-scalemax          100
setp hm2_7i92.0.encoder.00.counter-mode        FALSE
setp hm2_7i92.0.encoder.00.filter         TRUE
setp hm2_7i92.0.encoder.00.index-invert        FALSE
setp hm2_7i92.0.encoder.00.index-mask        FALSE
setp hm2_7i92.0.encoder.00.index-mask-invert        FALSE
setp hm2_7i92.0.encoder.00.scale            1
setp hm2_7i92.0.encoder.00.vel-timeout          0.5
setp hm2_7i92.0.gpio.000.invert_output        FALSE
setp hm2_7i92.0.gpio.000.is_opendrain        FALSE
setp hm2_7i92.0.gpio.000.is_output        FALSE
setp hm2_7i92.0.gpio.001.invert_output        FALSE
setp hm2_7i92.0.gpio.001.is_opendrain        FALSE
setp hm2_7i92.0.gpio.001.is_output        FALSE
setp hm2_7i92.0.gpio.002.invert_output        FALSE
setp hm2_7i92.0.gpio.002.is_opendrain        FALSE
setp hm2_7i92.0.gpio.002.is_output        FALSE
setp hm2_7i92.0.gpio.003.invert_output        FALSE
setp hm2_7i92.0.gpio.003.is_opendrain        FALSE
setp hm2_7i92.0.gpio.003.is_output        FALSE
setp hm2_7i92.0.gpio.004.invert_output        FALSE
setp hm2_7i92.0.gpio.004.is_opendrain        FALSE
setp hm2_7i92.0.gpio.004.is_output        FALSE
setp hm2_7i92.0.gpio.005.invert_output        FALSE
setp hm2_7i92.0.gpio.005.is_opendrain        FALSE
setp hm2_7i92.0.gpio.005.is_output        FALSE
setp hm2_7i92.0.gpio.006.invert_output        FALSE
setp hm2_7i92.0.gpio.006.is_opendrain        FALSE
setp hm2_7i92.0.gpio.006.is_output        FALSE
setp hm2_7i92.0.gpio.007.invert_output        FALSE
setp hm2_7i92.0.gpio.007.is_opendrain        FALSE
setp hm2_7i92.0.gpio.007.is_output        FALSE
setp hm2_7i92.0.gpio.008.invert_output        FALSE
setp hm2_7i92.0.gpio.008.is_opendrain        FALSE
setp hm2_7i92.0.gpio.008.is_output        FALSE
setp hm2_7i92.0.gpio.009.invert_output        FALSE
setp hm2_7i92.0.gpio.009.is_opendrain        FALSE
setp hm2_7i92.0.gpio.009.is_output        FALSE
setp hm2_7i92.0.gpio.010.invert_output        FALSE
setp hm2_7i92.0.gpio.010.is_opendrain        FALSE
setp hm2_7i92.0.gpio.012.invert_output        FALSE
setp hm2_7i92.0.gpio.012.is_opendrain        FALSE
setp hm2_7i92.0.gpio.012.is_output        FALSE
setp hm2_7i92.0.gpio.013.invert_output        FALSE
setp hm2_7i92.0.gpio.013.is_opendrain        FALSE
setp hm2_7i92.0.gpio.013.is_output        FALSE
setp hm2_7i92.0.gpio.017.invert_output        FALSE
setp hm2_7i92.0.gpio.017.is_opendrain        FALSE
setp hm2_7i92.0.gpio.017.is_output        FALSE
setp hm2_7i92.0.gpio.018.invert_output        FALSE
setp hm2_7i92.0.gpio.018.is_opendrain        FALSE
setp hm2_7i92.0.gpio.018.is_output        FALSE
setp hm2_7i92.0.gpio.019.invert_output        FALSE
setp hm2_7i92.0.gpio.019.is_opendrain        FALSE
setp hm2_7i92.0.gpio.019.is_output        FALSE
setp hm2_7i92.0.gpio.020.invert_output        FALSE
setp hm2_7i92.0.gpio.020.is_opendrain        FALSE
setp hm2_7i92.0.gpio.020.is_output        FALSE
setp hm2_7i92.0.gpio.021.invert_output        FALSE
setp hm2_7i92.0.gpio.021.is_opendrain        FALSE
setp hm2_7i92.0.gpio.021.is_output        FALSE
setp hm2_7i92.0.gpio.022.invert_output        FALSE
setp hm2_7i92.0.gpio.022.is_opendrain        FALSE
setp hm2_7i92.0.gpio.022.is_output        FALSE
setp hm2_7i92.0.gpio.023.invert_output        FALSE
setp hm2_7i92.0.gpio.023.is_opendrain        FALSE
setp hm2_7i92.0.gpio.023.is_output        FALSE
setp hm2_7i92.0.gpio.024.invert_output        FALSE
setp hm2_7i92.0.gpio.024.is_opendrain        FALSE
setp hm2_7i92.0.gpio.024.is_output        FALSE
setp hm2_7i92.0.gpio.025.invert_output        FALSE
setp hm2_7i92.0.gpio.025.is_opendrain        FALSE
setp hm2_7i92.0.gpio.025.is_output        FALSE
setp hm2_7i92.0.gpio.026.invert_output        FALSE
setp hm2_7i92.0.gpio.026.is_opendrain        FALSE
setp hm2_7i92.0.gpio.026.is_output        FALSE
setp hm2_7i92.0.gpio.027.invert_output        FALSE
setp hm2_7i92.0.gpio.027.is_opendrain        FALSE
setp hm2_7i92.0.gpio.027.is_output        FALSE
setp hm2_7i92.0.gpio.028.invert_output        FALSE
setp hm2_7i92.0.gpio.028.is_opendrain        FALSE
setp hm2_7i92.0.gpio.028.is_output        FALSE
setp hm2_7i92.0.gpio.029.invert_output        FALSE
setp hm2_7i92.0.gpio.029.is_opendrain        FALSE
setp hm2_7i92.0.gpio.029.is_output        FALSE
setp hm2_7i92.0.gpio.030.invert_output        FALSE
setp hm2_7i92.0.gpio.030.is_opendrain        FALSE
setp hm2_7i92.0.gpio.030.is_output        FALSE
setp hm2_7i92.0.gpio.031.invert_output        FALSE
setp hm2_7i92.0.gpio.031.is_opendrain        FALSE
setp hm2_7i92.0.gpio.031.is_output        FALSE
setp hm2_7i92.0.gpio.032.invert_output        FALSE
setp hm2_7i92.0.gpio.032.is_opendrain        FALSE
setp hm2_7i92.0.gpio.032.is_output        FALSE
setp hm2_7i92.0.gpio.033.invert_output        FALSE
setp hm2_7i92.0.gpio.033.is_opendrain        FALSE
setp hm2_7i92.0.gpio.033.is_output        FALSE
setp hm2_7i92.0.io_error        FALSE
setp hm2_7i92.0.packet-error-increment            2
setp hm2_7i92.0.packet-error-limit           10
setp hm2_7i92.0.packet-read-timeout           80
setp hm2_7i92.0.read-request.tmax            0
setp hm2_7i92.0.read.tmax       356949
setp hm2_7i92.0.sserial.port-0.fault-dec   0x00000001
setp hm2_7i92.0.sserial.port-0.fault-inc   0x0000000A
setp hm2_7i92.0.sserial.port-0.fault-lim   0x000000C8
setp hm2_7i92.0.watchdog.timeout_ns   0x004C4B40
setp hm2_7i92.0.write.tmax        43335
setp test-thread.tmax       401760
setp toggle.0.debounce   0x00000002
setp toggle.0.tmax         1593
# realtime thread/function links
addf toggle.0 test-thread
addf hm2_7i92.0.read test-thread
addf hm2_7i92.0.write test-thread

Then I do : halcmd :sets index-enable true thats sets hm2_7i92.0.encoder.00.index-enable to true.
Then rotate the shaft of the encoder to observe that hm2_7i92.0.encoder.00.index-enable comes false after some degrees of rotation and that no pulse occurs on the toggle.

That is the behavior observed in many posts of PCW or in John Thorton's Servo Tuning Tutorials/Encoders. Behavior I experienced running Linuxcnc.

I thought by using minimal HAL only and not launching linuxcnc that this behavior would not have existed.

Is there a way to manage to get my idea working ?

Thanks for help.
Last edit: 06 Oct 2019 15:53 by JC10. Reason: Typo

Please Log in or Create an account to join the conversation.

More
06 Oct 2019 17:45 #147275 by pl7i92
why not connecting it as it is suposed to and VIEW the Counts

Please Log in or Create an account to join the conversation.

More
06 Oct 2019 21:56 #147294 by PCW
In general its not useful to read the encoder index pin directly since with high resolution encoders, it will be a very narrow pulse and cannot be sampled reliably.

If you want to toggle a pin on index you need to use index enable, something like this:

loadrt not
loadrt tristate-bit
addf not.0 servo-thread
addf tristate-bit.0 servo-thread
setp tristate-bit.0.in 1
net enable hm2_somecard.0.encoder.00.index-enable tristate-bit.0.out not.0.in
net reset not.0.out tristate-bit.0.enable

The "reset" signal will be set for one servo thread period every detected index

Please Log in or Create an account to join the conversation.

More
07 Oct 2019 13:03 #147327 by JC10
PCW many thanks for your answer.

If I understand well, the 7i92 will always see the index and when it is observed, the 7i92 will reset the index-enable to 0.

With your code, if, in a given servo-thread, index-enable is observed as 0, it will be set to 1 in the next servo-thread by « reset « (you defined here above). So in all servo-threads except one, index-enable will be set to 1.

Therefore, I should be able to toggle on « reset ». Is this right ?

Please Log in or Create an account to join the conversation.

More
07 Oct 2019 13:31 #147335 by PCW
yep toggle or count indexes

Please Log in or Create an account to join the conversation.

More
08 Oct 2019 15:07 - 08 Oct 2019 15:07 #147466 by JC10
I tried to toggle but was not successful with your code added as follows :


loadrt hostmot2 
loadrt hm2_eth board_ip="10.10.10.10" config=" num_encoders=1 num_pwmgens=0 num_stepgens=0 sserial_port_0=0000xx" 
loadrt threads name1=servo-thread period1=1000000

loadrt not
loadrt tristate_bit
loadrt toggle 

addf hm2_7i92.0.read servo-thread
addf hm2_7i92.0.write servo-thread

addf not.0 servo-thread
addf tristate-bit.0 servo-thread
addf toggle.0 servo-thread

setp tristate-bit.0.in 1
setp toggle.0.debounce 1

net enable hm2_7i92.0.encoder.00.index-enable tristate-bit.0.out not.0.in 
net reset not.0.out tristate-bit.0.enable toggle.0.in

With halmeter, I observe that index-enabled is always set true so the code works.

But apparently toggle.0.out always stays false.

I also adjusted toggle.0.debounce to 0 but no success.

However I am apparently successful when I applied John Thorton tutorial : gnipsel.com/linuxcnc/tuning/encoder.html
or the same from many of your posts like here : forum.linuxcnc.org/10-advanced-configura...oder-index-questions

PCW wrote:
The way to check index operation is to "sets" the signal that carries the spindle index enable "true",
then hand rotate the spindle to see if this signal is cleared at the index position


Is my toggle code incorrect ?

Is any of the pins provided by 7i92 on an encoder also related to the index apart index itself and index-enable ?

Thanks
Last edit: 08 Oct 2019 15:07 by JC10.

Please Log in or Create an account to join the conversation.

More
08 Oct 2019 16:41 - 08 Oct 2019 16:41 #147471 by PCW
I could be a thread order issue (the hm2_card.0.write should always be the last thing done)

It also could be that toggle cannot count a single servo period long signal
I would first fix the thread order and then halscope the reset signal
if reset is ok then maybe the flip-flop component would be a better choice (than toggle)
Last edit: 08 Oct 2019 16:41 by PCW.

Please Log in or Create an account to join the conversation.

More
09 Oct 2019 12:14 - 09 Oct 2019 12:31 #147557 by JC10
Yes, hm2_7i92.0.write needs to be located in last position.
I removed the toggle to focus on the signal reset.

Here is the HAL corrected I ran including your code :
loadrt hostmot2 
loadrt hm2_eth board_ip="10.10.10.10" config=" num_encoders=1 num_pwmgens=0 num_stepgens=0 sserial_port_0=0000xx" 
loadrt threads name1=servo-thread period1=1000000

loadrt not
loadrt tristate_bit

addf hm2_7i92.0.read servo-thread
addf not.0 servo-thread
addf tristate-bit.0 servo-thread
setp tristate-bit.0.in 1

addf hm2_7i92.0.write servo-thread

net enable hm2_7i92.0.encoder.00.index-enable tristate-bit.0.out not.0.in 
net reset not.0.out tristate-bit.0.enable 


The "reset" signal observations with halscope show unexpected behavior.

I used halscope in Run mode : single and Trigger : normal + force.

I made a first record #1 where we observe that "reset" is raised to 1 but is not set back 0 after one cycle as expected.

Then I made a second record #2 where "reset" remains at 1 except when set back to 0 periodically for one cycle, I guess when the index is detected by 7i92 as i am rotating the rotary shaft.

I checked the code as follow and for me it should work, except some unexpected behavior on index-enable that is input and output for 7i92 or something else I ignored :(
First cycle
index-enable = 0
not.0.in = 0 
not.0.out = 1
tristate-bit.0.in = 1
tristate-bit.0.enable = 1
tristate-bit.0.out = 1
enable-index = 1

Cycles where 7i92 did not detect index
index-enable = 1
not.0.in = 1
not.0.out = 0
tristate-bit.0.in = 1
tristate-bit.0.enable = 0
tristate-bit.0.out = 1
enable-index = 1

Cycle following 7i92 detected index (exactly identical to First cycle)
index-enable = 0
not.0.in = 0
not.0.out = 1
tristate-bit.0.in = 1
tristate-bit.0.enable = 1
tristate-bit.0.out = 1
enable-index = 1
Attachments:
Last edit: 09 Oct 2019 12:31 by JC10. Reason: Typo

Please Log in or Create an account to join the conversation.

More
09 Oct 2019 13:35 #147561 by PCW
The middle plot looks as expected, what do you see thats wrong?
I think that there is possibility of missing indexes on reversals
(with less than a few servo periods between indexes)
but this is not an issue with normal index use

Please Log in or Create an account to join the conversation.

More
09 Oct 2019 14:47 - 09 Oct 2019 14:49 #147564 by JC10

PCW wrote: The middle plot looks as expected, what do you see thats wrong?

For me it looks inverted compared to what we expect according to what I determined by running your code on paper as in my previous post and especially according to your post here above :

PCW wrote: The "reset" signal will be set for one servo thread period every detected index

When I rotate the shaft, I only rotate in the same direction.
Last edit: 09 Oct 2019 14:49 by JC10.

Please Log in or Create an account to join the conversation.

Moderators: PCWjmelson
Time to create page: 0.104 seconds
Powered by Kunena Forum