Ian W. Wright wrote: > After struggling unsuccessfully for a long time to try to find the > direct relevance between the HAL tutorial and driving my stepper spindle > ( I haven't yet given up on this as I get the impression that it may > give me a bit more speed )
The tutorial is not "the way to solve your problem". The tutorial is intended to introduce you to the concepts of HAL. Then you can select from the available HAL modules to build whatever you need. > I came across a script that Geert had made > a year or so ago. With a little bit of tweaking this is now embedded in > a lathe HAL file and is driving the spindle motor. I must admit that I > can't understand just how this script works as it seems totally > different to the HAL tutorial and this is the reason that I still have a > couple of problems that I can't sort out. The HAL and INI files are here > - www.watchman.dsl.pipex.com/cnc/lathe.hal and > www.watchman.dsl.pipex.com/cnc/lathe.ini . Let's review what you have - I pulled out the stuff that relates to the spindle, and re-ordered it to make it easier to read. This is NOT the right way to do it, but for now I'm simply going to explain what it does - we'll get to the right way later. The data flow here is as follows: >> net spindle-cmd <= motion.spindle-speed-out => scale.1.in 1) from EMC's spindle speed output (which is in RPM) to the input of a scale block - so for example, if you ask for 1000 RPM with "M3S1000", the signal spindle-cmd will be 1000.0 >> setp scale.1.gain 0.15 2) the scale block multiplies the RPM value by 0.15 (I don't know where you got that number from). So when you ask for 1000 RPM, the signal spindle-freq will be 150.0 >> net spindle-freq <= scale.1.out => siggen.0.frequency 3) from the scale block it goes to the frequency input of a siggen. >> setp siggen.0.offset 0.5 >> setp siggen.0.amplitude 0.5 4) the siggen parameters are set so that its output swings +/-0.5 units around a centerpoint of 0.5 units. That means that the range is from 0.0 to 1.0. The square wave output of the siggen will switch from 0.0 to 1.0 and back at 150 cycles per second when you ask for 1000 RPM. >> net spindle-f12int <= siggen.0.square => conv-float-u32.0.in 5) from the square output of the siggen you go through a converter to convert the 0.0 to 1.0 swing into an integer range of 0 to 1. >> net spindle-int2bit <= conv-float-u32.0.out => conv-u32-bit.0.in >> net spindle-out <= conv-u32-bit.0.out 6) the integer goes through another conversion from integer 0 or 1 to a bit (true/false). >> net spindle-out => parport.0.pin-09-out 7) the resulting bit goes to pin 9 of the parallel port The end result is that when you ask for 1000 RPM, you will get 150 pulses per seoond on pin 9 of the parallel port. Because you are using siggen instead of stepgen, the maximum frequency is very limited - about 500 steps per second with the default servo period. Base period doesn't come into the calculation at all, since the siggen is running on the servo period. > The only way I found to get any speed out of the stepper with this > script was to tweak the BASE_PERIOD and SERVO_PERIOD in the ini file > until the computer began to complain - I think they may still need a > little adjustment as I occasionally still get a 'real time task delay' > error. Having done this, I can get the stepper to run up to 300 R.P.M - > not as fast as I would have liked but still fast enough for most of the > things I want to use it for at the moment. However, to get it to run at > this speed via G-code I need to tell it to M03 S60000 ! S60000 means you are asking for 60000 RPM, and the value of the signal "spindle-cmd" is 60000.0 (you should confirm this with halmeter or "halcmd show sig"). After the scale block with its gain of 0.l5, the signal "spindle-freq" is 9000.0. Your base period is 19950, which means 19.95 microseconds. Your servo period is a 65000 (65 microseconds), however that will be rounded to an integer multiple of the base period. I think it rounds up, so the servo period will become 19950 times 4, or 79.8 microseconds. This is actually quite astonishing - I doubt anyone has ever run EMC's motion control code (part of the servo thread) quite that fast. The normal servo rate is 1millisecond (1000 microseconds). In any case, with a 79.8 microsecond servo thread, the siggen will manage to produce the 9000Hz square wave you are asking it for. That gives you 9000 steps per second. You have a 200 step/rev stepper, with 1/8 step microstepping. That is 1600 steps per revolution. At 9000 steps per second, you will get 9000/1600 = 5.625 revs/second, or 337.5 RPM. > Try as I might I > can't see where I should apply a scaling factor to bring this down to a > realistic figure. Oh, and the link to John's description of how EMC2 > works 'under the bonnet' seems to be broken from the linuxcnc page. You don't want to be doing this with siggen. > If anyone can offer any advice to get me a bit further on with this I > would be most grateful. > > I now need to try to learn about classic ladder to find a way to set or > alter the spindle direction......... > You don't need classicladder to change the direction of rotation. I was hoping to avoid having to write out and explain every single line, but here goes: In your .hal file: change the line that reads >> loadrt stepgen step_type=0,0,0 to >> loadrt stepgen step_type=0,0,0,0 ctrl_type=p,p,p,v That will change from three stepgens, all position mode, to four, with the first three using position mode and the last one using velocity mode. Remove the lines that read >> # spindle speed pwm >> loadrt pwmgen output_type=0 I have no idea how you got a pwm generator in there - perhaps the sample you started with used it for an analog spindle drive? Remove the lines that read >> # generate spindle pwm >> addf pwmgen.make-pulses base-thread and >> addf pwmgen.update servo-thread more PWM related stuff that you don't need Remove all this stuff: >> # The spindle goes forward only >> loadrt siggen >> #loadrt scale >> loadrt conv_float_u32 >> loadrt conv_u32_bit >> >> addf conv-float-u32.0 servo-thread >> addf conv-u32-bit.0 servo-thread >> >> setp scale.1.in 0.0 >> setp scale.1.gain 0.15 >> setp scale.1.offset 0.0 >> addf scale.1 servo-thread >> setp siggen.0.offset 0.5 >> setp siggen.0.amplitude 0.5 >> addf siggen.0.update servo-thread >> >> net spindle-cmd <= motion.spindle-speed-out => scale.1.in >> net spindle-freq <= scale.1.out => siggen.0.frequency >> net spindle-f12int <= siggen.0.square => conv-float-u32.0.in >> net spindle-int2bit <= conv-float-u32.0.out => conv-u32-bit.0.in >> net spindle-out <= conv-u32-bit.0.out and replace it with: >> # convert RPM to revs/second >> net spindle-cmd-rpm <= motion.spindle-speed-out => scale.1.in >> addf scale.1 servo-thread >> setp scale.1.gain 0.01666667 >> # send revs/sec command to step generator >> net spindle-cmd-rps <= scale.1.out => stepgen.3.velocity-cmd >> # set stepgen scaling so 1 unit = 1 revolution = 1600 steps >> setp stepgen.3.position-scale 1600 >> # set maximum spindle speed in revs/sec, >> # example: 900 RPM = 15 revs/sec >> setp stepgen.3.maxvel 15 >> # set spindle accel rate, in revs/sec per second >> # example: from 0 to 900 RPM in 5 seconds = 0 to 15 revs/sec >> # in 5 seconds = 3 revs/sec per second >> setp stepgen.3.maxaccel 3 >> # connect step output to parport pin 9 >> net spindle-step <= stepgen.3.step => parport.0.pin-09-out >> # connect direction output to parport pin 8 (or whatever you need) >> net spindle-dir <= stepgen.3.dir => parport.0.pin-08-out Replace >> newsig spindle_on bit >> linksp spindle_on <= motion.spindle-on with >> net spindle_on <= motion.spindle-on => stepgen.3.enable And finally, remove: >> net spindle-out => parport.0.pin-09-out In your .ini file, you can probably leave BASE_PERIOD at 19950, but you need to change SERVO_PERIOD to something a bit more sane. I'd recommend the usual 1mS, "SERVO_PERIOD = 1000000". The actual max speed will depend on your base period, as well as your motors and drives. The 19950 base period will allow a bit over the 900RPM that I used as the example. (I'm not going to spell out that math, this email is too long already.) There is something called doublestep that you could use to get more speed, but again, this mail is too long to go into that. One step at a time. I can't guarantee that this is exactly right - I am away from home and typing this on a Windows computer, so I can't test it. There might be typos, or I might be forgetting something. But it should be very close - using the manual, halcmd, halmeter, etc, you should be able to get it working. Good luck, John Kasunich ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Emc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-users
