Making Sense of The C6 Code
I have had trouble with my Xylotex mini mill conversion since the start through my own lack of comprehension.
This came to a head today, when after many hours of wiring in all the components I was thwarted by the inability to read the code despite pouring over the manuals and spending most of last night and today studying the forums.
I have installed a C6 Variable Speed Control from CNC4PC.
I now cannot figure out what pins to use to control it.
I got the handy little HAL file from CNC4PC's website, but cannot decipher which pins control what or what needs to be added to make them work.
I would like to use pins 13 for step and 18 for ground
Can anyone give me an answer?
CNC4PC's Code posted below
"#
# 5th stepgen for controlling the spindle.
# Type must be set to velocity
#
loadrt stepgen step_type=0,0,0,0,0 ctrl_type=p,p,p,p,v #
# Use a scale module for offset and scaling of the stepgen
# Offset and scale are determined by first calculating and testing
#
setp scale.0.in 0
setp scale.0.gain 0.36
setp scale.0.offset 60.0
addf scale.0 servo-thread
#
# Initialise the stepgen for the spindle
#
setp stepgen.4.position-scale 1
setp stepgen.4.maxvel 1300
setp stepgen.4.steplen 1
setp stepgen.4.stepspace 0
setp stepgen.4.dirhold 20000
setp stepgen.4.dirsetup 20000
setp stepgen.4.maxaccel 200
#
# Enable
#
net spindle-enable <= motion.spindle-on => stepgen.4.enable #
# Connect spindle speed to scaler
#
net spindle-cmd motion.spindle-speed-out => scale.0.in #
# Connect scaler output to stepgen velocity
#
net spindle-freq <= scale.0.out => stepgen.4.velocity-cmd #
# Connect output to the pin for the analog voltage of cnc4pc board
#
net spindle-out <= stepgen.4.step => parport.0.pin-14-out #
# Control of spindle on/off (I1/I2 of KBIC speed controller over the
# relay instead of triac
#
net spindle-cw => parport.0.pin-16-out"
Please Log in or Create an account to join the conversation.
however the two lines of interest are
net spindle-out <= stepgen.4.step => parport.0.pin-14-out #
# Control of spindle on/off (I1/I2 of KBIC speed controller over the
# relay instead of triac
#
net spindle-cw => parport.0.pin-16-out"
the first .. net spindle-out ( parport.0.pin-14-out ) is your step pin
so as you wish to use pin 13 for your step , change this to parport.0.pin-13-out
i.e pin 13
net spindle-cw is as it says spindle clockwise ... i.e activate this pin when i want to go clockwise
or words to that effect !
or as you wish it's your direction pin , direction pins are nothing more than a switch between 0v or 5v
or forward = 0v , reverse = 5v ( or can of course be the other way round by using the invert logic.. not )
so changing this from 16 to 14 will give you the correct pin you are looking for
hope it helps understand a bit more
Dave
Please Log in or Create an account to join the conversation.
The problem you might be having is that your hal file probably already contains three stepgens, so you can't just paste-in that code, you need to merge it in. You will need to edit your existing stepgen loading line to add the velocity-mode one for the spindle.
You might find reading this HAL primer to be enlightening:
linuxcnc.org/docs/html/hal_basic_hal.html
Please Log in or Create an account to join the conversation.
This is good, with some sleep and your deciphering it is starting to make sense now.
The hard part is understanding what is relevant and what is not.
@ Andy
The fact that it was designed for Mach is what relegated it to the "parts to install" box under my desk for the last 2 years.
I do not understand why they didn't use the PWM ether, you see pwm to voltage boards on Eldorado tools like the mega series to drive the peck feature.
All in all with the file you suggested I am starting to understand the language.
I will post my Hal tonight when I get home, I will probably need help getting the C6 code sections in their proper places.
Thanks guys.
Please Log in or Create an account to join the conversation.
# Generated by stepconf at Tue Apr 5 01:43:27 2011
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt probe_parport
loadrt hal_parport cfg="0x378 out 0xc400 out "
setp parport.0.reset-time 2000
loadrt stepgen step_type=0,0,0
loadrt abs count=1
addf parport.0.read base-thread
addf parport.1.read base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
addf parport.1.write base-thread
addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
addf abs.0 servo-thread
net spindle-cmd <= motion.spindle-speed-out
net xstep => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xdir => parport.0.pin-03-out
net ystep => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
setp parport.0.pin-05-out-invert 1
net ydir => parport.0.pin-05-out
net zstep => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
setp parport.0.pin-07-out-invert 1
net zdir => parport.0.pin-07-out
setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 10000
setp stepgen.0.dirsetup 10000
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable
setp stepgen.1.position-scale [AXIS_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 0
setp stepgen.1.dirhold 10000
setp stepgen.1.dirsetup 10000
setp stepgen.1.maxaccel [AXIS_1]STEPGEN_MAXACCEL
net ypos-cmd axis.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => axis.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable axis.1.amp-enable-out => stepgen.1.enable
setp stepgen.2.position-scale [AXIS_2]SCALE
setp stepgen.2.steplen 1
setp stepgen.2.stepspace 0
setp stepgen.2.dirhold 10000
setp stepgen.2.dirsetup 10000
setp stepgen.2.maxaccel [AXIS_2]STEPGEN_MAXACCEL
net zpos-cmd axis.2.motor-pos-cmd => stepgen.2.position-cmd
net zpos-fb stepgen.2.position-fb => axis.2.motor-pos-fb
net zstep <= stepgen.2.step
net zdir <= stepgen.2.dir
net zenable axis.2.amp-enable-out => stepgen.2.enable
net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in
loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
A few things to mention.
I tried to put the C6 code in myself and it crashed. (have not tried again after new install)
I rewired the Xylotex board to reflect the pinout of the C6 control pins as specified in the unaltered CNC4PC code. P14 Step and P16 Relay CW
The Stepconf App will not allow me to configure the second card and according to HAL always sets it to OUT when I tell it IN in the config. (even after new install and updates)
I tried to add the port today by conf the wizard with the options I wanted on Port 0 and then changing them to port 1 in the hal.
No dice and EMC refused to load. (have not tried again)
I do not know if this is a huge problem though. The fresh install of 10.04 wants a new password every time I boot and a lot of the modules are not loading. (fixed with fresh install and updates)
Thanks
Please Log in or Create an account to join the conversation.
I have 3 axis movement and can run programs but still have no spindle control or limit/home switch control on port 1
I'm going to bed...
Please Log in or Create an account to join the conversation.
A few things to mention.
I tried to put the C6 code in myself and it crashed. (have not tried again after new install)
I rewired the Xylotex board to reflect the pinout of the C6 control pins as specified in the unaltered CNC4PC code. P14 Step and P16 Relay CW
The Stepconf App will not allow me to configure the second card and according to HAL always sets it to OUT when I tell it IN in the config.
There comes a time when stepgen ceases to be helpful, simply because it is not possible to cover all the possibilities. The time has come to hand-edit the hal file. Be warned that you will have to re-do these edits if you run stepconf again (but then you should have no reason to, just accept that any other features get coded in "Raw Hal"
Add/edit stuff in red, you can leave out anything green
change: loadrt hal_parport cfg="0x378 out 0xc400 out "
to: loadrt hal_parport cfg="0x378 out 0xc400 in " #change the second parport to input
loadrt stepgen step_type=0,0,0,0 ctrl_type=p,p,p,v #add an extra step/dir stepgen, make it velocity mode
loadrt abs count=1
loadrt scale count=1 #The CNC4PC config seems to have skipped this important step
# Use a scale module for offset and scaling of the stepgen
# (I am not sure why they use this, you could use the stepgen scale).
# This adds an offset to tweak, though.
setp scale.0.gain 0.36
setp scale.0.offset 60.0
addf scale.0 servo-thread
net spindle-cmd motion.spindle-speed-out => scale.0.in #link spindle speed to scale
net spindle-scaled scale.0.out => stepgen.3.velocity-cmd #send scaled speed to stepgen
net xstep => parport.0.pin-02-out
....
net zdir => parport.0.pin-07-out
net spindle-pulse => parport.0.pin-14-out #Feel free to change the parport and/or the pin
net spindle-dir => parport.0.pin-16-out #And it is far more sensible to change pins here than in hardware
setp stepgen.0.position-scale [AXIS_0]SCALE
.....
net zenable axis.2.amp-enable-out => stepgen.2.enable
# Setup spindle stepgen
setp stepgen.3.position-scale 1
setp stepgen.3.maxvel 1300
setp stepgen.3.steplen 1
setp stepgen.3.stepspace 0
setp stepgen.3.dirhold 10000
setp stepgen.3.dirsetup 10000
setp stepgen.3.maxaccel 200 #This is a factor you might like to change
net spindle-enable <= motion.spindle-on => stepgen.3.enable
net spindle-pulse <= stepgen.3.step
net spindle-dir <= stepgen.3.dir
No promises, this is all from guesswork with no access to an EMC2 setup. It should get you closer, though.
Start EMC2 from the command line, and it tells you what went wrong... (just type "emc" in a terminal window and when/if it cashes, see which pin it can't find.
Please Log in or Create an account to join the conversation.
This is the HAL modified as you outlined.
I will try it as soon as I get home and maybe it will just work without fussing with it too much.
Thanks Andy!
# Generated by stepconf at Tue Apr 5 01:43:27 2011
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt probe_parport
loadrt hal_parport cfg="0x378 out 0xc400 in "
setp parport.0.reset-time 2000
loadrt stepgen step_type=0,0,0,0 ctrl_type=p,p,p,v loadrt abs count=1 loadrt scale count=1 setp scale.0.gain 0.36
setp scale.0.offset 60.0
addf scale.0 servo-thread
addf parport.0.read base-thread
addf parport.1.read base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
addf parport.1.write base-thread
addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
addf abs.0 servo-thread
net spindle-cmd motion.spindle-speed-out => scale.0.in net spindle-scaled scale.0.out => stepgen.3.velocity-cmd
net xstep => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xdir => parport.0.pin-03-out
net ystep => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
setp parport.0.pin-05-out-invert 1
net ydir => parport.0.pin-05-out
net zstep => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
setp parport.0.pin-07-out-invert 1
net zdir => parport.0.pin-07-out net spindle-pulse => parport.0.pin-14-out net spindle-dir => parport.0.pin-16-out
setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 10000
setp stepgen.0.dirsetup 10000
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable
setp stepgen.1.position-scale [AXIS_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 0
setp stepgen.1.dirhold 10000
setp stepgen.1.dirsetup 10000
setp stepgen.1.maxaccel [AXIS_1]STEPGEN_MAXACCEL
net ypos-cmd axis.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => axis.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable axis.1.amp-enable-out => stepgen.1.enable
setp stepgen.2.position-scale [AXIS_2]SCALE
setp stepgen.2.steplen 1
setp stepgen.2.stepspace 0
setp stepgen.2.dirhold 10000
setp stepgen.2.dirsetup 10000
setp stepgen.2.maxaccel [AXIS_2]STEPGEN_MAXACCEL
net zpos-cmd axis.2.motor-pos-cmd => stepgen.2.position-cmd
net zpos-fb stepgen.2.position-fb => axis.2.motor-pos-fb
net zstep <= stepgen.2.step
net zdir <= stepgen.2.dir
net zenable axis.2.amp-enable-out => stepgen.2.enable
setp stepgen.3.position-scale 1
setp stepgen.3.maxvel 1300
setp stepgen.3.steplen 1
setp stepgen.3.stepspace 0
setp stepgen.3.dirhold 10000
setp stepgen.3.dirsetup 10000
setp stepgen.3.maxaccel 200 net spindle-enable <= motion.spindle-on => stepgen.3.enable
net spindle-pulse <= stepgen.3.step
net spindle-dir <= stepgen.3.dir
net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in
loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
Please Log in or Create an account to join the conversation.
No net, setp or loadrt commands should be in the middle of a line.
Please Log in or Create an account to join the conversation.
I did the HAL on a PC in notepad.
I will be sure to fix it when I implement it later tonight.
The Mill is on it's own dedicated PC.
Please Log in or Create an account to join the conversation.