MPG Handwheel - how to use encoder?

More
3 years 10 months ago #258345 by frogandspanner
I bought one of the MPG handwheels (rather like the ISM8060 at www.machinetoolproducts.com/content/Yumo...s%20Spec%20Sheet.jpg )

I have connected this to a parallel port,  (A,  B and gnd) and power it from   a bench supply at 5V.
Then:
Code:
$ halrunloadrt hal_parport cfg="0x3030 out" loadrt encoder num_chan=1 net mpg-a encoder.0.phase-A <= parport.0.pin-10-in net mpg-b encoder.0.phase-B <= parport.0.pin-11-in loadusr halmeter
Using halmeter I can see that encoder.0.phase-A and encoder.0.phase-B are being detected.

From reading various examples I assumed that encoder.0.counts would change as I operated the wheel, but it doesn't - and no other encoder pin does. I then

setp encoder.0.counter-mode TRUE

and still get no changes on any pins.

As the inputs change and are detected (at least at the hal pin level), and I get no output even in counter-mode, I assume I am doing something wrong.

Please Log in to join the conversation.

More
3 years 10 months ago #258367 by PCW
There are two encoder functions that must be added for the
encoder to operate:

addf encoder.capture-position servo-thread
addf encoder.update-counters base-thread

Please Log in to join the conversation.

More
3 years 10 months ago #258375 by frogandspanner
No joy:

halcmd: addf encoder.capture-position servo-thread
HAL: ERROR: thread 'servo-thread' not found
<stdin>:5: addf failed
halcmd: addf encoder.update-counters base-thread
HAL: ERROR: thread 'base-thread' not found
<stdin>:6: addf failed

Please Log in to join the conversation.

More
3 years 10 months ago #258377 by PCW
If you have other names for your fast (base) and slow (servo)
threads, you must use those

Please Log in to join the conversation.

More
3 years 10 months ago #258378 by frogandspanner
Do threads exist by defaul,t or must they be created? If the latter how is that done?

Please Log in to join the conversation.

More
3 years 10 months ago #258379 by PCW
They need to be created, If you have a parallel port step/dir hardware,
you should use stepconf to create a hal/ini configuration file set
that takes care of these details

Please Log in to join the conversation.

More
3 years 10 months ago #258382 by frogandspanner
I was hoping to shortcut that process and just use halrun. I managed to (I think) work out some things:

loadrt hal_parport cfg="0x3030 out"
loadrt encoder num_chan=1
net mpg-a encoder.0.phase-A <= parport.0.pin-10-in
net mpg-b encoder.0.phase-B <= parport.0.pin-11-in
loadrt threads name1=base-thread period1=50000 name2=servo-thread period2=1000000
addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread
loadusr halmeter

But encoder.0.counts refuses to budge when I rotate the wheel.

Please Log in to join the conversation.

More
3 years 10 months ago #258384 by PCW
I think you need to start the threads
(I don't recall exactly how, it may be as simple as typing "start")

Please Log in to join the conversation.

More
3 years 10 months ago #258438 by frogandspanner
I got it working with this:

$ halrun -I -f ptest.hal
loadrt encoder num_chan=1
net pin10 encoder.0.phase-A
net pin11 encoder.0.phase-B
loadusr halmeter
# Add encoder routines to the porttest thread from ptest.hal
addf encoder.update-counters porttest
addf encoder.capture-position porttest

Please Log in to join the conversation.

More
3 years 10 months ago #258541 by andypugh
I tend to just "loadrt threads" which gives you one thread (called "thread1") but all that was missing from your code above was "start" to start the threads.
Code:
loadrt hal_parport cfg="0x3030 out" loadrt encoder num_chan=1 net mpg-a encoder.0.phase-A <= parport.0.pin-10-in net mpg-b encoder.0.phase-B <= parport.0.pin-11-in loadrt threads name1=base-thread period1=50000 name2=servo-thread period2=1000000 addf encoder.update-counters base-thread addf encoder.capture-position servo-thread loadusr halmeter start

Please Log in to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum