Tutaj masz trochę wyższą szkołę jazdy:
Kod: Zaznacz cały
# add the encoder to HAL and attach it to threads.
loadrt encoder num_chan=1
addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread
loadrt comp count=2
addf comp.0 servo-thread
addf comp.1 servo-thread
setp comp.0.in1 0.01
setp comp.1.in0 -0.01
loadrt or2 count=2
addf or2.0 base-thread
addf or2.1 base-thread
loadrt and2 count=4
addf and2.0 base-thread
addf and2.1 base-thread
addf and2.2 base-thread
addf and2.3 base-thread
# set the HAL encoder to 160 pulses per revolution.
setp encoder.0.position-scale 160
#setp encoder.0.index-enable true
# set the HAL encoder to non-quadrature simple counting using A only.
#setp encoder.0.counter-mode true
# connect the HAL encoder outputs to LinuxCNC.
net spindle-position encoder.0.position spindle.0.revs
net spindle-velocity encoder.0.velocity spindle.0.speed-in comp.0.in0 comp.1.in1
net spindle-index-enable encoder.0.index-enable spindle.0.index-enable
net spindle-err-fwd-in comp.0.out and2.1.in1
net spindle-err-rev-in comp.1.out and2.0.in1
# connect the HAL encoder inputs to the real encoder.
net spindle-phase-a encoder.0.phase-A parport.0.pin-11-in
net spindle-phase-b encoder.0.phase-B parport.0.pin-12-in
net spindle-index encoder.0.phase-Z parport.0.pin-13-in-not
net spindle-fwd spindle.0.forward and2.0.in0 and2.2.in0
net spindle-rev spindle.0.reverse and2.1.in0 and2.3.in0
net spindle-dir-enable-in1 and2.0.out or2.0.in0
net spindle-dir-enable-in2 and2.1.out or2.0.in1
net spindle-dir-enable or2.0.out and2.2.in1 and2.3.in1
net spindle-fwd-out and2.2.out parport.0.pin-06-out
net spindle-rev-out and2.3.out parport.0.pin-07-out
Chodzi o to, że mam w tokarce silnik jednofazowy z kondensatorem rozruchowym.
Taki silnik nie zmieni kierunku kiedy jest w ruchu, pomimo przełączenia uzwojeń będzie się kręcił nadal w tym samym kierunku.
Komponenty comp, and i or są użyte aby nie dało się włączyć silnika będącego w ruchu (kiedy się obraca, niekoniecznie zasilany).
Jak widać enkoder może służyć nie tylko do gwintowania...