# 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=6 loadrt sum2 count=6 # 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-drovfd_dual.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 mux2.3 slow addf mux2.4 slow addf mux2.5 slow addf sum2.0 slow addf sum2.1 slow addf sum2.2 slow addf sum2.3 slow addf sum2.4 slow addf sum2.5 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 => mux2.3.in1 linksp Xpos-raw => sum2.0.in0 linksp Xpos-raw => sum2.3.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 XAoffset float newsig XBoffset float linksp XAoffset <= mux2.0.out linksp XBoffset <= mux2.3.out linksp XAoffset => mux2.0.in0 linksp XBoffset => mux2.3.in0 linksp XAoffset => sum2.0.in1 linksp XBoffset => sum2.3.in1 net YAoffset mux2.1.out => mux2.1.in0 sum2.1.in1 net YBoffset mux2.4.out => mux2.4.in0 sum2.4.in1 net ZAoffset mux2.2.out => mux2.2.in0 sum2.2.in1 net ZBoffset mux2.5.out => mux2.5.in0 sum2.5.in1 # output of summer is corrected position for display newsig XApos-corr float linksp XApos-corr <= sum2.0.out linksp XApos-corr => fred.XAdisplay newsig XBpos-corr float linksp XBpos-corr <= sum2.3.out linksp XBpos-corr => fred.XBdisplay net YApos-corr sum2.1.out => fred.YAdisplay net YBpos-corr sum2.4.out => fred.YBdisplay net ZApos-corr sum2.2.out => fred.ZAdisplay net ZBpos-corr sum2.5.out => fred.ZBdisplay # select input of mux comes from "zero" button newsig XAzero bit linksp XAzero <= fred.XAzerobutton linksp XAzero => mux2.0.sel newsig XBzero bit linksp XBzero <= fred.XBzerobutton linksp XBzero => mux2.3.sel net YAzero fred.YAzerobutton => mux2.1.sel net YBzero fred.YBzerobutton => mux2.4.sel net ZAzero fred.ZAzerobutton => mux2.2.sel net ZBzero fred.ZBzerobutton => mux2.5.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 setp sum2.3.gain0 1.0 setp sum2.3.gain1 -1.0 setp sum2.4.gain0 1.0 setp sum2.4.gain1 -1.0 setp sum2.5.gain0 1.0 setp sum2.5.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