Encoder mode multiplexing

More
31 Mar 2013 00:33 #32101 by gman
Hi,
I made a spindle encoder for my lathe, it works great in range 0 to 1900 RPM but at higher speed it does not work properly. The problem is in the paralel port, that has very low sampling frequency and can't keep up with encoder frequency.
My idea how to fix it is start using the encoder in two different modes:
  • high speed - counter mode
  • low speed - quadrature mode (x4 mode)
I tried to use comparator for switching encoder parameters, but i can't get it working. It looks like it is not able to connect signal and parameter.
Is it possible to fix it somehow?
Here is piece of my code:

loadrt abs count =1
loadrt comp count=1
loadrt not count=1
loadrt mux2 count=1

## get absolute value of comanded speed
net abs_in motion.spindle-speed-out => abs.0.in
## if(comanded speed > 1000) use counter mode
## else use x4 mode
net abs_out abs.0.out => comp.0.in1
setp comp.0.in0 1000
setp comp.0.hyst 20
## set encoder mode
net comp_out comp.0.out => encoder.0.counter-mode #here I get error
net comp_out => not.0.in
net encoder_mode not.0.out => encoder.0.x4-mode
net comp_out => mux2.0.sel
setp mux2.0.in0 90
setp mux2.0.in1 360
## set the scale
net mux2.0.out => encoder.0.position-scale

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

More
31 Mar 2013 19:18 #32121 by ArcEye
Replied by ArcEye on topic Encoder mode multiplexing

net comp_out comp.0.out => encoder.0.counter-mode #here I get error


What error do you get?

comp.0.out is a bit out pin and encoder.0.counter-mode is a bit I/O pin, that sometimes causes problems.

regards

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

More
01 Apr 2013 07:15 #32139 by andypugh
Replied by andypugh on topic Encoder mode multiplexing

]high speed - counter mode / low speed - quadrature mode (x4 mode)

My first thought was that that won't help, but actually it probably will give you twice the speed.

I checked the code and it looks like you can switch to counter-mode on the fly.

For some random reason lots of parameters were made into IO pins a while ago. This was meant to make it easier to do the sort of thing you want to do, but IO pins are awkward. That pin should be an input.

You probably need to use the "tristate" component to convert the output of your comparator into an IO type bit.
www.linuxcnc.org/docs/html/man/man9/tristate_bit.9.html
The following user(s) said Thank You: gman

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

More
01 Apr 2013 07:21 #32140 by gman
Replied by gman on topic Encoder mode multiplexing
Yes, you are right, that is the source of this problem.

Error: Can not add OUT pin "comp.0.out" It already has I/O pin "encoder.0.counter-mode"
Is there any solution how to make it work?

Thanks

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

More
01 Apr 2013 07:52 #32142 by gman
Replied by gman on topic Encoder mode multiplexing

My first thought was that that won't help, but actually it probably will give you twice the speed.

Using x4 mode - there are 4 possible states per period (per slot). Every single state should be sampled at least twice -> min sampling rate = 8x per period
Using counter mode - there are only two states, so as you said, it can double the speed(in my case 0 to 4000RPM). But there is no possibility to do threading, using this mode.

The "tristate" component looks promising. I'll try.
Thanks

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

More
01 Apr 2013 18:11 #32151 by BigJohnT
Replied by BigJohnT on topic Encoder mode multiplexing

Yes, you are right, that is the source of this problem.

Error: Can not add OUT pin "comp.0.out" It already has I/O pin "encoder.0.counter-mode"
Is there any solution how to make it work?

Thanks


Read about the net command here .

John

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

More
08 Apr 2013 02:14 #32394 by gman
Replied by gman on topic Encoder mode multiplexing
Thanks again guys, it is working very well with the tristate component. The encoder can handle frequency higher than 3300 RPM now. I don't know the maximal encoder RPM because my spindle can't go faster. :)

Here is my code,
# spindle E N C O D E R
loadrt encoder num_chan=1
loadrt tristate_bit count=2   #converts bit to IO signal
loadrt tristate_float count=1  #converts float value to IO signal
loadrt comp count=1
loadrt mux2 count=1
loadrt not count=2

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

net spindle-position encoder.0.position => motion.spindle-revs
net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
net spindle-cmd <= motion.spindle-speed-out
net spindle-phase-a encoder.0.phase-A <= parport.0.pin-11-in-not
net spindle-phase-b encoder.0.phase-B <= parport.0.pin-12-in-not
net spindle-index encoder.0.phase-Z <= parport.0.pin-13-in-not

net spindle-cmd => abs.1.in      #get absolute speed value
net abs_out abs.1.out => comp.0.in1
setp comp.0.in0 1000                 #compare component, if (speed>1000) switch encoder to counter mode
setp comp.0.hyst 20

setp tristate-bit.0.enable 1    #switch all tristate components on
setp tristate-bit.1.enable 1
setp tristate-float.0.enable 1

net comp_out comp.0.out  =>  tristate-bit.0.in
net comp_out  =>  not.0.in
net not_out not.0.out  =>  tristate-bit.1.in
net mode_select2 tristate-bit.1.out => encoder.0.x4-mode         #connect comparator to encoder mode selector
net mode_select tristate-bit.0.out => encoder.0.counter-mode  #connect comparator to encoder mode selector 
net comp_out => mux2.0.sel               # connect comparator to the multiplexer for scale setting
setp mux2.0.in1 90                                # 90 PPR in counter mode
setp mux2.0.in0 360                              # 360 PPR in x4 mode
net mux_out mux2.0.out => tristate-float.0.in
net scale_select tristate-float.0.out => encoder.0.position-scale   #connect mux to the scale 

addf tristate-float.0 servo-thread
addf abs.1 servo-thread
addf comp.0 servo-thread
addf mux2.0 servo-thread
addf tristate-bit.0 servo-thread
addf tristate-bit.1 servo-thread
addf not.0 servo-thread 

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

Time to create page: 0.305 seconds
Powered by Kunena Forum