New Stepper Driver Object - A Variant Of PulseTheStepPin
idbruce
Posts: 6,197
Here ya go
{{ StepperDriver Version ?.? Copyright 2015. Bruce Drummond. Release Date: 01/24/2015 Usage: X.Initialize(17, 18, 19, 0, 1, CLKFREQ / 1000000, CLKFREQ / 20000, CLKFREQ / 1600, CLKFREQ / 3200000, 2000) X.EnableStage X.IncreaseStagePosition(25) X.IncreaseStagePosition(50) X.IncreaseStagePosition(75) X.IncreaseStagePosition(100) X.DecreaseStagePosition(250) X.DisableStage or the equivalent X.Initialize(X_DIRECTION, X_STEP, X_ENABLE_DISABLE, CW, CCW, CLKFREQ / 1000000, CLKFREQ / 20000, CLKFREQ / 1600, CLKFREQ / 3200000, 2000) X.EnableStage X.MoveStagePosition(0, 25) X.MoveStagePosition(0, 50) X.MoveStagePosition(0, 75) X.MoveStagePosition(0, 100) X.MoveStagePosition(1, 250) X.DisableStage }} VAR BYTE bDirectionPin BYTE bStepPin BYTE bEnableDisablePin BYTE bIncreaseDirection BYTE bDecreaseDirection LONG lHighPulseWidth LONG lMaxExeMotorSpeed LONG lStartStopSpeed LONG lRampIncDec LONG lStepsPerRev LONG lRampingSteps LONG lTotalRampingSteps PUB Initialize(DirectionPin, StepPin, EnableDisablePin, IncreaseDirection, DecreaseDirection, HighPulseWidth, MaxExeMotorSpeed, StartStopSpeed, RampIncDec, StepsPerRev) {{ Method Description: This method initializes global variables and sets pin parameters which will be used by a stepper drive unit. Parameters: DirectionPin = This parameter is the I/O pin number going from the Propeller chip to the stepper drive unit. This pin is an output, which sets the OUTA register utilized by the bDirectionPin. This setting will control the direction of rotation for most stepper drives and it should be a value of 0 (LOW) or 1 (HIGH). StepPin = This parameter is the I/O pin number going from the Propeller chip to the stepper drive unit. This pin is an output, which sends pulses to the stepper drive unit, which it turn passes it on to the stepper motor, telling it when to make a step. EnableDisablePin = This parameter is the I/O pin number going from the Propeller chip to the stepper drive unit. This pin is an output, which sets the OUTA register utilized by the bEnableDisablePin. This setting will control the enabling and disabling of the stepper motor and it should be a value of 0 (LOW) or 1 (HIGH). IncreaseDirection = This parameter simply sets the direction of rotation for the stepper motor as clockwise or counter-clockwise, whichever increases the stage position. This value should be the opposite of the following DecreaseDirection parameter and it should be a value of 0 (LOW) or 1 (HIGH), because it will be used to set the OUTA register utilized by the bDirectionPin. DecreaseDirection = This parameter simply sets the direction of rotation for the stepper motor as clockwise or counter-clockwise, whichever decreases the stage position. This value should be the opposite of the proceeding IncreaseDirection parameter and it should be a value of 0 (LOW) or 1 (HIGH), because it will be used to set the OUTA register utilized by the bDirectionPin. HighPulseWidth = This parameter establishes the pulse width of the OUTA register utilized by the bStepPin, as per manufacturers specifications of a stepper drive unit. MaxExeMotorSpeed = The primary purpose of this parameter is to set the maximum execution speed of the iterations utilized within the MoveStagePosition method, therefore this parameter also directly affects the maximum speed of the stepper motor. StartStopSpeed = This parameter is a time delay between high and low pulses going out of the bStepPin. During the motor rotation, time will be added to and subtracted from the global variable lStartStopSpeed. RampIncDec = This parameter is the ramp incrementor/decrementor, and it will affect just how fast the motor ramps up to top speed and ramps down until the motor stops. Basically this is a setting of 1 - 25, at least for Gecko G251 stepper drives. StepsPerRev = This parameter establishes the number of steps per revolution for the stepper motor, regardless of full steps, half steps, or microsteps Example Usage: X.Initialize(17, 18, 19, 0, 1, CLKFREQ / 1000000, CLKFREQ / 20000, CLKFREQ / 1600, CLKFREQ / 3200000, 2000) Expected Results: When using a Gecko G251 stepper drive with an Applied Motion HT23-400 motor, the proceeding parameters will really make that motor ZING. However, please keep in mind that all of the timing related parameters are pretty much at a maximum level. Please expect every motor and driver to have different timing. Start out with slow speeds and work your way up. *After writing this, I began experimenting with a NEMA 17 with the following initialization and that motor was really zinging. Which just goes to show me that some of my theories are wrong about the maximum values stated above. All I can say is that you will have to experiment. X.Initialize(X_AXIS_DIRECTION, X_AXIS_STEP, X_AXIS_DISABLE, 1, 0, 80, 2500, 20000, 200, 2000) Additional Notes: Besides the mandatory settings as determined by your requirements or specified by manufacturer datasheets, the main parameters for affecting motor operation are MaxExeMotorSpeed, StartStopSpeed, and the RampIncDec. By altering the values of these three parameters, a wide variety of ramping and operating profiles can be achieved. }} bDirectionPin := DirectionPin bStepPin := StepPin bEnableDisablePin := EnableDisablePin bIncreaseDirection := IncreaseDirection bDecreaseDirection := DecreaseDirection lHighPulseWidth := HighPulseWidth lMaxExeMotorSpeed := MaxExeMotorSpeed lStartStopSpeed := StartStopSpeed lRampIncDec := RampIncDec lStepsPerRev := StepsPerRev lRampingSteps := (lStartStopSpeed - lMaxExeMotorSpeed) / lRampIncDec lTotalRampingSteps := lRampingSteps * 2 'Set the directions of the direction, step, and disable pins 'for the stepper driver as outputs. DIRA[bStepPin] := 1 DIRA[bDirectionPin] := 1 DIRA[bEnableDisablePin] := 1 PUB EnableStage {{ Method Description: This method enables a stepper drive unit. Example Usage: X.EnableStage }} 'Enable the motor. Depending on the stepper driver utilized, the following value 'may need to be 0 OUTA[bEnableDisablePin] := 1 PUB DisableStage {{ Method Description: This method disables a stepper drive unit. Example Usage: X.DisableStage }} 'Disable the motor. Depending on the stepper driver utilized, the following value 'may need to be 1 OUTA[bEnableDisablePin] := 0 PUB IncreaseStagePosition(TotalSteps) {{ Method Description: This method passes the direction of motor rotation and the total number of steps to the MoveStagePosition method. Example Usage: X.IncreaseStagePosition(5000) }} 'Move the stage MoveStagePosition(bIncreaseDirection, TotalSteps) PUB DecreaseStagePosition(TotalSteps) {{ Method Description: This method passes the direction of motor rotation and the total number of steps to the MoveStagePosition method. Example Usage: X.DecreaseStagePosition(5000) }} 'Move the stage MoveStagePosition(bDecreaseDirection, TotalSteps) PUB MoveStagePosition(Direction, TotalSteps) | Counter, RampingSteps, RunningSteps {{ Method Description: This method will ramp up a stepper motor until the maximum speed is obtained and it will maintain that maximum speed for a determined number of steps, at which point it will begin a ramp down of the stepper motor until it comes to a stop. Parameters: Direction = This parameter sets the OUTA register utilized for bDirectionPin. This setting will control the direction of rotation for stepper drives and it should be a value of 0 (LOW) or 1 (HIGH). TotalSteps = This is the total amount of steps or microsteps that you want the motor to rotate, and this should be equivalent to the number of high pulses sent to the stepper driver unit. Local Variables: Counter = This variable is used to hold the value of the System Counter for timing accuracy of the stepper driver. RampingSteps = After computations, this variable will contain the number of pulses required to obtain the highest speed possible with the provided parameters. RunningSteps = Providing TotalSteps is larger than the value of the global variable lTotalRampingSteps, this variable will contain the number of maximum speed steps. However, if TotalSteps is smaller than the value of the global variable lTotalRampingSteps, the value of this variable will become either 1 or 0. Example Usage: This method can be called directly as follows: X.MoveStagePosition(0, 5000) or X.MoveStagePosition(1, 5000) or it can be called through the IncreaseStagePosition and DecreaseStagePosition methods. }} 'If maximum speed can be obtained, determine the actual number of 'ramping and running steps. IF TotalSteps > lTotalRampingSteps 'Copy the global amount of ramping steps RampingSteps := lRampingSteps 'Determine the number of full speed steps. RunningSteps := TotalSteps - lTotalRampingSteps 'Else ramp upto the half-way point and then ramp down. ELSE RampingSteps := TotalSteps / 2 RunningSteps := TotalSteps // 2 'Set the OUTA register to match the desired direction of rotation. OUTA[bDirectionPin] := Direction 'Set up the CTRMODE of Counter A for NCO/PWM single-ended. CTRA[30..26] := %00100 'Set the output pin for Counter A. CTRA[5..0] := bStepPin 'Set the value to be added to PHSA with every clock cycle. FRQA := 1 'Set APIN as an output. DIRA[bStepPin] := 1 'Get the current System Counter value. Counter := CNT 'Ramp up the stepper motor to maximum speed. REPEAT RampingSteps 'Send out a high pulse on the step pin for the desired duration. PHSA := -lHighPulseWidth 'Wait for a specified period of time before sending another 'high pulse to the step pin. WAITCNT(Counter += lStartStopSpeed -= lRampIncDec) 'Maintain maximum speed REPEAT RunningSteps 'Send out a high pulse on the step pin for the desired duration. PHSA := -lHighPulseWidth 'Wait for a specified period of time before sending another 'high pulse to the step pin. WAITCNT(Counter += lStartStopSpeed) 'Ramp down the stepper motor and come to a stop. REPEAT RampingSteps 'Send out a high pulse on the step pin for the desired duration. PHSA := -lHighPulseWidth 'Wait for a specified period of time before sending another 'high pulse to the step pin. WAITCNT(Counter += lStartStopSpeed += lRampIncDec) DAT {{ ┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├─────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Copyright(C) 2015. Bruce Drummond. │ │ │ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and │ │associated documentation files (the "Software"), to deal in the Software without restriction, │ │including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,│ │and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,│ │subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial │ │portions of the Software. │ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT│ │LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ │IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER │ │LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION│ │WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └─────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}
Comments
NEMA 17 Motors: Applied Motion HT17-275
Linear Travel: 12 IN
Belt Pitch: 2 MM
Timing Pulley: 18 Teeth
Stepper Driver Module: Gecko G251X
In conjunction with the previously attached stepper driver object, the following code provided 40 feet of linear travel between the two actuators in approximately 55 seconds. 40 feet of travel could have been accomplished with this driver in much less time than 55 seconds, but then I would not have the smooth operation that I am now seeing.
did I read right? 40 foot of travel?
How big is this printer you want to build?
Curious!
Mike
Mike
They are 12 inch actuators. There are 2 - REPEAT 10 loops in the Main method which call upon forward and reverse travel of each actuator, for a total of 40 feet of linear travel. The bulid area of the printer will be 12" wide X 12" deep X 18" high
I got my 3D printer a couple of years ago. A Rapman 3.1 or something like that. UK company named BitsFromBytes now sold to some big player in the field.
I spend over one year with it, adjusting, printing, testing different materials, heating, cooling, superglue, rafts, no rafts.
Finally I gave up. As soon as your object gets bigger than a pack of cigarettes you are done. It's called warping. The layers are cooling down while being printed and change (slightly) size.
Nice tool for small prototypes. Small brackets. Ornaments to put on somewhere. But production work? I was (and am) quite disappointed. It is a slow process. But you need to stay there or have a superb feeding mechanism. The filament comes in rolls, usually, and is therefore bend. I does not straight out a easy as - say - wire. I ended up feeding from the top having the rolls mounted on the ceiling and pre feed the extruders with some second motors. Still no joy.
And when you need to watch them, all the time, you will be faster by bending and cutting some sheet metal with some pliers or even file that bracket or whatever out of a block of alu.
Overall I spend more than $3000 on that 3d print experiment. Should have saved the money for a laser or a small router.
My current plan is to replace the extruders (2) with some dremel or drill and a flexible drive to use it as a simple CNC. The Rapman came as a kit of rods and acryl pieces. I build it by myself and can reuse a lot of the existing stuff.
And for sure the new contraception will use a propeller to drive it.
So I am following your threads with a lot of attention.
Enjoy!
Mike
Although I have not yet experienced them, there are a lot of problems associated with 3D printing. I do believe that proper filament feeding will be one of the toughest problems to conquer, because wire feeding was one of the biggest problems to resolve on the wire bending CNC, and so far, I do not have what I consider to be a good plan for routing and feeding the filament. Besides that problem, I do believe that warping will be another major source of headaches. Either way, I will cross those bridges when I get to them.
Occassionally I lose sight of my ultimate goals, because I get wrapped up in some process or another, and I am at the point where it could easily happen. The goal of the 3D printer project has always been to build and test my linear actuators, and perhaps build a usable prototype in the process. As it stands now, I am currently pretty darn happy with the actuators that I have constructed, but I am not yet 100% satisfied with their construction and operation. Even though my heart wants to go forward with the 3D printer project, my brain is telling me to take the time out to perfect the belt actuators, because I am currently at a point where it would be a very wise decision to do so, especially since they are on a workbench, all wired up, with the software ready to run and test them. I do not believe there are any major issues, just some small things that I would like to resolve or change. And before I start the real construction of the printer, I should probably finish building the screw driven actuator for the Z axis, so that I may test and perfect that as well. When I am 100% satisfied with the construction and operation of all the actuators, I will then build the printer to test their durability.