Motor Stepper Example


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,140


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Pulsout really toggles the output. So if it was at '1' it makes it '0' and then '1' again.

    Thats why Alain made sure port B was reset in the first place.

    Besides the exact timing of the Subroutine version of the program, they should perform the same.

    Many ways to do the same thing.

    Ioannis

  2. #2
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    nice, now i need to collect all my components and start playing with the software.

    It might take a bit longer because i do not have mounting screw terminals for the big easy driver.

    For your reference i have completed the model so everything is ready apart from the electronic connections.
    Attached Images Attached Images     

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Alain,
    Thanks for editing my code. One small note though.
    You changed the delay from 2000 to 2 but I think you missed that I was using PauseUS. If you want 2ms between steps then it should be Delay=2000. Also, using Pulsout takes more program space than manually toggling the pin. But, as have been said, many ways to do the same thing.

    Astanapane,
    One last note, when you get to running the motor, make sure you start running it slow. If the speed of the pulses are two fast the motor won't be able to follow and will stall. No harm done but it might look like something is wrong. If you want to run at high speed you need to provide some acceleration/deceleration ramp instead of simply starting at the desired velocity.

    Keep up the nice work!

    /Henrik.

  4. #4
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Henrik,

    you can call me Leonardo.

    As from the time and the speed then i need to give longer time for a revolution. That will make the motor to run slower.

    Regarding the acceleration and deceleration i would like to do that YES. But i will do simple staff in the beggining.

    Let me get a soldering iron and some small components i need because here in Dubai there is nothing to find.

    I ordered all the components from US but didnt have in mind that i would need something to connect them. (all my electronic staff and my lab is back home in Hellas)

    thanks all of you for your help and time these days.

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    i think i will change the microcontroller to PIC16f628A because i have spare.

    I only have at the moment one PIC16f88 and 3 PIC16F688.

    Code:
    '*************************************************************************************
    '*  Name    : STEPPER MOTOR.BAS                                                      *
    '*  Author  : GOT a HELP FROM HENRIK, Acetronics and Ioannis at (MELABS forum)       * 
    '*  Notice  : Copyright (c) 2013                                                     *
    '*          : All Rights Reserved                                                    *
    '*  Date    : 3/3/2013                                                               *
    '*  Version : 1.0                                                                    *
    '*  Notes   : Stepper Motor                                                          *
    '*          :                                                                        *   
    '*************************************************************************************
    
    	   'we are going to use the PIC16F628A for controling BIG EASY DRIVER
    
    define osc 4
    Include "MODEDEFS.BAS"
    
    
    StepCount var word      ; distance to move
    delay var word     ; time in ms between each step pulse
    i var word
    
    
        but var PORTB.1            ; ASIGN THE PIC16F628A PORTB.1 AS A PUSH BUTTON
        Motor_Step VAR PORTB.2     ; ASIGN THE PIC16F628A PORTB.2 TO STEP PIN ON THE BIG EASY DRIVER
        DIRECTION VAR PORTB.3      ; ASIGN THE PIC16F628A PORT.3 TO DIR PIN ON THE BIG EASY DRIVER
    
    CW    con 0                    ;HERE WE GIVE A CONSTANT DIRECTION
    CCW   con 1                    ;HERE WE GIVE A CONSTANT DIRECTION
    
    ANSEL = 0
    cmcon = 7                      
    PORTB = 0                      ;Reset PORT B (thanks to Acetronics from MELabs
    TRISB = %11110011              ;Make Portb.2 and Portb.3 O/P and rest I/P
    
    BEGIN: 
        LOW Motor_Step ; WE CAN START BY MAKING LOW THE PORTB.2
        LOW DIRECTION ; WE CAN START BY MAKING LOW THE PORTB.3
        PAUSE 1000 ; THEN WE GIVE 1 SECOND DELAY
        
        if but = 0 then            ; WE HAVE CONNECTED A PUSH BUTTON AT PORTB.1
            StepCount = 200        ; the number of the motor steps
            delay = 100            ; 100us between each step
            direction = CW         ; THE DIRECTION IS COUNTERWISE 
            gosub Rotation
        endif
        goto begin
    end
        
        
                                   ;THE FOLLOWING CODE SUPPOSE TO ROTATE THE SHAFT with a pulse of 200
      
    ROTATION:
        for i = 0 to (StepCount - 1) 
            PULSEOUT Motor_Step, 1  ;gosub StepIt
            pauseUs delay
        next
        return
        
    ;StepIt:
    ;    motor_step = 1             ;generate a 10us wide pulse on the step pin
    ;    pauseus 10
    ;    motor_step = 0
        
    ;    RETURN
    
    	                       ;thanks to Henrik at Melabs forum.
    Do i need to add the code marked in RED? I think i need to say some how to the motor_step to be 1 or 0

    I havent compiled the code yet because i'm at work but hopefully tonight i will do the first tests. So i might need your help.
    Last edited by astanapane; - 6th March 2013 at 09:51.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,140


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    The red lines are for the version of the code using subroutine. You can delete them.

    I recommend using the port toggle instead of the Pulsout command though.

    Ioannis

  7. #7
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    thanks Ioanni.

    I'm building up the test board now. Once i go home after work i will try to make the first test with the code.

    lets see.

  8. #8
    Join Date
    Jan 2015
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Motor Stepper Example

    Hi there astanapane!, i just read all threads and i have to congratulate you for your progress in programation, as i am a big fanatic to electrnonics and robotics. I have a request to anybody willing to help, i dont have a stepper driver as LEonardo has (big easy) but i made one with a 16f84a, i programmed it to receive a dir and step pulse from another pic, and to give the combinations to som mosfets and to the coils of the bipolar motor. At first it worked well with some weird movements sometimes, (i guess it wass because of the supply or some electrical noises), but as i have been studying, im interested in programming a pic to work as a microstepper driver. Until now, i know that some pwm are required to make the required signals to operate the coils, but i dont have it very clear.

    Of course, if somebody can help me out with this in picbasic pro i would be very grateful!. So teh basic idea is:

    -Inputs:
    *Full Step
    *Half Step
    *switches to select the microstepping config (4, 8, 16, 32)
    *Step
    *DIR
    *Enable
    -Outputs
    *the pwm signals to the power transistors or the Hbridges to drive the Bi Polar Motor
    *anything else needed
    I think that just one pic would control one motor, because it would be too much to ask for the three motors.
    I guess it is to much to ask, but i want to learn futher about programming in picbasic pro and maybe it can be done .

    And sorry for my bad english, im from Mexico!

    Best Regards and happy holidays.!

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