Spindle control, 2 speed gear changer and 2 encoders

16 Dec 2017 16:38 #103170 by Gene1934
Gene1934 created the topic: Spindle control, 2 speed gear changer and 2 encoders
Recently giving up on an interrupter based spindle encoder, primarily because there is not enough room in a G0704 for a decent sized, and slot count wheel. A 2.5" with 64 slots just doesn't cut it

So I undertook to make the spindle encoder inputs from the index of my shop made encoder on the spindle,
but the a/b quadrature taken from a 1000 line encoder driven off the rear of the 1 hp PMDC motor.

So I bought a $21 Omron on eBay. When it arrived. I found it had a differential output, and any attempts to use it as single ended were stymied by very poor waveforms and noise.

So first I had to make some rs485-ttl gizmo's into a small hammond box as receivers, disabling the transmitters, but they did a fine job and are unbelievably cheap from eBay. Took the ttl output on into the BoB.

But this leaves a huge problem yet to be solved. Changing the spindles 2 speed gear changer messes with the spindles scale count from index to index, so one can only do rigid tapping in one gear or the other. I solved the 'tell LCNC what gear" its in with a pair of switches on the knob that are only true when the knob is firmly in gear. That may be the subject of another post however. Suffice to say we play with hal a bit.

But first we need to know what the working encoder scale is, so here's the hal code to tell one the measured
scales in each speed.

# need some compares for this
loadrt comp names=comp_drvbooted,comp_cal0,comp_cal1
# and some mux2's as sample-holds
loadrt mux2 names=mux2.fwd-rev,mux2_spndl,mux2cal0,mux2cal1
# and something to show the result
loadrt sum2 names=sum2_ovrtrvl,sum2_gearchg,sum2_bias,spndl_tally
# and something to count spindle revs
loadrt updown names=spndl_cntr
# and a data format conversion
loadrt conv_s32_float names=S32_float_cmd,S32_float_spndl,S32_float-cntr,S32_float-cal
# then the addf's
addf S32_float_spndl servo-thread # is conv-s32-float
addf S32_float-cntr servo-thread # ditto
addf spndl_cntr servo-thread
addf spndl_tally servo-thread
addf comp_cal0 servo-thread
addf comp_cal1 servo-thread
addf S32_float-cal servo-thread
addf mux2cal0 servo-thread
addf mux2cal1 servo-thread
# there's stuff not related above that occur on the same loadrt line

# this is near the top of the halfile
# calibrate spindle to new encoder *
# use halshow to reset updown for new count *
# this code is not part of normal operation *
# used only to determine working gear ratios *
# sample rate now turned up so filter can be used
setp hm2_5i25.0.encoder.00.filter true
net scalibrate0 <= mux2cal0.out => mux2cal0.in1 spndl_tally.in0 # make it a sample-hold
net scalibrate1 <= mux2cal1.out => mux2cal1.in1 spndl_tally.in1 # ditto
# this is index from old spindle opto
net ztrack <= hm2_5i25.0.gpio.016.in => spndl_cntr.countup
net ztrakS32 <= spndl_cntr.count => S32_float-cntr.in
net ztrackF <= S32_float-cntr.out => comp_cal0.in1 comp_cal1.in1
# spndl_tally is a sum2
setp spndl_tally.gain0 -1.00000000000
setp spndl_tally.gain1 1.00000000000
# set to log 100 indexes
setp comp_cal0.in0 5.5
setp comp_cal1.in0 105.5
net Scounter-in <= hm2_5i25.0.encoder.00.rawcounts => S32_float-cal.in
net Fcounter-in <= S32_float-cal.out => mux2cal0.in0 mux2cal1.in0
net shhold0 <= comp_cal0.out =>mux2cal0.sel
net shhold1 <= comp_cal1.out =>mux2cal1.sel

# when mux2-cal1.out is frozen, do [spndl-tally.out / 100] to get scale.
# repeat for other gear for 2nd scale factor. When done, comment it all out

In my case, high gear was a 7161.61, while in low gear, it was 140##.##
and in the ini file, those were set like this:
SCALE_UP = 1.96818033933710437
SCALE_DOWN = 0.508083522639397134

The latter 2 are for use in hal to scale the drive to the pid.command, and to the tach display
in the axis gui to maintain its accuracy regardless of the gear selected.

With some hal trickery I can do an s1400m3, and the gear doesn't matter, I get 1400 revs.

With some more hal trickery, I can reach over and change the gear on the fly with the spindle
running because I don't stop the motor when the tallies go false, but leave it turning about
20 revs when neither gear tally input is true, so when the knob gets to
where the gears are re-engaging, the motor is turning very slow and gear meshing is silent
and automatic. Only when the tally line goes true does it speed the motor back up to the set speed.

But this shows how an accurate scale is measured for use later when the actual gear scale
in the mills head is unknown.

All this can be commented out once the measurements for each gear have been done and recorded.

To reset the counter for the other measurement, I used a setp in the hal_show-config screen to raise
and lower the updown's reset line.

For best accuracy, run the spindle slow, although I got quite similar results at 1500 as I got at 50 rpms.

I hope this helps someone.
Time to create page: 0.109 seconds
Powered by Kunena Forum