Test index of rotary encoder with hal only

More
7 years 3 weeks ago - 7 years 3 weeks ago #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 :
Code:
# 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: 7 years 3 weeks ago by JC10. Reason: Typo

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

More
7 years 3 weeks ago #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
7 years 3 weeks ago #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
7 years 3 weeks ago #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
7 years 3 weeks ago #147335 by PCW
yep toggle or count indexes

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

More
7 years 3 weeks ago - 7 years 3 weeks ago #147466 by JC10
I tried to toggle but was not successful with your code added as follows :

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 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: 7 years 3 weeks ago by JC10.

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

Moderators: PCW, jmelson
Time to create page: 0.058 seconds
Powered by Kunena Forum