spindle encoder setup in hal
- b2unit
- Offline
- Senior Member
- Posts: 44
- Thank you received: 1
I install my encoder exactly the same with here
but my system is mesa 5i25/7i76. here's the sample hal code from the site.
I don't know which part I have to change it for mine. please let me know..
thanks,
Byoungil Choi
### This code goes in your main .hal file
############# Spindle Encoder #############
# add scale and lowpass, these will be used in custom_postgui.hal
loadrt scale count=1
loadrt lowpass count=1
# 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
# set the HAL encoder to 60 pulses per revolution.
setp encoder.0.position-scale 60
# set the HAL encoder to non-quadrature simple counting using A only.
setp encoder.0.counter-mode true
#setp encoder.0.counter-mode 1 - alternative line
# connect the HAL encoder outputs to LinuxCNC.
net spindle-position encoder.0.position => motion.spindle-revs
net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
# connect the HAL encoder inputs to the real encoder.
net spindle-phase-a encoder.0.phase-A <= hm2_5i25.0.7i76.0.0.input-10
net spindle-phase-b encoder.0.phase-B
net spindle-index encoder.0.phase-Z <= hm2_5i25.0.7i76.0.0.input-11
############# End Spindle Encoder #############
#### The following code goes in custom_postgui.hal
# **** Setup of spindle speed display using pyvcp -START ****
# **** Use ACTUAL spindle velocity from spindle encoder
# **** spindle-velocity bounces around so we filter it with lowpass
# **** spindle-velocity is signed so we use absolute component to remove sign
# **** ACTUAL velocity is in RPS not RPM so we scale it.
setp scale.0.gain 60
setp lowpass.0.gain 0.010000
net spindle-velocity => lowpass.0.in
net spindle-fb-filtered-rps lowpass.0.out => abs.0.in
net spindle-fb-filtered-abs-rps abs.0.out => scale.0.in
net spindle-fb-filtered-abs-rpm scale.0.out => pyvcp.spindle-speed
# **** set up spindle at speed indicator ****
net spindle-cmd => near.6.in1
net spindle-velocity => near.6.in2
net spindle-at-speed <= near.6.out
setp near.6.scale 1.500000
net spindle-at-speed => pyvcp.spindle-at-speed-led
Please Log in or Create an account to join the conversation.
- PCW
- Away
- Moderator
- Posts: 17877
- Thank you received: 4780
# 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
# set the HAL encoder to 60 pulses per revolution.
setp encoder.0.position-scale 60
# set the HAL encoder to non-quadrature simple counting using A only.
setp encoder.0.counter-mode true
#setp encoder.0.counter-mode 1 - alternative line
# connect the HAL encoder outputs to LinuxCNC.
net spindle-position encoder.0.position => motion.spindle-revs
net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
# connect the HAL encoder inputs to the real encoder.
net spindle-phase-a encoder.0.phase-A <= hm2_5i25.0.7i76.0.0.input-10
net spindle-phase-b encoder.0.phase-B
net spindle-index encoder.0.phase-Z <= hm2_5i25.0.7i76.0.0.input-11
############# End Spindle Encoder #############
with this
# set the HAL encoder to 60 pulses per revolution.
setp hm2_5i25.0.encoder.00.scale 60
# set the encoder to non-quadrature simple counting using A only.
setp hm2_5i25.0.encoder.00.counter-mode true
# connect the HAL encoder outputs to LinuxCNC.
net spindle-position hm2_5i25.0.encoder.00.position => motion.spindle-revs
net spindle-velocity hm2_5i25.0.encoder.00.velocity => motion.spindle-speed-in
net spindle-index-enable hm2_5i25.0.encoder.00.index-enable <=> motion.spindle-index-enable
############# End Spindle Encoder #############
and then connect the encoder to the 7I76's encoder input
Please Log in or Create an account to join the conversation.
- b2unit
- Offline
- Senior Member
- Posts: 44
- Thank you received: 1
and
you mean delete this
# connect the HAL encoder inputs to the real encoder.
net spindle-phase-a encoder.0.phase-A <= hm2_5i25.0.7i76.0.0.input-10
net spindle-phase-b encoder.0.phase-B
net spindle-index encoder.0.phase-Z <= hm2_5i25.0.7i76.0.0.input-11
and
make physical wire connection from encoder to input pin 14 for index and input pin 16 for A pulse?
Print file information:
RUN_IN_PLACE=no
LINUXCNC_DIR=
LINUXCNC_BIN_DIR=/usr/bin
LINUXCNC_TCL_DIR=/usr/lib/tcltk/linuxcnc
LINUXCNC_SCRIPT_DIR=
LINUXCNC_RTLIB_DIR=/usr/realtime-2.6.32-122-rtai/modules/linuxcnc
LINUXCNC_CONFIG_DIR=
LINUXCNC_LANG_DIR=/usr/share/linuxcnc/tcl/msgs
INIVAR=inivar
HALCMD=halcmd
LINUXCNC_EMCSH=/usr/bin/wish8.5
LINUXCNC - 2.5.3
Machine configuration directory is '/home/cnc/linuxcnc/configs/CNC_D525MW'
Machine configuration file is 'CNC_D525MW.ini'
INIFILE=/home/cnc/linuxcnc/configs/CNC_D525MW/CNC_D525MW.ini
PARAMETER_FILE=linuxcnc.var
TASK=milltask
HALUI=halui
DISPLAY=axis
Starting LinuxCNC...
Starting LinuxCNC server program: linuxcncsvr
Loading Real Time OS, RTAPI, and HAL_LIB modules
Starting LinuxCNC IO program: io
Starting HAL User Interface program: halui
Shutting down and cleaning up LinuxCNC...
Running HAL shutdown script
Killing task linuxcncsvr, PID=3702
Removing HAL_LIB, RTAPI, and Real Time OS modules
Removing NML shared memory segments
Cleanup done
Debug file information:
Can not find -sec MOT -var MOT -num 1
Can not find -sec IO -var IO -num 1
Can not find -sec LINUXCNC -var NML_FILE -num 1
Can not find -sec EMC -var NML_FILE -num 1
HAL: ERROR: thread 'base-thread' not found
CNC_D525MW.hal:164: addf failed
3702
PID TTY STAT TIME COMMAND
Stopping realtime threads
Unloading hal components
Kernel message information:
[13396.660568] I-pipe: Domain RTAI registered.
[13396.660582] RTAI[hal]: <3.8.1> mounted over IPIPE-NOTHREADS 2.6-03.
[13396.660587] RTAI[hal]: compiled with gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) .
[13396.660670] RTAI[hal]: mounted (IPIPE-NOTHREADS, IMMEDIATE (INTERNAL IRQs DISPATCHED), ISOL_CPUS_MASK: 0).
[13396.660675] PIPELINE layers:
[13396.660680] fbcb3e20 9ac15d93 RTAI 200
[13396.660685] c085cb20 0 Linux 100
[13396.708891] RTAI[malloc]: global heap size = 2097152 bytes, <BSD>.
[13396.709204] RTAI[sched]: IMMEDIATE, MP, USER/KERNEL SPACE: <with RTAI OWN KTASKs>, kstacks pool size = 524288 bytes.
[13396.709216] RTAI[sched]: hard timer type/freq = APIC/12500288(Hz); default timing: periodic; linear timed lists.
[13396.709224] RTAI[sched]: Linux timer freq = 250 (Hz), TimeBase freq = 1800144000 hz.
[13396.709229] RTAI[sched]: timer setup = 999 ns, resched latency = 2943 ns.
[13396.709359] RTAI[usi]: enabled.
[13396.867000] RTAI[math]: loaded.
[13397.005154] hm2: loading Mesa HostMot2 driver version 0.15
[13397.012832] hm2_pci: loading Mesa AnyIO HostMot2 driver version 0.7
[13397.012888] hm2_pci 0000:05:00.0: PCI INT A -> GSI 20 (level, low) -> IRQ 20
[13397.012896] hm2_pci: discovered 5i25 at 0000:05:00.0
[13397.013503] hm2/hm2_5i25.0: Smart Serial Firmware Version 35
[13397.139285] hm2/hm2_5i25.0: 34 I/O Pins used:
[13397.139296] hm2/hm2_5i25.0: IO Pin 000 (P3-01): StepGen #0, pin Direction (Output)
[13397.139304] hm2/hm2_5i25.0: IO Pin 001 (P3-14): StepGen #0, pin Step (Output)
[13397.139311] hm2/hm2_5i25.0: IO Pin 002 (P3-02): StepGen #1, pin Direction (Output)
[13397.139318] hm2/hm2_5i25.0: IO Pin 003 (P3-15): StepGen #1, pin Step (Output)
[13397.139325] hm2/hm2_5i25.0: IO Pin 004 (P3-03): StepGen #2, pin Direction (Output)
[13397.139332] hm2/hm2_5i25.0: IO Pin 005 (P3-16): StepGen #2, pin Step (Output)
[13397.139339] hm2/hm2_5i25.0: IO Pin 006 (P3-04): StepGen #3, pin Direction (Output)
[13397.139346] hm2/hm2_5i25.0: IO Pin 007 (P3-17): StepGen #3, pin Step (Output)
[13397.139353] hm2/hm2_5i25.0: IO Pin 008 (P3-05): StepGen #4, pin Direction (Output)
[13397.139360] hm2/hm2_5i25.0: IO Pin 009 (P3-06): StepGen #4, pin Step (Output)
[13397.139368] hm2/hm2_5i25.0: IO Pin 010 (P3-07): Smart Serial Interface #0, pin TxData0 (Output)
[13397.139376] hm2/hm2_5i25.0: IO Pin 011 (P3-08): Smart Serial Interface #0, pin RxData0 (Input)
[13397.139383] hm2/hm2_5i25.0: IO Pin 012 (P3-09): IOPort
[13397.139388] hm2/hm2_5i25.0: IO Pin 013 (P3-10): IOPort
[13397.139395] hm2/hm2_5i25.0: IO Pin 014 (P3-11): Encoder #0, pin Index (Input)
[13397.139402] hm2/hm2_5i25.0: IO Pin 015 (P3-12): Encoder #0, pin B (Input)
[13397.139409] hm2/hm2_5i25.0: IO Pin 016 (P3-13): Encoder #0, pin A (Input)
[13397.139415] hm2/hm2_5i25.0: IO Pin 017 (P2-01): IOPort
[13397.139421] hm2/hm2_5i25.0: IO Pin 018 (P2-14): IOPort
[13397.139427] hm2/hm2_5i25.0: IO Pin 019 (P2-02): IOPort
[13397.139432] hm2/hm2_5i25.0: IO Pin 020 (P2-15): IOPort
[13397.139438] hm2/hm2_5i25.0: IO Pin 021 (P2-03): IOPort
[13397.139444] hm2/hm2_5i25.0: IO Pin 022 (P2-16): IOPort
[13397.139449] hm2/hm2_5i25.0: IO Pin 023 (P2-04): IOPort
[13397.139455] hm2/hm2_5i25.0: IO Pin 024 (P2-17): IOPort
[13397.139461] hm2/hm2_5i25.0: IO Pin 025 (P2-05): IOPort
[13397.139466] hm2/hm2_5i25.0: IO Pin 026 (P2-06): IOPort
[13397.139472] hm2/hm2_5i25.0: IO Pin 027 (P2-07): IOPort
[13397.139478] hm2/hm2_5i25.0: IO Pin 028 (P2-08): IOPort
[13397.139484] hm2/hm2_5i25.0: IO Pin 029 (P2-09): IOPort
[13397.139489] hm2/hm2_5i25.0: IO Pin 030 (P2-10): IOPort
[13397.139495] hm2/hm2_5i25.0: IO Pin 031 (P2-11): IOPort
[13397.139501] hm2/hm2_5i25.0: IO Pin 032 (P2-12): IOPort
[13397.139506] hm2/hm2_5i25.0: IO Pin 033 (P2-13): IOPort
[13397.139655] hm2/hm2_5i25.0: registered
[13397.139661] hm2_5i25.0: initialized AnyIO board at 0000:05:00.0
[13397.747420] hm2_5i25.0: dropping AnyIO board at 0000:05:00.0
[13397.747432] hm2/hm2_5i25.0: unregistered
[13397.747468] hm2_pci 0000:05:00.0: PCI INT A disabled
[13397.747516] hm2_pci: driver unloaded
[13397.754932] hm2: unloading
[13397.838301] RTAI[math]: unloaded.
[13397.940160] SCHED releases registered named ALIEN RTGLBH
[13397.972437] RTAI[malloc]: unloaded.
[13398.072033] RTAI[sched]: unloaded (forced hard/soft/hard transitions: traps 0, syscalls 0).
[13398.077692] I-pipe: Domain RTAI unregistered.
[13398.077784] RTAI[hal]: unmounted.
Please Log in or Create an account to join the conversation.
- PCW
- Away
- Moderator
- Posts: 17877
- Thank you received: 4780
(there should be no basethread mentioned _anywhere_ in the hal file)
You connect the encoder to 7I76 TB3 pin 7 (ENCA+) and 7I76 TB3 pin 15 (IDX+)
and jumper the 7I76 encoder inputs for TTL mode if you are using OPTO interrupters
Please Log in or Create an account to join the conversation.
- b2unit
- Offline
- Senior Member
- Posts: 44
- Thank you received: 1
but in 7i76 manual
IDX+ is 7i76 TB3 pin 13.. which one is correct?
(now I use TB3 pin 13 for IDX+)
and
I put a sentence below
net spindle-velocity hm2_5i25.0.encoder.00.velocity => pyvcp.spindle-speed
in custom_postgui.hal file.
pyvcp spindle speed displays several numbers when spindle is turning but those are minus value.
and doesn't looks like rpm value..could you show me what else is added more to get rpm value of spindle?
there are several samples using parallel port without 5i25(with 7i76). I couldn't edit those lack of my knowledge..
Please Log in or Create an account to join the conversation.
- PCW
- Away
- Moderator
- Posts: 17877
- Thank you received: 4780
net spindle-velocity hm2_5i25.0.encoder.00.velocity => pyvcp.spindle-speed
is not right since encoder velocity is in RPS
This code from your original post does the RPS --> RPM conversion
and also filters and the RPM and forces it to be positive:
setp scale.0.gain 60
setp lowpass.0.gain 0.010000
net spindle-velocity => lowpass.0.in
net spindle-fb-filtered-rps lowpass.0.out => abs.0.in
net spindle-fb-filtered-abs-rps abs.0.out => scale.0.in
net spindle-fb-filtered-abs-rpm scale.0.out => pyvcp.spindle-speed
Also if hm2_5i25.0.encoder.00.velocity is negative for forward direction spindle motion
you will need to change the encoder scale to a negative number.
Please Log in or Create an account to join the conversation.
- b2unit
- Offline
- Senior Member
- Posts: 44
- Thank you received: 1
and I did try already..
but when I tried it I got error message there's no pin or parameter scale.0.gain.
I'm really embarrassed with name of parameter and pin in 5i25(w/7i76) situation.
which parameter I have to use instead of parameter scale.0.gain?( and lowpass.0.gain)
Is there any full reference of 5i25(7i76)'s parameter and pins..?
I tried find those in pncconf but what i got is(only have relevant with encoder)
and I stucked. Did I misunderstand? I'm very new to programming.
sorry for bothering you..
pins
hm2_5i25.0.encoder.00.count
hm2_5i25.0.encoder.00.count-latched
hm2_5i25.0.encoder.00.index-enable
hm2_5i25.0.encoder.00.latch-enable
hm2_5i25.0.encoder.00.latch-polarity
hm2_5i25.0.encoder.00.position
hm2_5i25.0.encoder.00.position-latched
hm2_5i25.0.encoder.00.rawcounts
hm2_5i25.0.encoder.00.rawlatch
hm2_5i25.0.encoder.00.reset
hm2_5i25.0.encoder.00.velocity
parameters
hm2_5i25.0.encoder.00.counter-mode
hm2_5i25.0.encoder.00.filter
hm2_5i25.0.encoder.00.index-invert
hm2_5i25.0.encoder.00.index-mask
hm2_5i25.0.encoder.00.index-mask-invert
hm2_5i25.0.encoder.00.scale
hm2_5i25.0.encoder.00.vel-timeout
Please Log in or Create an account to join the conversation.
- PCW
- Away
- Moderator
- Posts: 17877
- Thank you received: 4780
actually I could guess role of the source code in custom_postgui.hal..
and I did try already..
but when I tried it I got error message there's no pin or parameter scale.0.gain.
Thats likely because you did not load the scale component
loadrt scale count=1
addf scale.0 servo-thread
This is not specific to 5I25/7i76 but is general
linuxcnc.org/docs/html/hal/basic_hal.html
Please Log in or Create an account to join the conversation.
- b2unit
- Offline
- Senior Member
- Posts: 44
- Thank you received: 1
error message I got..
>Debug file information:
>>Can not find -sec MOT -var MOT -num 1
>>Can not find -sec IO -var IO -num 1
>>Can not find -sec LINUXCNC -var NML_FILE -num 1
>>Can not find -sec EMC -var NML_FILE -num 1
>>insmod: error inserting '/usr/realtime-2.6.32-122-rtai/modules/linuxcnc/scale.ko': -1 Invalid parameters
>>CNC_D525MW.hal:159: exit value: 1
>>CNC_D525MW.hal:159: insmod failed, returned -1
>>See the output of 'dmesg' for more information.
>>5425
>> PID TTY STAT TIME COMMAND
>>Stopping realtime threads
>>Unloading hal components
there's problem with CNC_D525MW.hal:159 line.
>loadrt scale count = 1
I changed value 1 to -1 but still got the same error message above.
I attached relevant files..please check those and let me know what is the problem.
thank you so much,
Byoungil Choi
Please Log in or Create an account to join the conversation.
- PCW
- Away
- Moderator
- Posts: 17877
- Thank you received: 4780
# Generated by PNCconf at Wed Mar 5 16:38:09 2014
# If you make changes to this file, they will be
# overwritten when you run PNCconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt probe_parport
loadrt hostmot2
loadrt hm2_pci config=" num_encoders=1 num_pwmgens=0 num_3pwmgens=0 num_stepgens=5 sserial_port_0=00xxxxxx "
#add scale and lowpass, these will be used in custom_postgui.hal
loadrt scale count=1
loadrt lowpass count=1
setp hm2_5i25.0.watchdog.timeout_ns 10000000
addf hm2_5i25.0.read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf hm2_5i25.0.write servo-thread
addf hm2_5i25.0.pet_watchdog servo-thread
addf scale.0 servo-thread
addf lowpass.0 servo-thread
and deleting the
loadrt scale
and
loadrt lowpass
lines from spindle section near the bottom
Please Log in or Create an account to join the conversation.