× Forum Header

Driving a ULN2003 Darlington array IC

More
24 Sep 2012 20:09 #24592 by liam2317
Hello everyone,

I am a pretty big noob when it comes to CNC and LinuxCNC and am having trouble getting my system working.

What I have is a really basic two axis setup that I made myself from some old 5 wire stepper motors out of a printer. I would like to control them with a pair of ULN2003 Darlington array ICs (because they are amazingly cheap and I already have them). I have found a few sites/forum posts that say that this setup is possible with LinuxCNC and hint at how to do it but most of them are quite old and I can't get it working.

From what I understand I need to edit my .hal file and change stepgen from type 0 to type 5 as well as edit some other items in that file which will assign the proper output pin configuration. It also looks like I have to remove some items which only apply to type 0 but I can't figure out what. Is there an example .hal file for a type 5 stepgen anywhere? I have read the stepgen documentation but I am still lost.

The attached file shows how my configuration is wired.

Thanks for any help you can provide and sorry if this is in the wrong section!

-Liam
Attachments:

Please Log in or Create an account to join the conversation.

More
24 Sep 2012 20:17 #24593 by BigJohnT
In your hal file you will find the line that loads stepgen and change the type0 to type5.

loadrt stepgen step_type=type0,type0,type0

to

loadrt stepgen step_type=type5,type5,type5

John

Please Log in or Create an account to join the conversation.

More
25 Sep 2012 07:18 #24599 by liam2317
Thanks for the tip John but I think I have to change more than just that. Since a normal driver needs only two serial port pins per motor and the ULN2003 requires 4 serial port pins per motor I'm defiantly going to have to change something. When I change only the stepgen step type LinuxCNC will not run and gives me the following error message. Below that is my current hal file which I have tried to edit a bit to allow for 4 pins/motor but I'm sure is still not right.

Any ideas? Thanks!

Error Message:
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.0
Machine configuration directory is '/home/liam/linuxcnc/configs/uln2003'
Machine configuration file is 'uln2003.ini'
INIFILE=/home/liam/linuxcnc/configs/uln2003/uln2003.ini
PARAMETER_FILE=linuxcnc.var
TASK=milltask
HALUI=
DISPLAY=axis
Starting LinuxCNC...
Starting LinuxCNC server program: linuxcncsvr
Loading Real Time OS, RTAPI, and HAL_LIB modules
Starting LinuxCNC IO program: io
Shutting down and cleaning up LinuxCNC...
Killing task linuxcncsvr, PID=1687
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 
uln2003.hal:44: parameter or pin 'stepgen.0.stepspace' not found
1687
  PID TTY      STAT   TIME COMMAND
Stopping realtime threads
Unloading hal components

Kernel message information:
[  116.455113] I-pipe: Domain RTAI registered.
[  116.455127] RTAI[hal]: <3.8.1> mounted over IPIPE-NOTHREADS 2.6-03.
[  116.455132] RTAI[hal]: compiled with gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) .
[  116.455199] RTAI[hal]: mounted (IPIPE-NOTHREADS, IMMEDIATE (INTERNAL IRQs DISPATCHED), ISOL_CPUS_MASK: 0).
[  116.455204] PIPELINE layers:
[  116.455210] f9287e20 9ac15d93 RTAI 200
[  116.455214] c085cb20 0 Linux 100
[  116.483192] RTAI[malloc]: global heap size = 2097152 bytes, <BSD>.
[  116.483848] RTAI[sched]: IMMEDIATE, MP, USER/KERNEL SPACE: <with RTAI OWN KTASKs>, kstacks pool size = 524288 bytes.
[  116.483860] RTAI[sched]: hard timer type/freq = APIC/12468680(Hz); default timing: periodic; linear timed lists.
[  116.483867] RTAI[sched]: Linux timer freq = 250 (Hz), TimeBase freq = 2992575000 hz.
[  116.483872] RTAI[sched]: timer setup = 999 ns, resched latency = 2943 ns.
[  116.484166] RTAI[usi]: enabled.
[  116.581806] RTAI[math]: loaded.
[  116.676945] config string '0x378 out  '
[  117.138028] RTAI[math]: unloaded.
[  117.195230] SCHED releases registered named ALIEN RTGLBH
[  117.224420] RTAI[malloc]: unloaded.
[  117.324021] RTAI[sched]: unloaded (forced hard/soft/hard transitions: traps 0, syscalls 0).
[  117.328567] I-pipe: Domain RTAI unregistered.
[  117.328650] RTAI[hal]: unmounted.

