Motor Stepper Example


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1
    mslaney's Avatar
    mslaney Guest


    Did you find this post helpful? Yes | No

    Default

    Hey Mister E!!!
    Thanks for the tips on the chips!

  2. #2
    mslaney's Avatar
    mslaney Guest


    Did you find this post helpful? Yes | No

    Default

    And you too Luciano. The drivers look like the right thing. I may continue hacking printer motors for my project.

    I truly hate the L297/298 arrangement!

  3. #3
    mslaney's Avatar
    mslaney Guest


    Did you find this post helpful? Yes | No

    Default

    How do I cycle through an array in reverse order?

    Ok, I ditched the bi-polar and I'm using a pic and mosfets to drive a uni motor. No translator.
    I can spin the motor both ways with the following code but there has to be a more elegant way....I'm thinking I could cut the code in half.

    Here's a clip of the program:

    'Array vars
    stepccw VAR BYTE(4) 'coils
    stepcw var byte(4)
    'Load Arrays
    stepcw[0] = %10100000
    stepcw[1] = %01100000
    stepcw[2] = %01010000
    stepcw[3] = %10010000

    stepccw[0] = %10010000
    stepccw[1] = %01010000
    stepccw[2] = %01100000
    stepccw[3] = %10100000

    CW:
    steps = 0
    for delaytime = 1 to 27
    steps = steps + 1
    portb = stepccw[steps //4]
    pause 10
    next

    pause 1000
    steps = 0
    CCW:
    for delaytime = 27 to 1 step -1
    steps = steps + 1
    portb = stepcw[steps //4]
    pause 10
    next

    pause 1000
    goto cw

  4. #4
    hansknec's Avatar
    hansknec Guest


    Did you find this post helpful? Yes | No

    Default Master Code for a serial network of steppers

    It looks like this code could be valuable to quite a few users, so here you go. I originally developed this system about 15 years ago using basic stamps, but over the years it has had modifications as the hardware has changed and moved on to PICS. I work at a National Laboratory and wanted to save the Govt some money, so instead of buying commercial stepper systems I developed my own. The system began as a single stepper that needed to be moved remotely via RS-232. It eventually grew to a requirement to drive about 10 separate (UNIPOLAR) motors on a laser table to operate attenuators and X-Y linear stages. The theory behind the system is each stepper has its own PIC. All PICS are sitting on a single RS-232 bus in parallel. Each PIC "listens" for its name to be called and reponds only when called. This avoids any chance of a communication collision. The code will work for any number of PICS placed on the single RS-232 bus until you have loaded down the impedance of the bus so far that you cannot sustain communications. I have never needed more than 10 steppers on a single bus, but if you work out the math you could calculate the maximum. This code doesn't use the USART pin, so I have a 20K resistor on each PIC for the SerIn pin.
    Hardware: Each stepper motor is on an apparatus that has a limit switch for the "home" position. If a power failure occurs or if requested to reset via the RS-232, it will drive the stage home and reset its counter to zero position.
    I have found that the system is so reliable that I do not need to have additional encoders to sense the position. If you ensure that your motor is not overloaded and drive it with the proper current, it will never slip poles and the software count of current position will be quite accurate.

    Software: The code follows. This same software is loaded into each PIC on the system, but the name and travel limit settings are changed for each . I have another version of the code that allows one to input a new name and travel limit via the RS-232 into NVRAM, but I felt it was overly complicated for sharing.

    Command protocol: A terminal program (terraterm or equivalent) would send the name of the stepper followed by a space and then the new postion command or a special control code.
    Example 1. Send the stepper to reset position:
    ATTENB 65535<CR>

    Example 2. Move the stepper to position 415:
    ATTENB 415<CR>

    Example 3. Ask the stepper its current position:
    ATTENB 65534<CR>
    The PIC would then respond with "AttenB @ 415"

    Heres the PIC code:
    Code:
    '****************************************************************
    '*  Name    : StepNetwork.pbp        Target=PIC16F84 OR F628    *
    '*  Author  : John C. Hansknecht                                *
    '*  Notice  : Copyright (c) 2004                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/14/04                                          *
    '*  Version : 1.0                                               *
    '*  Notes   :  
    '  Universal code for all stepper controllers in a serial network.
    '  Only the name and travel limit
    '  are changed for the specific device.
    '****************************************************************
    '_______ Declarations _____________________________________________________
    PAUSE 500
    include "modedefs.bas"
    '@ device INTRC_OSC_NOCLKOUT   'default to internal oscillator
    '@ device WDT_ON               'watchdog timer on
    '@ device PWRT_ON              'power on timer on
    '@ device MCLR_OFF             ' master clear option off
    '@ device BOD_OFF              ' brown out detect
    '@ device LVP_OFF              '  low voltage programming off
    '@ device PROTECT_OFF          ' program code protect off
    Steps    var word
    I        var word
    newval   var word
    oldval   var word
    resetbit var byte
    b0       var byte 
    pins     var portb
    endstop var portb.4
    define osc 4
    '_______ Initializations __________________________________________________
    TRISB = %10110000 
    pins = 0             ' Initialize output all output transistor OFF.
    oldval = 0
    input portb.5  'make serout a high impedence so all others can talk
    '________Main program______________________________________________________
    pause 500
    reset:  resetbit = 0
            if endstop = 0 then  del1   'take motor CCW to limit switch on pwrup.
    	    oldval = 0
    
    Cmd:resetbit = 1
        serin 7,N2400,["ATTENB"],#newval      ' Get orders from terminal.
    	if newval = 65534 then report         'just report current position
    	if newval = 65535 then reset          'send motor to limit switch
    	if newval > 600 then Cmd              ' My own software motion limit
    	if newval < oldval then delstep
    	if newval = oldval then Cmd
    	' else we will drop into addstep (inferred goto)
    addstep: 
        steps = newval - oldval
        for I = 1 to Steps      ' Number of steps.
    	for b0 = 0 to 7         'full step mode used here.  
    	LOOKUP b0,[9,1,3,2,6,4,12,8],PINS         'forward drive sequence
    	pause 1
    	next b0
       	NEXT I
    	oldval = newval         'make oldval reflect the current position.
     	goto Cmd
    	
    delstep:     
            steps = oldval - newval 
            FOR I = 1 TO steps
    del1:   for b0 = 0 to 7              'enters sub here if resetting motor
    	    LOOKUP b0,[12,4,6,2,3,1,9,8],PINS
        	pause 1
    	    next b0	
    	    if resetbit = 0 then reset   'exit this sub if resetting motor
      	    NEXT I
    	    oldval = newval
            goto Cmd
    
    report: serout 5, N2400, ["ATTENB @  ",#oldval,13]    
    	    input portb.5		'make serout pin an input so others can talk
            goto Cmd        
    
    '___ End of program ________________________________________________________
    Hope you find it useful. You should realize of course that this serial network is not limited to stepper motors. I also have the ability to remotely send values to DAC's, position Servos, Control and readback digital I/O and remotely read ADC's and via the same network using very similar code that has been modified for the application. I call the system PSUB. (polarized source universal bus)
    John

  5. #5
    Join Date
    Feb 2013
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    hey!!! im using a simple bipolar stepper motor with L297 and L298N and want a degree resolution of 1 degree, both in CCW and CW directions. but im clueless about the coding.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    The resolution depends on the motor and the type of stepping sequence you do.
    Most step-motors from have 200 "natural" steps per revolution - or a step angle of 1.8° per step.
    The L297 can do either full- or half-step depending on the state of pin 9. So if your motor has a step angle of 1.8° you get either that or 0.9°
    If you need better than that you need to change the motor to one with a more steps/rev (motors with 400 steps/rev are available but not very common) or change the driver to one capable of microstepping.

    The L297 is pretty easy to drive. You set the CW/CCW pin high or low depending on which direction you want the motor to move and then give it a pulse on CLOCK pin for each step. Want to move one rev, send a total of 400 pulses (if you're halfstepping with a 1.8°/step motor).

    /Henrik.

  7. #7
    Join Date
    Feb 2013
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    ok!!so the stepper i intend to use is
    http://www.geeetech.com/wiki/index.p...rd_for_Arduino
    so basically to get a resolution if 1 degree i need to use 0.9 is it? and half and full steps isnt an issue?

    would you be able to provide me with the required coding? as im VERY new to C language as well!!!! and thanku soo much for ur reply

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Hi,
    First off all, that motor is an unipolar motor with a single common connection for both windings, it can not be driven by a L298.
    The documentation for that motor isn't really that great. It looks like there's a gearbox on the motor but I can't figure out if the stated step angle of 5.625° includes the gearbox, if there is one. If 5.625° includes the gearbox then you won't be able to get 1° resolution. Fullstep would give you 5.625°, halfstep 2.8125°.

    Finally this is a forum for PBP, most of us don't do C so if you're looking for that you're in the wrong place basically.

Members who have read this thread : 5

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts