PIC16F628A STEPPER MOTOR WITH BUTTON (2)

‘PROGRAM NAME:  CONTROLLER WITH BUTTON
‘AUTHOUR: NIGEL (LEDLABS)
‘A PROGRAM TO TURN A STEPPER MOTOR 90 DEGREES AND ‘WAIT FOR 10 SECONDS
‘THEN TURN BACK TO POINT OF ORIGIN WHEN BUTTON ‘PRESSED
‘DATE WRITTEN: 18/6/07
‘LANGUAGE: PIC BASIC COMPILER
‘VERSION: 1A
‘STEPPER MOTOR: 3.6 DEGREES STEP/RESOLUTION
‘PIC MICROCONTROLLER: 16F628A
‘100 milliamps used when motor in use for 4 seconds there and back
‘1 miliamps in its quiescent state

output 4 ‘ unused pins set as outputs
output 5 ‘ to avoid floating inputs
output 7 ‘ and pickup

b5 = 0 ‘working button variable set zero

SYMBOL delay = B0 ‘ use b0 as the delay variable
delay = 75 ‘ set the delay to 75msecs

loop: BUTTON 6,0,255,10,b5,0,notp

for B2 = 1 TO 4 ‘loop counter

HIGH 0 ‘ turn on transistor1
PAUSE delay ‘ wait 75 ms
LOW 0 ‘ turn off transistor1
HIGH 1 ‘ turn on transistor2
PAUSE delay ‘ wait 75 ms
LOW 1 ‘ turn off transistor2
HIGH 2 ‘ turn on transistor3
PAUSE delay ‘ wait 75 ms
LOW 2 ‘ turn off transistor3
HIGH 3 ‘ turn on transistor4
PAUSE delay ‘ wait 75 ms
LOW 3 ‘ turn off transistor4

next B2

pause 10000      ’10 sec delay
‘ pause 30000 ’30sec delay for test purposes, for longer delays than     ’30secs, seperate pause commands can be used on different lines           ‘and the total time adds up.

for b3 = 1 to 4 ‘loop counter

high 3 ‘ turn on Q4
pause delay ‘ wait for delay ms
low 3 ‘ turn off Q4
high 2 ‘ turn on Q3
pause delay ‘ wait for delay ms
low 2 ‘ turn off Q3
high 1 ‘ turn on Q2
pause delay ‘ wait for delay ms
low 1 ‘ turn off Q2
high 0 ‘ turn on Q1
pause delay ‘ wait for delay ms
low 0 ‘ turn off Q1
next b3
pause 1000

notp:
goto loop

end

THIS IS THE SAME AS THE OTHER STEPPER ROUTINE PROGRAM ON HERE, APART FROM IT HAS A BUTTON COMMAND AND TIME DELAY, SO HOW THIS PROGRAM WORKS, IS IT WAITS FOR AN INPUT SIGNAL, THIS COULD BE A BUTTON, SEE THE LOOP ABOVE THIS HAS THE BUTTON COMMAND ‘PART OF PIC BASIC COMPILER INSTRUCTION SET’ BY MICRO ENGINEERING LABS.
AND IT BASICALLY STAYS IN THE LOOP UNTIL IT BREAKS OUT BY A BUTTON BEEN PRESSED ON PIN 6 OF THE PIC MICRO-CONTROLLER, THIS PIN CAN BE CHANGED BY CHANGING THE BUTTON PIN, SAY TO 5 FOR EXAMPLE, THE OTHER INFORMATION IN THIS COMMAND IS SWITCH DEBOUNCE, BUTTON PULL-UP/PULL-DOWN ETC.
THEN THE PROGRAM WAITS BY THE PAUSE COMMAND WHICH CAN BE CHANGED
THEN IT RUNS THE PROGRAM BACKWARDS WHICH TURNS THE STEPPER BACK TO THE POINT OF ORIGIN.
THIS IS HOW THE BUTTON COMMAND CAN BE SET:
BUTTON PIN,DOWN,DELAY,RATE,BVAR,ACTION,LABEL
PIN : IS MADE AN INPUT AUTOMATICALLY
DELAY : CYCLE COUNT BEFORE AUTO REPEAT (0-255) IF 0 NO DEBOUNCE
RATE: AUTO REPEAT RATE (0-255)
BVAR : BYTE SIZE VARIABLE USED FOR DELAY AND MUST BE INITIALISED TO 0 IN DECLARATION OF PROGRAM.
ACTION : STATE OF BUTTON TO ACT 0 IF NOT PRESSED 1 IF PRESSED
LABEL : PROGRAM RESUMES AT THIS LABEL IF ACTION IS TRUE
SEE MICRO ENGINEERING LABS INC ‘PIC BASIC COMPILER’ FOR FULL INSTRUCTION SET
THE BUTTON REQUIRES A PULL DOWN RESISTOR, OR PULL-UP DEPENDING ON BUTTON COMMAND IN THE ACTION VARIABLE. EITHER SET TO 1 OR 0                                                                           THESE PULLUP/PULLDOWN SWITCHES ARE ON LEDLABS ALREADY, AS IS THE STEPPER MOTOR MODULE.
CIRCUIT DIAGRAM TO FOLLOW 08/09/2016

picdiagram
PIC 16F628A STEPPER MOTOR DRIVER PROGRAM USING A PIC MICRO TO CONNECT TO DRIVER MODULE.