Hal file:
# Generated by stepconf at Mon Sep 24 10:57:34 2012
# 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  "
setp parport.0.reset-time 5000
loadrt stepgen step_type=5,5,5

addf parport.0.read base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset 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
net spindle-cmd <= motion.spindle-speed-out

net xstep => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xstep => parport.0.pin-03-out
setp parport.0.pin-03-out-reset 1
net xstep => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
net xstep => parport.0.pin-05-out
setp parport.0.pin-05-out-reset 1
net ystep => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
net ystep => parport.0.pin-07-out
setp parport.0.pin-07-out-reset 1
net ystep => parport.0.pin-08-out
setp parport.0.pin-08-out-reset 1
net ystep => parport.0.pin-09-out
setp parport.0.pin-09-out-reset 1

setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 35000
setp stepgen.0.dirsetup 35000
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 35000
setp stepgen.1.dirsetup 35000
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 35000
setp stepgen.2.dirsetup 35000
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

Please Log in or Create an account to join the conversation.

More
25 Sep 2012 10:27 #24601 by PCW
uln2003.hal:44: parameter or pin 'stepgen.0.stepspace' not found

Is the problem, stepspace only exists in stepgen modes 0, and 1
so you need to delete or comment out all the setp stepgen.X.stepspace 0
statements in your hal file

For more information, take a look at the stepgen manual:

type
man stepgen
in a terminal window

Please Log in or Create an account to join the conversation.

More
25 Sep 2012 11:31 - 25 Sep 2012 11:31 #24604 by BigJohnT
My approach to this kind of problem is to comment out all the offending lines and once the config will run open Machines > Show Hal Configuration and examine what pins are there. If the stepgen is no longer making step space and step length pins you will be able to see this.

A far easier way is to return the first 3 back to type 0 and add one more as type 5 and see what pins are created for this and work from there.

In any case if you have not read the Basic Hal info you should as you will be modifying the hal files for sure.

John
Last edit: 25 Sep 2012 11:31 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
27 Sep 2012 19:50 - 27 Sep 2012 19:58 #24673 by liam2317
Thanks for the help guys but I still can't quite get it working!

I have done a lot of reading and messing around with my .hal file but still have no output.

BigJohnT wrote:

A far easier way is to return the first 3 back to type 0 and add one more as type 5 and see what pins are created for this and work from there.

I have not been able to figure out how to do this unless you mean running something like this in hal command: halcmd loadrt stepgen step_type=0,0,5 ctrl_type=p,p,v
I tried that but it doesn't generate any pins or anything. How else could I do this?

Anyway, my current .hal file loads fine, and when I go 'Machine > Show Hal Configuration' it looks to me like the pins and stepgen are set up properly. I have also tested my set-up by running it off an Arduino and can confirm that the ULN2003s and stepper motors are working properly. I also got some little breakout boards for the ULN chips that include LEDs so you can see when each pin is getting a signal, three pins on axis 0 are constantly lit and one on axis 1 but they do not change when the machine is jogged. Is there anything else other than my .hal file I need to configure?

At the moment I only have axis 0 and 1 connected to ULN2003s and mapped to parallel port pins but I would like to add the third axis in the future. Is it okay to leave it in the hal file as is or could the third axis be what is causing my problems?

Below is my .hal file and attached are some screenshots from my Show Hal Config page.

Any ideas what I'm doing wrong?? Thanks!!!


# Generated by stepconf at Mon Sep 24 10:57:34 2012
# 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  "
setp parport.0.reset-time 5000
loadrt stepgen step_type=5,5,5 ###ctrl_type=v,v,v  
## uncommenting ctrl_type makes no difference

addf parport.0.read base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset 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
net spindle-cmd <= motion.spindle-speed-out

net xpa => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xpb => parport.0.pin-03-out
setp parport.0.pin-03-out-reset 1
net xpc => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
net xpd => parport.0.pin-05-out
setp parport.0.pin-05-out-reset 1
net ypa => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
net ypb => parport.0.pin-07-out
setp parport.0.pin-07-out-reset 1
net ypc => parport.0.pin-08-out
setp parport.0.pin-08-out-reset 1
net ypd => parport.0.pin-09-out
setp parport.0.pin-09-out-reset 1




setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 200
#setp stepgen.0.stepspace 0
#setp stepgen.0.dirhold 35000
#setp stepgen.0.dirsetup 35000
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 xpa <= stepgen.0.phase-A
net xpb <= stepgen.0.phase-B
net xpc <= stepgen.0.phase-C
net xpd <= stepgen.0.phase-D
setp stepgen.0.maxaccel 0.0
#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 200
#setp stepgen.1.stepspace 0
#setp stepgen.1.dirhold 35000
#setp stepgen.1.dirsetup 35000
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 ypa <= stepgen.1.phase-A
net ypb <= stepgen.1.phase-B
net ypc <= stepgen.1.phase-C
net ypd <= stepgen.1.phase-D
setp stepgen.1.maxaccel 0.0
#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 200
#setp stepgen.2.stepspace 0
#setp stepgen.2.dirhold 35000
#setp stepgen.2.dirsetup 35000
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 zpa <= stepgen.2.phase-A
net zpb <= stepgen.2.phase-B
net zpc <= stepgen.2.phase-C
net zpd <= stepgen.2.phase-D
setp stepgen.2.maxaccel 0.0
#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
Attachments:
Last edit: 27 Sep 2012 19:58 by liam2317.

Please Log in or Create an account to join the conversation.

More
27 Sep 2012 22:29 #24675 by BigJohnT
liam2317 wrote:

Thanks for the help guys but I still can't quite get it working!

I have done a lot of reading and messing around with my .hal file but still have no output.

BigJohnT wrote:

A far easier way is to return the first 3 back to type 0 and add one more as type 5 and see what pins are created for this and work from there.

I have not been able to figure out how to do this unless you mean running something like this in hal command: halcmd loadrt stepgen step_type=0,0,5 ctrl_type=p,p,v
I tried that but it doesn't generate any pins or anything. How else could I do this?


Open your hal file and find the loadrt stepgen line and change it to:

loadrt stepgen step_type=0,0,0,5

John

Please Log in or Create an account to join the conversation.

More
28 Sep 2012 04:13 #24679 by liam2317
As far as I can tell doing that does absolutely nothing. Where should I be looking? What do I do after that? Running that hal file doesn't give an error but it doesn't make another axis show up or anything. Looking at it's Show Hal Config page doesn't give me any new info either.

Now I'm really confused.... :S

Please Log in or Create an account to join the conversation.

More
28 Sep 2012 05:14 #24680 by liam2317
Apologies for the double post,

I have made some changes to my .hal file and am now seeing much more positive results however it is still not working.

First I changed:

net xpa => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1

to:

net xpa => parport.0.pin-01-out
setp parport.0.pin-01-out-reset 1

I now have all four of the pins I wanted showing output.

I also changed to stepgen type from 5 to 6 because this generates the same type of signal as my arduino uses which makes comparing the two easier.

The problem, I have realized now is with my parallel port or some setting involving output pin voltage. When a parallel port pin is driven high it is only reading 0.32V (low is about 0.09V) when high should be near 5.0V! Any ideas what the problem could be? Do I just have a bad parallel port? I have measured the voltage by sticking a pin the the parallel port so I know it is not the cable.

Thanks!

Please Log in or Create an account to join the conversation.

More
28 Sep 2012 10:29 #24687 by andypugh
liam2317 wrote:

net xpa => parport.0.pin-01-out
setp parport.0.pin-01-out-reset 1

You absolutely do not want RESET active in this setup.
Reset sets a pin low reset-time after the parport-write thread runs. This is good for step/dir drives as it doubles the available step rate. It is disastrous for direct phase generation like you are attempting.

I also changed to stepgen type from 5 to 6 because this generates the same type of signal as my arduino uses which makes comparing the two easier.

When a parallel port pin is driven high it is only reading 0.32V (low is about 0.09V) when high should be near 5.0V! [/color][/b] Any ideas what the problem could be?


Is this the case even with nothing connected?
What are you measuring with?

Please Log in or Create an account to join the conversation.

Time to create page: 0.172 seconds
Powered by Kunena Forum