here is an addition code which controllig the enable and sleep modes on the Big Easy Driver.
Now everything is safe when the motor is not working.
Now i need to play with the code for making some linear accelerations. Any help of how can i start that?
Code:
'****************************************************************************************
'* Name : STEPPER MOTOR.BAS *
'* Author : [Leonardo Bilalis] GOT a HELP FROM HENRIK, Acetronics and Ioannis *
'* 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
'********************************* PIC16F628A *******************************************
' ______________________________ *
' / _____________________________/| *
' | PIN 1 : RA2/AN2/VREF | | *
' | PIN 2 : RA3/AN3/CMP1 | | *
' | PIN 3 : RA4/TOCKI/CMP2 | | *
' 9 8 7 6 5 4 3 2 1 | PIN 4 : RA5/MCLR/VPP | | *
' ------------------------------------ | PIN 5 : VSS | | *
' | R R R R V R R R R *| | PIN 6 : RB0/INT | | *
' | B B B B S A A A A | | PIN 7 : RB1/RX/DT | | *
' | 3 2 1 0 S 5 4 3 2 | | PIN 8 : RB2/TX/CK | | *
' | | | PIN 9 : RB3/CCP1 | | *
' | PIC16F628A | |______________________________|/ *
' | | /_____________________________ /| *
' | R R R R V R R R R | | PIN 10 : RB4/PGM | | *
' | B B B B D A A A A | | PIN 11 : RB5 | | *
' | 4 5 6 7 D 7 6 0 1 | | PIN 12 : RB6/T10SO/T1CKI/PGC| | *
' ------------------------------------ | PIN 13 : RB7/T1OSI/PGC | | *
' 10 11 12 13 14 15 16 17 18 | PIN 14 : VDD | | *
' | PIN 15 : RA6/OSC2/CLOCKOUT | | *
' | PIN 16 : RA7/OSC1/CLOCKIN | | *
' | PIN 17 : RA0/AN0 | | *
' | PIN 18 : RA1/AN1 | | *
' |______________________________|/ *
'****************************************************************************************
@ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON
define osc 4
Include "MODEDEFS.BAS"
StepM var WORD ; distance to move
delay var word ; time in ms between each step pulse
i var word
j var word
cmcon = 7
PORTB = 0
PORTA = 0
TRISB = %11100011 ;we are setting the ports to inputs or outputs
TRISA = %00100001 ;we are setting the ports to inputs or outputs
led var porta.1 ; I just put a power led for the PIC16f628 at PORTA.1
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
MS1 VAR PORTA.2 ;big easy driver microstep control
MS2 VAR PORTA.3 ;big easy driver microstep control
MS3 VAR PORTA.4 ;big easy driver microstep control
ENABLE_BED VAR PORTA.6 ;use this in order to cut current to the stepper motor, it is very important when motor is not doing anything
SLEEP_THE_BED VAR PORTB.4 ;WE DO MAKE THE BED GO LOW POWER MODE
CW con 1 ;HERE WE GIVE A CONSTANT DIRECTION
CCW con 0 ;HERE WE GIVE A CONSTANT DIRECTION
ACTIVATED con 0 ;THIS IS AN ACTIVATION SIGNAL FROM PORTA.6 TO ENABLE PIN ON BED (IS RELATED TO ENABLE_BED VAR PORTA.6)
DEACTIVATED con 1 ;THIS IS A DEACTIVATION SIGNAL FROM PORTA.6 TO ENABLE PIN ON BED (IS RELATED TO ENABLE_BED VAR PORTA.6)
SLEEP_BED CON 0 ;BIG EASY DRIVER IS GOING TO SLEEP
WAKEUP CON 1 ;BIG EASY DRIVER IS AWAKE
for j = 0 to 2 ; this is just a loop for flashing the LED
pauseus 100
low led ; power led for the pic in porta.1
pause 500
high led
pause 1
next
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 100 ; THEN WE GIVE 1 SECOND DELAY
HIGH MS1 ; MS1, as from the datasheet when all are high 16 microsteps can be applied
HIGH MS2 ; MS2, as from the datasheet when all are high 16 microsteps can be applied
HIGH MS3 ; MS3, as from the datasheet when all are high 16 microsteps can be applied
PAUSE 100
IF BUT = 1 THEN ;there is a button at PORTB.1, so if we do not push it
pause 100
ENABLE_BED = DEActivated ; the enable port on the big easy driver will remain high.
;as from the datasheed of the BED when high the output to the motor is dissabled.
SLEEP_THE_BED = SLEEP_BED
ENDIF
if but = 0 then ; WE HAVE CONNECTED A PUSH BUTTON AT PORTB.2
PAUSE 100
for j = 0 to 15 ;loop
ENABLE_BED = Activated ; will activate the PORTA.6 on the pic16f628A which is connected to enable pin on the Big Easy Driver
SLEEP_THE_BED = WAKEUP
pause 500 ; every step takes 500us
stepM = 1 ; the number of the motor steps
DELAY = 500 ; 500us between each step
direction = CW ; THE DIRECTION IS COUNTERWISE
gosub Rotation ; check ROTATION routin
next j
PAUSE 200
for j = 0 to 199 ;loop of 200
pause 1
stepM = 1 ; the number of the motor steps
DELAY = 300 ; 300us between each step
direction = CCW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
PAUSE 5
next j
pause 200
for j = 0 to 199 ;loop of 200
pause 1
stepM = 1 ; the number of the motor steps
DELAY = 300 ; 300us between each step
direction = CW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
PAUSE 5
next j
pause 200
stepM = 800 ; the number of the motor steps
DELAY = 100 ; 100us between each step
direction = CCW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
PAUSE 2000
stepM = 800 ; the number of the motor steps
DELAY = 100 ; 100us between each step
direction = CW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
PAUSE 200
for j = 0 to 1599
pause 1
stepM = 1 ; the number of the motor steps
DELAY = 5000 ; 100us between each step
direction = CCW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
next j
PAUSE 2000
stepM = 1600 ; the number of the motor steps
DELAY = 50 ; 500us between each step
direction = CW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
PAUSE 2000
stepM = 3200 ; the number of the motor steps
DELAY = 50 ; 100us between each step
direction = CW ; THE DIRECTION IS COUNTERWISE
gosub Rotation
PAUSE 200
for j = 1 to 15
pause 1
stepm = 1
delay = 300
direction = Ccw
gosub rotation
next j
pause 200
ENDIF
goto BEGIN
;THE FOLLOWING CODE SUPPOSE TO ROTATE THE SHAFT 1 STEP AT A TIME
ROTATION:
for i = 0 to (stepM - 1)
;@ BSF PORTB,2
;@ BCF PORTB,2
gosub StepIt
pauseUS delay
next
return
;ROTATION2:
;for i = 0 to stepM
;@ BSF PORTB,2
;@ BCF PORTB,2
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.
Bookmarks