Motor Stepper Example


Results 1 to 40 of 135

Threaded View

  1. #11
    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.

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