# pyvcp-dro2-bp2.hal # three axis PyVCP/HAL DRO configuration # this uses HAL and PyVCP only, no EMC # # this assumes software encoder counting, with the encoder # signals coming in through the parallel port. If you have # hardware encoder counters, you would load the appropriate # driver instead #- This is a version of the original, for use with Pico UPC #- encoder counters, Pico DAC and spindle VFD by #- kwallace@wallacecompany.com 2007/12/15 #- It needs an EMC 2.2 install because earlier versions #- don't seem to have the xor2 component, there may be other #- options. #- The display layout is in pyvcp-dro2-bp2.xml # install Universal PWM Controller driver loadrt hal_ppmc extradac=0x00 # load mux and sum blocks # mux2: in0 (float) in1 (float) sel (bit) out (float) # sum2: in0 (float) in1 (float) out (float)(=in0 * gain0 + in1 * gain1 + offset) loadrt mux2 count=3 loadrt sum2 count=3 # Load xor's and flipflop's for spindle buttons loadrt xor2 count=2 loadrt flipflop count=2 # Load toggle for main power ##loadrt toggle count=1 # load PyVCP loadusr -Wn fred pyvcp -c fred pyvcp-dro2-bp2.xml # create 20uS and 1mS realtime threads # the 20uS fast thread means that the DRO can keep # up with encoder rates of 10-15KHz loadrt threads name1=fast period1=20000 name2=slow period2=1000000 # add realtime functions to threads addf ppmc.0.read slow addf xor2.0 fast addf xor2.1 fast addf flipflop.0 fast addf flipflop.1 fast addf mux2.0 slow addf mux2.1 slow addf mux2.2 slow addf sum2.0 slow addf sum2.1 slow addf sum2.2 slow addf ppmc.0.write slow # interconnections # # NOTE: for demo purposes, I used the old (and still valid) # "newsig+linksp" syntax for X, and the new "net" syntax # for Y and Z. The resulting connections are the same, but # you can see that the "net" syntax is much more compact. # It is only available in CVS HEAD, but the same is true of # PyVCP. # raw positions from encoders to one input of mux and summer newsig Xpos-raw float linksp Xpos-raw <= ppmc.0.encoder.00.position linksp Xpos-raw => mux2.0.in1 linksp Xpos-raw => sum2.0.in0 net Ypos-raw ppmc.0.encoder.01.position => mux2.1.in1 sum2.1.in0 net Zpos-raw ppmc.0.encoder.02.position => mux2.2.in1 sum2.2.in0 # offset position from mux output to other input of mux and summer newsig Xoffset float linksp Xoffset <= mux2.0.out linksp Xoffset => mux2.0.in0 linksp Xoffset => sum2.0.in1 net Yoffset mux2.1.out => mux2.1.in0 sum2.1.in1 net Zoffset mux2.2.out => mux2.2.in0 sum2.2.in1 # output of summer is corrected position for display newsig Xpos-corr float linksp Xpos-corr <= sum2.0.out linksp Xpos-corr => fred.Xdisplay net Ypos-corr sum2.1.out => fred.Ydisplay net Zpos-corr sum2.2.out => fred.Zdisplay # select input of mux comes from "zero" button newsig Xzero bit linksp Xzero <= fred.Xzerobutton linksp Xzero => mux2.0.sel net Yzero fred.Yzerobutton => mux2.1.sel net Zzero fred.Zzerobutton => mux2.2.sel # finally, we need to set a few parameters # set the scaling for X, Y, and Z setp ppmc.0.encoder.00.scale -2000 setp ppmc.0.encoder.01.scale 2000 setp ppmc.0.encoder.02.scale 2000 # we want the summer to subtract the offset from the # raw position, so we set the gains appropriately setp sum2.0.gain0 1.0 setp sum2.0.gain1 -1.0 setp sum2.1.gain0 1.0 setp sum2.1.gain1 -1.0 setp sum2.2.gain0 1.0 setp sum2.2.gain1 -1.0 # set the scaling for X, Y, and Z setp ppmc.0.encoder.00.scale -2000 setp ppmc.0.encoder.01.scale 2000 setp ppmc.0.encoder.02.scale 2000 # Spindle VFD Control # connect spindle DAC, set scale value to match spindle # RPM at +10 V on VFD (ex. 3000 rpm = 10 V * 300 rpm/V) setp ppmc.0.DAC8.00.scale 300 newsig SpindleSpeed float newsig SpindleDACenable bit linksp SpindleSpeed fred.SpindleRPM linksp SpindleSpeed ppmc.0.DAC8.00.value linksp SpindleDACenable ppmc.0.dout.02.out newsig SpindleStopButton bit newsig SpindleForwardButton bit newsig SpindleReverseButton bit newsig SpindleVFDforward bit newsig SpindleVFDreverse bit newsig FFclock bit linksp SpindleStopButton fred.SpindleStop linksp SpindleForwardButton fred.SpindleForward linksp SpindleReverseButton fred.SpindleReverse linksp SpindleForwardButton xor2.0.in0 linksp SpindleReverseButton xor2.0.in1 linksp FFclock xor2.0.out linksp SpindleForwardButton flipflop.0.data linksp FFclock flipflop.0.clk linksp SpindleVFDforward flipflop.0.out linksp SpindleStopButton flipflop.0.reset linksp SpindleReverseButton flipflop.1.data linksp FFclock flipflop.1.clk linksp SpindleVFDreverse flipflop.1.out linksp SpindleStopButton flipflop.1.reset linksp SpindleVFDforward xor2.1.in0 linksp SpindleVFDreverse xor2.1.in1 linksp SpindleDACenable xor2.1.out linksp SpindleVFDforward ppmc.0.dout.00.out linksp SpindleVFDreverse ppmc.0.dout.01.out newsig MainPowerButton bit newsig MainPower bit linksp MainPowerButton fred.PWR linksp MainPowerButton ppmc.0.dout.07.out # start realtime execution start show pin waitusr fred