Congratulations Leonardo.
Robert
Hi Robert,
thanks a lot, i didnt do much, Henrik Acetronics and Ioannis helped me with the code a lot. Now it is easier to understand some things. But as i dont have much knowledge with programming language i'm moving slow and i know that i make you some times to lough with my stupid questions. Hehehehe. I hope with this small jig and fixtire model i will have some more practice.
At the end i compiled the following code which is working just fine. Please have a look at the code and the video.
I hope the video and the code will help you to understand why i designed and build this jig and fixture modelCode:'************************************************* ************************************ '* 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 '************************************************* ************************************ @ 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 = %11110011 ;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 CW con 0 ;HERE WE GIVE A CONSTANT DIRECTION CCW con 1 ;HERE WE GIVE A CONSTANT DIRECTION 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 = 1 ; 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. ENDIF if but = 0 then ; WE HAVE CONNECTED A PUSH BUTTON AT PORTB.2 PAUSE 100 for j = 0 to 15 ;loop ENABLE_BED = 0 ; will activate the PORTA.6 on the pic16f628A which is connected to enable pin on the Big Easy Driver pause 500 ; every step takes 500us stepM = 1 ; the number of the motor steps DELAY = 500 ; 500us between each step direction = cCW ; 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 = CW ; 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 = cCW ; 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 = CW ; THE DIRECTION IS COUNTERWISE gosub Rotation PAUSE 2000 stepM = 800 ; the number of the motor steps DELAY = 100 ; 100us between each step direction = cCW ; THE DIRECTION IS COUNTERWISE gosub Rotation PAUSE 200 for j = 0 to 1599 pause 1 stepM = 1 ; the number of the motor steps DELAY = 4000 ; 100us between each step direction = CW ; 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 = cCW ; THE DIRECTION IS COUNTERWISE gosub Rotation PAUSE 2000 stepM = 3200 ; the number of the motor steps DELAY = 50 ; 100us between each step direction = CCW ; THE DIRECTION IS COUNTERWISE gosub Rotation PAUSE 200 for j = 1 to 15 pause 1 stepm = 1 delay = 300 direction = cw 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 Henri
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.
On the following code you can make the motor to run fast in the beggining and slow at the end.
I did have high all the MS on the Big Easy driver so lets thing with 3200 microsteps per rev.
So what i'm trying to do is to give form low speed to high from 0 degrees home possition to 45 degrees and then from 45 to end of travel high speed to low.
Then back the same way to home possition.
Is there any other way to make it?
apart from that i would like to design a very small stupid cnc machine that i can give very basic shapes like square and cyrcle.
Then i will write a data base with all the letters and i will try to call them each time i need them from a file or lookup.
I know that i'm going to far now, i really dont know yet the basic of the PICBASIC. hehehhe.
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 a var word q var word w 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 ;WILL DEACTIVATE THE PORTB.4 ON THE PIC16F628A WHICH IS CONNECTED TO SLEEP PIN ON THE BIG EASY DRIVER ENDIF if but = 0 then ; WE HAVE CONNECTED A PUSH BUTTON AT PORTB.2 PAUSE 100 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 ; WILL ACTIVATE THE PORTB.4 ON THE PIC16F628A WHICH IS CONNECTED TO SLEEP PIN ON THE BIG EASY DRIVER pause 500 ; every step takes 500us stepM = 16 ; the number of the motor steps DELAY = 300 ; 500us between each step direction = CW ; THE DIRECTION IS COUNTERWISE gosub Rotation ; check ROTATION routin PAUSE 200 a = 0 for j = 0 to 400 pause 1 stepM = 1 ; the number of the motor steps if a < 1200 THEN ; here we secure the a not to be negative value DELAY = 1200 - a ; we put delay and substract a which in our case is a = a+3 ENDIF a = a+3 ; we give a variable a for controlling the delay direction = CCW ; THE DIRECTION IS COUNTERWISE gosub Rotation next j a=0 for q = 0 to 400 pause 1 stepM = 1 ; the number of the motor steps if a < 1200 then a = a+3 endif DELAY = a ; between each step direction = cCW ; THE DIRECTION IS COUNTERWISE gosub Rotation next q a=0 for j = 0 to 400 pause 1 stepM = 1 ; the number of the motor steps if a < 1200 THEN ; here we secure the a not to be negative value DELAY = 1200 - a ; we put delay and substract a which in our case is a = a+3 ENDIF a = a+3 ; we give a variable a for controlling the delay direction = CW ; THE DIRECTION IS COUNTERWISE gosub Rotation next j a=0 for q = 0 to 400 pause 1 stepM = 1 ; the number of the motor steps if a < 1200 then a = a+3 endif DELAY = a ; between each step direction = CW ; THE DIRECTION IS COUNTERWISE gosub Rotation next q a=0 ENDIF goto BEGIN ;THE FOLLOWING CODE SUPPOSE TO ROTATE THE SHAFT 1 STEP AT A TIME ROTATION: for i = 0 to (stepM - 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
Bookmarks